Example #1
0
        public bool LoadFromXML(XmlNode node)
        {
            if (node.Name == "request" && node["name"] != null)
            {
                Name = node["name"].InnerText;
                bool isinitial = false;
                if (node["isinitial"] != null)
                    if (!bool.TryParse(node["isinitial"].InnerText, out isinitial))
                        isinitial = false;
                IsInitial = isinitial;
                if (node["params"] != null)
                {
                    XmlElement prs = node["params"];

                    foreach (XmlNode param in prs.ChildNodes)
                    {
                        ProjectScheduleRequestParameter psrp = new ProjectScheduleRequestParameter();
                        psrp.LoadFromXML(param);
                        Parameters.Items.Add(psrp);
                    }
                }

                return true;
            }

            return false;
        }
Example #2
0
        public bool LoadFromXML(string filename)
        {
            if (!System.IO.File.Exists(filename)) return false;

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(filename);

            XmlElement root = xmldoc["project"];

            if (root == null) return false;

            if (root["name"] == null || root["id"] == null) return false;

            name = root["name"].InnerText;
            id = root["id"].InnerText;

            if (root["startfrom"] != null)
            {
                try
                {
                    startFrom = DateTime.ParseExact(root["startfrom"].ToString(), "dd.MM.yyyy", null);
                }
                catch
                {
                    startFrom = DateTime.Now;
                }
            }

            XmlElement schedules = root["schedules"];

            if (schedules == null) return false;

            foreach (XmlNode node in schedules.ChildNodes)
            {
                if (node.Name.ToLower() != "schedule") return false;

                XmlNode provider = node["provider"];
                XmlNode start = node["start"];
                XmlNode interval = node["interval"];

                if (provider == null) return false;

                DateTime st = DateTime.Now;
                if (!DateTime.TryParse(start.InnerText, out st))
                    st = DateTime.Now;



                string it = "daily";
                if (interval.InnerText == "daily" ||
                    interval.InnerText == "hourly" ||
                    interval.InnerText == "weekly")
                    it = interval.InnerText;

                ProjectSchedule ps = new ProjectSchedule();
                ps.ParentProject = this;
                ps.Provider = (APIServiceProvider)SyncManager.Providers.ServiceProviders[provider.InnerText];
                ps.Interval = it;
                ps.StartAt = st;
                ps.LastExecutedAt = st;

                XmlElement requests = node["requests"];

                if (requests != null)
                {
                    foreach (XmlNode nd in requests.ChildNodes)
                    {
                        if (nd.Name == "request" && nd["name"] != null)
                        {
                            ProjectScheduleRequest psr = new ProjectScheduleRequest();
                            psr.Schedule = ps;
                            psr.Name = nd["name"].InnerText;
                            bool isinitial = false;
                            if (nd["isinitial"] != null)
                                if (!bool.TryParse(nd["isinitial"].InnerText, out isinitial))
                                    isinitial = false;
                            psr.IsInitial = isinitial;
                            if (nd["params"] != null)
                            {
                                XmlElement prs = nd["params"];

                                foreach (XmlNode param in prs.ChildNodes)
                                {
                                    if (param["name"] != null && param["type"] != null && param["value"] != null)
                                    {
                                        ProjectScheduleRequestParameter psrp = new ProjectScheduleRequestParameter();
                                        psrp.Name = param["name"].InnerText;
                                        psrp.Type = param["type"].InnerText;
                                        psrp.Value = param["value"].InnerText;
                                        if (param["format"] != null)
                                            psrp.Format = param["format"].InnerText;
                                        psr.Parameters.Items.Add(psrp);
                                    }
                                }
                            }

                            ps.Requests.Items.Add(psr);
                        }
                    }
                }

                Schedules.Items.Add(ps);
            }

            return true;
        }