public async void DeployWithSqlCmdVariables() { var result = GetLiveAutoCompleteTestObjects(); SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, query : storedProcScript, dbNamePrefix : "DacFxDeploySqlCmdVarsTest"); SqlTestDb targetDb = null; try { DacFxService service = new DacFxService(); // First extract a db to have a dacpac to deploy later string dacpacPath = InitialExtract(service, sourceDb, result); // Deploy the created dacpac with SqlCmdVars var deployParams = new DeployParams { PackageFilePath = dacpacPath, DatabaseName = string.Concat(sourceDb.DatabaseName, "-deployed"), UpgradeExisting = false, SqlCommandVariableValues = new Dictionary <string, string>() { { databaseRefVarName, "OtherDatabase" }, { filterValueVarName, "Employee" } } }; DeployOperation deployOperation = new DeployOperation(deployParams, result.ConnectionInfo); service.PerformOperation(deployOperation, TaskExecutionMode.Execute); targetDb = SqlTestDb.CreateFromExisting(deployParams.DatabaseName); string deployedProc; using (SqlConnection conn = new SqlConnection(targetDb.ConnectionString)) { try { await conn.OpenAsync(); deployedProc = (string)ReliableConnectionHelper.ExecuteScalar(conn, "SELECT OBJECT_DEFINITION (OBJECT_ID(N'Procedure1'));"); } finally { conn.Close(); } } Assert.Contains(deployParams.SqlCommandVariableValues[databaseRefVarName], deployedProc); Assert.Contains(deployParams.SqlCommandVariableValues[filterValueVarName], deployedProc); VerifyAndCleanup(dacpacPath); } finally { sourceDb.Cleanup(); if (targetDb != null) { targetDb.Cleanup(); } } }
private async Task <Mock <RequestContext <DacFxResult> > > SendAndValidateDeployRequest() { // first extract a db to have a dacpac to import later var result = GetLiveAutoCompleteTestObjects(); var extractRequestContext = new Mock <RequestContext <DacFxResult> >(); extractRequestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object())); SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxDeployTest"); string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest"); Directory.CreateDirectory(folderPath); var extractParams = new ExtractParams { DatabaseName = sourceDb.DatabaseName, PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)), ApplicationName = "test", ApplicationVersion = "1.0.0.0" }; DacFxService service = new DacFxService(); ExtractOperation extractOperation = new ExtractOperation(extractParams, result.ConnectionInfo); service.PerformOperation(extractOperation); // deploy the created dacpac var deployRequestContext = new Mock <RequestContext <DacFxResult> >(); deployRequestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object())); var deployParams = new DeployParams { PackageFilePath = extractParams.PackageFilePath, DatabaseName = string.Concat(sourceDb.DatabaseName, "-deployed"), UpgradeExisting = false }; DeployOperation deployOperation = new DeployOperation(deployParams, result.ConnectionInfo); service.PerformOperation(deployOperation); SqlTestDb targetDb = SqlTestDb.CreateFromExisting(deployParams.DatabaseName); // cleanup VerifyAndCleanup(extractParams.PackageFilePath); sourceDb.Cleanup(); targetDb.Cleanup(); return(deployRequestContext); }
public async void DeployDacpac() { // first extract a db to have a dacpac to import later var result = GetLiveAutoCompleteTestObjects(); SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxDeployTest"); SqlTestDb targetDb = null; string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest"); Directory.CreateDirectory(folderPath); try { var extractParams = new ExtractParams { DatabaseName = sourceDb.DatabaseName, PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)), ApplicationName = "test", ApplicationVersion = "1.0.0.0" }; DacFxService service = new DacFxService(); ExtractOperation extractOperation = new ExtractOperation(extractParams, result.ConnectionInfo); service.PerformOperation(extractOperation, TaskExecutionMode.Execute); // deploy the created dacpac var deployParams = new DeployParams { PackageFilePath = extractParams.PackageFilePath, DatabaseName = string.Concat(sourceDb.DatabaseName, "-deployed"), UpgradeExisting = false }; DeployOperation deployOperation = new DeployOperation(deployParams, result.ConnectionInfo); service.PerformOperation(deployOperation, TaskExecutionMode.Execute); targetDb = SqlTestDb.CreateFromExisting(deployParams.DatabaseName); VerifyAndCleanup(extractParams.PackageFilePath); } finally { sourceDb.Cleanup(); if (targetDb != null) { targetDb.Cleanup(); } } }
/// <summary> /// Handles request to deploy a dacpac /// </summary> /// <returns></returns> public async Task HandleDeployRequest(DeployParams parameters, RequestContext <DacFxResult> requestContext) { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection( parameters.OwnerUri, out connInfo); if (connInfo != null) { DeployOperation operation = new DeployOperation(parameters, connInfo); ExecuteOperation(operation, parameters, SR.DeployDacpacTaskName, requestContext); } } catch (Exception e) { await requestContext.SendError(e); } }
/// <summary> /// Handles request to deploy a dacpac /// </summary> /// <returns></returns> public async Task HandleDeployRequest(DeployParams parameters, RequestContext <DacFxResult> requestContext) { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection( parameters.OwnerUri, out connInfo); if (connInfo != null) { SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connInfo, "Deploy"); DeployOperation operation = new DeployOperation(parameters, sqlConn); await ExecuteOperation(operation, parameters, "Deploy dacpac", requestContext); } } catch (Exception e) { await requestContext.SendError(e); } }
public DeployOperation(DeployParams parameters, ConnectionInfo connInfo) : base(connInfo) { Validate.IsNotNull("parameters", parameters); this.Parameters = parameters; }
public void Deploy() { String code = "scilla_version 0\n" + "\n" + " (* HelloWorld contract *)\n" + "\n" + " import ListUtils\n" + "\n" + " (***************************************************)\n" + " (* Associated library *)\n" + " (***************************************************)\n" + " library HelloWorld\n" + "\n" + " let one_msg =\n" + " fun (msg : Message) =>\n" + " let nil_msg = Nil {Message} in\n" + " Cons {Message} msg nil_msg\n" + "\n" + " let not_owner_code = Int32 1\n" + " let set_hello_code = Int32 2\n" + "\n" + " (***************************************************)\n" + " (* The contract definition *)\n" + " (***************************************************)\n" + "\n" + " contract HelloWorld\n" + " (owner: ByStr20)\n" + "\n" + " field welcome_msg : String = \"\"\n" + "\n" + " transition setHello (msg : String)\n" + " is_owner = builtin eq owner _sender;\n" + " match is_owner with\n" + " | False =>\n" + " msg = {_tag : \"Main\"; _recipient : _sender; _amount : Uint128 0; code : not_owner_code};\n" + " msgs = one_msg msg;\n" + " send msgs\n" + " | True =>\n" + " welcome_msg := msg;\n" + " msg = {_tag : \"Main\"; _recipient : _sender; _amount : Uint128 0; code : set_hello_code};\n" + " msgs = one_msg msg;\n" + " send msgs\n" + " end\n" + " end\n" + "\n" + "\n" + " transition getHello ()\n" + " r <- welcome_msg;\n" + " e = {_eventname: \"getHello()\"; msg: r};\n" + " event e\n" + " end"; List <Values> init = new List <Values>() { new Values() { Type = "Uint32", Value = "0", VName = "_scilla_version" }, new Values() { Type = "ByStr20", Value = "0x9bfec715a6bd658fcb62b0f8cc9bfa2ade71434a", VName = "owner" }, }; Wallet wallet = new Wallet(); wallet.AddByPrivateKey("e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930"); ContractFactory factory = new ContractFactory() { Provider = new HttpProvider("https://api.zilliqa.com/"), Signer = wallet }; LaksaCsharp.Contract.Contract contract = factory.NewContract(code, (Values[])init.ToArray(), ""); DeployParams deployParams = new DeployParams() { GasLimit = "10000", GasPrice = "1000000000", SenderPubKey = "0246e7178dc8253201101e18fd6f6eb9972451d121fc57aa2a06dd5c111e58dc6a", Version = Wallet.Pack(2, 8).ToString() }; Tuple <Transaction, LaksaCsharp.Contract.Contract> result = contract.Deploy(deployParams, 300, 3); Console.WriteLine("result is: " + result.ToString()); String transactionFee = new BigInteger(result.Item1.Receipt.Cumulative_gas).Multiply(new BigInteger(result.Item1.GasPrice)).ToString(); Console.WriteLine("transaction fee is: " + transactionFee); }
public DeployOperation(DeployParams parameters, SqlConnection sqlConnection) : base(sqlConnection) { Validate.IsNotNull("parameters", parameters); this.Parameters = parameters; }