Esempio n. 1
0
 public void Update(SynchroHandle _syncHandle)
 {
     if ((_syncHandle.Requested && _syncHandle.Finished))
     {
         _syncHandle.SetSynchroStatus(Status.Synchronized);
     }
     else if ((_syncHandle.Requested && !_syncHandle.Finished))
     {
         _syncHandle.SetSynchroStatus(Status.InProgress);
         addToQueue(_syncHandle);
     }
     else
     {
         _syncHandle.SetSynchroStatus(Status.NoRequest);
         removeFromQueue(_syncHandle);
     }
 }
Esempio n. 2
0
        public async Task Login_callback(String _code)
        {
            String _dropboxURL = "https://api.dropbox.com/1/oauth2/token?code=" + Uri.EscapeDataString(_code) +
                                 "&grant_type=authorization_code";

            HttpResponseMessage _response  = null;
            HttpClient          httpClient = new HttpClient();

            HttpContent content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("client_id", ClientId),
                new KeyValuePair <string, string>("client_secret", Secret)
            });

            try
            {
                _response = await httpClient.PostAsync(new Uri(_dropboxURL), content);
            }
            catch (HttpRequestException e)
            {
                Debug.WriteLine(e.Message);
            }
            if ((_response != null) && (_response.StatusCode == HttpStatusCode.OK))
            {
                ResponseToken _t = await Serialization.DeserializeHttpToJson <ResponseToken>(_response.Content) as ResponseToken;

                Token = _t.access_token;
                LocalSettings.SaveStorageValue <String>(LOCAL_OAUTH_TOKEN, Token);

                //Get UserName
                String _respJson = await httpClient.GetStringAsync(new Uri("https://api.dropbox.com/1/account/info?access_token=" + Token));

                if (_response != null)
                {
                    var value = JsonValue.Parse(_respJson).GetObject();
                    UserName = value.GetNamedString("display_name");
                    LocalSettings.SaveStorageValue <String>(LOCAL_USER_NAME, UserName);

                    //end of auth process
                    LoggedIn = WebAccountState.Connected;

                    // force synchronization
                    if (_handle != null)
                    {
                        _handle.SetSynchroStatus(SynchroManager.Status.InProgress);
                        await Synchronize(_handle);
                    }
                }
            }

            return;
        }
Esempio n. 3
0
        internal async Task Synchronize()
        {
            if (_syncInProgress)
            {
                return;
            }

            _syncInProgress = true;

            while (_listSyncHandle.Count > 0)
            {
                SynchroHandle _syncHandle = _listSyncHandle.First <SynchroHandle>();
                Status        _status     = SynchroManager.Status.ErrorOrNotConnected;

                StorageServer _server = CloudServerFromName(_syncHandle.Server);
                _server.SyncMngr    = this;
                _server.Compression = _syncHandle.Compression;
                if (Parent != null)
                {
                    _server.Parent = Parent;
                }

                // start synchronization, reset Cts before
                _syncHandle.InProgress = true;
                _server.ResetCts();
                _status = await _server.Synchronize(_syncHandle);

                _syncHandle.InProgress = false;

                if (_status == Status.Synchronized)
                {
                    _syncHandle.Finished = true;
                }

                _syncHandle.SetSynchroStatus(_status);

                removeFromQueue(_syncHandle);

                if ((_listSyncHandle.Count == 0) && (Parent != null) && (Parent is ViewHome))
                {
                    await(Parent as ViewHome).SaveSummary();
                }
            }

            _syncInProgress = false;
        }
Esempio n. 4
0
        public async override Task <SynchroManager.Status> Synchronize(SynchroHandle _syncHandle)
        {
            Boolean _status = true;

            SynchroManager.Status _syncStatus = SynchroManager.Status.NoRequest;

            if (LoggedIn != WebAccountState.Connected)
            {
                _syncHandleSav = _syncHandle;
                _status        = await SyncMngr.Login(SynchroManager.ServerName.Usb);
            }
            if (_status)
            {
                Trip _trip = await Trip.LoadFromSummary(_syncHandle.TripSummary);

                _status &= await SynchronizeTrip(_trip);

                ProgressFinished("");

                // check error status
                if (CancelInProgress())
                {
                    _syncStatus = SynchroManager.Status.NoRequest;
                }
                else if (!_status)
                {
                    _syncStatus = SynchroManager.Status.ErrorOrNotConnected;
                }
                else
                {
                    _syncStatus = SynchroManager.Status.Synchronized;
                }
            }
            else
            {
                _syncStatus = SynchroManager.Status.ErrorOrNotConnected;
            }

            _syncHandle.SetSynchroStatus(_syncStatus);
            return(_syncStatus);
        }
Esempio n. 5
0
        async Task LoginCallback(String _id)
        {
            StorageFolder _storage = await getDeviceGTFolder(_id);

            if (_storage != null)
            {
                LoggedIn = WebAccountState.Connected;
                UserName = _storage.Path;

                LocalSettings.SaveStorageValue <String>(LOCAL_OAUTH_TOKEN, _id);
                LocalSettings.SaveStorageValue <String>(LOCAL_USER_NAME, UserName);
                LocalSettings.SaveStorageValue <String>(LOCAL_OAUTH_TOKEN_REFRESH, _storage.Path);

                if (_syncHandleSav != null)
                {
                    await Synchronize(_syncHandleSav);
                }
            }
            else if (_syncHandleSav != null)
            {
                _syncHandleSav.SetSynchroStatus(SynchroManager.Status.ErrorOrNotConnected);
            }
        }