private static string WriteNewGuid(string pathway)
        {
            // create new guid
            string tempGuid = Guid.NewGuid().ToString();

            // write it to disk
            CrestronXMLSerialization.SerializeObject(pathway, tempGuid);

            // return it to calling method
            return(tempGuid);
        }
Esempio n. 2
0
        /// <summary>
        ///     Serialize the object as XML
        /// </summary>
        /// <param name="obj">Object to serialize</param>
        /// <returns>XML as string</returns>
        public string Serialize(object obj)
        {
            var ns = new CrestronXmlSerializerNamespaces();

            ns.Add(string.Empty, Namespace);

            var writer = new EncodingStringWriter(Encoding);

            CrestronXMLSerialization.SerializeObject(writer, obj, ns);

            return(writer.ToString());
        }
Esempio n. 3
0
        public void Save()
        {
            if (Details.Modified)
            {
                try
                {
                    CrestronXMLSerialization.SerializeObject(this.FileName, this.Details);

                    Details.Modified = false;

                    CrestronConsole.PrintLine("Saved '{0}' successfully", this.FileName);
                }
                catch (Exception e)
                {
                    CrestronConsole.PrintLine("Could not save '{0}'. Cause: {1}", this.FileName, e.Message);
                    ErrorLog.Error("Could not save '{0}'. Cause: {1}", this.FileName, e.Message);
                }
            }
            else
            {
                CrestronConsole.PrintLine("Config unchanged. No need to save.");
            }
        }
Esempio n. 4
0
 public void SerializeList(List <Preset> tempList)
 {
     CrestronXMLSerialization.SerializeObject(_filePath, tempList);
     CrestronConsole.PrintLine(filePath + " Successfully Written to File.\n");
 }                         // Writes the List to an .xml file
Esempio n. 5
0
        public void GetEntry()                                                     // Reads file and passes data to S+
        {
            try
            {
                if (File.Exists(filePath))                                       // Check for existing file
                {
                    if (_debug == 1)
                    {
                        CrestronConsole.PrintLine("File Found: " + filePath + "\n");
                    }
                    ReadEntries = CrestronXMLSerialization.DeSerializeObject <List <Entry> >(filePath);   // Populate the list with deserialized data
                    if (_debug == 1)
                    {
                        CrestronConsole.PrintLine("{0} Read and Deserialized!\n", filePath);
                    }

                    int i = 0;

                    foreach (Entry item in ReadEntries)
                    {
                        if (_debug == 1)
                        {
                            CrestronConsole.PrintLine(String.Format("Entry " + (i + 1) + ": Name: " + ReadEntries[i].Name + " Type: " + ReadEntries[i].Type + " Value: " + ReadEntries[i].Value + "\n"));
                        }
                        i++;
                    }
                    SendValues();
                }
                // If no file is found, create one at the specified path with sample data
                else
                {
                    if (_debug == 1)
                    {
                        CrestronConsole.PrintLine("File Not Found. Creating: " + filePath + "\n");
                    }

                    List <Entry> SampleValues = new List <Entry>();

                    for (int i = 1; i <= 5; i++)                                 // Populate the SampleValues list with values to serve as an example structure to modify manually
                    {
                        Entry tempEntry = new Entry();

                        SampleValues.Add(new Entry()
                        {
                            Name = String.Format("AnalogName {0}", i), Type = analogType, Value = string.Format("{0}", i)
                        });
                    }

                    for (int i = 1; i <= 5; i++)                                 // Populate the SampleValues list with values to serve as an example structure to modify manually
                    {
                        Entry tempEntry = new Entry();

                        SampleValues.Add(new Entry()
                        {
                            Name = String.Format("SerialName {0}", i), Type = serialType, Value = string.Format("{0}", i)
                        });
                    }
                    CrestronXMLSerialization.SerializeObject(_filePath, SampleValues);
                    if (_debug == 1)
                    {
                        CrestronConsole.PrintLine(filePath + " Successfully Created.\n");
                    }
                    GetEntry();
                }
            }
            catch (Exception e)
            {
                if (_debug == 1)
                {
                    CrestronConsole.PrintLine("Error Loading or Creating XML File." + e);
                }
            }
        }