// This method will check all blocks for new Events.
        private async Task <Dictionary <string, ChangeRequest> > checkCREvents(string contractAdress)
        {
            ChangeManagerService changeManagerService = new ChangeManagerService(new Web3(), contractAddress);
            Event newVoteEventLog          = changeManagerService.ContractHandler.GetEvent <NewVoteEventDTO>();
            Event newChangeRequestEventLog = changeManagerService.ContractHandler.GetEvent <NewChangeRequestEventDTO>();

            Dictionary <string, ChangeRequest> result = new Dictionary <string, ChangeRequest>();

            BlockParameter firstBlock = BlockParameter.CreateEarliest();
            BlockParameter lastBlock  = BlockParameter.CreateLatest();
            NewFilterInput filterCR   = newChangeRequestEventLog.CreateFilterInput(firstBlock, lastBlock);
            NewFilterInput filterVote = newVoteEventLog.CreateFilterInput(firstBlock, lastBlock);

            List <EventLog <NewChangeRequestEventDTO> > logCR = await newChangeRequestEventLog.GetAllChanges <NewChangeRequestEventDTO>(filterCR);

            List <EventLog <NewVoteEventDTO> > logVote = await newVoteEventLog.GetAllChanges <NewVoteEventDTO>(filterVote);

            // Get confirmation for CR creation. Then add CR to table and combobox for management vote.
            Debug.WriteLine("Checking for CR Events: " + logCR.Count);
            foreach (EventLog <NewChangeRequestEventDTO> cr in logCR)
            {
                ChangeRequest changeRequest;
                String        gitHash = Converter.ByteArrayToBinHex(cr.Event.GitHash);

                HexBigInteger blocknumber = cr.Log.BlockNumber;
                Block         block       = await web3.Eth.Blocks.GetBlockWithTransactionsHashesByNumber.SendRequestAsync(blocknumber);

                if (result.ContainsKey(gitHash))
                {
                    changeRequest = result[gitHash];
                }
                else
                {
                    changeRequest = new ChangeRequest(this.contractAddress);
                    result.Add(gitHash, changeRequest);
                }
                changeRequest.updateChangeRequest(gitHash, cr.Event.AdditionalInformation, cr.Event.Costs, cr.Event.Estimation, block.Timestamp.Value);
            }

            // Get vote confirmation. Then update State of the vote.
            Debug.WriteLine("Checking for Vote Events: " + logVote.Count);
            foreach (EventLog <NewVoteEventDTO> vote in logVote)
            {
                String        gitHash       = Converter.ByteArrayToBinHex(vote.Event.GitHash);
                ChangeRequest changeRequest = result[gitHash];

                HexBigInteger blocknumber = vote.Log.BlockNumber;
                Block         block       = await web3.Eth.Blocks.GetBlockWithTransactionsHashesByNumber.SendRequestAsync(blocknumber);

                if (!changeRequest.votes.ContainsKey(vote.Event.Voter))
                {
                    changeRequest.updateVotes((State)vote.Event.CurrentState, vote.Event.VoteInfo, vote.Event.VotesLeft, vote.Event.Voter, vote.Event.Vote, block.Timestamp.Value);
                }
            }

            return(result);
        }
Exemple #2
0
        internal async Task managementVoteAsync(string privateKey, bool accept, List <string> responsibleParties, string voteInfo)
        {
            ManagementVoteFunction managementFunction = new ManagementVoteFunction();

            managementFunction.GitHash            = gitHashByte;
            managementFunction.AcceptChange       = accept;
            managementFunction.ResponsibleParties = responsibleParties;
            managementFunction.VoteInfo           = voteInfo;

            Web3 web3 = new Web3(new Account(privateKey));

            ChangeManagerService managementService = new ChangeManagerService(web3, this.contractAddress);

            await managementService.ManagementVoteRequestAsync(managementFunction);
        }
Exemple #3
0
        private async void NewChangeManager(string gitProject, string privateKey)
        {
            // Deploy new ChangeManager on blockchain
            web3       = new Web3(new Account(privateKey));
            deployment = new ChangeManagerDeployment();
            TransactionReceipt receipt = await ChangeManagerService.DeployContractAndWaitForReceiptAsync(web3, deployment);

            changeManagerService = new ChangeManagerService(web3, receipt.ContractAddress);

            Web3.GetAddressFromPrivateKey(privateKey);
            MainWindow mWnd = new MainWindow(receipt.ContractAddress, gitProject);

            mWnd.Title = "ChangeManager for https://github.com/" + gitProject + " Managed by: " + Web3.GetAddressFromPrivateKey(privateKey);;
            mWnd.Show();
        }
