Beispiel #1
0
        public Template(string _projectPath, string _currentEnvironment)
        {
            this.projectPath        = _projectPath;
            this.currentEnvironment = _currentEnvironment;
            this.environmentsFile   = Path.Combine(this.projectPath, "ConfigResourceValue.xml");
            Dictionary <string, string> defaultConfig = new Dictionary <string, string>
            {
                {
                    "Key_RootNode",
                    "ConfigResourceValueRoot"
                },
                {
                    "Key_Environments",
                    "Environments"
                },
                {
                    "Key_Environment",
                    "Environment"
                },
                {
                    "Key_ConfigResourceValues",
                    "ConfigResourceValues"
                },
                {
                    "Key_CurrentEnvironment",
                    this.currentEnvironment
                }
            };

            this.Environments = TemplateEnvironment.GetEnvironments(this.environmentsFile, defaultConfig);
        }
Beispiel #2
0
        public void CloneFile(TemplateEnvironment _currentEnvironment)
        {
            foreach (KeyValuePair <string, string> replaceSignItem in this.replaceSign)
            {
                this.fileContent = this.fileContent.Replace(replaceSignItem.Key, _currentEnvironment.NodePairs[replaceSignItem.Value]);
            }
            string fileExtension = string.Format(".{0}", "tpl");
            string newFileName   = this.fileName.Replace(fileExtension, "");
            string newFilePath   = Path.Combine(this.fileDirectory, newFileName);

            File.WriteAllText(newFilePath, this.fileContent);
        }
Beispiel #3
0
        private List <string> PrintDifference(TemplateEnvironment source, TemplateEnvironment target)
        {
            List <string> differenceContents = new List <string>();

            foreach (KeyValuePair <string, string> sourceNodePair in source.NodePairs)
            {
                if (!target.NodePairs.ContainsKey(sourceNodePair.Key))
                {
                    string keyDifference = string.Format("{0}-{1}:{2}", source.EnvironmentName, target.EnvironmentName, sourceNodePair.Key);
                    differenceContents.Add(keyDifference);
                }
            }
            this.ResolveDifference(target, source, differenceContents);
            return(differenceContents);
        }
Beispiel #4
0
 private void ResolveDifference(TemplateEnvironment target, TemplateEnvironment source, List <string> differenceContents)
 {
     foreach (KeyValuePair <string, string> targetNodePair in target.NodePairs)
     {
         if (!source.NodePairs.ContainsKey(targetNodePair.Key))
         {
             string keyDifference = string.Format("{0}-{1}:{2}", source.EnvironmentName, target.EnvironmentName, targetNodePair.Key);
             if ((from difference in differenceContents
                  where difference.Equals(keyDifference)
                  select difference).Count <string>() == 0)
             {
                 differenceContents.Add(keyDifference);
             }
         }
     }
 }
Beispiel #5
0
        public ComplierMessage IsSame()
        {
            ComplierMessage     result = new ComplierMessage(true);
            TemplateEnvironment currentEnvironmentTemplate = (from template in this.Environments
                                                              where template.EnvironmentName.Equals(this.currentEnvironment)
                                                              select template).First <TemplateEnvironment>();

            foreach (TemplateEnvironment environmentTemplate in this.Environments)
            {
                if (!currentEnvironmentTemplate.Equals(environmentTemplate))
                {
                    result.Success = false;
                    result.ComplierMsg.AddRange(this.PrintDifference(currentEnvironmentTemplate, environmentTemplate));
                }
            }
            return(result);
        }
Beispiel #6
0
        internal static List <TemplateEnvironment> GetTemplateInfoFromFile()
        {
            List <TemplateEnvironment> templateEnvironments = new List <TemplateEnvironment>();
            string      environmentNodeSelect = string.Format("/{0}/{1}/{2}", "ConfigResourceValueRoot", "Environments", "Environment");
            string      resourceNodeSelect    = string.Format("/{0}/{1}/{2}", "ConfigResourceValueRoot", "ConfigResourceValues", "{0}");
            XmlNodeList environmentNodes      = TemplateEnvironment.templateXmlDocument.SelectNodes(environmentNodeSelect);

            foreach (XmlNode environmentNodeItem in environmentNodes)
            {
                TemplateEnvironment templateEnvironment = new TemplateEnvironment(environmentNodeItem.Attributes["Name"].Value.Trim());
                string      resourceEnvironmentSelect   = string.Format(resourceNodeSelect, templateEnvironment.environmentName);
                XmlNode     resourceEnvironmentNode     = TemplateEnvironment.templateXmlDocument.SelectSingleNode(resourceEnvironmentSelect);
                XmlNodeList resourceNodes = resourceEnvironmentNode.ChildNodes;
                foreach (XmlNode resourceNode in resourceNodes)
                {
                    templateEnvironment.keyNodesStack.Append(resourceNode.Name);
                    templateEnvironment.nodePairs.Add(resourceNode.Name, resourceNode.InnerText.Trim());
                }
                templateEnvironments.Add(templateEnvironment);
            }
            return(templateEnvironments);
        }
Beispiel #7
0
 public static List <TemplateEnvironment> GetEnvironments(string _templateFilePath, Dictionary <string, string> _defaultConfig)
 {
     TemplateEnvironment.templateXmlDocument.Load(_templateFilePath);
     TemplateEnvironment.defaultConfig = _defaultConfig;
     return(TemplateEnvironment.GetTemplateInfoFromFile());
 }
Beispiel #8
0
 public Configs(string _projectPath, TemplateEnvironment _currentEnvironment)
 {
     this.projectPath        = _projectPath;
     this.currentEnvironment = _currentEnvironment;
     this.TplFiles           = TplFile.GetTplFiles(this.projectPath);
 }