Example #1
0
        public ConfigLoader(string paramFilePathway)
        {
            CrestronConsole.PrintLine("trying to load {0}", paramFilePathway);

            if (string.IsNullOrEmpty(paramFilePathway))
            {
                throw new ArgumentNullException("Must pass a valid file pathway parameter");
            }

            if (File.Exists(paramFilePathway))
            {
                this.FileName = paramFilePathway;

                try
                {
                    this.Details  = CrestronXMLSerialization.DeSerializeObject <T>(paramFilePathway);
                    this.IsLoaded = true;
                    CrestronConsole.PrintLine("Yo the file loaded");
                }
                catch (Exception e)
                {
                    this.LoadError = string.Format("Could not load '{0}'. Cause: {1}", paramFilePathway, e.Message);
                    CrestronConsole.PrintLine("Yo the file {0} did not loaded because {1}", paramFilePathway, e.Message);
                }
            }
            else
            {
                this.LoadError = string.Format("File '{0}' does not exist.", paramFilePathway);
                CrestronConsole.PrintLine("Yo the file aint loaded");
            }
        }
        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);
        }
Example #3
0
        public T Deserialize <T> (IRestResponse response)
        {
            if (string.IsNullOrEmpty(response.Content))
            {
                return(default(T));
            }

            using (var stream = new MemoryStream(Encoding.GetBytes(response.Content)))
            {
                return(CrestronXMLSerialization.DeSerializeObject <T> (stream));
            }
        }
Example #4
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());
        }
        /// <summary>
        /// Method to get/create a GUID for general use. If a matching .guid file is found, it reads the contents, if not a new GUID is created and return. This new GUID is then written to disk for future recalling by this method.
        /// </summary>
        /// <param name="ObjectName">Unique object name for which this GUID will be used.<example>example.</example></param>
        /// <returns>Unique GUID.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static string GetGuid(string ObjectName)
        {
            // ensure the parameter contains a valid string
            if (string.IsNullOrEmpty(ObjectName))
            {
                throw new ArgumentNullException("Object name cannot be null or an empty string");
            }

            // string object to return
            string guid = string.Empty;

            // pathway to guid directory
            string dir = string.Format("{0}\\GUIDS", Directory.GetApplicationDirectory());

            // fully qualified pathway name
            string fullPath = string.Format("{0}\\{1}.guid", dir, ObjectName);

            // check to see if the directory exists already
            if (Directory.Exists(dir))
            {
                // check to see if the file name exists
                if (File.Exists(fullPath))
                {
                    // deserialize object
                    guid = CrestronXMLSerialization.DeSerializeObject <string>(fullPath);
                }
                else
                {
                    // get new guid and write to disk
                    guid = WriteNewGuid(fullPath);
                }
            }
            else
            {
                // create the directory
                Directory.Create(dir);

                // get new guid and write to disk
                guid = WriteNewGuid(fullPath);
            }

            return(guid);
        }
Example #6
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.");
            }
        }
