Example #1
0
        public bool LoadFromXML(string filename, LoadOptions lo)
        {
            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 cfs = root["coefs"];

            if (cfs != null && (lo == LoadOptions.All || lo == LoadOptions.Coefs))
            {
                coefs.Clear();
                foreach (XmlNode cf in cfs.ChildNodes)
                {
                    ProjectCoef pc = new ProjectCoef();
                    pc.CoefProject = this;
                    if (pc.LoadFromXML(cf))
                        coefs[pc.ProviderName] = pc;
                }
            }

            XmlElement schedules = root["schedules"];

            if (schedules == null) return false;

            if (lo == LoadOptions.All || lo == LoadOptions.Schedules)
            {
                Schedules.Items.Clear();
                foreach (XmlNode node in schedules.ChildNodes)
                {
                    if (node.Name.ToLower() != "schedule") continue;

                    ProjectSchedule ps = new ProjectSchedule();
                    ps.ParentProject = this;

                    if (ps.LoadFromXML(node))
                        Schedules.Items.Add(ps);
                }
            }

            return true;
        }
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;
        }