Exemplo n.º 1
0
        public override async void Enter()
        {
            var api = await this._container.RegisterYnabApiAsync();

            this._budget = await api.GetBudgetAsync(this.BudgetName);
            this._device = await this._budget.RegisterDevice(Windows.Networking.Proximity.PeerFinder.DisplayName);

            this._sessionStateService.DeviceGuid = this._device.DeviceGuid;

            this.Application.Actions.Add(this._overviewItem);
            this.Application.Actions.Add(this._transactionsItem);
            this.Application.Actions.Add(this._addTransactionItem);
            this.Application.Actions.Add(this._refreshItem);

            this.Application.SecondaryActions.Add(this._changeBudgetItem);

            this.Overview();
        }
Exemplo n.º 2
0
 protected override async void OnInitialize()
 {
     this._budget = await this._ynabApi.GetBudgetAsync(this._sessionStateService.BudgetName);
     this._device = await this._budget.GetRegisteredDevice(this._sessionStateService.DeviceGuid);
 }
Exemplo n.º 3
0
        public async Task<RegisteredDevice> RegisterDevice(string deviceName)
        {
            try
            {
                var alreadyRegisteredDevices = await this.GetRegisteredDevicesAsync();

                var existingDevice = alreadyRegisteredDevices.FirstOrDefault(f => 
                    f.FriendlyName == deviceName && 
                    f.YnabVersion == this._settings.ApplicationName && 
                    f.DeviceType == this._settings.DeviceType);

                if (existingDevice != null)
                    return existingDevice;

                var deviceId = await this.GetNextFreeDeviceIdAsync();
                var deviceGuid = EntityId.CreateNew();

                var json = new JObject
                {
                    { "deviceType", this._settings.DeviceType },
                    { "highestDataVersionImported", "4.2" },
                    { "friendlyName", deviceName },
                    { "shortDeviceId", deviceId },
                    { "hasFullKnowledge", false },
                    { "knowledge", Knowledge.CreateKnowledgeForNewDevice(alreadyRegisteredDevices.First(f => f.HasFullKnowledge).KnowledgeString, deviceId) },
                    { "deviceGUID", deviceGuid },
                    { "knowledgeInFullBudgetFile", null },
                    { "YNABVersion", this._settings.ApplicationName },
                    { "formatVersion", Constants.Ynab.FormatVersion },
                    { "lastDataVersionFullyKnown", Constants.Ynab.LastDataVersionFullyKnown }
                };
            
                var dataFolderPath = await this.GetDataFolderPathAsync();
                var deviceFilePath = YnabPaths.DeviceFile(dataFolderPath, deviceId);

                await this._settings.FileSystem.WriteFileAsync(deviceFilePath, json.ToString());
                await this._settings.FileSystem.CreateDirectoryAsync(YnabPaths.DeviceFolder(dataFolderPath, deviceGuid));
            
                var result = new RegisteredDevice(this._settings, this, json);
                (await this.GetRegisteredDevicesAsync()).Add(result);

                await this._settings.FileSystem.FlushWritesAsync();

                return result;
            }
            catch (Exception exception) when (exception is YnabApiException == false)
            {
                throw new YnabApiException($"Error while registering the device {deviceName}.", exception);
            }
        }
Exemplo n.º 4
0
        protected override async void OnInitialize()
        {
            using (this._loadingService.Show("Loading data..."))
            {
                this._budget = await this._api.GetBudgetAsync(this._sessionStateService.BudgetName);
                this._device = await this._budget.GetRegisteredDevice(this._sessionStateService.DeviceGuid);
                
                var payees = await this._device.GetPayeesAsync();
                this.Payees.AddRange(payees.OnlyActive().WithoutTransfers());

                var accounts = await this._device.GetAccountsAsync();
                this.Accounts.AddRange(accounts);

                var masterCategories = await this._device.GetCategoriesAsync();
                this.Categories.AddRange(masterCategories.OnlyActive().SelectMany(f => f.SubCategories.OnlyActive().Select(d => new CategoryViewModel(f, d))));
            }
        }