コード例 #1
0
    public CognitoSyncManager GetSyncManager(string userId)
    {
        var credential = cognito.GetCredential(userId);

        CognitoSyncManager syncManager;
        if(!syncManagers.TryGetValue(userId, out syncManager))
        {
            syncManager = new CognitoSyncManager(credential, RegionEndpoint.USEast1);
            syncManagers.Add(userId, syncManager);
        }

        return syncManager;
    }
コード例 #2
0
    private void Init(string authProvider, string accessToken)
    {
		enabled = true;

		if (string.IsNullOrEmpty(IDENTITY_POOL_ID))
		{
			throw new NotSupportedException ("Please setup your the identity pool id in SceneController");
		}

		//Create a Credentials provider that uses Cognito Identity
		credentials = new CognitoAWSCredentials(IDENTITY_POOL_ID, ENDPOINT);

		//If fbAccesToken is set, we can use Cognito's authenticated identities
		if (accessToken != null) {
			credentials.AddLogin(authProvider, accessToken);
		}

		syncManager = new CognitoSyncManager (credentials, new AmazonCognitoSyncConfig { RegionEndpoint = ENDPOINT });

        InitializeCharactersDataset();
    }
コード例 #3
0
ファイル: SyncManager.cs プロジェクト: lawandeneel/Fashion
        public void ResolveConflictTest()
        {
            using (CognitoSyncManager syncManager = new CognitoSyncManager(UnAuthCredentials))
            {
                syncManager.WipeData();
                using (Dataset d = syncManager.OpenOrCreateDataset("testDataset4"))
                {
                    d.Put("a", "1");
                    d.Put("b", "2");
                    d.Put("c", "3");
                    d.OnSyncSuccess += delegate(object sender, SyncSuccessEventArgs e)
                    {
                        d.ClearAllDelegates();
                        syncManager.WipeData();
                        using (Dataset d2 = syncManager.OpenOrCreateDataset("testDataset4"))
                        {
                            d2.Put("a", "10");
                            d2.Put("b", "20");
                            d2.Put("c", "30");

                            bool resolved = false;
                            d2.OnSyncConflict += delegate(Dataset dataset, List<SyncConflict> conflicts)
                            {
                                List<Amazon.CognitoSync.SyncManager.Record> resolvedRecords = new List<Amazon.CognitoSync.SyncManager.Record>();
                                int i = 0;
                                foreach (SyncConflict conflictRecord in conflicts)
                                {
                                    if (i == 0) resolvedRecords.Add(conflictRecord.ResolveWithLocalRecord());
                                    else if (i == 1) resolvedRecords.Add(conflictRecord.ResolveWithValue("42"));
                                    else resolvedRecords.Add(conflictRecord.ResolveWithRemoteRecord());
                                    i++;
                                }
                                dataset.Resolve(resolvedRecords);
                                resolved = true;
                                return true;
                            };
                            d2.OnSyncSuccess += delegate(object sender4, SyncSuccessEventArgs e4)
                            {
                                if (resolved)
                                {
                                    Assert.AreSame(d2.Get("a"), "10");
                                    Assert.AreSame(d2.Get("b"), "42");
                                    Assert.AreSame(d2.Get("c"), "3");
                                }
                                else
                                {
                                    Assert.Fail("Expecting SyncConflict instead of SyncSuccess");
                                }

                            };
                            d2.OnSyncFailure += delegate(object sender4, SyncFailureEventArgs e4)
                            {
                                Assert.Fail("Expecting SyncConflict instead of SyncFailure");
                            };
                            RunAsSync(async () => await d2.SynchronizeAsync());
                        }
                    };
                    RunAsSync(async () => await d.SynchronizeAsync());
                }
            }
        }
コード例 #4
0
ファイル: SyncManager.cs プロジェクト: lawandeneel/Fashion
        public void ConflictTest()
        {
            using (CognitoSyncManager syncManager = new CognitoSyncManager(UnAuthCredentials))
            {
                syncManager.WipeData();
                using (Dataset d = syncManager.OpenOrCreateDataset("testDataset3"))
                {
                    d.Put("testKey3", "the initial value");
                    d.OnSyncSuccess += delegate(object sender, SyncSuccessEventArgs e)
                    {
                        d.ClearAllDelegates();
                        syncManager.WipeData();
                        using (Dataset d2 = syncManager.OpenOrCreateDataset("testDataset3"))
                        {
                            bool conflictTriggered = false;
                            d2.Put("testKey3", "a different value");

                            d2.OnSyncConflict += delegate(Dataset dataset, List<SyncConflict> conflicts)
                            {
                                conflictTriggered = true;
                                return false;
                            };
                            d2.OnSyncSuccess += delegate(object sender4, SyncSuccessEventArgs e4)
                            {
                                Assert.Fail("Expecting OnSyncConflict instead of OnSyncSuccess");
                            };
                            d2.OnSyncFailure += delegate(object sender4, SyncFailureEventArgs e4)
                            {
                                Assert.IsTrue(conflictTriggered, "Expecting OnSyncConflict instead of OnSyncFailure");
                            };
                            RunAsSync(async () => await d2.SynchronizeAsync());
                        }
                    };
                    RunAsSync(async () => await d.SynchronizeAsync());
                }
            }
        }