Example #7
0
        public void getMeetings(string respFromFusion)
        {
            try
            {
                if (!string.IsNullOrEmpty(respFromFusion))
                {
                    respFromFusion = respFromFusion.Replace("Event", "Event12");

                    int loc2 = respFromFusion.IndexOf("</ScheduleResponse>");
                    int loc1 = respFromFusion.IndexOf("<Event12>");

                    respFromFusion = respFromFusion.Insert(loc2, "</EventList>");
                    respFromFusion = respFromFusion.Insert(loc1, "<EventList>");

                    byte[]       array  = Encoding.UTF8.GetBytes(respFromFusion);
                    MemoryStream stream = new MemoryStream(array);

                    ScheduleResponse eventSchedule = CrestronXMLSerialization.DeSerializeObject <ScheduleResponse>(stream);

                    if (eventSchedule is ScheduleResponse)
                    {
                        List <Event12> eventList = eventSchedule.EventList;

                        meetingNum = eventList.Count;

                        scheduleIdList.Clear();
                        scheduleStartList.Clear();
                        scheduleEndList.Clear();
                        scheduleOrganizerList.Clear();
                        scheduleSubjectList.Clear();

                        if (scheduleOrder == 0)     //按照时间顺序进行排列
                        {
                            for (int i = 0; i <= meetingNum - 1; i++)
                            {
                                scheduleIdList.Add(eventList[i].MeetingID);

                                DateTime startTime;
                                startTime = eventList[i].dtStart;
                                scheduleStartList.Add(startTime);
                                //string startTimeS = string.Format("{0:00}:{1:00}", startTime.Hour, startTime.Minute);

                                DateTime endTime;
                                endTime = eventList[i].dtEnd;
                                scheduleEndList.Add(endTime);
                                //string endTimeS = string.Format("{0:00}:{1:00}", endTime.Hour, endTime.Minute);

                                //int confState = meetingState(startTime, endTime);

                                scheduleOrganizerList.Add(eventList[i].Organizer);

                                scheduleSubjectList.Add(eventList[i].Subject);

                                //MeetingsArgs myArg = new MeetingsArgs(meetingNum, i + 1, startTimeS, endTimeS, eventList[i].Subject, eventList[i].Organizer, confState);
                                //if (meetingsCallback != null)
                                //meetingsCallback(this, myArg);

                                //if (debugging)
                                //CrestronConsole.PrintLine("Current meeting number: {0}, start time: {1}, end time: {2}, subject: {3}, organizer: {4}, status: {5}", i + 1, startTimeS, endTimeS, eventList[i].Subject, eventList[i].Organizer, confState == 0 ? "Not started" : confState == 1 ? "On going" : "Ended");
                            }
                        }
                        else if (scheduleOrder == 1)    //按照时间倒序进行排列
                        {
                            for (int i = meetingNum - 1; i >= 0; i--)
                            {
                                scheduleIdList.Add(eventList[i].MeetingID);

                                DateTime startTime;
                                startTime = eventList[i].dtStart;
                                scheduleStartList.Add(startTime);
                                //string startTimeS = string.Format("{0:00}:{1:00}", startTime.Hour, startTime.Minute);

                                DateTime endTime;
                                endTime = eventList[i].dtEnd;
                                scheduleEndList.Add(endTime);
                                //string endTimeS = string.Format("{0:00}:{1:00}", endTime.Hour, endTime.Minute);

                                //int confState = meetingState(startTime, endTime);

                                scheduleOrganizerList.Add(eventList[i].Organizer);

                                scheduleSubjectList.Add(eventList[i].Subject);

                                //MeetingsArgs myArg = new MeetingsArgs(meetingNum, meetingNum - i, startTimeS, endTimeS, eventList[i].Subject, eventList[i].Organizer, confState);
                                //if (meetingsCallback != null)
                                //meetingsCallback(this, myArg);

                                //if (debugging)
                                //CrestronConsole.PrintLine("Current meeting number: {0}, start time: {1}, end time: {2}, subject: {3}, organizer: {4}, status: {5}", meetingNum - i, startTimeS, endTimeS, eventList[i].Subject, eventList[i].Organizer, confState == 0 ? "Not started" : confState == 1 ? "On going" : "Ended");
                            }
                        }
                    }
                }
                else
                {
                    if (debugging)
                    {
                        CrestronConsole.PrintLine("fail|Unexpected error");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLog.Error("--------------Error when get schedule: {0}", ex.Message);
                if (debugging)
                {
                    CrestronConsole.PrintLine("--------------Error when get schedule: {0}", ex.Message);
                }
            }
            finally
            {
                checkSchedule();
            }
        }
Example #8
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
Example #9
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);
                }
            }
        }
