Exemplo n.º 1
0
        private static string GetManageScript(ManageParams manageParams)
        {
            StringBuilder sb = new StringBuilder();

            if (manageParams.EnableClr)
            {
                sb.AppendLine(PwrSqlClrCommandBuilder.EnableClr_CommandText());
            }

            if (manageParams.TrustworthyOn)
            {
                sb.AppendLine(PwrSqlClrCommandBuilder.TrustworthyOn_CommandText());
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        private static void Deploy(string[] args)
        {
            DeployCommand deployCommand = ParseDeployCommand(args[0]);
            string        scriptText    = string.Empty;

            string connectionString = args
                                      .Skip(1)
                                      .Take(args.Length - 2)
                                      .FirstOrDefault(t => t.ToLower().StartsWith(key_Connection))
                                      .With(t => t == null ? null : t.Substring(key_Connection.Length));

            string scriptPath = args
                                .Skip(1)
                                .Take(args.Length - (deployCommand == DeployCommand.Manage ? 1 : 2))
                                .FirstOrDefault(t => t.ToLower().StartsWith(key_Script))
                                .With(t => t == null ? null : t.Substring(key_Script.Length));

            if (deployCommand == DeployCommand.Manage)
            {
                ManageParams manageParams = new ManageParams();

                manageParams.EnableClr = args
                                         .Skip(1)
                                         .Take(args.Length - 2)
                                         .Any(t => t.ToLower().Equals(key_EnableClr));

                manageParams.TrustworthyOn = args
                                             .Skip(1)
                                             .Take(args.Length - 2)
                                             .Any(t => t.ToLower().Equals(key_Trustworthy));

                scriptText = GetManageScript(manageParams);
            }
            else
            {
                DeployParams deployParams = new DeployParams();

                deployParams.PermissionSet = args
                                             .Skip(1)
                                             .Take(args.Length - 2)
                                             .FirstOrDefault(t => t.ToLower().StartsWith(key_Permission))
                                             .With(t => t == null ? default(PermissionSet?) : ParsePermissionSet(t.Substring(key_Permission.Length)));

                deployParams.Owner = args
                                     .Skip(1)
                                     .Take(args.Length - 2)
                                     .FirstOrDefault(t => t.ToLower().StartsWith(key_Owner))
                                     .With(t => t == null ? null : t.Substring(key_Owner.Length));

                deployParams.Schema = args
                                      .Skip(1)
                                      .Take(args.Length - 2)
                                      .FirstOrDefault(t => t.ToLower().StartsWith(key_Schema))
                                      .With(t => t == null ? null : t.Substring(key_Schema.Length));

                deployParams.UncheckedData = args
                                             .Skip(1)
                                             .Take(args.Length - 2)
                                             .Any(t => t.ToLower().Equals(key_Unchecked));

                deployParams.Assembly = args
                                        .Skip(1)
                                        .Take(args.Length - 2)
                                        .FirstOrDefault(t => t.ToLower().StartsWith(key_Assembly))
                                        .With(t => t == null ? null : t.Substring(key_Assembly.Length));

                deployParams.Reference = args
                                         .Skip(1)
                                         .Take(args.Length - 2)
                                         .Any(t => t.ToLower().Equals(key_Invisible));

                deployParams.Strong = args
                                      .Skip(1)
                                      .Take(args.Length - 2)
                                      .Any(t => t.ToLower().Equals(key_Strong));

                string mapPath = args
                                 .Skip(1)
                                 .Take(args.Length - 2)
                                 .FirstOrDefault(t => t.ToLower().StartsWith(map_Script))
                                 .With(t => t == null ? null : t.Substring(map_Script.Length));

                deployParams.Map = string.IsNullOrEmpty(mapPath) ? new Dictionary <string, string>() :
                                   File.ReadAllLines(mapPath)
                                   .Select(s => s.Split(';'))
                                   .Where(t => t.Length == 2 && !string.IsNullOrWhiteSpace(t[0]) && !string.IsNullOrWhiteSpace(t[1]))
                                   .ToDictionary(t => t[0], t => t[1]);

                Assembly assembly = deployParams.Strong ? Assembly.Load(args[args.Length - 1]) : Assembly.LoadFrom(args[args.Length - 1]);

                switch (deployCommand)
                {
                case DeployCommand.Register:
                    scriptText = GetCreateScript(assembly, deployParams);
                    break;

                case DeployCommand.Unregister:
                    scriptText = GetDropScript(assembly, deployParams);
                    break;

                case DeployCommand.Modify:
                    scriptText = GetAlterScript(assembly, deployParams);
                    break;
                }
            }

            if (!string.IsNullOrWhiteSpace(scriptPath))
            {
                bool append = args
                              .Skip(1)
                              .Take(args.Length - 2)
                              .Any(t => t.ToLower().Equals(key_Append));

                string encoding = args
                                  .Skip(1)
                                  .Take(args.Length - 2)
                                  .FirstOrDefault(t => t.ToLower().StartsWith(key_Encoding))
                                  .With(t => t == null ? null : t.Substring(key_Encoding.Length));

                SaveScript(scriptPath, scriptText, encoding, append);
            }

            if (!string.IsNullOrWhiteSpace(connectionString))
            {
                ExecuteScript(connectionString, scriptText);
            }
        }