Esempio n. 1
0
        public bool Delete(string pk)
        {
            #region try
            try
            {
                #region preconditions
                if (string.IsNullOrEmpty(pk))
                {
                    throw new Exception("Invalid parameters");
                }
                #endregion

                TableQuery <TableStorageEntry> rangeQuery = new TableQuery <TableStorageEntry>().Where(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, pk));

                TableStorageEntry _entry = table.ExecuteQuery(rangeQuery).FirstOrDefault <TableStorageEntry>();

                if (_entry != null)
                {
                    TableOperation delete = TableOperation.Delete(_entry);
                    table.Execute(delete);
                }
                return(true);
            }
            #endregion
            #region catch
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError(ex.Message);
                return(false);
            }
            #endregion
        }
Esempio n. 2
0
        public TableStorageEntry Get(string pk, string rk)
        {
            #region try
            try
            {
                #region preconditions
                if (string.IsNullOrEmpty(pk) || string.IsNullOrEmpty(rk))
                {
                    throw new Exception("Invalid parameters");
                }
                #endregion

                TableQuery <TableStorageEntry> rangeQuery = new TableQuery <TableStorageEntry>().Where(
                    TableQuery.CombineFilters(
                        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, pk),
                        TableOperators.And,
                        TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rk)));

                TableStorageEntry _entry = table.ExecuteQuery(rangeQuery).FirstOrDefault <TableStorageEntry>();
                if (_entry == null)
                {
                    return(null);
                }

                return(_entry);
            }
            #endregion
            #region catch
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError(ex.Message);
                return(null);
            }
            #endregion
        }
Esempio n. 3
0
        /// <summary>
        /// Convert the TableStorageEntry x in the object of type T
        /// </summary>
        public T convert <T>(object x)
        {
            TableStorageEntry entry = (TableStorageEntry)x;
            T elem = Utilities.GetObject <T>(entry.ToDictionary(partitionKey, rowKey));

            return(elem);
        }
Esempio n. 4
0
        public Dictionary <string, object> ToDictionary(object element)
        {
            if (element == null)
            {
                return(null);
            }

            TableStorageEntry entry = (TableStorageEntry)element;

            return(entry.ToDictionary(partitionKey, rowKey));
        }
Esempio n. 5
0
        /// <summary>
        /// It performs the update into the TableStorage
        /// The element dictionary can be written in the form {"PartitionKey",pkvalue},{"RowKey",rkvalue}
        /// or using explicitely the name for the partitionkey and rowkey
        /// </summary>
        public bool update(Dictionary <string, object> element)
        {
            #region try
            try
            {
                TableStorageEntry table_entry     = new TableStorageEntry(partitionKey, rowKey, element);
                TableOperation    insertOperation = TableOperation.InsertOrMerge(table_entry);
                table.Execute(insertOperation);

                return(true);
            }
            #endregion
            #region catch
            catch (Exception ex)
            {
                string error = "Error in function " + System.Reflection.MethodBase.GetCurrentMethod().Name + " - " + ex.Message;
                System.Diagnostics.Trace.TraceError(error);
                return(false);
            }
            #endregion
        }