Пример #1
0
 public void Reset()
 {
     BatchFiles.Clear();
     Status = " ";
     Schedules.Clear();
     fields.Clear();
     ConObj.Clear();
 }
Пример #2
0
        public void LoadConfig(string ConfigFile)
        {
            Reset();
            XmlDocument map = new XmlDocument();

            #region SetXMLReader
            try
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings();
                readerSettings.IgnoreWhitespace             = true;
                readerSettings.IgnoreComments               = true;
                readerSettings.CheckCharacters              = true;
                readerSettings.CloseInput                   = true;
                readerSettings.IgnoreProcessingInstructions = false;
                readerSettings.ValidationFlags              = System.Xml.Schema.XmlSchemaValidationFlags.None;
                readerSettings.ValidationType               = ValidationType.None;
                XmlReader reader = XmlReader.Create(ConfigFile, readerSettings);

                map.Load(reader);
            }
            catch
            {
                Status = "Error Loading Config File. Please select a config file";
                return;
            }
            #endregion

            #region loadinputfile_and_counters

            XmlNodeList bl = map.SelectNodes("configuration/Source/Batch");
            foreach (XmlNode batchfile in bl)
            {
                Batch B = new Batch();
                B.BatchName  = batchfile.Attributes["Name"].Value;
                B.SourceFile = batchfile.Attributes["Path"].Value;
                B.SuccessLog = B.SourceFile.Insert(B.SourceFile.IndexOf("."), "_Success");
                B.ErrorLog   = B.SourceFile.Insert(B.SourceFile.IndexOf("."), "_Error");

                bool duplicate = BatchFiles.Any(item => item.SourceFile == B.SourceFile);
                if (duplicate)
                {
                    Status = "Duplicate Batch Files"; Reset(); return;
                }
                else
                {
                    BatchFiles.Add(B);
                }
            }

            #endregion

            #region loadDelimiter
            var delimnode = map.SelectSingleNode("configuration/Delimiter/Delimiter");
            delimiter = delimnode.Attributes["Character"].Value.ToCharArray().First();
            #endregion

            #region loadFields
            XmlNodeList fieldNodes = map.SelectNodes("configuration/FileMap/Field");
            //Loop through the nodes and create a field object
            // for each one.
            foreach (XmlNode fieldNode in fieldNodes)
            {
                Field field = new Field
                {
                    //Set the field's name
                    Name = fieldNode.Attributes["Name"].Value,

                    //Set the field's type
                    Type = fieldNode.Attributes["Type"].Value,
                };
                bool duplicate = fields.Any(item => item.Name == field.Name);
                if (duplicate)
                {
                    Status = "Duplicate Field Names"; Reset(); return;
                }
                else
                {
                    fields.Add(field);
                }
            }

            #endregion

            #region loadTimes

            Schedules.Clear();
            XmlNodeList b2 = map.SelectNodes("configuration/schedules");
            foreach (XmlNode node in b2)
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    List <TimeSlot> slots = new List <TimeSlot>();

                    foreach (XmlNode gchildNode in childNode)
                    {
                        TimeSlot t = new TimeSlot();
                        t.StartTime = gchildNode.Attributes["Start"].Value;
                        t.EndTime   = gchildNode.Attributes["End"].Value;
                        if (Convert.ToInt32(t.StartTime) > Convert.ToInt32(t.EndTime))
                        {
                            Status = "Start Time cannot be greater than End Time"; BatchFiles.Clear(); Schedules.Clear(); fields.Clear();   return;
                        }
                        else
                        {
                            slots.Add(t);
                        }
                    }
                    if (Schedules.ContainsKey(childNode.Name.ToString()))
                    {
                        Schedules[childNode.Name.ToString()] = slots;
                    }
                    else
                    {
                        Schedules.Add(childNode.Name.ToString(), slots);
                    }
                }
            }
            #endregion

            #region LoadConnection
            var     connname     = map.SelectSingleNode("configuration/System/connection");
            string  connectionid = connname.Attributes["Name"].Value.ToString();
            XmlNode conn         = map.SelectSingleNode("configuration/Connections/connection[@Name='" + connectionid + "']");


            foreach (XmlNode childnode in conn.ChildNodes)
            {
                var Param    = childnode.Name;
                var ParamVal = childnode.InnerText.ToString();
                ConObj.AddProperty(Param, ParamVal);
            }

            #endregion
        }