/// <summary>
        /// Returns a TOU schedule file based on the tou schedule name provided.
        /// </summary>
        /// <param name="iTOUID">
        /// The ID of the TOU schedule to find.
        /// </param>
        /// <returns>
        /// Returns a CTOUScheduleFile if the schedule exists or it returns null.
        /// </returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------------
        //  07/17/07 mrj 9.00.00		Created
        //
        public CTOUScheduleFile Find(int iTOUID)
        {
            CTOUScheduleFile TOUFile = null;

            foreach (CTOUScheduleFile file in InnerList)
            {
                if (file.ID == iTOUID)
                {
                    //The TOU file was found to break out of the loop and return it
                    TOUFile = file;
                    break;
                }
            }

            return(TOUFile);
        }
        } // Delete(string)

        /// <summary>
        /// Returns a TOU schedule file based on the tou schedule name provided.
        /// </summary>
        /// <param name="strTOUName">
        /// The name of the TOU schedule to find.
        /// </param>
        /// <returns>
        /// Returns a CTOUScheduleFile if the schedule exists or it returns null.
        /// </returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------------
        //  07/17/07 mrj 9.00.00		Created
        //
        public CTOUScheduleFile Find(string strTOUName)
        {
            CTOUScheduleFile TOUFile = null;

            foreach (CTOUScheduleFile file in InnerList)
            {
                if (file.Name == strTOUName)
                {
                    //The TOU file was found to break out of the loop and return it
                    TOUFile = file;
                    break;
                }
            }

            return(TOUFile);
        }
        /// <summary>
        /// Returns a TOU schedule based on the tou schedule name provided.
        /// </summary>
        /// <param name="iTOUID">
        /// The ID of the TOU schedule to find.
        /// </param>
        /// <returns>
        /// Returns a CTOUSchedule if the schedule exists or it returns null.
        /// </returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------------
        //  07/17/07 mrj 9.00.00		Created
        //
        public CTOUSchedule FindSchedule(int iTOUID)
        {
            CTOUSchedule     TOUSchedule = null;
            CTOUScheduleFile TOUFile     = Find(iTOUID);

            if (TOUFile != null)
            {
                try
                {
                    TOUSchedule = new CTOUSchedule(TOUFile.FilePath);
                }
                catch
                {
                    TOUSchedule = null;
                }
            }

            return(TOUSchedule);
        }
        /// <summary>
        /// Returns a TOU schedule based on the tou schedule name provided.
        /// </summary>
        /// <param name="strTOUName">
        /// The name of the TOU schedule to find.
        /// </param>
        /// <returns>
        /// Returns a CTOUSchedule if the schedule exists or it returns null.
        /// </returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------------
        //  07/17/07 mrj 9.00.00		Created
        //
        public CTOUSchedule FindSchedule(string strTOUName)
        {
            CTOUSchedule     TOUSchedule = null;
            CTOUScheduleFile TOUFile     = Find(strTOUName);

            if (TOUFile != null)
            {
                try
                {
                    TOUSchedule = new CTOUSchedule(TOUFile.FilePath);
                }
                catch
                {
                    TOUSchedule = null;
                }
            }

            return(TOUSchedule);
        }
        /// <summary>
        /// Implements the compare method for comparing CTOUScheduleFile objects. It
        /// compares the TOU schedule names only.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------------
        //  10/11/06 mrj 7.35.04        Created
        //
        int IComparer.Compare(object x, object y)
        {
            CTOUScheduleFile scheduleX = (CTOUScheduleFile)x;
            CTOUScheduleFile scheduleY = (CTOUScheduleFile)y;

            if (scheduleX == null && scheduleY == null)
            {
                return(0);
            }
            else if (scheduleX == null && scheduleY != null)
            {
                return(-1);
            }
            else if (scheduleX != null && scheduleY == null)
            {
                return(1);
            }
            else
            {
                return(scheduleX.Name.CompareTo(scheduleY.Name));
            }
        }