コード例 #5
0
ファイル: SyncManager.cs プロジェクト: lawandeneel/Fashion
        public void MetadataTest()
        {
            using (CognitoSyncManager syncManager = new CognitoSyncManager(UnAuthCredentials))
            {
                syncManager.WipeData();
                using (Dataset d = syncManager.OpenOrCreateDataset("testDataset3"))
                {
                    d.Put("testKey3", "the initial value");

                    //Initial properties
                    var records = d.Records;
                    Record r = d.Records[records.Count - 1];
                    long initialSyncCount = r.SyncCount;
                    bool initialDirty = r.IsModified;
                    DateTime initialDate = r.DeviceLastModifiedDate.Value;

                    d.OnSyncSuccess += delegate(object sender, SyncSuccessEventArgs e)
                    {
                        //Properties after Synchronize
                        Record r2 = d.Records[records.Count - 1];
                        long synchronizedSyncCount = r2.SyncCount;
                        bool synchronizedDirty = r2.IsModified;
                        DateTime synchronizedDate = r2.DeviceLastModifiedDate.Value;

                        d.Put("testKey3", "a new value");

                        //Properties after changing the content again
                        Record r3 = d.Records[records.Count - 1];
                        long finalSyncCount = r3.SyncCount;
                        bool finalDirty = r3.IsModified;
                        DateTime finalDate = r3.DeviceLastModifiedDate.Value;

                        Assert.IsTrue(initialDirty);
                        Assert.IsTrue(!synchronizedDirty);
                        Assert.IsTrue(finalDirty);

                        Assert.IsTrue(synchronizedSyncCount > initialSyncCount);
                        Assert.IsTrue(synchronizedSyncCount == finalSyncCount);

                        Assert.IsTrue(finalDate > initialDate);
                        Assert.IsTrue(initialDate == synchronizedDate);
                    };
                    RunAsSync(async () => await d.SynchronizeAsync());
                }
            }
        }