Example #10
0
        public void GetPresets()                                                    // Reads presets from file if present or creates file with sample preset values if not
        {
            try
            {
                if (File.Exists(filePath))                                      // Check for existing file
                {
                    if (_debug == 1)
                    {
                        CrestronConsole.PrintLine("File Found: " + filePath + "\n");
                    }
                    ReadPresets = CrestronXMLSerialization.DeSerializeObject <List <Preset> >(filePath);     // Populate the list with deserialized data
                    if (_debug == 1)
                    {
                        CrestronConsole.PrintLine("{0} Read and Deserialized!\n", filePath);
                    }

                    int i = 0;


                    foreach (Preset item1 in ReadPresets)
                    {
                        if (_debug == 1)
                        {
                            CrestronConsole.PrintLine(String.Format("ID: " + ReadPresets[i].ID + " Name: " + ReadPresets[i].Name + "\n"));
                        }

                        int j = 0;
                        int k = 0;
                        int l = 0;

                        foreach (Destination item2 in ReadPresets[i].Destination)
                        {
                            CrestronConsole.PrintLine(String.Format(" Name: " + ReadPresets[i].Destination[j].Name +
                                                                    " Source: " + ReadPresets[i].Destination[j].Value + "\n"));
                            j++;
                        }

                        foreach (Source item3 in ReadPresets[i].Source)
                        {
                            CrestronConsole.PrintLine(String.Format("Name: " + ReadPresets[i].Source[k].Name +
                                                                    " Video: " + ReadPresets[i].Source[k].Video +
                                                                    " Audio: " + ReadPresets[i].Source[k].Audio +
                                                                    " Icon: " + ReadPresets[i].Source[k].Icon +
                                                                    " Control: " + ReadPresets[i].Source[k].Control +
                                                                    " Share: " + ReadPresets[i].Source[k].Share + "\n"));
                            k++;
                        }
                        foreach (Share item4 in ReadPresets[i].Share)
                        {
                            CrestronConsole.PrintLine(String.Format("Name: " + ReadPresets[i].Share[l].Name +
                                                                    "Video: " + ReadPresets[i].Share[l].Video +
                                                                    "Audio: " + ReadPresets[i].Share[l].Audio +
                                                                    "Icon: " + ReadPresets[i].Share[l].Icon +
                                                                    "Control: " + ReadPresets[i].Share[l].Control + "\n"));
                            l++;
                        }
                        i++;
                    }
                    RecallPreset(PresetID, 0);
                }
                else                // If no file is found, create one at the specified path with sample data
                {
                    if (_debug == 1)
                    {
                        CrestronConsole.PrintLine("File Not Found. Creating: " + filePath + "\n");
                    }

                    List <Preset> SamplePreset = new List <Preset>();

                    List <Destination> SampleDestinations = new List <Destination>();

                    List <Source> SampleSources = new List <Source>();

                    List <Share> SampleShares = new List <Share>();

                    for (int i = 1; i <= 4; i++)        // Populate the SampleValues
                    {
                        SampleSources.Add(new Source()
                        {
                            Name    = "Source" + (ushort)i,
                            Video   = (ushort)i,
                            Audio   = (ushort)i,
                            Icon    = Convert.ToUInt16("166"),
                            Control = Convert.ToUInt16("0"),
                            Share   = Convert.ToUInt16("1")
                        });
                    }

                    for (int i = 1; i <= 4; i++)        // Populate the SampleValues
                    {
                        SampleShares.Add(new Share()
                        {
                            Name    = "Shared Source" + (ushort)i,
                            Video   = (ushort)i,
                            Audio   = (ushort)i,
                            Icon    = Convert.ToUInt16("166"),
                            Control = Convert.ToUInt16("0")
                        });
                    }

                    for (int i = 1; i <= 4; i++)        // Populate the SampleValues
                    {
                        SampleDestinations.Add(new Destination()
                        {
                            Name  = "Destination" + (ushort)i,
                            Value = (ushort)i
                        });
                    }


                    for (int i = 0; i <= 5; i++)        // Populate the SampleValues list with values to serve as an example structure to modify manually
                    {
                        SamplePreset.Add(new Preset()
                        {
                            ID                  = (ushort)i,
                            Name                = "Example Preset" + (ushort)i,
                            RoomName            = "RoomName",
                            ACNumber            = "(xxx) yyy-zzzz",
                            ACMode              = 0,
                            VCNumber            = "My VC Number",
                            VCMode              = 0,
                            PRESMode            = 1,
                            CalendarMode        = 0,
                            LIGHTMode           = 1,
                            OCCUPANCYVisible    = 0,
                            HALLWAYVisible      = 0,
                            SKYFOLDVisible      = 0,
                            SourceMax           = 4,
                            DestinationMax      = 4,
                            SharingMax          = 4,
                            SharingInputPos     = 5,
                            LightZoneMax        = 1,
                            ShadeZoneMax        = 3,
                            ShadeCfg            = 1,
                            ConferenceMicMax    = 16,
                            OtherMicMax         = 2,
                            CombineMax          = 0,
                            ScreenMax           = 0,
                            LiftMax             = 0,
                            VCLocalCamera       = 1,
                            VCLocalCameraEnable = 1,
                            VCSpeakerTrack      = 0,
                            VCPreset            = 3,
                            AutoSwitching       = 0,
                            AudioFollow         = 0,
                            VolumeModeBasic     = 0,
                            AdvanceDisable      = 1,
                            LanguageDisable     = 0,
                            LanguageDefault     = 0,
                            Destination         = SampleDestinations,
                            Source              = SampleSources,
                            Share               = SampleShares
                        });
                    }

                    SerializeList(SamplePreset);
                    GetPresets();       // Recall the File to propagate the Sample Value to system.
                }
            }
            catch (Exception e)
            {
                if (_debug == 1)
                {
                    CrestronConsole.PrintLine("Error Loading or Creating XML File." + e);
                }
            }
        }