Example #6
0
        }        //FilePath

        /// <summary>
        /// This method searchs the list of given TOU files for a specific TOU name.  If that
        /// schedule name is found, the index of the item will be returned
        /// </summary>
        /// <param name="strTOUName" type="string"></param>
        /// <param name="lstTOUs"></param>
        /// <param name="nListIndex"></param>
        /// <returns>
        ///  A flag indicating whether or not the given display name was found in the list of items
        /// </returns>
        /// <remarks>
        ///  Revision History
        ///  MM/DD/YY Who Version Issue# Description
        ///  -------- --- ------- ------ -------------------------------------------
        ///  08/03/07 MAH		Created
        ///
        /// </remarks>
        static public Boolean FindIndexOf(String strTOUName,
                                          ref List <CTOUScheduleFile> lstTOUs, out int nListIndex)
        {
            nListIndex = 0;
            Boolean boolMatchFound = false;

            // Now search this collection one by one
            while (nListIndex < lstTOUs.Count && !boolMatchFound)
            {
                CTOUScheduleFile touSchedule = lstTOUs[nListIndex];

                if (touSchedule.Name == strTOUName)
                {
                    boolMatchFound = true;
                }
                else
                {
                    nListIndex++;
                }
            }

            return(boolMatchFound);
        }
        }        //CTOUScheduleFileCollection(string)

        /// <summary>
        /// Used to refresh the collection of TOU Schedules
        /// </summary>
        //  Revision History
        //  MM/DD/YY who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------
        //  02/15/06 rrr N/A	 N/A	Creation of class
        //	04/10/07 mrj 8.00.27 2860	If this is an SCS device then check that
        //								any SCS device is supported.
        //
        private void Refresh(string strDevice)
        {
            //Local variables
            XmlDocument      xmldomSchedule     = null;
            XmlNodeList      xmlnodelistDevices = null;
            CTOUScheduleFile objSchedule        = null;
            DirectoryInfo    objDir             = null;
            bool             blnCorrectID       = false;
            string           strTOUID           = null;
            int    intTOUID    = 0;
            string strName     = null;
            string strFilePath = null;


            //Get the directory for the TOU Schdule files
            m_strDataDirectory = CRegistryHelper.GetDataDirectory(CALENDAR_EDITOR);


            //Throw an error if the directory comes back null
            if (null == m_strDataDirectory)
            {
                throw new Exception("The directory for TOU Schedules does not exist");
            }

            //Create a directory info object based on the directory
            objDir = new DirectoryInfo(m_strDataDirectory);

            //Go through the list of xml files in the directory
            foreach (FileInfo objFile in objDir.GetFiles("*.xml"))
            {
                blnCorrectID = true;

                //Check the first 4 characters of the name to make sure they are digits
                strTOUID = objFile.Name.Substring(0, 4);

                for (int intCount = 0; intCount < 4; intCount++)
                {
                    if (!Char.IsDigit(strTOUID, intCount))
                    {
                        blnCorrectID = false;
                    }
                }
                //Check that there is a least one char after the TOU ID
                if (!(strTOUID.Length < (objFile.Name.Length -
                                         objFile.Extension.Length)))
                {
                    blnCorrectID = false;
                }

                //if the collection needs to be filtered
                if (null != strDevice)
                {
                    blnCorrectID = false;

                    //Create a new XmlDocument and load the file
                    xmldomSchedule = new XmlDocument();
                    xmldomSchedule.Load(objFile.FullName);

                    //Get the SupportedDevice nodes from the xml document and check for the
                    //given device name
                    xmlnodelistDevices = xmldomSchedule.GetElementsByTagName(
                        "SupportedDevice");
                    for (int intCount = 0; intCount < xmlnodelistDevices.Count &&
                         blnCorrectID == false; intCount++)
                    {
                        if (strDevice == xmlnodelistDevices[intCount].InnerText)
                        {
                            blnCorrectID = true;
                        }
                        else if (strDevice == SENTINEL_ADVANCED)
                        {
                            // If the device has reported itself as a SENTINEL advanced schedule, then it should support the
                            //  SENTINEL - Basic as well.
                            if (SENTINEL_BASIC == xmlnodelistDevices[intCount].InnerText)
                            {
                                blnCorrectID = true;
                            }
                        }
                        else if (((CENTRON_POLY_DEVICE == strDevice) ||
                                  (CENTRON_POLY_DEVICE_OBSOLETE == strDevice)) &&
                                 ((CENTRON_POLY_DEVICE == xmlnodelistDevices[intCount].InnerText) ||
                                  (CENTRON_POLY_DEVICE_OBSOLETE == xmlnodelistDevices[intCount].InnerText)))
                        {
                            // Depending on the version of the msxml DOM object the file was
                            // saved with, the CENTRON (V&I) string can have 2 formats.
                            // Support both
                            blnCorrectID = true;
                        }
                        else if (strDevice == VECTRON ||
                                 strDevice == CENTRON ||
                                 strDevice == FULCRUM ||
                                 strDevice == QUANTUM ||
                                 strDevice == MT200)
                        {
                            //This is an SCS device so make sure any of these are supported
                            if (xmlnodelistDevices[intCount].InnerText == VECTRON ||
                                xmlnodelistDevices[intCount].InnerText == CENTRON ||
                                xmlnodelistDevices[intCount].InnerText == FULCRUM ||
                                xmlnodelistDevices[intCount].InnerText == QUANTUM ||
                                xmlnodelistDevices[intCount].InnerText == MT200)
                            {
                                //The device type is an SCS device and at least one of the
                                //SCS devices are supported so we can continue
                                blnCorrectID = true;
                            }
                        }
                    }
                }

                //If the first 4 chars are digits then get the info for the
                //CTOUScheduleFile class
                if (blnCorrectID)
                {
                    intTOUID = int.Parse(strTOUID);
                    strName  = objFile.Name.Substring(4, objFile.Name.Length - 4);
                    strName  = strName.Remove(strName.Length - objFile.Extension.Length,
                                              objFile.Extension.Length);
                    strFilePath = objFile.FullName;

                    //Create a new CTOUScheduleFile from the File info object
                    objSchedule = new CTOUScheduleFile(intTOUID, strName, strFilePath);

                    //Add the CTOUScheduleFile to the collection
                    InnerList.Add(objSchedule);
                }
            }
        }        //Refresh()