コード例 #6
0
ファイル: SyncManager.cs プロジェクト: lawandeneel/Fashion
        /// <summary>
        /// Test Case: 
        /// </summary>
        //[TestMethod]
        //[TestCategory("SyncManager")]
        public void MergeTest()
        {
            var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            string uniqueName = ((DateTime.UtcNow - epoch).TotalSeconds).ToString();
            string uniqueName2 = uniqueName + "_";

            UnAuthCredentials.Clear();

            using (CognitoSyncManager sm1 = new CognitoSyncManager(AuthCredentials))
            {
                sm1.WipeData();
                Thread.Sleep(2000);
                using (Dataset d = sm1.OpenOrCreateDataset("test"))
                {
                    d.Put(uniqueName, uniqueName);
                    d.OnSyncSuccess += delegate(object s1, SyncSuccessEventArgs e1)
                    {
                        UnAuthCredentials.Clear();

                        using (CognitoSyncManager sm2 = new CognitoSyncManager(UnAuthCredentials))
                        {
                            Thread.Sleep(2000);
                            using (Dataset d2 = sm2.OpenOrCreateDataset("test"))
                            {
                                d2.Put(uniqueName2, uniqueName2);
                                d2.OnSyncSuccess += delegate(object s2, SyncSuccessEventArgs e2)
                                {
                                    AuthCredentials.Clear();
                                    UnAuthCredentials.Clear();
                                    //now we will use auth credentials.
                                    using (CognitoSyncManager sm3 = new CognitoSyncManager(AuthCredentials))
                                    {
                                        Thread.Sleep(2000);
                                        using (Dataset d3 = sm3.OpenOrCreateDataset("test"))
                                        {
                                            bool mergeTriggered = false;
                                            d3.OnSyncSuccess += (object sender, SyncSuccessEventArgs e) =>
                                            {
                                                if (!mergeTriggered)
                                                    Assert.Fail("Expecting DatasetMerged instead of OnSyncSuccess");
                                            };
                                            d3.OnSyncConflict += (Dataset dataset, List<SyncConflict> syncConflicts) =>
                                            {
                                                Assert.Fail();
                                                return false;
                                            };
                                            d3.OnDatasetDeleted += (Dataset dataset) =>
                                            {
                                                Assert.Fail();
                                                return false;
                                            };
                                            d3.OnDatasetMerged += (Dataset ds, List<string> datasetNames) =>
                                            {
                                                mergeTriggered = true;
                                                datasetNames.ForEach((mergeds) =>
                                                {
                                                    Dataset mergedDataset = sm3.OpenOrCreateDataset(mergeds);
                                                    mergedDataset.Delete();
                                                    RunAsSync(async () => await mergedDataset.SynchronizeAsync());
                                                });
                                                return true;
                                            };
                                            RunAsSync(async () => await d3.SynchronizeAsync());
                                        }
                                    }
                                };
                                d2.OnSyncFailure += (object sender, SyncFailureEventArgs e) =>
                                {
                                    Console.WriteLine(e.Exception.Message);
                                    Console.WriteLine(e.Exception.StackTrace);
                                    Assert.Fail();
                                };
                                d2.OnSyncConflict += (Dataset dataset, List<SyncConflict> conflicts) =>
                                {
                                    Assert.Fail();
                                    return false;
                                };
                                d2.OnDatasetDeleted += (Dataset dataset) =>
                                {
                                    Assert.Fail();
                                    return false;
                                };
                                d2.OnDatasetMerged += (Dataset dataset, List<string> datasetNames) =>
                                {
                                    Assert.Fail();
                                    return false;
                                };
                                RunAsSync(async () => await d2.SynchronizeAsync());
                            }
                        }
                    };
                    d.OnSyncFailure += delegate(object s, SyncFailureEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        Console.WriteLine(e.Exception.StackTrace);
                        Assert.Fail("Sync Failed");
                    };
                    d.OnSyncConflict += (Dataset dataset, List<SyncConflict> syncConflicts) =>
                    {
                        Assert.Fail();
                        return false;
                    };
                    d.OnDatasetDeleted += (Dataset dataset) =>
                    {
                        Assert.Fail();
                        return false;
                    };
                    d.OnDatasetMerged += (Dataset dataset, List<string> datasetNames) =>
                    {
                        Assert.Fail();
                        return false;
                    };
                    RunAsSync(async () => await d.SynchronizeAsync());
                }
            }
        }
コード例 #7
0
ファイル: SyncManager.cs プロジェクト: lawandeneel/Fashion
        public void DatasetCloudStorageTest()
        {
            using (CognitoSyncManager syncManager = new CognitoSyncManager(UnAuthCredentials))
            {
                syncManager.WipeData();
                Thread.Sleep(2000);
                using (Dataset d = syncManager.OpenOrCreateDataset("testDataset2"))
                {
                    d.Put("key", "he who must not be named");

                    d.OnSyncSuccess += delegate(object sender, SyncSuccessEventArgs e)
                    {
                        d.ClearAllDelegates();
                        string erasedValue = d.Get("key");
                        syncManager.WipeData();
                        d.OnSyncSuccess += delegate(object sender2, SyncSuccessEventArgs e2)
                        {
                            string restoredValues = d.Get("key");
                            Assert.IsNotNull(erasedValue);
                            Assert.IsNotNull(restoredValues);
                            Assert.AreEqual(erasedValue, restoredValues);
                        };

                        RunAsSync(async () => await d.SynchronizeAsync());
                    };
                    d.OnSyncFailure += delegate(object sender, SyncFailureEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        Console.WriteLine(e.Exception.StackTrace);
                        Assert.Fail("sync failed");
                    };
                    d.OnSyncConflict += (Dataset dataset, List<SyncConflict> conflicts) =>
                    {
                        Assert.Fail();
                        return false;
                    };
                    d.OnDatasetMerged += (Dataset dataset, List<string> datasetNames) =>
                    {
                        Assert.Fail();
                        return false;
                    };
                    d.OnDatasetDeleted += (Dataset dataset) =>
                    {
                        Assert.Fail();
                        return false;
                    };
                    d.SynchronizeAsync().Wait();
                }
            }
        }
コード例 #8
0
ファイル: SyncManager.cs プロジェクト: lawandeneel/Fashion
 public void DatasetLocalStorageTest()
 {
     {
         using (CognitoSyncManager syncManager = new CognitoSyncManager(UnAuthCredentials))
         {
             syncManager.WipeData();
             Dataset d = syncManager.OpenOrCreateDataset("testDataset");
             d.Put("testKey", "testValue");
         }
     }
     {
         using (CognitoSyncManager syncManager = new CognitoSyncManager(UnAuthCredentials))
         {
             Dataset d = syncManager.OpenOrCreateDataset("testDataset");
             Assert.AreEqual("testValue", d.Get("testKey"));
         }
     }
 }