Example #1
0
        private void ProcessDeployment(DeployRequest model)
        {
            //Backup
            var backupFolder = Path.Combine(model.DestinationRootLocation, "_Backup",
                                            string.Format("{0}_{1}", model.DestinationProjectFolder, DateTime.Now.ToString("yyyyMMdd_hhmmss")));
            var projectPath = Path.Combine(model.DestinationRootLocation, model.DestinationProjectFolder);

            NotifyAndLog("Copying folder {0} to {1}...", projectPath, backupFolder);
            FileSystem.CopyDirectory(projectPath, backupFolder);

            //Copy files to project folder
            var source = Path.Combine(model.DropLocation, model.SourceSubFolder);

            NotifyAndLog("Deploying files from folder {0} to {1}...", source, projectPath);
            FileSystem.CopyDirectory(source, projectPath, true);

            //copy web.config
            var sourceConfig = Path.Combine(backupFolder, "Web.config");
            var destConfig   = Path.Combine(projectPath, "Web.config");

            NotifyAndLog("Copying {0} to {1}...", sourceConfig, destConfig);
            FileSystem.CopyFile(sourceConfig, destConfig, true);

            //update version number
            NotifyAndLog("Update application version number [{0}] to {1}", model.VersionKeyName, model.NextVersion);
            Helper.SetVersionNumber(destConfig, model.VersionKeyName, model.NextVersion);

            NotifyAndLog("Deployment process completed");
        }
Example #2
0
        public async Task <IActionResult> Deploy([FromBody] DeployRequest deployRequest)
        {
            _logger.LogInformation($"Downloading version with GUID '{deployRequest.VersionGuid}'...");

            var fileInfo = new FileInfo($"{deployRequest.VersionGuid}.zip");

            var response = await _httpClient.GetAsync($"{_options.DeployerUrl}{Routes.VersionDownload.Replace("{guid}", deployRequest.VersionGuid)}");

            response.EnsureSuccessStatusCode();
            await using var stream = await response.Content.ReadAsStreamAsync();

            await using var fileStream = System.IO.File.Create(fileInfo.FullName);
            stream.Seek(0, SeekOrigin.Begin);
            await stream.CopyToAsync(fileStream);

            _logger.LogInformation($"Version saved temporarily as '{fileInfo.Name}'.");

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                DeployToIIS(fileInfo, deployRequest.Projects);
            }).Start();

            return(Ok());
        }
Example #3
0
        public async Task <IActionResult> Index(String code, String username)
        {
            if (!String.IsNullOrEmpty(code))
            {
                token = await GetToken(client_id, "91c4df350fa87192ffc1d53468c1b2e4311c1d7f", code);

                HttpContext.Session.SetString("githubtoken", token);
            }
            else
            {
                Response.Redirect("https://github.com/login/oauth/authorize?client_id=" + client_id);
            }

            DeployRequest model = new DeployRequest()
            {
                Username     = "******",
                Repo         = "mythril-classic",
                Branch       = "develop",
                ContractPath = "solidity_examples",
                Contract     = "BecToken",
                Password     = "******",
                //Node = "https://rinkeby.infura.io",
                Node    = "http://121.210.77.231:8545",
                Network = "Rinkeby"
            };

            return(View(model));
        }
