Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
H

Hessam Jalali

@Hessam Jalali
About
Posts
124
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Create Rsa Signature
    H Hessam Jalali

    RSA keys are in pairs, but you used public key in both methods. replacing provided key in CheckSignature with private key should solve your problem. and in CheckSignature method you should feed VerifySignature with MD5 hash of key varibale, the code should be more like this

        public static byte\[\] CreateSignature(string key64)
        {
            var data = Convert.FromBase64String(key64);
    
            var rSaCryptoServiceProvider = new RSACryptoServiceProvider(new CspParameters
            {
                Flags = CspProviderFlags.UseMachineKeyStore
            });
    
            rSaCryptoServiceProvider.FromXmlString(privateKey);
    
    
            var RSAform = new RSAPKCS1SignatureFormatter();
            RSAform.SetKey(rSaCryptoServiceProvider);
            RSAform.SetHashAlgorithm("MD5");
    
            var md5 = MD5.Create();
            byte\[\] hashData = md5.ComputeHash(data);
    
            return RSAform.CreateSignature(hashData);
        }
    

    hope this helps

    C# question

  • Hosting XNA in a windows forms control and in turn hosting that control in WPF
    H Hessam Jalali

    Hello using WPF and XNA together seems to be a little tricky. I've seen two different approach for integrating XNA and WPF XNA integration inside WPF Integrating XNA with Windows Presentation Foundation however these techniques are more like a hack than a reliable solution. if you need a GUI for your game I suggest you to have a look at NeoForce Controls good luck

    .NET (Core and Framework) csharp winforms graphics game-dev question

  • Preventing the dropdown from being opened when drop down button pressed in combobox?
    H Hessam Jalali

    Hello, I think this can be done by intercepting WM_COMMAND message in "WndProc" method. this may help

    public class SuperComboBox:ComboBox
    {
    public class DropDownValidate:EventArgs
    {
    public bool AllowDropDown{get;set;}

            public DropDownValidate()
            {
                this.AllowDropDown = true;
            }
        }
    
        private const int WM\_COMMAND = 0x0111;
    
        public event EventHandler<DropDownValidate> ValidateOnDropDown;
    
        private bool \_haltDrop;
    
        protected virtual void OnValidateDropDown(DropDownValidate e)
        {
            if (this.ValidateOnDropDown != null)
                this.ValidateOnDropDown(this, e);
        }
    
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM\_COMMAND)
            {
                var validationArg = new DropDownValidate();
                this.OnValidateDropDown(validationArg);
                \_haltDrop = !validationArg.AllowDropDown;
                if (\_haltDrop) return;
            }
            base.WndProc(ref m);
        }
    }
    

    Good luck

    C# question

  • How to set modeless form to stay modeless?
    H Hessam Jalali

    Hey That's why they made Modals!!! but if you used your second form as a modalDialog for preventing access to the mainForm. the simplest way to get rid of it (if you don't care your controls going to be Grey) is to use Show instead of show dialog and pass the mainform instance to form (previously was shown as modal) and disable the mainForm then after hiding the dialog enable it again. or http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2192114&SiteID=1[^] Hope its going to help!

    C# help tutorial question

  • Cancelling a background worker
    H Hessam Jalali

    really sorry, I didn't mean that ,I make these type of careless mistakes alot myself can you send some code?

    C# algorithms

  • Cancelling a background worker
    H Hessam Jalali

    you must first set the WorkerSupportsCancellation Property of BackgroungWorker instance to true. then you can cancel it good luck :)

    C# algorithms

  • Users in local users and groups
    H Hessam Jalali

    you can do that using WMI through System.Management namespace (you must add it as reference) you can query Win32_UserAccount and Win32_UserGroup from WMI for collecting your data maybe this is not the best solution but it's going to work :) here is the code

    public class UserManagements
    {
    public class GroupUser
    {
    const string PATTERNNAME = ".*Name=\"(?'name'.*)\".*";
    const string PATTERNDOMAIN = ".*Domain=\"(?'domain'.*)\",.*";

                public readonly string groupName;
                public readonly string partName;
    
                public readonly string groupDomain;
                public readonly string partDomain;
    
                public GroupUser(string groupComponent, string partComponent)
                {
                    this.groupName = Regex.Replace(groupComponent, PATTERNNAME, "${name}");
                    this.partName = Regex.Replace(partComponent, PATTERNNAME, "${name}");
    
                    this.groupDomain = Regex.Replace(groupComponent, PATTERNDOMAIN, "${domain}");
                    this.partDomain = Regex.Replace(partComponent, PATTERNDOMAIN, "${domain}");
                }
    
            }
    
            public class UserAccount
            {
                public readonly int AccountType;
                public readonly string Caption;
                public readonly string Description;
                public readonly bool Disabled;
                public readonly string Domain;
                public readonly string FullName;
    
                public readonly bool LocalAccount;
                public readonly bool Lockout;
                public readonly string Name;
                public readonly bool PasswordChangeable;
                public readonly bool PasswordExpires;
                public readonly bool PasswordRequired;
                public readonly string SID;
                public readonly int SIDType;
                public readonly string Status;
    
                public UserAccount(ManagementObject userMO)
                {
                    this.AccountType = Convert.ToInt32(userMO.Properties\["AccountType"\].Value);
                    this.Caption = userMO.Properties\["Caption"\].Value as string;
                    this.Description = userMO.Properties\["Description"\].Value as string;
                    this.Disabled = Convert.ToBoolean(userMO.Properties\["AccountType"\].Value);
                    this.Domai
    
    C# sysadmin help

  • how to check the files are exist or not in a floder
    H Hessam Jalali

    you can use System.IO.File.Exists(string path) method to check whether the file exists or not. good luck

    C# csharp help tutorial

  • Selecting an item in a listbox control
    H Hessam Jalali

    Hi I suggest to use MouseDown or MouseUp events instead of Click because they give you the mouse button and position all together and you can find the index of pointed item by using IndexFromPoint method of listBox instance here is the code I tested to see how it can be done

        void listBox1\_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right) return;
    
            int index=this.listBox1.IndexFromPoint(e.Location);
    
            if (index == -1) return;
    
            object selectedObj = this.listBox1.Items\[index\];
    
            // if you want to select that in the list
    
            this.listBox1.SelectedIndex = index;
    
            MessageBox.Show(selectedObj.ToString());//just for test
        }
    

    good luck :)

    C# question

  • Locating Zip folders
    H Hessam Jalali

    you can filter the files with using the overloaded version of the GetFiles(string path,string searchPattern) it would be somewhat like this for zip files

    string[] files=System.IO.Directory.GetFiles(path, "*.zip");
    

    good luck

    C# csharp tutorial

  • Perfect Timing!
    H Hessam Jalali

    you need an accurate timer (there is one in DXUtils class in DirectX SDK) and define your move formula depend on time and speed just like X=Vt+X0 for example if X0=0 and V=100px/sec then in 2Sec it would be 200px or in 0.01 sec it would be just 1px so it does not depend on the framerate you can take two approach depends on your need 1- X0 would be always zero so after 10 sec you pass the 10sec to formula 2-use time Elapsed method (use in most games) you can calculate the elapsed time using the timer and the previuos position would be X0. for example if X0=0 and V=100px/Sec after one sec X=100px and after 1.5 sec from beginning it would be X0=100px ,V=100px/sec,ElapsedTime=0.5 sec X=100*0.5+100=150px and if you are doing it in the 3D you must define each speed for every dimension or calculate them thruogh total speed using math and ofcourse you involve acceleration too. hope the post would be useful

    C# help

  • Scaling a Polygon
    H Hessam Jalali

    I don't know this would be useful or not (and I think you already know this!)but this is all it's math it can be done using rectangle technique and i'm think is fast enough for normal size shapes you can assume all your shapes you are going to resize are in a rectangle (x1,y1),(x2,y2) which the first one is top left and the second is bottom right so for resizing the shape you can resize the rectangle and map the changes to your shape the easiest way is to get one point as a reference inside the rectangle for fixing the shape the rectangle would be used for calculating the ratio if you get the ratio directly you wouldn't need the ectangle points for example I suppose that I have a polygon with (10,10),(21,21),(15,40) and I want to resize it to 2X (the ratio) I assume my reference point to (10,10) my new resized polygon without fixing to its position is (20,20),(42,42),(30,80) my referene point is (20,20) in new polygon so it has linear transform (10,10) from the actual reference so I must subtract it and my refDiff would be (10,10) the resized fixed position polygon would be (10,10),(32,32),(20,70) but if you dont have the ratio you must find ir from the rectangle which "x1 is Min of all x" "x2 is Max of all x" "y1 is Min of all y" and "y2 is Max of all y" you cn find the ratio from changing the first ractangle Width and Height from the second one and use the ratio as before so the formula foreach point would be Xn=ratioAtx*xn-refxDiff Yn=ratioAty*yn-refyDiff I think this is the easiest way to do that in math and implementing it is depend on yourself (sorry if you didn't mean this) hope this would be useful

    C# help question graphics performance

  • Time elapsed since user logged in
    H Hessam Jalali

    first sorry for delay I was in vacation :) yes you're right it cannot be done as straight as a simple win App but with services you can, and writing services in .NET is not harder than writing simple winApp it can be done with services because they'll works even when a user switch or logoff. and I think you must log some data byyourself if you need accurate times (like finding hibernate time and subtract it and ...)

    gajatko wrote:

    if e.g. some other guy kicked him out for a while because he "just wanted to check mailbox", but after that that guy could return back

    there is another event in SystemEvents Class name SessionSwitch it will occur when the user going to change so I think UserSwitch would be included and when you hibernate it seems something like userSwitch happens (but I'm not sure) so maybe this event would be useful.

    gajatko wrote:

    from yesterday evening, when Windows was hibernated (28 hours?? Oh God...).

    another event is PowerModeChanged which will return your computer is going to suspend mode or not and hibernate is counted as a suspend mode (atleast in .NET)this event may help to retrieve hibernate status too. and at last I think you can retrieve some data from the Service status (like Puase/Stop) and use it for finding machine state like shutdown hibernate good luck :)

    C# data-structures question workspace

  • Time elapsed since user logged in
    H Hessam Jalali

    unfortunately it seems there is no LogOutTime property (at least I didn't found out anyOne) but AFAIK In windows only on user can work at the same time so there is a class in .NET name Microsoft.Win32.SystemEvents.SessionEnding it happens when a user trying to logoff or shutdown so you can find active user through WMI again or through System.Environment.UserName and find you are in which session. I think with adding the event to the class you can find total duration.(but it needs your program always run or atleaset when user is going to logout or shutdown) if you get the duration inside the method associated with that event it would be total user log time. ofcourse there is another approaches like looking inside eventlogs but i think this is the easiest one hope the post would be useful

    C# data-structures question workspace

  • Time elapsed since user logged in
    H Hessam Jalali

    it can be done using WMI (System.Management namespace),I don't know but maybe .NET has some classes which give you these info. with WMI you can retrieve these data through Win32_LogonSession and Win32_LoggedOnUser and extract start time from them. with subtracting from DateTime.Now you'll have the duration it would be somewhat like this

    class UserLogonData
    {
        const string ALLUSERS = "All";
    
        readonly string userName;
        readonly DateTime loggedOnTime;
        string logonId;
    
        public string UserName
        {
            get { return this.userName; }
        }
        public DateTime LoggedOnTime
        {
            get { return this.loggedOnTime; }
        }
        public string LogonID
        {
            get { return this.logonId; }
        }
        public TimeSpan LoggedDuration
        {
            get { return DateTime.Now.Subtract(this.loggedOnTime); }
        }
    
        private UserLogonData(string userName, string logonId, DateTime loggedOnTime)
        {
            this.userName = userName;
            this.logonId = logonId;
            this.loggedOnTime = loggedOnTime;
        }
    
        public override string ToString()
        {
            return this.userName;
        }
    
        public static UserLogonData\[\] GetUsersLogonTime(string userName)
        {
            List dataList = new List();
    
            ManagementObjectSearcher mosUser = new ManagementObjectSearcher(new SelectQuery("Win32\_LoggedOnUser"));
            ManagementObjectSearcher mosSession = new ManagementObjectSearcher(new SelectQuery("Win32\_LogonSession"));
    
            ManagementObjectCollection mocUser = mosUser.Get();
            ManagementObjectCollection mocSession = mosSession.Get();
    
            foreach (ManagementObject moUser in mocUser)
            {
                string userLogonAntecedentData = moUser.Properties\["Antecedent"\].Value.ToString();
                string userLogonUserName = Regex.Replace(userLogonAntecedentData, @".\*Name=""(?'name'.+)"".\*", "${name}");
                if (userName!=ALLUSERS && userLogonUserName != userName) continue;
                string userLogonDependentData = moUser.Properties\["Dependent"\].Value.ToString();
                string userLogonSessionId = Regex.Replace(userLogonDependentData, @".\*LogonId=""(?'id'\\d+)"".\*", "${id}");
                foreach (ManagementObject moSession in mocSession)
                {
    
    C# data-structures question workspace

  • copy Xml to Xml files
    H Hessam Jalali

    You must first Import the node from another doc to yours,you can do that using ImportNode method from from XmlDocumrent instance so it would be somewhat like this and if you want to create a whole new coy of your node pass deep argument as true otherwise just the selected node would be impoterd not the childs

    XmlDocument doc1 = new XmlDocument();
    doc1.AppendChild(doc1.CreateElement("MyElement"));
    doc1.Save(@"N:\doc1.xml");

    XmlDocument doc2 = new XmlDocument();
    XmlNode importedNode = doc2.ImportNode(doc1["MyElement"], true);
    doc2.AppendChild(importedNode);
    doc2.Save(@"N:\doc2.xml");

    good luck

    C# xml help question

  • How do I incorporate these two routines?
    H Hessam Jalali

    it seems from your second method you need to parse your string from string builder to lines like what you read from the Stream Am I right? if it is what you need you can do with Split method from string instances like

    string s = "hello \r\n how are you? \r\n";
    string[] sArr = s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
    StringCollection col = new StringCollection();
    col.AddRange(sArr);

    it was the easiest way with least code change however your methods are not efficient you can add your string to StringCollection instance instead of writing sb.Append("/r/n") hope the post would be useful good luck

    C# question

  • Accessing ACPI Thermal Zone from C#
    H Hessam Jalali

    Have a look at these links, these may help NHC ACPI : http://www.pbus-167.com/nhc/nhc_advanced.htm#anchor_acpi_programming[^] ACPI Control System Programming Guide:http://www.p35-forum.de/board/notebook-hardware-control/nhc-english/6399-acpi-control-system-programming-guide/[^] good luck

    C# csharp json help tutorial question

  • Fast possiblity to send data from Server to Client
    H Hessam Jalali

    hansipet wrote:

    do you know if it is possible to deserialize objectes allways from the same stream?

    If you mean one stream for all Yes it is possible but you must set the pointers of the stream manually eachtime by yourself for preventing errors.and ofcourse you need some implementation for preventing asynchronous calls from clients for requesting the stream and update requests from the server on the that. and if you mean same stream as serialized in request the answer is yes again and this time you just need to set the pointers to first of the stream with using methods like seek

    hansipet wrote:

    I don't wan't to poll allways the server

    if you said that because of the singleton it can be singleCall so after calling and disposing the stream the resources from server side will release and there would be no problem. but if your Log files are not so huge I think creating a class as LogDataHolder and mark it as serializible then return it as value to clients would be a better idea. good luck

    C# question sysadmin

  • declaring xmlserializer where typeof is a class derived from arraylist
    H Hessam Jalali

    your welcome :) have a nice day too

    C# question xml help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups