Exemple #1
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            LayoutSchedule compare = obj as LayoutSchedule;

            return(id == compare.id &&
                   scheduleid == compare.scheduleid &&
                   FromDt.Ticks == compare.FromDt.Ticks &&
                   ToDt.Ticks == compare.ToDt.Ticks);
        }
Exemple #2
0
        /// <summary>
        /// Sets an empty schedule into the _layoutSchedule Collection
        /// </summary>
        private void SetEmptySchedule()
        {
            Debug.WriteLine("Setting an empty schedule", LogType.Info.ToString());

            // Remove the existing schedule
            _layoutSchedule.Clear();

            // Schedule up the default
            LayoutSchedule temp = new LayoutSchedule();

            temp.layoutFile = ApplicationSettings.Default.LibraryPath + @"\Default.xml";
            temp.id         = 0;
            temp.scheduleid = 0;

            _layoutSchedule.Add(temp);
        }
Exemple #3
0
        /// <summary>
        /// Sets an empty schedule into the _layoutSchedule Collection
        /// </summary>
        private void SetEmptySchedule()
        {
            Debug.WriteLine("Setting an empty schedule", LogType.Info.ToString());

            // Remove the existing schedule
            _layoutSchedule.Clear();

            // Schedule up the default
            LayoutSchedule temp = new LayoutSchedule();
            temp.layoutFile = Properties.Settings.Default.LibraryPath + @"\Default.xml";
            temp.id = 0;
            temp.scheduleid = 0;

            _layoutSchedule.Add(temp);
        }
Exemple #4
0
        /// <summary>
        /// Loads the schedule from file.
        /// </summary>
        /// <returns></returns>
        private void LoadScheduleFromFile()
        {
            // Empty the current schedule collection
            _layoutSchedule.Clear();

            // Get the schedule XML
            XmlDocument scheduleXml = GetScheduleXml();

            // Parse the schedule xml
            XmlNodeList nodes = scheduleXml["schedule"].ChildNodes;

            // Are there any nodes in the document
            if (nodes.Count == 0)
            {
                SetEmptySchedule();
                return;
            }

            // We have nodes, go through each one and add them to the layoutschedule collection
            foreach (XmlNode node in nodes)
            {
                LayoutSchedule temp = new LayoutSchedule();

                // Node name
                temp.NodeName = node.Name;

                // Pull attributes from layout nodes
                XmlAttributeCollection attributes = node.Attributes;

                // All nodes have file properties
                temp.layoutFile = attributes["file"].Value;

                // Replace the .xml extension with nothing
                string replace = ".xml";
                string layoutFile = temp.layoutFile.TrimEnd(replace.ToCharArray());

                // Set these on the temp layoutschedule
                temp.layoutFile = Properties.Settings.Default.LibraryPath + @"\" + layoutFile + @".xlf";
                temp.id = int.Parse(layoutFile);

                // Get attributes that only exist on the default
                if (temp.NodeName != "default")
                {
                    // Priority flag
                    temp.Priority = (attributes["priority"].Value == "1") ? true : false;

                    // Get the fromdt,todt
                    temp.FromDt = DateTime.Parse(attributes["fromdt"].Value);
                    temp.ToDt = DateTime.Parse(attributes["todt"].Value);

                    // Pull out the scheduleid if there is one
                    string scheduleId = "";
                    if (attributes["scheduleid"] != null) scheduleId = attributes["scheduleid"].Value;

                    // Add it to the layout schedule
                    if (scheduleId != "") temp.scheduleid = int.Parse(scheduleId);
                }

                _layoutSchedule.Add(temp);
            }

            // Clean up
            nodes = null;
            scheduleXml = null;

            // We now have the saved XML contained in the _layoutSchedule object
        }
Exemple #5
0
        /// <summary>
        /// Loads a new schedule from _layoutSchedules
        /// </summary>
        /// <returns></returns>
        private Collection<LayoutSchedule> LoadNewSchdule()
        {
            // We need to build the current schedule from the layout schedule (obeying date/time)
            Collection<LayoutSchedule> newSchedule = new Collection<LayoutSchedule>();
            Collection<LayoutSchedule> prioritySchedule = new Collection<LayoutSchedule>();

            // Temporary default Layout incase we have no layout nodes.
            LayoutSchedule defaultLayout = new LayoutSchedule();

            // For each layout in the schedule determine if it is currently inside the _currentSchedule, and whether it should be
            foreach (LayoutSchedule layout in _layoutSchedule)
            {
                // Is the layout valid in the cachemanager?
                try
                {
                    if (!_cacheManager.IsValidLayout(layout.id + ".xlf"))
                        continue;
                }
                catch
                {
                    // TODO: Ignore this layout.. raise an error?
                    Trace.WriteLine("Unable to determine if layout is valid or not");
                    continue;
                }

                // If this is the default, skip it
                if (layout.NodeName == "default")
                {
                    // Store it before skipping it
                    defaultLayout = layout;
                    continue;
                }

                // Look at the Date/Time to see if it should be on the schedule or not
                if (layout.FromDt <= DateTime.Now && layout.ToDt >= DateTime.Now)
                {
                    // Priority layouts should generate their own list
                    if (layout.Priority)
                    {
                        prioritySchedule.Add(layout);
                    }
                    else
                    {
                        newSchedule.Add(layout);
                    }
                }
            }

            // If we have any priority schedules then we need to return those instead
            if (prioritySchedule.Count > 0)
                return prioritySchedule;

            // If the current schedule is empty by the end of all this, then slip the default in
            if (newSchedule.Count == 0)
                newSchedule.Add(defaultLayout);

            return newSchedule;
        }
