Exemplo n.º 1
0
 public bool setSharedObject(T obj)
 {
     try
     {
         lock (this._synLock)
         {
             XmlDocument xmlDocument = CustomXmlSerializer.Serialize(obj, 8, "SharedObject");
             string      outerXml    = xmlDocument.OuterXml;
             byte[]      bytes       = Encoding.UTF8.GetBytes(outerXml);
             if ((long)bytes.Length < this._shareMemSize)
             {
                 long   value  = (long)bytes.Length;
                 byte[] bytes2 = BitConverter.GetBytes(value);
                 byte[] array  = new byte[8 + bytes.Length];
                 Array.Copy(bytes2, 0, array, 0, 8);
                 Array.Copy(bytes, 0, array, 8, bytes.Length);
                 this.WriteShareArray(0L, array);
                 return(true);
             }
         }
     }
     catch (Exception)
     {
     }
     return(false);
 }
Exemplo n.º 2
0
        public virtual void Save(string TaskPath)
        {
            this.SelectedKeywordsCount = 0;

            this.Random     = null;
            this.Keywords   = null;
            this.FileTokens = null;
            this.Context    = null;
            this.Logger     = null;

            try
            {
                CustomXmlSerializer.Serialize(this.Settings, 1, this.Settings.Name).Save(IO.Path.Combine(TaskPath, "task.xml"));

                // Saving text maker
                if (this.TextMaker != null)
                {
                    this.TextMaker.Save(TaskPath);
                }

                // Saving image maker
                if (this.ImageMaker != null)
                {
                    this.ImageMaker.Save(TaskPath);
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Save settings to file
 /// </summary>
 /// <param name="ImagePath">File path</param>
 public virtual void Save(string ImagePath)
 {
     try
     {
         CustomXmlSerializer.Serialize(this.Settings, 1, this.Settings.Name).Save(IO.Path.Combine(ImagePath, "images.xml"));
     }
     catch (Exception) { }
 }
        public void Serialize_ShouldSerializeListOfFoodObjectsToXml_ReturnsXmlSerializedString()
        {
            CustomXmlSerializer serializer = new CustomXmlSerializer(_foods);
            string result = serializer.Serialize();

            Assert.IsTrue(result.Contains("<Name>Apple</Name><Calories>15</Calories><Carbohydrates>10</Carbohydrates><Fat>5</Fat><Proteins>13</Proteins><Weight>100</Weight>"));
            Assert.IsTrue(result.Contains("<Name>Melon</Name><Calories>8</Calories><Carbohydrates>12</Carbohydrates><Fat>22</Fat><Proteins>33</Proteins><Weight>100</Weight>"));
            Assert.IsTrue(result.Contains("<Name>Orange</Name><Calories>1</Calories><Carbohydrates>2</Carbohydrates><Fat>3</Fat><Proteins>4</Proteins><Weight>100</Weight>"));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Save Settings
 /// </summary>
 /// <param name="TextPath">Path to the configuration file</param>
 public virtual void Save(string TextPath)
 {
     this.TextData = null;
     try
     {
         CustomXmlSerializer.Serialize(this.Settings, 1, this.Settings.Name).Save(IO.Path.Combine(TextPath, "text.xml"));
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 6
0
        private void TestSerialization <T>(T message)
            where T : class
        {
            CustomXmlSerializer serializer = new CustomXmlSerializer();

            byte[] data = serializer.Serialize(message);

            Trace.WriteLine("Result XML:");
            Trace.WriteLine(Encoding.UTF8.GetString(data));

            serializer.Deserialize(data);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Saves provided settings to data source.
 /// </summary>
 protected static void Save(Settings settings)
 {
     try
     {
         XmlDocument doc = CustomXmlSerializer.Serialize(settings, 1, "Test1");
         doc.Save(Settings.FilePath);
         //Helper.Serialize(settings, FilePath);
     }
     catch (Exception exception)
     {
         Common.Logging.AddExceptionLog(exception);
     }
 }
Exemplo n.º 8
0
        public void OneThreadWithTimeChecking()
        {
            longCalc.ShortRecursiveMethod(null);
            string xml         = serializer.Serialize(tracer.GetTraceResult());
            bool   timeCorrect = true;

            foreach (var pair in tracer.GetTraceResult().GetResults())
            {
                if (pair.Value.Methods.Count != 0)
                {
                    CheckTime(pair.Value.Methods, timeCorrect);
                }
            }
            Assert.IsTrue(timeCorrect);
        }
Exemplo n.º 9
0
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            if (int.TryParse(caloriesTextBox.Text, out int calories) && int.TryParse(carbohydratesTextBox.Text, out int carbohydrates) && int.TryParse(fatTextBox.Text, out int fat) && int.TryParse(proteinsTextBox.Text, out int proteins) && int.TryParse(weightTextBox.Text, out int weight))
            {
                App.Foods.Add(new Food(nameTextBox.Text, calories, carbohydrates, fat, proteins, weight));

                CustomXmlSerializer serializer = new CustomXmlSerializer(App.Foods);
                string output = serializer.Serialize();

                File.WriteAllText("FoodDatabase.xml", output);
            }
            else
            {
                MessageBox.Show("Please input correct data");
            }
        }
Exemplo n.º 10
0
        private bool OpenInterProcessShared()
        {
            Semaphore semaphore = InterProcessBase.OpenGlobalSemaphore(this._semaphoreName, 1, 1);

            if (semaphore == null)
            {
                return(false);
            }
            this._semaphoreEcoInstance = semaphore;
            int num = (int)this._shareMemSize + 8;

            this._semaphoreEcoInstance.WaitOne();
            int num2 = InterProcessBase.SetupShareMemoryWithSercurity(this._strMapFileName, num, ref this._hMapFile, ref this._pMapBuf);

            if (num2 < 0)
            {
                this._semaphoreEcoInstance.Release();
                this._semaphoreEcoInstance = null;
                return(false);
            }
            if (num2 <= 0)
            {
                byte[] array = new byte[num];
                Array.Clear(array, 0, array.Length);
                this.WriteShareArray(0L, array);
                T           t           = (default(T) == null) ? Activator.CreateInstance <T>() : default(T);
                XmlDocument xmlDocument = CustomXmlSerializer.Serialize(t, 8, "SharedObject");
                string      outerXml    = xmlDocument.OuterXml;
                byte[]      bytes       = Encoding.UTF8.GetBytes(outerXml);
                if ((long)bytes.Length < this._shareMemSize)
                {
                    long   value  = (long)bytes.Length;
                    byte[] bytes2 = BitConverter.GetBytes(value);
                    byte[] array2 = new byte[8 + bytes.Length];
                    Array.Copy(bytes2, 0, array2, 0, 8);
                    Array.Copy(bytes, 0, array2, 8, bytes.Length);
                    this.WriteShareArray(0L, array2);
                }
            }
            this._semaphoreEcoInstance.Release();
            return(true);
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            ITracer tracer = new Tracer();

            Thread[] threads =
            {
                new Thread(new LongCalcClass(tracer).ShortRecursiveMethod),
                new Thread(new LongCalcClass(tracer).LongRecursiveMethod),
                new Thread(new ShortCalcClass(tracer).SimpleMethodWithAnotherSimleMethod)
            };
            foreach (Thread th in threads)
            {
                th.Start();
            }
            ShortCalcClass c1 = new ShortCalcClass(tracer);

            c1.SimpleMethod();

            LongCalcClass c2 = new LongCalcClass(tracer);

            c2.ShortRecursiveMethod(null);

            foreach (Thread th in threads)
            {
                th.Join();
            }

            ISerialization serializer = new CustomXmlSerializer();
            string         xmlStr     = serializer.Serialize(tracer.GetTraceResult());

            serializer = new JsonSerialization();
            string jsonStr = serializer.Serialize(tracer.GetTraceResult());

            Displayer displ = new Displayer();

            displ.Display(Console.Out, jsonStr + "\n" + xmlStr);
            displ.Display(new FileStream("methods.json", FileMode.Create), jsonStr);
            displ.Display(new FileStream("methods.xml", FileMode.Create), xmlStr);
        }
Exemplo n.º 12
0
        public static byte[] AppProtResponse_Srv(int protocal_ID, string para, int fromUID)
        {
            XmlDocument xmlDocument = null;

            if (protocal_ID == 1)
            {
                try
                {
                    List <int> list      = new List <int>();
                    DataTable  dataTable = DBTools.CreateDataTable(para);
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        for (int j = 0; j < dataTable.Columns.Count; j++)
                        {
                            if (dataTable.Rows[i].ItemArray[j] == DBNull.Value)
                            {
                                list.Add(i);
                                break;
                            }
                        }
                    }
                    if (list.Count > 0)
                    {
                        for (int k = list.Count - 1; k >= 0; k--)
                        {
                            dataTable.Rows.RemoveAt(list[k]);
                        }
                    }
                    dataTable.TableName = "RCI";
                    xmlDocument         = CustomXmlSerializer.Serialize(dataTable, 8, "RCI");
                    goto IL_59A;
                }
                catch (Exception ex)
                {
                    Common.WriteLine("AppProtResponse_Srv---[RCI]: {0}", new string[]
                    {
                        ex.Message
                    });
                    goto IL_59A;
                }
            }
            if (protocal_ID == 2)
            {
                try
                {
                    ArrayList curRacks            = DataSetManager.getCurRacks();
                    Dictionary <long, string> obj = AppData.LoadheatLoadDissipation(curRacks, Convert.ToInt32(para));
                    xmlDocument = CustomXmlSerializer.Serialize(obj, 8, "HEAT");
                    goto IL_59A;
                }
                catch (Exception ex2)
                {
                    Common.WriteLine("AppProtResponse_Srv---[HEAT]: {0}", new string[]
                    {
                        ex2.Message
                    });
                    goto IL_59A;
                }
            }
            if (protocal_ID == 3)
            {
                try
                {
                    DeviceInfo deviceByID = DeviceOperation.getDeviceByID(Convert.ToInt32(para));
                    xmlDocument = CustomXmlSerializer.Serialize(deviceByID, 8, "RemoteCall_getDeviceByID");
                    goto IL_59A;
                }
                catch (Exception ex3)
                {
                    Common.WriteLine("AppProtResponse_Srv---[RemoteCall_getDeviceByID]: {0}", new string[]
                    {
                        ex3.Message
                    });
                    goto IL_59A;
                }
            }
            if (protocal_ID == 4)
            {
                try
                {
                    DeviceInfo      deviceByID2 = DeviceOperation.getDeviceByID(Convert.ToInt32(para));
                    List <PortInfo> obj2        = null;
                    if (deviceByID2 != null)
                    {
                        obj2 = deviceByID2.GetPortInfo();
                    }
                    xmlDocument = CustomXmlSerializer.Serialize(obj2, 8, "RemoteCall_AllPort_in1Dev");
                    goto IL_59A;
                }
                catch (Exception ex4)
                {
                    Common.WriteLine("AppProtResponse_Srv---[RemoteCall_AllPort_in1Dev]: {0}", new string[]
                    {
                        ex4.Message
                    });
                    goto IL_59A;
                }
            }
            if (protocal_ID == 7)
            {
                try
                {
                    List <DeviceInfo> list2 = new List <DeviceInfo>();
                    string[]          array = para.Split(new string[]
                    {
                        ","
                    }, StringSplitOptions.RemoveEmptyEntries);
                    string[] array2 = array;
                    for (int l = 0; l < array2.Length; l++)
                    {
                        string text  = array2[l];
                        string value = text.Trim();
                        if (!string.IsNullOrEmpty(value))
                        {
                            DeviceInfo deviceByID3 = DeviceOperation.getDeviceByID(Convert.ToInt32(value));
                            if (deviceByID3 != null)
                            {
                                list2.Add(deviceByID3);
                            }
                        }
                    }
                    xmlDocument = CustomXmlSerializer.Serialize(list2, 8, "RemoteCall_getDeviceInfoList");
                    goto IL_59A;
                }
                catch (Exception ex5)
                {
                    Common.WriteLine("AppProtResponse_Srv---[RemoteCall_getDeviceInfoList]: {0}", new string[]
                    {
                        ex5.Message
                    });
                    goto IL_59A;
                }
            }
            if (protocal_ID == 100)
            {
                try
                {
                    string[] array3 = para.Split(new char[]
                    {
                        '\n'
                    });
                    switch (array3.Length)
                    {
                    case 1:
                        LogAPI.writeEventLog(array3[0], new string[0]);
                        break;

                    case 2:
                    {
                        string user       = SessionAPI.getUser((long)fromUID);
                        string remoteIP   = SessionAPI.getRemoteIP((long)fromUID);
                        string remoteType = SessionAPI.getRemoteType((long)fromUID);
                        if (array3[0].Equals("0230003", StringComparison.InvariantCultureIgnoreCase))
                        {
                            LogAPI.writeEventLog("0230003", new string[]
                                {
                                    user,
                                    remoteIP
                                });
                        }
                        else
                        {
                            if (!remoteType.Equals("remote", StringComparison.InvariantCultureIgnoreCase))
                            {
                                LogAPI.writeEventLog(array3[0], new string[]
                                    {
                                        array3[1]
                                    });
                            }
                        }
                        break;
                    }

                    case 3:
                        LogAPI.writeEventLog(array3[0], new string[]
                        {
                            array3[1],
                            array3[2]
                        });
                        break;

                    case 4:
                        LogAPI.writeEventLog(array3[0], new string[]
                        {
                            array3[1],
                            array3[2],
                            array3[3]
                        });
                        break;

                    case 5:
                        LogAPI.writeEventLog(array3[0], new string[]
                        {
                            array3[1],
                            array3[2],
                            array3[3],
                            array3[4]
                        });
                        break;

                    case 6:
                        LogAPI.writeEventLog(array3[0], new string[]
                        {
                            array3[1],
                            array3[2],
                            array3[3],
                            array3[4],
                            array3[5]
                        });
                        break;

                    case 7:
                        LogAPI.writeEventLog(array3[0], new string[]
                        {
                            array3[1],
                            array3[2],
                            array3[3],
                            array3[4],
                            array3[5],
                            array3[6]
                        });
                        break;
                    }
                    int num = 1;
                    xmlDocument = CustomXmlSerializer.Serialize(num, 8, "RemoteCall_writeEventLog");
                    goto IL_59A;
                }
                catch (Exception ex6)
                {
                    Common.WriteLine("AppProtResponse_Srv---[RemoteCall_AllPort_in1Dev]: {0}", new string[]
                    {
                        ex6.Message
                    });
                    goto IL_59A;
                }
            }
            if (protocal_ID == 101)
            {
                try
                {
                    int num2 = 1;
                    xmlDocument = CustomXmlSerializer.Serialize(num2, 8, "RemoteCall_setEventFlag");
                    goto IL_59A;
                }
                catch (Exception ex7)
                {
                    Common.WriteLine("AppProtResponse_Srv---[RemoteCall_setEventFlag]: {0}", new string[]
                    {
                        ex7.Message
                    });
                    goto IL_59A;
                }
            }
            if (protocal_ID == 102)
            {
                DataTable allSessions = SessionAPI.getAllSessions();
                xmlDocument = CustomXmlSerializer.Serialize(allSessions, 8, "Sessions");
            }
            else
            {
                if (protocal_ID == 103)
                {
                    string obj3 = "Success";
                    if (!SessionAPI.KillSessions(fromUID, para))
                    {
                        obj3 = "Failed";
                    }
                    xmlDocument = CustomXmlSerializer.Serialize(obj3, 8, "KillSession");
                }
                else
                {
                    if (protocal_ID == 104)
                    {
                        DateTime now = DateTime.Now;
                        xmlDocument = CustomXmlSerializer.Serialize(now, 8, "RemoteCall_getSrvDateTime");
                    }
                    else
                    {
                        if (protocal_ID == 8)
                        {
                            Dictionary <long, List <long> > dictionary = SessionAPI.getDeviceListClone((long)fromUID);
                            if (dictionary == null)
                            {
                                dictionary = new Dictionary <long, List <long> >();
                            }
                            xmlDocument = CustomXmlSerializer.Serialize(dictionary, 8, "RemoteCall_UACDev2Port");
                        }
                    }
                }
            }
IL_59A:
            if (xmlDocument == null)
            {
                return(null);
            }
            byte[] result;
            try
            {
                string outerXml = xmlDocument.OuterXml;
                byte[] bytes    = Encoding.UTF8.GetBytes(outerXml);
                result = bytes;
            }
            catch (Exception ex8)
            {
                Common.WriteLine("AppProtResponse_Srv: #{0}({1}), {2}", new string[]
                {
                    protocal_ID.ToString(),
                    para,
                    ex8.Message
                });
                result = null;
            }
            return(result);
        }
Exemplo n.º 13
0
        public void Serialize <T>(Stream stream, T message)
        {
            var envelope = XmlMessageEnvelope.Create(message);

            _serializer.Serialize(stream, envelope);
        }