Пример #1
0
        /// <summary>
        /// Load Configuration Edit Rules.
        /// </summary>
        public void LoadConfigurationEditRules()
        {
            string    fileSpec = String.Format(@"{0}{1}.xml", Administrator.ProfileManager.SystemProfile.CloneConfigurationPath, RunMode);
            XDocument doc      = XDocument.Load(fileSpec);

            foreach (XElement step in doc.Descendants("Step"))
            {
                //Edit Rules.
                _editRules     = new SortedDictionary <string, EditRule>();
                _editRuleCount = 0;
                foreach (XElement edits in step.Descendants("Edits"))
                {
                    foreach (XElement rule in edits.Descendants("Edit"))
                    {
                        string active = (string)rule.Attribute("Active");
                        if (IsAffirmative(active))
                        {
                            string find        = (string)rule.Attribute("Find");
                            string replacement = (string)rule.Attribute("Replacement");
                            if (find.Length > 0 && replacement.Length > 0)
                            {
                                if (!_editRules.ContainsKey(find))
                                {
                                    _editRuleCount++;
                                    var editRUle = new EditRule(find, replacement, _editRuleCount);
                                    _editRules.Add(editRUle.Order, editRUle);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
 private void XCopyModels(DirectoryInfo sourceDirectory, DirectoryInfo targetDirectory)
 {
     if (DirectoryExclusionsHelper.AllowDirectory(sourceDirectory.FullName))
     {
         if (!Directory.Exists(targetDirectory.FullName))
         {
             Directory.CreateDirectory(targetDirectory.FullName);
         }
         _log.WriteLn();
         _log.WriteTimedMsg("000", "I", String.Format(@"Copy From : ""{0}""", sourceDirectory.ToString()));
         _log.WriteTimedMsg("000", "I", String.Format(@"Copy To   : ""{0}""", targetDirectory.ToString()));
         foreach (FileInfo fi in sourceDirectory.GetFiles())
         {
             if (true)
             {
                 if (_action != "Cancel")
                 {
                     string sourceFileName  = fi.Name;
                     string sourceClassName = fi.Name;
                     string ext             = fi.Extension;
                     int    pos             = sourceClassName.LastIndexOf(ext);
                     if (pos != -1)
                     {
                         sourceClassName = sourceClassName.Substring(0, pos);
                     }
                     string targetClassName = sourceClassName + MODEL_CLASS_SUFFIX;
                     string targetFileName  = targetClassName + ext;
                     _apiToModelClassNameMapping.Add(sourceClassName, targetClassName);
                     _apiToModelClassNameEditRuleCount++;
                     var _apiToModelClassNameEditRule = new EditRule(sourceClassName, targetClassName, _apiToModelClassNameEditRuleCount);
                     _apiToModelClassNameEditRules.Add(_apiToModelClassNameEditRule.Order, _apiToModelClassNameEditRule);
                     try
                     {
                         string   targetFile     = System.IO.Path.Combine(targetDirectory.ToString(), targetFileName);
                         FileInfo targetFileInfo = new FileInfo(targetFile);
                         if (true)
                         {
                             try
                             {
                                 if (targetFileInfo.Exists)
                                 {
                                     targetFileInfo.IsReadOnly = false;
                                 }
                                 fi.CopyTo(System.IO.Path.Combine(targetDirectory.ToString(), targetFileName), true);
                                 targetFileInfo = new FileInfo(targetFile);
                                 if (targetFileInfo.Exists)
                                 {
                                     targetFileInfo.IsReadOnly = false;
                                 }
                                 _log.WriteTimedMsg("000", "I", String.Format(@"{0} - Copied", targetFileName));
                             }
                             catch (Exception ex)
                             {
                                 _log.WriteLn();
                                 _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Error : {1}{2}", targetFileName, Environment.NewLine, ex.Message));
                                 _log.WriteLn();
                             }
                         }
                     }
                     catch (Exception ex2)
                     {
                         _log.WriteLn();
                         _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Target File (Name too long) Error : {1}{2}", targetFileName, Environment.NewLine, ex2.Message));
                         _log.WriteLn();
                     }
                 }
             }
         }
         foreach (DirectoryInfo di in sourceDirectory.GetDirectories())
         {
             if (_action != "Cancel")
             {
                 try
                 {
                     if (DirectoryExclusionsHelper.AllowDirectory(di.FullName))
                     {
                         DirectoryInfo targetDirectoryInfo = targetDirectory.CreateSubdirectory(di.Name);
                         XCopyModels(di, targetDirectoryInfo);
                     }
                 }
                 catch (Exception ex)
                 {
                     _log.WriteLn();
                     _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Target Directory (Name too long) Error : {1}{2}", di.Name, Environment.NewLine, ex.Message));
                     _log.WriteLn();
                 }
             }
         }
     }
     //Check if user has chosen to cancel run.
     if (_action == "Cancel")
     {
         _log.WriteTimedMsg("000", "I", String.Format(@"XCopyModels cancelled"));
         return;
     }
 }