Exemplo n.º 1
0
        public void WriteEntityContactMessage()
        {
            var msg = new ContactMessage
            {
                From = new Contact
                {
                    ContactId = "A",
                    DisplayName = "Bob"
                },
                To = new Contact
                {
                    ContactId = "B",
                    DisplayName = "Jane"
                },
                MessageBody = "Test"
            };

            var context = new OperationContext();
            var proxy = new TableEntityProxy<ContactMessage>(msg);
            var props = proxy.WriteEntity(context);
            Assert.AreEqual("A", props["FromContactId"].StringValue);
            Assert.AreEqual("Bob", props["FromDisplayName"].StringValue);
            Assert.AreEqual("B", props["ToContactId"].StringValue);
            Assert.AreEqual("Jane", props["ToDisplayName"].StringValue);
        }
        public void WriteEntityContactMessage()
        {
            var msg = new ContactMessage
            {
                From = new Contact
                {
                    ContactId   = "A",
                    DisplayName = "Bob"
                },
                To = new Contact
                {
                    ContactId   = "B",
                    DisplayName = "Jane"
                },
                MessageBody = "Test"
            };

            var context = new OperationContext();
            var proxy   = new TableEntityProxy <ContactMessage>(msg);
            var props   = proxy.WriteEntity(context);

            Assert.AreEqual("A", props["FromContactId"].StringValue);
            Assert.AreEqual("Bob", props["FromDisplayName"].StringValue);
            Assert.AreEqual("B", props["ToContactId"].StringValue);
            Assert.AreEqual("Jane", props["ToDisplayName"].StringValue);
        }
Exemplo n.º 3
0
        public void WriteEntityContact()
        {
            var contact = new Contact
            {
                ContactId = "A",
                DisplayName = "Bob"
            };

            var context = new OperationContext();
            var proxy = new TableEntityProxy<Contact>(contact);
            var props = proxy.WriteEntity(context);
            Assert.AreEqual("A", props["ContactId"].StringValue);
            Assert.AreEqual("Bob", props["DisplayName"].StringValue);
        }
        public void WriteEntityContact()
        {
            var contact = new Contact
            {
                ContactId   = "A",
                DisplayName = "Bob"
            };

            var context = new OperationContext();
            var proxy   = new TableEntityProxy <Contact>(contact);
            var props   = proxy.WriteEntity(context);

            Assert.AreEqual("A", props["ContactId"].StringValue);
            Assert.AreEqual("Bob", props["DisplayName"].StringValue);
        }
        private TableEntityProxy<DynamicTableEntity> CreateSequenceFromSchema(string tableName)
        {
            var schema = SchemaTableProxy.Get(tableName.GetValidPartitionKey(), tableName.GetValidRowKey());
            if (schema == null)
                throw new ArgumentException(String.Format("Sequence '{0}' is not defined.  Cannot get the latest reserved key value.", tableName));

            var sequence = new TableEntityProxy<DynamicTableEntity>(new DynamicTableEntity(schema.PartitionKey, schema.RowKey, "",
                new Dictionary<string, EntityProperty>()));
            sequence.Entity.Properties.Add(PropertyFinalCachedId, new EntityProperty(schema.Entity.SeedValue));
            SequenceTableProxy.Insert(sequence.Entity);
            //Insert would throw if another thread created after SequenceTableProxy.Get was called above.  Only one thread can create the sequence.
            //  - a lock would not help, since the other thread may be in another role (web or worker) instance
            return sequence;
        }
 /// <summary>
 /// Gets all sequence definitions available.
 /// </summary>
 /// <returns></returns>
 public IEnumerable<SequenceIdStore> GetSequenceIdStores()
 {
     var schemas = SchemaTableProxy.QueryPartitions("0", "zzzzz");
     var sequences = SequenceTableProxy.QueryPartitions("0", "zzzzz") ?? new List<TableEntityProxy<DynamicTableEntity>>();
     var stores = new List<SequenceIdStore>();
     foreach (var schema in schemas)
     {
         var sequence =
             sequences.FirstOrDefault(x =>
                 String.Equals(schema.Entity.TableName, x.Entity[TableConstants.PartitionKey].StringValue,
                               StringComparison.InvariantCultureIgnoreCase));
         if (sequence == null)
         {
             sequence = new TableEntityProxy<DynamicTableEntity>(new DynamicTableEntity(schema.PartitionKey, schema.RowKey, "",
                 new Dictionary<string, EntityProperty>()));
             sequence.Entity.Properties.Add(PropertyFinalCachedId, new EntityProperty(schema.Entity.SeedValue));
             SequenceTableProxy.Insert(sequence.Entity); //this could throw if another thread created after SequenceTableProxy.QueryPartitions was called above.
         }
         stores.Add(new SequenceIdStore
             {
                 FinalCachedId = sequence.Entity.Properties[PropertyFinalCachedId].StringValue,
                 Schema = schema.Entity
             });
     }
     return stores;
 }