Exemplo n.º 1
0
 private void StartSynchronizeInternalAsync(ISyncCallback callback)
 {
     if (SdkUtils.UnknownIdentityId == _identityId || this._isAnonymousUser)
     {
         _logger.DebugFormat("Sync is cancelled since the user has not full login.");
         callback.OnError(this, new SyncCanceledException("Sync is cancelled since user has not login yet."));
         return;
     }
     _currentSyncSequenceId++;
     SynchronizeInternalAsync(callback, _currentSyncSequenceId, MaxRetry);
 }
Exemplo n.º 2
0
        public void PullRecordsAsync(PullRecordsRequest request, CloudSaveCallback <PullRecordsResponse> callback)
        {
            if (Logger.LoggingConfig.LogHttpOption == LogHttpOption.Always)
            {
                _logger.DebugFormat("INTERNAL LOG - Pull request is : {0}", JsonUtility.ToJson(request));
            }

            _credentialProvider.GetOrRefreshCredentialAsync((err, credential) =>
            {
                if (err != null)
                {
                    var exception = err as Exception;
                    callback(
                        exception != null
                            ? new CredentialException("Failed to GetOrRefresh credential.", exception)
                            : new CredentialException(err.ToString()), null);
                    return;
                }

                SuperAgent.Get(Endpoints.CloudSaveEndpoint + "/identities/" + request.IdentityId + "/datasets/" +
                               request.DatasetName + "/records")
                .Query("syncCount", request.OldSyncRevisions)
                .Set("Authorization", "Bearer " + credential.token)
                .End((agentErr, response) =>
                {
                    if (agentErr != null)
                    {
                        callback(agentErr, null);
                        return;
                    }

                    // todo:
                    // call _credentialProvider.Logout() in case of invalid token.

                    var jsonStr = Encoding.UTF8.GetString(response.Body);

                    if (Logger.LoggingConfig.LogHttpOption == LogHttpOption.Always)
                    {
                        _logger.DebugFormat("Pull response is : {0}", jsonStr);
                    }

                    var pullRecordsResponse = JsonUtility.FromJson <PullRecordsResponse>(jsonStr);

                    callback(null, pullRecordsResponse);
                });
            });
        }
        private void SetupDatabase()
        {
            using (var connection = new SqliteConnection(_filePath))
            {
                connection.Open();
                const string createDatasetTable = @"CREATE TABLE IF NOT EXISTS Datasets (
                                                    IdentityId TEXT NOT NULL,
                                                    Name TEXT NOT NULL,
                                                    SyncRevisions TEXT,
                                                    UNIQUE (IdentityId, Name))";

                using (var command = new SqliteCommand(createDatasetTable, connection))
                {
                    command.ExecuteNonQuery();
                }

                const string createRecordsTable = @"CREATE TABLE IF NOT EXISTS Records (
                                                  IdentityId TEXT NOT NULL,
                                                  Name TEXT NOT NULL,
                                                  Key TEXT NOT NULL,
                                                  Value TEXT,
                                                  SyncCount INTEGER NOT NULL DEFAULT 0,
                                                  SyncRegion TEXT,
                                                  LastModifiedDate TEXT DEFAULT '0',
                                                  DeviceLastModifiedDate TEXT DEFAULT '0',
                                                  LastModifiedBy TEXT,
                                                  IsDirty INTEGER NOT NULL DEFAULT 1,
                                                  UNIQUE (IdentityId, Name, Key))";

                using (var command = new SqliteCommand(createRecordsTable, connection))
                {
                    command.ExecuteNonQuery();
                }
            }
            _logger.DebugFormat("INTERNAL LOG - LocalStorage - Completed setup databas");
        }