Exemplo n.º 1
0
        public IDictionary<string, object> InsertRow(IDictionary<string, object> row)
        {
            ThrowIfMissing(row, "PartitionKey", "RowKey");

            var entry = DataServicesHelper.CreateDataElement(row);
            var request = _azureHelper.CreateTableRequest(_tableName, POST, entry.ToString());

            string text = string.Empty;

            if (_autoCreate)
            {
                try
                {
                    text = new RequestRunner().Request(request);
                }
                catch (TableServiceException ex)
                {
                    if (ex.Code == "TableNotFound")
                    {
                        Trace.WriteLine("Auto-creating table");
                        new TableService(_azureHelper).CreateTable(_tableName);
                        request = _azureHelper.CreateTableRequest(_tableName, POST, entry.ToString());

                        text = new RequestRunner().Request(request);
                    }
                }
            }
            else
            {
                text = new RequestRunner().Request(request);
            }

            return DataServicesHelper.GetData(text).First();
        }
Exemplo n.º 2
0
        private IEnumerable<IDictionary<string, object>> Get(string url)
        {
            IEnumerable<IDictionary<string, object>> result;
            var request = _azureHelper.CreateTableRequest(url, GET);

            using (var response = new RequestRunner().TryRequest(request))
            {
                Trace.WriteLine(response.StatusCode, "HttpResponse");

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    result = Enumerable.Empty<IDictionary<string, object>>();
                }
                else
                {
                    result = DataServicesHelper.GetData(response.GetResponseStream());
                }
            }

            return result;
        }