//XmlDeserialize method
 public SortableBindingList <T> XmlDeserialize(string fileName)
 {
     try
     {
         using (CrossProcessLockFactory.CreateCrossProcessLock(Path.GetFileName(fileName)))
         {
             try
             {
                 string data = System.IO.File.ReadAllText(fileName);
                 System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(typeof(SortableBindingList <T>));
                 TextReader reader = new StringReader(data);
                 object     obj    = xmlSer.Deserialize(reader);
                 return((SortableBindingList <T>)obj);
             }
             catch (Exception ex)
             {
                 Console.WriteLine("[XmlDeserialize] Exception [" + ex + "]");
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("[XmlDeserialize CreateCrossProcessLock] Exception [" + ex + "]");
         return(null);
     }
 }
Example #2
0
        public bool DoRedguard(string accountName)
        {
            using (CrossProcessLockFactory.CreateCrossProcessLock(-1, "redguard"))
            {
                int    hwndRedGuard = 0;
                IntPtr hwndListBox  = (IntPtr)0;
                IntPtr hwndOKButton = (IntPtr)0;

                int i = 0;
                while (hwndRedGuard == 0)
                {
                    if (i >= 150)
                    {
                        return(false);
                    }
                    hwndRedGuard = FindWindow(null, "Red Guard Account Selection");
                    Application.DoEvents();
                    Thread.Sleep(200);
                    i++;
                }


                hwndListBox  = FindWindowEx((IntPtr)hwndRedGuard, IntPtr.Zero, "ListBox", "");
                hwndOKButton = FindWindowEx((IntPtr)hwndRedGuard, IntPtr.Zero, "Button", "OK");

                int cnt = SendMessage((int)hwndListBox, LB_GETCOUNT, 0, null);

                bool found = false;
                for (i = 0; i < cnt; i++)
                {
                    StringBuilder sb = new StringBuilder(256);
                    SendMessage((int)hwndListBox, LB_GETTEXT, (int)i, sb);
                    if (sb.ToString().Contains(accountName))
                    {
                        found = true;
                        SendMessage((int)hwndListBox, LB_SETCURSEL, (int)i, null);
                    }
                }

                if (!found)
                {
                    CloseWindow(hwndRedGuard);
                    return(false);
                }


                SendMessage((int)hwndOKButton, WM_LBUTTONDOWN, 0, null);
                SendMessage((int)hwndOKButton, WM_LBUTTONUP, 0, null);
                SendMessage((int)hwndOKButton, WM_LBUTTONDOWN, 0, null);
                SendMessage((int)hwndOKButton, WM_LBUTTONUP, 0, null);

                return(true);
            }
        }
Example #3
0
        //XmlDeserialize method
        public SortableBindingList <T> XmlDeserialize(string fileName)
        {
            using (CrossProcessLockFactory.CreateCrossProcessLock(Path.GetFileName(fileName))){
                string data = System.IO.File.ReadAllText(fileName);
                System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(typeof(SortableBindingList <T>));
                TextReader reader = new StringReader(data);
                object     obj    = xmlSer.Deserialize(reader);

                return((SortableBindingList <T>)obj);
            }
        }
Example #4
0
 //XmlSerialize method
 public void XmlSerialize(string fileName)
 {
     using (CrossProcessLockFactory.CreateCrossProcessLock(Path.GetFileName(fileName))){
         using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName))
         {
             System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(this.GetType());
             StringWriter textWriter = new StringWriter();
             xmlSer.Serialize(textWriter, this);
             xmlSer = null;
             file.Write(textWriter.ToString());
         }
     }
 }
Example #5
0
 private void InitializeFluentMappings()
 {
     using (CrossProcessLockFactory.CreateCrossProcessLock())
     {
         DefaultTypeMap.MatchNamesWithUnderscores = true;
         if (FluentMapper.EntityMaps.IsEmpty)
         {
             FluentMapper.Initialize(config =>
             {
                 config.AddMapFromCurrentAssembly();
             });
         }
     }
 }