Exemplo n.º 1
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            string xmla                = request.DataStore.GetValue("xmlaFilePath");
            string asDatabase          = request.DataStore.GetValue("ASDatabase");
            string sqlConnectionString = request.DataStore.GetValue("SqlConnectionString");
            var    connectionStringObj = SqlUtility.GetSqlCredentialsFromConnectionString(sqlConnectionString);
            string connectionString    = request.DataStore.GetValue("ASConnectionString");

            Server server = new Server();

            server.Connect(connectionString);

            string xmlaContents = File.ReadAllText(request.Info.App.AppFilePath + "/" + xmla);

            var obj = JsonUtility.GetJsonObjectFromJsonString(xmlaContents);

            obj["create"]["database"]["name"] = asDatabase;
            //obj["create"]["database"]["model"]["dataSources"][0]["name"] = "Sql Connection for" + asDatabase;
            obj["create"]["database"]["model"]["dataSources"][0]["connectionString"] =
                $"Provider=SQLNCLI11.1;Persist Security Info=False;User ID={connectionStringObj.Username};Password={connectionStringObj.Password};" +
                $"Initial Catalog={connectionStringObj.Database};Data Source=tcp:{connectionStringObj.Server};Initial File Name=;Server SPN=";


            //Delete existing
            var db = server.Databases.Find(asDatabase);

            db?.Drop(DropOptions.Default);
            server.Refresh(true);

            //Deploy
            var response = server.Execute(obj.ToString());

            if (response.ContainsErrors)
            {
                return(new ActionResponse(ActionStatus.Failure, response[0].Value));
            }

            server = new Server();
            server.Connect(connectionString);
            db = server.Databases.Find(asDatabase);
            if (db == null)
            {
                return(new ActionResponse(ActionStatus.Failure, string.Empty, null, null, "AS Database was not deployed"));
            }

            return(new ActionResponse(ActionStatus.Success));
        }
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            string connectionString = request.DataStore.GetValue("ASConnectionString");

            AzureUtility.GetEmailFromToken(request.DataStore.GetJson("AzureToken"));
            string asDatabase = request.DataStore.GetValue("ASDatabase");

            Server server = new Server();

            server.Connect(connectionString);

            // Process
            var db = server.Databases.Find(asDatabase);

            db.Model.RequestRefresh(RefreshType.Full);
            db.Model.SaveChanges();
            return(new ActionResponse(ActionStatus.Success));
        }