public async Task Post(AddSyncTarget request)
        {
            var config = PluginConfiguration.Configuration;
            var userToken = await GetUserToken(request);

            var syncAccount = new OneDriveSyncAccount
            {
                Id = Guid.NewGuid().ToString(),
                Name = WebUtility.UrlDecode(request.Name),
                EnableForEveryone = request.EnableForEveryone,
                UserIds = request.UserIds,
                RefreshToken = userToken.RefreshToken
            };

            if (!string.IsNullOrEmpty(request.Id))
            {
                syncAccount.Id = request.Id;
            }
            else
            {
                request.Id = syncAccount.Id;
            }

            PluginConfiguration.Configuration.SyncAccounts.Add(syncAccount);

            try
            {
                syncAccount.FolderId = await GetOrCreateFolder(request, userToken);
                Plugin.Instance.SaveConfiguration();
            }
            catch
            {
                PluginConfiguration.Configuration.SyncAccounts.Remove(syncAccount);
            }
        }
示例#2
0
        /// <summary>
        /// Default ctor.
        /// </summary>
        public RequestFactory(SyncTarget target, string accessToken)
        {
            var config = PluginConfiguration.Configuration;

            this.syncAccount = config.SyncAccounts.FirstOrDefault(x => x.Id == target.Id);
            this.accessToken = accessToken;
        }
        public OneDriveSyncAccount RemoveSyncAccount(OneDriveSyncAccount syncAccount)
        {
            PluginConfiguration.Configuration.SyncAccounts.Remove(syncAccount);
            Plugin.Instance.SaveConfiguration();

            return syncAccount;
        }