Exemple #6
0
        /// <summary>
        /// Loads the schedule from file.
        /// </summary>
        /// <returns></returns>
        private void LoadScheduleFromFile()
        {
            // Empty the current schedule collection
            _layoutSchedule.Clear();

            // Get the schedule XML
            XmlDocument scheduleXml = GetScheduleXml();

            // Parse the schedule xml
            XmlNodeList nodes = scheduleXml["schedule"].ChildNodes;

            // Are there any nodes in the document
            if (nodes.Count == 0)
            {
                SetEmptySchedule();
                return;
            }

            // We have nodes, go through each one and add them to the layoutschedule collection
            foreach (XmlNode node in nodes)
            {
                LayoutSchedule temp = new LayoutSchedule();

                // Node name
                temp.NodeName = node.Name;

                if (temp.NodeName == "dependants")
                {
                    // Do nothing for now
                }
                else
                {
                    // Pull attributes from layout nodes
                    XmlAttributeCollection attributes = node.Attributes;

                    // All nodes have file properties
                    temp.layoutFile = attributes["file"].Value;

                    // Replace the .xml extension with nothing
                    string replace    = ".xml";
                    string layoutFile = temp.layoutFile.TrimEnd(replace.ToCharArray());

                    // Set these on the temp layoutschedule
                    temp.layoutFile = ApplicationSettings.Default.LibraryPath + @"\" + layoutFile + @".xlf";
                    temp.id         = int.Parse(layoutFile);

                    // Get attributes that only exist on the default
                    if (temp.NodeName != "default")
                    {
                        // Priority flag
                        temp.Priority = (attributes["priority"].Value == "1") ? true : false;

                        // Get the fromdt,todt
                        temp.FromDt = DateTime.Parse(attributes["fromdt"].Value, CultureInfo.InvariantCulture);
                        temp.ToDt   = DateTime.Parse(attributes["todt"].Value, CultureInfo.InvariantCulture);

                        // Pull out the scheduleid if there is one
                        string scheduleId = "";
                        if (attributes["scheduleid"] != null)
                        {
                            scheduleId = attributes["scheduleid"].Value;
                        }

                        // Add it to the layout schedule
                        if (scheduleId != "")
                        {
                            temp.scheduleid = int.Parse(scheduleId);
                        }

                        // Dependents
                        if (attributes["dependents"] != null && !string.IsNullOrEmpty(attributes["dependents"].Value))
                        {
                            foreach (string dependent in attributes["dependents"].Value.Split(','))
                            {
                                temp.Dependents.Add(dependent);
                            }
                        }
                    }

                    _layoutSchedule.Add(temp);
                }
            }

            // Clean up
            nodes       = null;
            scheduleXml = null;

            // We now have the saved XML contained in the _layoutSchedule object
        }
Exemple #7
0
        /// <summary>
        /// Loads a new schedule from _layoutSchedules
        /// </summary>
        /// <returns></returns>
        private Collection <LayoutSchedule> LoadNewSchdule()
        {
            // We need to build the current schedule from the layout schedule (obeying date/time)
            Collection <LayoutSchedule> newSchedule      = new Collection <LayoutSchedule>();
            Collection <LayoutSchedule> prioritySchedule = new Collection <LayoutSchedule>();

            // Temporary default Layout incase we have no layout nodes.
            LayoutSchedule defaultLayout = new LayoutSchedule();

            // For each layout in the schedule determine if it is currently inside the _currentSchedule, and whether it should be
            foreach (LayoutSchedule layout in _layoutSchedule)
            {
                if (!ApplicationSettings.Default.ExpireModifiedLayouts && layout.id == CurrentLayoutId)
                {
                    Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Skipping validity test for current layout."), LogType.Audit.ToString());
                }
                else
                {
                    // Is the layout valid in the cachemanager?
                    try
                    {
                        if (!_cacheManager.IsValidPath(layout.id + ".xlf"))
                        {
                            Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout invalid: " + layout.id), LogType.Info.ToString());
                            continue;
                        }
                    }
                    catch
                    {
                        // Ignore this layout.. raise an error?
                        Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Unable to determine if layout is valid or not"), LogType.Error.ToString());
                        continue;
                    }

                    // Check dependents
                    foreach (string dependent in layout.Dependents)
                    {
                        if (!string.IsNullOrEmpty(dependent) && !_cacheManager.IsValidPath(dependent))
                        {
                            Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout has invalid dependent: " + dependent), LogType.Info.ToString());
                            continue;
                        }
                    }
                }

                // If this is the default, skip it
                if (layout.NodeName == "default")
                {
                    // Store it before skipping it
                    defaultLayout = layout;
                    continue;
                }

                // Look at the Date/Time to see if it should be on the schedule or not
                if (layout.FromDt <= DateTime.Now && layout.ToDt >= DateTime.Now)
                {
                    // Priority layouts should generate their own list
                    if (layout.Priority)
                    {
                        prioritySchedule.Add(layout);
                    }
                    else
                    {
                        newSchedule.Add(layout);
                    }
                }
            }

            // If we have any priority schedules then we need to return those instead
            if (prioritySchedule.Count > 0)
            {
                return(prioritySchedule);
            }

            // If the current schedule is empty by the end of all this, then slip the default in
            if (newSchedule.Count == 0)
            {
                newSchedule.Add(defaultLayout);
            }

            return(newSchedule);
        }