|
I actually almost say the contrary is true.
Mark Nischalke's answer holds true, you do have access to both the Moo() and Foo() methods by passing the subclass. However to do so couples the method to the subclass, and other instances of the animal class cannot be passed:
class Program
{
static void MakeAnimalSpeak(Animal animal)
{
animal.MakeNoise();
}
static void MakeAnimalSpeakCoupled(Cow animal)
{
animal.MakeNoise();
}
static void Milk(Cow animal)
{
animal.Milk();
animal.MakeNoise();
}
static void Main(string[] args)
{
Cow cow = new Cow();
Duck duck = new Duck();
MakeAnimalSpeak(cow);
MakeAnimalSpeak(duck);
MakeAnimalSpeakCoupled(cow);
Milk(cow);
}
}
abstract class Animal
{
public abstract void MakeNoise();
}
class Cow : Animal
{
public override void MakeNoise() { Console.WriteLine("Moo"); }
public void Milk() { Console.Write("Sloooosh"); }
}
class Duck : Animal
{
public override void MakeNoise() { Console.WriteLine("Quack"); }
}
Of course it is horses for courses, as with everythign in the code world. In the example Mark gave, you should pass the cow if you need access to both Moo() and Foo() but otherwise IMO is is better to pass an Animal instead. Better yet, coding to Intefraces produces cleaner results still, and helps with testing (as mock objects can be passed more easily)
Cpianism: I have a negative number in my Rep so please fix it.
Chris Maunder: That isn't a bug.
|
|
|
|
|
This is great, I like the humor involved too. I am saving this reply as a PDF on my computer.
Thanks again!
|
|
|
|
|
Hi,
I had a question regarding the Windows Aero Glass Feature, found in Windows API Code Pack. This feature is not included in Windows XP and Vista, I believe. So if the GlassForm is shown in Windows XP, will an error be thrown? or will the GlassForm window be shown, without the aero feature and without anyerror error?
To be more clear: What will happen if the GlassForm is show in Windows XP/Windows Vista?
Thanks,
Harsimran Singh
|
|
|
|
|
WPF also allows aero to be forced on an app, but when you do that, the appropriate DLL is already in the GAC on the user's machine (because they're running the appropriate version of .Net. I suspect that if you include a CodePack assembly in your references, the appropriate DLL will get copied to your bin folder.
Try it and see...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Even if I try that, I can't test it. I don't own a XP or a Vista machine. I only have Windows 7.
For more information, you should check out my article: Windows 7 FTP Application
It only runs on Windows 7, because of the Windows 7-specific features. I can control other windows 7-specific features on Windows XP/Vista using if(CoreHelpers.RunningOnWin7), however, some of my forms use the glass form. which I can't really control using CoreHelpers.RunningOnWin7, because a Form inherits from GlassForm to use the GlassForm feature.
First question would be: What happens if GlassForm is shown in Windows XP? Will an error be thrown? It doesn't matter if the aero feature is not shown, since it is Windows XP/Vista. I only require the glass feature in Windows 7.
I hope I am clear,
Thanks,
Harsimran Singh
|
|
|
|
|
Pathachiever wrote: It only runs on Windows 7, because of the Windows 7-specific features.
If it only runs on Windows 7, then why are you asking about XP? If you don't want it to to run on XP, then do a Windows version check before you display the first form, and terminate the program if it's running on XP.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Sorry. I knew I wasn't clear on my side.
Actually, I want the application to run on Windows XP. However, I don't know what will happen if the application is ran on Windows XP, since Windows XP probably does not support the glass form feature.
I hope I am more clear now. I just need to know what will happen when the Glass Form is shown in Windows XP.
Thanks,
Harsimran Singh
|
|
|
|
|
Then run it on XP (in a VM if necessary) and see what happens. If you're not doing anything to actually skin the forms, it should fall back to whatever the host OS is capable of..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Trying to make an update function for lets say apples
Apple Table contains color and size and ID
lets say i have 10 apples
and i navigate to apple 5, how can i determine what its ID is ?
Basically the bindingnavigator would say 5 of 10 but what if I seeded my identity column starting with 200
obviously simply id = applebindingsource.position +1 will not work...
I thought maybe making a
List<apple>tempapple = null;
tempapple = db.apple.tolist();
currentapple id = tempapple[applebindingsource.position + 1].ID;
but that doesn't appear to work either cause it's out of range
any help on this would be great...
|
|
|
|
|
Doesn't the object contain the ID?
|
|
|
|
|
I am writing an application in C# and want to use the objects I created in C++, but don't want to have to rewrite them in C#. I've read that you can do it using the IJW mechanism, but I don't fully understand it. If I am compiling my C++ class with /clr, what then do I have to do to be able to make an instance of that object in C#.
Thanks
|
|
|
|
|
|
Hi,
I made a sample remoting library and a simple windows application to run and stop the remoting service. When I start for the first time it is starting fine, but when I stop and start it it is giving me following error.
Only one usage of each socket address (protocol/network address/port) is normally permitted Can anybody help me inthis regard.
My code is as below.
private void Run()
{
ArkClass.running = true;
channel = new HttpServerChannel(1111);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ArkClass),
"ArkClass", WellKnownObjectMode.Singleton);
}
private void btnRun_Click(object sender, EventArgs e)
{
try
{
Run();
MessageBox.Show("Server is Running", "Info", MessageBoxButtons.OK,MessageBoxIcon.Information);
btnRun.Enabled = false;
btnShutdown.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show("An error has occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine(ex.Message);
}
}
private void btnShutdown_Click(object sender, EventArgs e)
{
MessageBox.Show("Server is shutting down", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
btnRun.Enabled = true;
btnShutdown.Enabled = false;
ArkClass.running = false;
}
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
sounds to me like .running = false is not stopping the remoting channel, unregistering the port correctly!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
My program watches C:\Incoming using .Net 3.5's FileSystemWatcher with the following paramters:
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Created += new FileSystemEventHandler(fsw_Created);
fsw.Path = @"C:\Incoming";
fsw.IncludeSubdirectories = false;
fsw.EnableRaisingEvents = true;
static void fsw_Created(object sender, FileSystemEventArgs e)
{
while (!FileReady.isFileReady(e.FullPath))
{
Thread.Sleep(2000);
}
}
The C:\Incoming directory is shared for network access. If I manually copy a file to the directory from another machine it sees it fine and processes it. However, if I download a similar (or the same) file from a website in IE and have it save to that mapped drive (shared directory) nothing happens.
Anyone know why FileSystemWatcher doesn't see it and how to resolve the issue?
- Joshua
|
|
|
|
|
I just tried it with your code and it seemed to work fine. I replaced all your logic in fsw_Created with a MessageBox.ShowDialog and it popped up 2 or 3 times when I downloaded and saved a file to the C:\Incoming folder.
Perhaps the logic in FileReady.isFileReady is doing something funky? Maybe it's throwing an exception? One thing to watch out for is that IE downloads the file to a temporary folder first, then copies it over from that temp folder to the destination. That could maybe cause some issues.
|
|
|
|
|
Thank you for testing the code. My question is: Did you save the file downloaded from IE to a mapped drive shared on a second computer and not to a local directory?
|
|
|
|
|
There is no resolution to the problem. The FSW was designed to work with local filesystems, not network ones. Read up on this list[^].
|
|
|
|
|
Dave:
Thank you for your response. From what I gather in the google search you sent me it seems people are trying to tell the FileSystemWatcher server to watch a mapped drive (i.e. creating a mapped drive to a share somewhere else, setting it as M:, and then telling the FSW to watch M:\).
That is not what I'm doing. I have the FSW installed as a service on a server running local to that machine so that it is watching the local C:\Incoming. So I don't think it should matter if I'm copying a file locally or via the network to that shared folder from a third-party machine.
Here is some additional information that may help explain where I am. I can copy a file to that share from my workstation and the FSW will work no problem. But if I download a file on my workstation and tell IE to save it to my I: drive (which is a mapped drive to that share on the server where FSW is) nothing happens.
So, I'm thinking that it has something to do with how IE is writing the file to a share and not triggering a CREATE even for FSW to see? Make sense.
|
|
|
|
|
I misunderstood what you're doing.
Well, this may change things a bit. IE doesn't write the file to the location you tell it to. It writes the content of the file to the Temporary Internet Files folder then either moves the file to the final location or copies it if the file is on a different volume, then deletes the file in the TIF folder.
|
|
|
|
|
I kinda of figured that was the process that IE followed but it doesn't make sense that when it copies the file to the network share it doesn't look just like any other simple copy process so that FSW will see the Created event.
Perhaps this is a bug?
|
|
|
|
|
Does not anyone have an answer?
|
|
|
|
|
Hi,
I have very similar problem.
I'm running FSW as a service and watch for the all events. Folder contains photos and when the new one dropped or changed/renamed/deleted we make some resizing and put results in two other unwatched folders.
The problem raise up when I try to download something from internet and as destination set the watched folder.
We using firefox and if we choose "Save image as" everything works ok, but if we have a link to photo and choose "Save link as" we run into problems.
First, there is issue with file locking. We try to solve it using System.IO.FileStream. If we get error we wait 1000ms and try again... I think you use similar logic in your FileReady.isFileReady. Sometimes file doesn't processed.
Next, sometimes we got firefox error (can't write destination folder). We try to use different options in filestream (readwrite, shared...) but with no success.
I think that solution might be making some type of log which contains file names, and process files later.
The strange thing is when we copy files to watched directory even from a source on a slow link everything works ok. Sync script runs on the same machine running FSW service (we pull files from distant folder and put them into local one watched by FSW)
Main problem is file locking issue and multiple events for the same file (created, deleted, created, multiple changed...) while downloading from internet using firefox (firefox crate destination file with size 0, .part file which is used as temp file while downloading, and finally probably copy .part into destination file when download finished into .part file). It happens regardless the size of file downloaded (needed time for downloading).
I'm interested in your logic you use in FileReady.isFileReady. Could you please give some hint about it?
Thanks
Goran
|
|
|
|
|
Sure, nothing I'm doing is proprietary in my code and in fact some of the code from that class was found online. Here is the code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
namespace WQADEncoder
{
public class FileReady
{
public static bool isFileReady(string File)
{
FileInfo fi = new FileInfo(File);
try
{
FileStream fs = fi.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
fs.Close();
fs.Dispose();
Thread.Sleep(5000);
return true;
}
catch
{
return false;
}
}
}
}
I still haven't found a solution the problem that works with FSW directly. I could see adding a method & timer to check the directory ever x minutes and then scraping files that FSW missed but why should I have to do that? Microsoft, where are you!? FSW has been a pain in but for years now, is used frequently, but yet it still works the same way? Helps us out MS!
|
|
|
|
|
Thanks for your code...
Yes, help us out MS!
Goran
|
|
|
|