示例#1
0
        public static bool SetEnterpriseDefaultScripts(List <DefaultScriptRegistryFile> defaultScriptRegs, List <string> groupMemberships)
        {
            DefaultScriptRegistryFile defaultReg = GetApplicableDefaultScriptReg(defaultScriptRegs, groupMemberships);

            if (defaultReg == null)
            {
                return(false);
            }

            if (!ValidateLocalToEnterprise(SqlBuildFileHelper.DefaultScriptXmlFile, Path.Combine(defaultReg.Path, defaultReg.FileName)))
            {
                if (!CopyEnterpriseToLocal(SqlBuildFileHelper.DefaultScriptXmlFile, Path.Combine(defaultReg.Path, defaultReg.FileName)))
                {
                    return(false);
                }
            }

            sb.DefaultScriptRegistry reg = GetEnterpriseRegistrySetting(SqlBuildFileHelper.DefaultScriptXmlFile);
            if (reg == null)
            {
                return(false);
            }

            if (reg.Items == null)
            {
                log.LogWarning($"The enterprise default script registry file contains no default script items! ({Path.Combine(defaultReg.Path, defaultReg.FileName)}");
                return(false);
            }

            string localScriptPath = Path.GetDirectoryName(SqlBuildFileHelper.DefaultScriptXmlFile);

            foreach (sb.DefaultScript item in reg.Items)
            {
                if (!ValidateLocalToEnterprise(Path.Combine(localScriptPath, item.ScriptName), Path.Combine(defaultReg.Path, item.ScriptName)))
                {
                    CopyEnterpriseToLocal(Path.Combine(localScriptPath, item.ScriptName), Path.Combine(defaultReg.Path, item.ScriptName));
                }
            }


            return(true);
        }
示例#2
0
 internal static sb.DefaultScriptRegistry GetEnterpriseRegistrySetting(string filePath)
 {
     sb.DefaultScriptRegistry registry = null;
     log.LogDebug($"Deserializing DefaultScriptRegistry file from '{filePath}'");
     try
     {
         using (StreamReader sr = new StreamReader(filePath))
         {
             System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(sb.DefaultScriptRegistry));
             object obj = serializer.Deserialize(sr);
             registry = (sb.DefaultScriptRegistry)obj;
             sr.Close();
         }
     }
     catch (Exception exe)
     {
         log.LogError(exe, $"Unable to deserialize the DefaultScriptRegistry object XML file at {filePath}");
     }
     return(registry);
 }