Exemple #4
0
        internal async Task responsibleVoteAsync(string privateKey, bool accept, string voteInfo)
        {
            ResponsibleVoteFunction responsibleVoteFunction = new ResponsibleVoteFunction();

            responsibleVoteFunction.GitHash      = gitHashByte;
            responsibleVoteFunction.FromAddress  = Web3.GetAddressFromPrivateKey(privateKey);
            responsibleVoteFunction.AcceptChange = accept;
            responsibleVoteFunction.VoteInfo     = voteInfo;

            Web3 web3 = new Web3(new Account(privateKey));

            ChangeManagerService responsibleService = new ChangeManagerService(web3, this.contractAddress);

            responsibleVoteFunction.Gas = 500000;

            await responsibleService.ResponsibleVoteRequestAsync(responsibleVoteFunction);
        }
Exemple #5
0
        internal async Task createChangeRequestAsync(string privateKey, string gitHash, string additionalInformation, uint estimation, uint costs)
        {
            CreateNewChangeRequestFunction changeRequestFunction = new CreateNewChangeRequestFunction();

            changeRequestFunction.GitHash = Converter.HashStringToByteArray(gitHash);
            changeRequestFunction.AdditionalInformation = additionalInformation;
            changeRequestFunction.Estimation            = estimation;
            changeRequestFunction.Costs = costs;

            Web3 web3 = new Web3(new Account(privateKey));

            ChangeManagerService createService = new ChangeManagerService(web3, this.contractAddress);

            changeRequestFunction.Gas = 500000;

            await createService.CreateNewChangeRequestRequestAsync(changeRequestFunction);
        }
        public MainWindow(string contractAddress, string gitProject)
        {
            InitializeComponent();
            tabControl.Items.Remove(responsibleTab);
            tabControl.Items.Remove(managementTab);

            this.contractAddress = contractAddress;
            changeRequests       = new Dictionary <string, ChangeRequest>();
            web3 = new Web3();
            ChangeManagerService changeManagerService = new ChangeManagerService(web3, contractAddress);

            newVoteEventLog          = changeManagerService.ContractHandler.GetEvent <NewVoteEventDTO>();
            newChangeRequestEventLog = changeManagerService.ContractHandler.GetEvent <NewChangeRequestEventDTO>();
            firstBlock = BlockParameter.CreateEarliest();

            timer          = new DispatcherTimer();
            timer.Tick    += new EventHandler(checkEventsAndUpdateTable);
            timer.Interval = new TimeSpan(0, 0, 2);
            timer.Start();
            this.gitProject = gitProject;

            getGitCommits(gitProject);
        }
Exemple #7
0
        private void PublishImpl(XrmService context, VersioningService gitvc, DeployConfigurationModel deployConfiguration, TelemetryWrapper telemetry, RawChanges[] changes, string project)
        {
            try
            {
                ChangeManagerService container = new ChangeManagerService(changes, deployConfiguration.Prefix, context);
                telemetry.TrackCustomEventWithCustomMetrics("Deploy Started", new MetricData("Project Name", project));

                if (container.WebResources.Count > 0)
                {
                    ReportProgress?.Invoke(this, $"[DYNAMICS] => Found {container.WebResources.Count} Web Resource.");
                    ReportProgress?.Invoke(this, $"[DYNAMICS] => '{deployConfiguration.Prefix}' used as base path.");
                    ReportProgress?.Invoke(this, $"[DYNAMICS] => Fetching '{deployConfiguration.Solution}' solution from CRM.");
                    container.EnsureContinue(deployConfiguration.Solution, deployConfiguration.Prefix);

                    ReportProgress?.Invoke(this, $"[DYNAMICS] => Publishing changes to the CRM.");
                    var faultedFlushResult = context.Flush(container.BuildRequestList(deployConfiguration.Solution));

                    if (!faultedFlushResult && deployConfiguration.CheckInEnabled)
                    {
                        ReportProgress?.Invoke(this, $"[AZOPS] => Commit & Push in progress.");
                        gitvc.CommitAndPush(deployConfiguration.Password);
                    }

                    ReportProgress?.Invoke(this, $"[AZOPS] => Publish completed.");
                }

                telemetry.TrackCustomEventWithCustomMetrics("Deploy Finished", new MetricData("Project Name", project));
            }
            catch (Exception exception)
            {
                ReportProgress?.Invoke(this, $"[ERROR] => {exception.Message}\n");
                if (!(exception is ToolkitException))
                {
                    telemetry.TrackExceptionWithCustomMetrics(exception);
                }
            }
        }