Ejemplo n.º 1
0
    private async static Task TestWebPostStream()
    {
        var dmTable = GetATestTable();
        var dmSet   = new DmSet();

        dmSet.Tables.Add(dmTable);
        var surrgotabeTable = new DmSetSurrogate(dmSet);

        DmSerializer serializer = new DmSerializer();
        var          binaryData = serializer.Serialize(surrgotabeTable);

        Uri target = new Uri("http://localhost:5000/api/sync");

        var client = new HttpClient();

        ByteArrayContent arrayContent = new ByteArrayContent(binaryData);
        var response = await client.PostAsync(target, arrayContent);

        if (response.IsSuccessStatusCode)
        {
            using (var stream = await response.Content.ReadAsStreamAsync())
            {
                var ds = serializer.Deserialize <DmSetSurrogate>(stream);

                var newDs = ds.ConvertToDmSet();
            }
        }
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Clear the in memory Surrogate
 /// </summary>
 internal void Clear()
 {
     if (this.DmSetSurrogate != null)
     {
         this.DmSetSurrogate.Dispose();
         this.DmSetSurrogate = null;
     }
 }
        public void SetCacheConfiguration(SyncConfiguration configuration)
        {
            var dmSetConf = new DmSet();

            SyncConfiguration.SerializeInDmSet(dmSetConf, configuration);
            var dmSSetConf = new DmSetSurrogate(dmSetConf);

            this.CacheManager.Set(SYNC_CONF, dmSSetConf);
        }
Ejemplo n.º 4
0
        public void Create_DmSetSurrogate()
        {
            DmSetSurrogate dmSetSurrogate = new DmSetSurrogate(set);

            Assert.Equal(set.Tables.Count, dmSetSurrogate.Tables.Count);

            var records = dmSetSurrogate.Tables[0].Records;

            Assert.Equal(set.Tables[0].Rows.Count, records[0].Count);
        }
Ejemplo n.º 5
0
        public static void Serialize(DmSetSurrogate set, string fileName)
        {
            FileInfo fi = new FileInfo(fileName);

            if (!Directory.Exists(fi.Directory.FullName))
            {
                Directory.CreateDirectory(fi.Directory.FullName);
            }

            // Serialize on disk.
            using (var f = new FileStream(fileName, FileMode.CreateNew, FileAccess.ReadWrite))
            {
                BinaryFormatter serializer = new BinaryFormatter();
                serializer.Serialize(f, set);
            }
        }
Ejemplo n.º 6
0
        private async Task <HttpMessage> EnsureConfigurationAsync(HttpMessage httpMessage)
        {
            // we are calling the server side, so no need to pass a config object, since the config is stored on the server
            var(syncContext, conf) = await this.EnsureConfigurationAsync(httpMessage.SyncContext);

            httpMessage.SyncContext = syncContext;
            var scopeSurrogate = new DmSetSurrogate(conf.ScopeSet);

            conf.ScopeSet = null;
            httpMessage.EnsureConfiguration = new HttpEnsureConfigurationMessage
            {
                Configuration    = conf,
                ConfigurationSet = scopeSurrogate
            };

            return(httpMessage);
        }
Ejemplo n.º 7
0
        private async Task<HttpMessage> EnsureConfigurationAsync(HttpMessage httpMessage)
        {
            // we are calling the server side, so no need to pass a config object, since the config is stored on the server
            var (syncContext, conf) = await this.EnsureConfigurationAsync(httpMessage.SyncContext);

            httpMessage.SyncContext = syncContext;

            // since I will delete ScopeSet, we need to clone Cong
            // to be sure the caller will be able to reuse it
            var conf2 = conf.Clone();
            var scopeSurrogate = new DmSetSurrogate(conf2.ScopeSet);
            conf2.Clear();
            conf2.ScopeSet = null;

            httpMessage.EnsureConfiguration = new HttpEnsureConfigurationMessage
            {
                Configuration = conf2,
                ConfigurationSet = scopeSurrogate
            };

            return httpMessage;
        }
Ejemplo n.º 8
0
        public void Serialize_Object()
        {
            BaseConverter <Client> serializer = new DmBinaryConverter <Client>();

            Guid guid   = Guid.NewGuid();
            var  client = new Client
            {
                Id        = 1,
                ClientId  = guid,
                Birthday  = new DateTime(1976, 10, 23),
                FirstName = "sébastien",
                LastName  = "Pertus"
            };

            using (var ms = new MemoryStream())
            {
                serializer.Serialize(client, ms);

                ms.Position = 0;

                var client2 = serializer.Deserialize(ms);

                Assert.NotSame(client, client2);
                Assert.Equal(1, client2.Id);
                Assert.Equal(guid, client2.ClientId);
                Assert.Equal("sébastien", client2.FirstName);
            }

            var serializer2 = new DmBinaryConverter <List <Client> >();

            // Test List<T>
            var lst = new List <Client>();

            lst.Add(client);
            lst.Add(client);
            lst.Add(client);

            using (var ms = new MemoryStream())
            {
                serializer2.Serialize(lst, ms);

                ms.Position = 0;

                var lst2 = serializer2.Deserialize(ms);
                Assert.NotSame(lst, lst2);
                Assert.Equal(3, lst2.Count);
            }

            var serializer3 = new DmBinaryConverter <NullableClient>();

            // test nullable
            var client3 = new NullableClient
            {
                Id        = null,
                ClientId  = null,
                Birthday  = null,
                FirstName = "~#'\"é{[",
                LastName  = null,
                Money     = null
            };

            using (var ms = new MemoryStream())
            {
                serializer3.Serialize(client3, ms);

                ms.Position = 0;

                var client4 = serializer3.Deserialize(ms);

                Assert.NotSame(client3, client4);
                Assert.Null(client4.Id);
                Assert.Null(client4.ClientId);
                Assert.Null(client4.Birthday);
                Assert.Null(client4.LastName);
                Assert.Null(client4.Money);
                Assert.Equal("~#'\"é{[", client4.FirstName);
            }

            var serializer4 = new DmBinaryConverter <DmSetSurrogate>();


            // Test on datatable
            var ds  = new DmSet("Fabrikam");
            var tbl = new DmTable("ServiceTickets");
            var id  = new DmColumn <Guid>("ServiceTicketID");

            tbl.Columns.Add(id);
            var key = new DmKey(new DmColumn[] { id });

            tbl.PrimaryKey = key;
            tbl.Columns.Add(new DmColumn <string>("Title"));
            tbl.Columns.Add(new DmColumn <string>("Description"));
            tbl.Columns.Add(new DmColumn <int>("StatusValue"));
            tbl.Columns.Add(new DmColumn <int>("EscalationLevel"));
            tbl.Columns.Add(new DmColumn <DateTime>("Opened"));
            tbl.Columns.Add(new DmColumn <DateTime>("Closed"));
            tbl.Columns.Add(new DmColumn <int>("CustomerID"));

            var st = tbl.NewRow();

            st["ServiceTicketID"] = Guid.NewGuid();
            st["Title"]           = "Titre AER";
            st["Description"]     = "Description 2";
            st["EscalationLevel"] = 1;
            st["StatusValue"]     = 2;
            st["Opened"]          = DateTime.Now;
            st["Closed"]          = null;
            st["CustomerID"]      = 1;
            tbl.Rows.Add(st);
            ds.Tables.Add(tbl);

            var dsSurrogate = new DmSetSurrogate(ds);

            using (var ms = new MemoryStream())
            {
                serializer4.Serialize(dsSurrogate, ms);

                ms.Position = 0;

                var dsSurrogate2 = serializer4.Deserialize(ms);

                var ds2 = dsSurrogate2.ConvertToDmSet(ds);

                Assert.NotSame(ds, ds2);
                Assert.Equal(ds.CaseSensitive, ds2.CaseSensitive);
                Assert.Equal(ds.Culture, ds2.Culture);
                Assert.Equal(ds.DmSetName, ds2.DmSetName);
                Assert.Equal(ds.Tables.Count, ds2.Tables.Count);
                Assert.Equal(ds.Tables[0].Columns.Count, ds2.Tables[0].Columns.Count);
                Assert.Equal(ds.Tables[0].Rows.Count, ds2.Tables[0].Rows.Count);
                Assert.Equal(ds.Tables[0].PrimaryKey.Columns.Length, ds2.Tables[0].PrimaryKey.Columns.Length);
            }
        }