Пример #1
0
        private void removeContractMenuItem_Click(object sender, EventArgs e)
        {
            ContractItem manageritem = this.managersListView.SelectedItem;

            if (manageritem != null)
            {
                ManagerContract manager = manageritem.Contract as ManagerContract;
                ContractItem    item    = this.contractListView.SelectedItem;
                if (item != null)
                {
                    if (Constants.LinuxMode)
                    {
                        item.StartWait();
                        manageritem.StartWait();
                        ThreadStack.Run(delegate(object[] param)
                        {
                            ManagerContract mc  = param[0] as ManagerContract;
                            ContractItem ctitem = param[1] as ContractItem;
                            if (mc.RemoveContact(ctitem.Contract))
                            {
                                mc.Contracts.Remove(ctitem.Contract);
                                Utils.Invoke(this, delegate
                                {
                                    this.contractListView.Items.Remove(ctitem);
                                });
                                mc.WaitGramsChangedLoop();
                            }
                        }, manager, item);
                    }
                }
            }
        }
        public Contract Load(string address, string privKey)
        {
            Owner owner = GetOwner(address);

            if (owner != null)
            {
                Contract contract = null;
                switch (owner.Type)
                {
                case ContractType.Manager:
                    contract = new ManagerContract(owner.Name, owner.OwnerType);
                    break;

                case ContractType.Messenger:
                    contract = new MessengerContract(owner.Name, (MessagerType)owner.OwnerType);
                    break;
                }
                if (contract != null)
                {
                    contract.Update(owner.PubKey, privKey, address, owner.State);
                }
                return(contract);
            }
            return(null);
        }
Пример #3
0
        private void copyAddresManagerMenuItem_Click(object sender, EventArgs e)
        {
            ManagerContract manager = this.SelectedManager;

            if (manager != null)
            {
                Clipboard.SetText(manager.Address);
            }
        }
Пример #4
0
        public void LoadManagers(Form form)
        {
            if (this.managers.Count == 0)
            {
                ThreadStack.Run(delegate(object[] param)
                {
                    if (Constants.LinuxMode)
                    {
                        ClientExecutor.Instance.Start();
                    }
                    foreach (string file in Directory.GetFiles(Constants.ContractsDirectory, "*.ct"))
                    {
                        using (StreamReader reader = new StreamReader(file))
                        {
                            ManagerContract manager = new ManagerContract(reader);
                            this.managers.Add(manager);
                            if (Constants.LinuxMode)
                            {
                                Owner owner = ClientExecutor.Instance.GetOwner(manager.Address);
                                if (owner != null)
                                {
                                    manager.Update(owner);
                                    manager.LoadContracts();
                                }
                            }
                            else
                            {
                                MessengerContract contract = new MessengerContract("Александр Гордиенко", MessagerType.Private);
                                contract.Update("0", null, null, ContractState.Online);
                                contract.Members.Add(new Member("Вася", "1", ContractState.Online, MessagerType.Private));
                                contract.Members.Add(new Member("Петя", "2", ContractState.Offline, MessagerType.Private));
                                manager.Contracts.Add(contract);

                                contract = new MessengerContract("Вася", MessagerType.Public);
                                contract.Update("1", null, null, ContractState.Online);
                                contract.Members.Add(new Member("Андрей", "3", ContractState.Online, MessagerType.Public));
                                contract.Members.Add(new Member("Сергей", "4", ContractState.Offline, MessagerType.Private));
                                manager.Contracts.Add(contract);

                                contract = new MessengerContract("Андрей", MessagerType.Public);
                                contract.Update("3", null, null, ContractState.Online);
                                contract.Members.Add(new Member("Алексей", "5", ContractState.Offline, MessagerType.Public));
                                contract.Members.Add(new Member("Михаил", "6", ContractState.Online, MessagerType.Public));
                                manager.Contracts.Add(contract);
                            }
                        }
                    }

                    Utils.Invoke(form, this.StartLoaded);
                });
            }
        }
Пример #5
0
 private void createManagerButton_Click(object sender, EventArgs e)
 {
     using (CreateManagerForm form = new CreateManagerForm(Utils.GetNext("Manager", managers)))
     {
         if (form.ShowDialog(this) == DialogResult.OK)
         {
             ManagerContract manager = new ManagerContract(form.ContractName, 0);
             this.Add(manager);
             if (Constants.LinuxMode)
             {
                 ThreadStack.Run(delegate(object[] param)
                 {
                     ClientExecutor.Instance.CreateContract(param[0] as Contract, param[1] as string);
                 }, manager, form.WorkchainID);
             }
         }
     }
 }
Пример #6
0
        private void createContractButton_Click(object sender, EventArgs e)
        {
            ContractItem manageritem = this.managersListView.SelectedItem;

            if (manageritem != null)
            {
                ManagerContract manager = manageritem.Contract as ManagerContract;

                using (CreateContractForm form = new CreateContractForm(Utils.GetNext("Messenger", this.contractListView.Items)))
                {
                    if (form.ShowDialog(this) == DialogResult.OK)
                    {
                        Contract     contract = Contract.Create(form.ContractName, form.ContractType, form.OwnerType);
                        ContractItem item     = new ContractItem(contract);
                        this.contractListView.Items.Add(item);
                        this.contractListView.SelectedItem = item;
                        item.StartWait();
                        manageritem.StartWait();
                        if (Constants.LinuxMode)
                        {
                            ThreadStack.Run(delegate(object[] param)
                            {
                                ManagerContract mgr = param[0] as ManagerContract;
                                Contract ct         = param[1] as Contract;
                                ClientExecutor.Instance.CreateContract(ct, param[2] as string);
                                if (!item.IsWaitState)
                                {
                                    item.StartWait();
                                }
                                mgr.Contracts.Add(contract);
                                ClientExecutor.Instance.InitContract(mgr, ct, (double)param[3]);
                                manageritem.StartWait();
                                mgr.AddContract(ct);
                                Utils.Invoke(this, this.OnManagersLoaded);
                            }, manager, contract, form.WorkchainID, (double)form.Grams);
                        }
                    }
                }
            }
        }
Пример #7
0
        private void Add(ManagerContract manager)
        {
            ContractItem item = new ContractItem(manager);

            this.managersListView.Items.Add(item);
        }