Пример #1
0
        private static void InitializeContracts()
        {
            _eoiDataContracts = new List <EoiDataContract>();
            var users = GetUsers();
            var user  = users.FirstOrDefault(x => x.GetAccessToken() != null);

            if (user != null)
            {
                var contracts = CorporationWebInterface.GetContracts(user.Name);
                foreach (var contract in contracts)
                {
                    _eoiDataContracts.Add(new EoiDataContract(contract));
                }
            }
        }
Пример #2
0
        internal static bool SynchronizeCorporationContracts()
        {
            var updated = false;

            var users = GetUsers();
            var user  = users.FirstOrDefault(x => x.GetAccessToken() != null);

            if (user != null)
            {
                _eoiDataContracts.ForEach(x => x.Synchronized = false);
                var corpContracts = CorporationWebInterface.GetContracts(user.Name);

                foreach (var corpContract in corpContracts)
                {
                    EoiDataContract eoiDataContract = _eoiDataContracts.FirstOrDefault(x => x.Id == corpContract.Id);
                    if (eoiDataContract == null)
                    {
                        eoiDataContract = new EoiDataContract(corpContract);
                        eoiDataContract.Synchronized = true;
                        _eoiDataContracts.Add(eoiDataContract);
                        EoiInterface.InvokeDispatcherAddContract(eoiDataContract.GetEoiContract());
                        updated = true;
                    }
                    else
                    {
                        if (eoiDataContract.Synchronize(corpContract))
                        {
                            updated = true;
                        }
                    }
                }

                var notSynchronizedContracts = _eoiDataContracts.Where(x => !x.Synchronized).ToList();
                foreach (var contract in notSynchronizedContracts)
                {
                    EoiInterface.InvokeDispatcherRemoveContract(contract.GetEoiContract());
                    contract.Dispose();
                    _eoiDataContracts.Remove(contract);
                }
            }

            if (updated)
            {
                EoiInterface.InvokeDispatcherContractsPropertyChanged();
            }

            return(updated);
        }