|
I need C# code to moderate e-mails.
If anybody has any simple code how to moderate e-mails,
I will appreciate if you will direct me to the site to download it.
Thanks.
A.Kwakye
|
|
|
|
|
What do you mean by "e-mail moderator"? I've never heard of it. I've heard of a moderating forum's posts though...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I assume you mean a spam filter. First your code needs to actually be running the mail server, then a simple reg-ex can be used to remove a lot of stuff.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Moderating emails is rather "vague". If you want a spam filter, there are many good solutions out there. If you want to block certain addresses, regardless of the "spam factor" (ex-girlfriends or so ).. you can have a mail relay tweaked. Postfix for example.
--
michael - www.code.ae
|
|
|
|
|
I need C# code to moderate e-maild.
If anybody has any simple code how to moderate e-mails,
I will appreciate if you will direct me to the site to download it.
Thanks.
A.Kwakye
|
|
|
|
|
Hi, all
I have designed an windows application in C#. I want to embed the plug-in functionality in it (like Winamp software), such that a third party can create a plug-in and can add its functionality to my application. How can I do it? What should I do extra on a simple Windows Application written in C#?
Thank you in advance.
Anindya Chatterjee
|
|
|
|
|
|
I'm confused on how to convert between enum types and integer types effeciently. Here's the code I'm working with:
public enum Rank
{
Hearts = 0, Diamonds = 1, Spades = 3, Clubs = 4
}
public enum Suit
{
Deuce = 0, Trey = 1, Four = 2, Five = 3, Six = 4, Seven = 5, Eight = 6,
Nine = 7, Ten = 8, Jack = 9, Queen = 10, King = 11, Ace = 12
}
Inside the card, the rank and suit are stored as:
Rank rank;
Suit suit;
The point being: I have a function shuffle which shuffles the deck using for loops.
public void Shuffle()
{
FillDeck();
Card tempCard = new Card();
Random rInt = new Random();
for (int i = 0; i < 100; i++)
{
int first = rInt.Next(51);
int second = rInt.Next(51);
// Copy deck[first] to tempCard
// Copy deck[second] to deck[first]
// Copy tempCard to deck[second]
tempCard.Set(deck[first].Rank, deck[first].Suit);
deck[first].Set(deck[second].Rank, deck[second].Suit);
deck[second].Set(tempCard.Rank, tempCard.Suit);
}
}
I'm attemping to pass integer values from the for loops into the Set function of card which takes Rank and Suit parameters. It's obviously causing errors.
Can I simply typecast an integer to the equivalent suit or rank like so without causing problems, and is it proper programming practice or is there a better way to do it?
tempCard.Set( (Rank)deck[first].Rank, (Suit)deck[first].Suit );
|
|
|
|
|
Whew, where to begin. First about the enums. I am assuming your Card class set method is structured as such: Card.Set ( Rank r, Suit s) and you have an array of Cards in deck[]. So to set your first card you would say deck[0].Set ( Rank.Hearts, Suit.Ace ).
Now the first problem is you have Rank and Suit mixed up, the Suit should be hearts, clubs, etc. Confusing to read.
Your second issue is your Card property Rank and Suit have the same name as your enum, that cannot be. I see what you are doing, you want to return that enum to set the next card with it, but you can't have the same name. I would change the name to CardRank and CardSuit and define the property like this:
//member variables
private Rank cardRank;
private Suit cardSuit;
//Properties
public Rank CardRank
{
set
{
cardRank = value;
}
get
{
return cardRank;
}
}
// do the same for CardSuit
now your swap functions will be:
tempCard.Set ( deck[first].CardRank, deck[first].CardSuit );
If you used integers in you Set function prototype then this won't work and you have to modify your properties to convert to integer or from integer depending on what your members are.
Your third issue is your last card will never get shuffled, Random returns a number less than the number passed in and your first and second could theoretcially be the same card (not a real problem, just wasted a shuffle)
If you want the integer value of an enum do this:
int x = (int) Rank.Clubs; //now x = 4
or
Rank r = Rank.Clubs;
int x = (int) r; //x = 4
finally if you want the string value:
string s = Rank.Clubs.ToString(); // s = "Clubs"
|
|
|
|
|
Awesome. Thanks for those pointers. That will certainly help me get sorted out.
There is one issue, the big one, that you didn't mention however (I don't think).
I have two integers from the four loops, s and r. s is between 0 and 3 and r is between 0 and 12. They correspond directly to the integer values I assigned the suits and ranks in the enum.
From those integers, I need to store the suit and rank, in the for loops.
So - I need to do something like:
Rank rank = (Rank)r; // r is in integer. if r == 12, then this should set rank equal to Rank.Ace, however, you can't typecast an integer to the equavalent enum value. I don't need the string. You see what I'm saying?
|
|
|
|
|
I just wrote my own static functions to do this, and added them to the card class:
public static Rank ConvertToRank(int i);
public static Suit ConvertToSuit(int i);
... just filled with switch statements to return the appropriote enum object.
I was hoping there was a better way to do this though.
|
|
|
|
|
In vb you can do
Dim r as Integer '<- Random rank
'Make r as random number
CardRank = CType(r, Rank)
I think in think in c# that would be
int r;
CardRank = (Rank)r;
But you say that doesn't work
Pretty weird...
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
-- modified at 18:30 Thursday 27th October, 2005
|
|
|
|
|
In C# use the Enum static method ToObject
Suit myCard = (Suit) Enum.ToObject ( typeof ( Suit ), 12 );
This will set myCard to an ace (substitute the 12 for your integer you want the enum to be).
Hope that helps
|
|
|
|
|
Hello,
In the old C style, I could create a window whenever I desired.
Is there a wrapped way of creating windowses an child windowses in C# (not Forms or Controls), or I have to make lots of pInvokes?
I hope you understand...because is a rough world out there...
|
|
|
|
|
Do u mean that u want to launch another process?
<< >>
|
|
|
|
|
No.
A Window is a basic element for rendering graphics to it, it has it's own messsage queue.
Every Control in .Net is based on something like that.
Afther some researching I think I found a minimalist wrapper in System.Windows.Forms.NativeWindow
I hope you understand...because is a rough world out there...
|
|
|
|
|
Since FileSystemWatcher doesn't work over samba (not implemented for performance reasons), i've had to write my own class using the FindFirstChangeNotification(...) api call. It's a blocking call that doesn't return until a change is made in the targeted directory, so I'm running my watcher in it's own thread. The problem is that when I call watcherthread.Abort(), the thread doesn't die until after a change is made to the folder. How can I force the thread to stop waiting for the api call adn to shut down.
|
|
|
|
|
I bypassed my problem after looking more closely at the code, and realizing I could pass a fixed ammount of time to wait before having FindFirstChangeNotification() return a timeout.
|
|
|
|
|
Hi
I'm writing a small WebServer for as a project.
I have a class called Pack1 that contians some properties which I want to send to the client.
[Serializable]
public class Pack1 : ISerializable {
public float[] FloatArray1;
public float[] FloatArray2;
public Pack1(){
FloatArray1 = new float[10];
FloatArray2 = new float[10];
//
// Set Data to these arays.
//
}
public Pack1(SerializationInfo info, StreamingContext ctxt) {
FloatArray1 = (float[])info.GetValue("FloatArray1",typeof(float[]));
FloatArray2 = (float[])info.GetValue("FloatArray2",typeof(float[]));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt) {
info.AddValue("FloatArray1",FloatArray1);
info.AddValue("FloatArray2",FloatArray2);
}
}
I use binary Serialization to for the process:
[WebMethod]
public byte[] Test_Func3(){
Pack1 P = new Pack1();
byte[] Buffer;
IFormatter formatter = new BinaryFormatter();
Stream stream = new MemoryStream(1024);
formatter.Serialize(stream,P);
Buffer = new byte[stream.Length];
stream.Seek(0,System.IO.SeekOrigin.Begin);
stream.Read(Buffer,0,Buffer.Length);
return Buffer;
}
And, I have a Binder class to with with Deserialize:
[Serializable]
public sealed class Pack1Binder : System.Runtime.Serialization.SerializationBinder {
public Pack1Binder(){
}
public override Type BindToType(string assemblyName, string typeName){
string[] typeInfo = typeName.Split('.');
string className = typeInfo[typeInfo.Length -1];
if (className.Equals("Pack1")) return typeof(Pack1);
else return Type.GetType(string.Format("{0}, {1}",typeName, assemblyName));
}
}
and a small helper:
[WebMethod]
public System.Runtime.Serialization.SerializationBinder GetSerializationBinder(){ System.Runtime.Serialization.SerializationBinder binder = new Pack1Binder();
return (System.Runtime.Serialization.SerializationBinder)binder;
}
Up until now everything is OK.
The problem is when I deserialize the data on the other side.
On the client Side I have:
Service1 Ser = new Service1();
IFormatter formatter = new BinaryFormatter();
Stream stream = new MemoryStream(1024 * 16);
stream.Flush();
byte[] Buffer = Ser.Test_Func3(10);
stream.Seek(0,System.IO.SeekOrigin.Begin);
stream.Read(Buffer,0,Buffer.Length);
stream.Flush();
stream.Write(Buffer,0,Buffer.Length);
stream.Seek(0,System.IO.SeekOrigin.Begin);
System.Runtime.Serialization.SerializationBinder binder = Ser.GetSerializationBinder(); <-- ???
formatter.Binder = binder;
Pack1 PP = (Pack1)formatter.Deserialize(stream);
The problem here is that the method GetSerializationBinder does not return the same type as System.Runtime.Serialization.SerializationBinder. If I try moving Pack1Binder to the Client then I get a message stating "Pack1 isn't serializable".
I looked over the net for a couple of hours for a solution and only found various similar questions asking pretty much the same thing.
Anyone ?
Gilad.
|
|
|
|
|
I am using an installer project for my application. On the installation folder dialog, there are two radio buttons, "Install the app for 1. everyone or 2. just me".
How do I get rid of this option? If not possible, how do I make the default selection to be "everyone" instead of "just me"?
Thanks.
My articles and software tools
|
|
|
|
|
You can edit the built MSI file using Microsoft's Orca program. Orca comes with the Microsoft Windows Software Development Kit. Here's the link.
http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en[^]
(I know it's a huge download just to get 1 little program, but I don't know how else to get it.)
Once you've installed Orca, you can right click on your MSI file and choose "Edit with Orca".
From there it'll display all of the MSI's innards like a database. Select the Property table and then right click on the right pane (on any row) and then select Add Row. Set the property name to "ALLUSERS" and its value to "1". This will make your installer install for everyone by default.
Now, I've noticed that in the RadioButton table that there are two rows named FolderForm_AllUsers. I've never played with these options before, but it looks like this is where you want to experiment with changing the installers behavior.
I hope this helps. Let me know if it works out for you.
|
|
|
|
|
|
Joshua Quick wrote: Orca comes with the Microsoft Windows Software Development Kit.
I didn't notice it is for Windows Server 2003. We are still using Windows 2000. I will definitely try it when we move to Windows 2003. Thanks.
My articles and software tools
|
|
|
|
|
Xiangyang Liu wrote: I didn't notice it is for Windows Server 2003. We are still using Windows 2000. I will definitely try it when we move to Windows 2003. Thanks.
The version I'm using is just called "Microsoft Platform SDK February 2003", which works fine on my XP system. I tried to link to the version I was using on Microsoft's site and it pointed me to the Windows Server 2003 SDK page. It looks like the same thing. Its system requirements does say it supports Win2000.
However, it looks like someone at Microsoft has provided easy access to Orca via his blog. Try this...
http://blogs.msdn.com/astebner/archive/2004/07/12/180792.aspx[^]
|
|
|
|
|
That just means that the SDK supports Windows 2003 and below. It's not a requirement to have 2003 to use it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|