public static TableEntity Get(string data)
        {
            TableEntity entity = new TableEntity();

            string[] lines = data.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries);

            if (lines.Count<string>() < 1)
                throw new Exception(string.Format("'{0}' is not a valid input",data));

            foreach (string line in lines)
            {
                string[] values = line.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                Debug.Assert(values.Length == 2);

                if (values.Count<string>() != 2)
                    throw new Exception(string.Format("'{0}' is not a valid input",line));

                if (values[0] == "PartitionKey")
                    entity.PartitionKey = values[1];
                else if (values[0] == "RowKey")
                    entity.RowKey = values[1];
                else
                    entity[values[0]] = values[1];
            }

            if (string.IsNullOrEmpty(entity.PartitionKey))
                entity.PartitionKey = "1";
            if (string.IsNullOrEmpty(entity.RowKey))
                entity.RowKey = Guid.NewGuid().ToString();

            return entity;
        }
		public static JsonTableData FromTableEntity(TableEntity table)
		{
			JsonTableData json = new JsonTableData();
			json.PartitionKey = table.PartitionKey;
			json.RowKey = table.RowKey;
			json.Payload = table.Values;
			return json;
		}
Esempio n. 3
0
        public static void DeleteEntity(string account, string key, string table, string partitionKey, string rowKey)
        {
            CloudTableClient tableClient = Client.GetTableClient(account, key);
            TableServiceContext context = tableClient.GetDataServiceContext();

            TableEntity entity = new TableEntity() { PartitionKey = partitionKey, RowKey = rowKey };

            context.AttachTo(table, entity, "*");
            context.DeleteObject(entity);
            context.SaveChangesWithRetries(SaveChangesOptions.None);
        }
Esempio n. 4
0
        public static void DeleteEntity(string account, string key, string table, string partitionKey, string rowKey)
        {
            CloudTableClient    tableClient = Client.GetTableClient(account, key);
            TableServiceContext context     = tableClient.GetDataServiceContext();

            TableEntity entity = new TableEntity()
            {
                PartitionKey = partitionKey, RowKey = rowKey
            };

            context.AttachTo(table, entity, "*");
            context.DeleteObject(entity);
            context.SaveChangesWithRetries(SaveChangesOptions.None);
        }
Esempio n. 5
0
        public static void Insert(string account, string key, string tableName, string data)
        {
            CloudTableClient tableClient = Client.GetTableClient(account, key);
            CloudTable       table       = tableClient.GetTableReference(tableName);
            TableEntity      entity      = TableEntity.Get(data);
            TableOperation   insert      = TableOperation.Insert(entity);

            table.Execute(insert);

            //TableServiceContext context = tableClient.GetTableServiceContext();
            //context.WritingEntity += new EventHandler<ReadingWritingEntityEventArgs>(context_WritingEntity);

            //context.AddObject(table, entity);

            //context.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate);
        }
Esempio n. 6
0
        public static TableEntity Get(string data)
        {
            TableEntity entity = new TableEntity();

            string[] lines = data.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            if (lines.Count <string>() < 1)
            {
                throw new Exception(string.Format("'{0}' is not a valid input", data));
            }

            foreach (string line in lines)
            {
                string[] values = line.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                Debug.Assert(values.Length == 2);

                if (values.Count <string>() != 2)
                {
                    throw new Exception(string.Format("'{0}' is not a valid input", line));
                }

                if (values[0] == "PartitionKey")
                {
                    entity.PartitionKey = values[1];
                }
                else if (values[0] == "RowKey")
                {
                    entity.RowKey = values[1];
                }
                else
                {
                    entity[values[0]] = values[1];
                }
            }

            if (string.IsNullOrEmpty(entity.PartitionKey))
            {
                entity.PartitionKey = "1";
            }
            if (string.IsNullOrEmpty(entity.RowKey))
            {
                entity.RowKey = Guid.NewGuid().ToString();
            }

            return(entity);
        }
Esempio n. 7
0
        static void context_WritingEntity(object sender, ReadingWritingEntityEventArgs e)
        {
            TableEntity entity = e.Entity as TableEntity;

            if (entity == null)
            {
                return;
            }

            XElement properties = e.Data.Element(AtomNamespace + "content").Element(AstoriaMetadataNamespace + "properties");

            properties.Element(AstoriaDataNamespace + "Values").Remove();

            foreach (KeyValuePair <string, string> pair in entity.GetProperties())
            {
                properties.Add(new XElement(AstoriaDataNamespace + pair.Key, pair.Value));
            }
        }
Esempio n. 8
0
        //static void context_ReadingEntity(object sender, ReadingWritingEntityEventArgs args)
        //{
        //	TableEntity entity = args.Entity as TableEntity;
        //	if (entity == null)
        //		return;

        //	// read each property, type and value in the payload
        //	var properties = args.Entity.GetType().GetProperties();
        //	var q = from p in args.Data.Element(AtomNamespace + "content")
        //							.Element(AstoriaMetadataNamespace + "properties")
        //							.Elements()
        //			where properties.All(pp => pp.Name != p.Name.LocalName)
        //			select new
        //			{
        //				Name = p.Name.LocalName,
        //				p.Value
        //			};

        //	foreach (var dp in q)
        //		entity[dp.Name] = dp.Value;
        //}

        public static void DeleteEntity(string account, string key, string tableName, string partitionKey, string rowKey)
        {
            CloudTableClient tableClient = Client.GetTableClient(account, key);
            CloudTable       table       = tableClient.GetTableReference(tableName);
            TableEntity      entity      = new TableEntity()
            {
                PartitionKey = partitionKey, RowKey = rowKey, ETag = "*"
            };
            TableOperation delete = TableOperation.Delete(entity);

            table.Execute(delete);

            //TableServiceContext context = tableClient.GetDataServiceContext();


            //context.AttachTo(table, entity, "*");
            //context.DeleteObject(entity);
            //context.SaveChangesWithRetries(SaveChangesOptions.None);
        }