Example #4
0
        public async Task <IActionResult> Deploy(DeployRequest model)
        {
            try
            {
                var gitHubClient = new GitHubClient(new ProductHeaderValue(client_id));
                gitHubClient.Credentials = new Credentials(HttpContext.Session.GetString("githubtoken"));

                IReadOnlyList <RepositoryContent> contents = await gitHubClient.Repository.Content.GetAllContentsByRef(model.Username, model.Repo, model.ContractPath, model.Branch);

                String temp = Path.GetTempPath();

                foreach (RepositoryContent content in contents.Where(c => c.Name.EndsWith(".sol")))
                {
                    using (var client = new HttpClient())
                    {
                        var stream = await client.GetStreamAsync(content.DownloadUrl);

                        using (var fileStream = System.IO.File.Create(temp + content.Name))
                            using (var reader = new StreamReader(stream))
                            {
                                stream.CopyTo(fileStream);
                                fileStream.Flush();
                            }
                    }

                    //String hash = CheckHash(temp + content.Name);
                }

                var solcLib  = SolcLib.Create("");
                var compiled = solcLib.Compile(temp + model.Contract + ".sol", outputSelection);

                var output = compiled.Contracts[temp + model.Contract + ".sol"][model.Contract];

                DeployResult result = new DeployResult()
                {
                    JSON = output.AbiJsonString,
                    ABI  = "",
                    Bin  = BitConverter.ToString(output.Evm.Bytecode.ObjectBytes).Replace("-", String.Empty)
                };

                var account = new Wallet(model.Password, null).GetAccount(Convert.ToInt32(model.KeyFile));
                var web3    = new Nethereum.Web3.Web3(account, model.Node);

                result.TxID = await web3.Eth.DeployContract.SendRequestAsync(result.Bin, model.KeyFile, new Nethereum.Hex.HexTypes.HexBigInteger(model.Gas));

                return(View(result));
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                throw ex;
            }
        }
        public async Task <string> StartDeployingAsync(DeployRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(await m_Web3.Eth.DeployContract.SendRequestAsync(
                       request.Abi, request.Bin, Owner.Address, new HexBigInteger(request.GasLimit),
                       request.ConstructorArguments
                       .Select(x => x.ParsedValue)
                       .ToArray()));
        }
Example #6
0
        public HttpResponseMessage Post(DeployRequest request)
        {
            try
            {
                if (request == null || string.IsNullOrEmpty(request.TfsProjectName))
                {
                    NotifyAndLog("Deployment request is rejected because of invalid data");
                    return(new HttpResponseMessage(HttpStatusCode.NotAcceptable));
                }

                request.CreatedAt = DateTime.Now;

                NotifyAndLog("Deployment request received for project '{0}'", request.TfsProjectName);
                ProcessDeployment(request);

                request.DeploySucceeded = true;

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                NotifyAndLog(ex.Message);
                NotifyAndLog(ex.StackTrace);
                //todo: rollback process

                if (request != null)
                {
                    request.DeploySucceeded = false;
                }

                return(new HttpResponseMessage(HttpStatusCode.ExpectationFailed));
            }
            finally
            {
                if (request != null)
                {
                    DocSession.Store(request);
                }
            }
        }
Example #7
0
        public async Task DeployAsync(Version version, DeploymentGroup deploymentGroup)
        {
            var nodeProjectsDict = new Dictionary <Node, List <Project> >();

            foreach (var project in deploymentGroup.Projects)
            {
                if (project.Node.Deleted || !project.Node.Registered)
                {
                    _logger.LogDebug($"Projects '{project.Name}' Node '{project.Node.Name}' not registered or deleted, skipping...");
                    continue;
                }

                if (nodeProjectsDict.ContainsKey(project.Node))
                {
                    nodeProjectsDict[project.Node].Add(project);
                }
                else
                {
                    nodeProjectsDict.Add(project.Node, new List <Project> {
                        project
                    });
                }
            }

            foreach (var(node, projects) in nodeProjectsDict)
            {
                var request = new DeployRequest
                {
                    VersionGuid = version.Id,
                    Projects    = projects.Select(i => i.Name).ToList(),
                };

                var response = await _httpClient.PostAsJsonAsync($"{node.ApiEndpoint}{Routes.Deploy}", request);

                response.EnsureSuccessStatusCode();
            }

            _logger.LogInformation("Uploading is complete.");
        }
 /// <summary>
 ///  发布版本
 /// </summary>
 /// <param name="request">请求参数信息</param>
 /// <returns>请求结果信息</returns>
 public async Task <DeployResponse> Deploy(DeployRequest request)
 {
     return(await new DeployExecutor().Client(this).Execute <DeployResponse, DeployResult, DeployRequest>(request).ConfigureAwait(false));
 }
 /// <summary>
 ///  发布版本
 /// </summary>
 /// <param name="request">请求参数信息</param>
 /// <returns>请求结果信息</returns>
 public DeployResponse Deploy(DeployRequest request)
 {
     return(new DeployExecutor().Client(this).Execute <DeployResponse, DeployResult, DeployRequest>(request));
 }