public void InsertToTableStorage(string auditLogMessage)
        {
            string value = Constants.TableStorageConnection;// ConfigurationManager.AppSettings["TableStorageConnectionString"].ToString();

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(value);

            // Create the table client.
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            // Retrieve a reference to the table.
            CloudTable table = tableClient.GetTableReference(this._StorageName);

            // Create the table if it doesn't exist.
            table.CreateIfNotExists();

            string partitionKey = DateTime.Now.ToString("MMMMyyyy");
            ////Since rowKey should be constant
            string rowKey = DateTime.Now.Ticks.ToString();

            //var guid = Guid.NewGuid().ToString().Replace("-", string.Empty);
            //var rowKey = guid.Substring(0, 18);

            // Create a new entity.
            TableStorageEntity tableStorageEntity = new TableStorageEntity(partitionKey, rowKey);

            tableStorageEntity.jsonResp     = this._jsonResp;
            tableStorageEntity.RequestToken = this._RequestToken;
            tableStorageEntity.Response     = this._Response;
            tableStorageEntity.Stage        = this._Stage;
            tableStorageEntity.Clientid     = this._Clientid;
            tableStorageEntity.UserName     = this._UserName;
            tableStorageEntity.ClientSecret = this._ClientSecret;
            tableStorageEntity.Statecd      = this._Statecd;
            tableStorageEntity.AuthToken    = this._AuthToken;
            tableStorageEntity.IpUsr        = this._IpUsr;
            tableStorageEntity.AuditMessage = auditLogMessage;
            tableStorageEntity.Time         = this._Time;
            this._RowKKey                   = rowKey;
            tableStorageEntity.RowKey       = this._RowKKey;
            tableStorageEntity.PartitionKey = this._PartitionKey;

            // Create the TableOperation object that inserts the entity.
            TableOperation insertOperation = TableOperation.Insert(tableStorageEntity);

            // Execute the insert operation.
            table.Execute(insertOperation);
        }
Beispiel #2
0
        public static string BuildKey(object dataItem)
        {
            TableStorageEntity SE = dataItem as TableStorageEntity;

            return(string.Format("{0}|{1}", SE.PartitionKey, SE.RowKey));
        }
        /*
         * public void Total_TableStorage_Count()
         * {
         *  string value = Constants.TableStorageConnection;// ConfigurationManager.AppSettings["TableStorageConnectionString"].ToString();
         *
         *  CloudStorageAccount storageAccount = CloudStorageAccount.Parse(value);
         *
         *  // Create the table client.
         *  CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
         *
         *  // Retrieve a reference to the table.
         *  CloudTable table = tableClient.GetTableReference(_StorageName);
         *
         *  // Create the table if it doesn't exist.
         *  table.CreateIfNotExists();
         *
         *  string partitionKey = this._PartitionKey;
         *  string rowKey = this._RowKKey;
         *
         *  // Create a new entity.
         *  TableStorageEntity tableStorageEntity = new TableStorageEntity(partitionKey, rowKey);
         *
         *  tableStorageEntity.Clientid = this._Clientid;
         *
         *  // Construct the query operation for all customer entities where PartitionKey="Smith".
         *  TableQuery<TableStorageEntity> query = new TableQuery<TableStorageEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, this._PartitionKey));
         *
         *  int ClientIdCount = table.ExecuteQuery(query).Count();
         *
         *  Console.WriteLine("ClientId Count {0}", ClientIdCount);
         *
         *
         *
         * }
         *
         */
        public bool ReadFromTableStorage(string clientid)
        {
            string value = Constants.TableStorageConnection;// ConfigurationManager.AppSettings["TableStorageConnectionString"].ToString();

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(value);

            // Create the table client.
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            // Retrieve a reference to the table.
            CloudTable table = tableClient.GetTableReference(_StorageName);

            // Create the table if it doesn't exist.
            table.CreateIfNotExists();

            string partitionKey = this._PartitionKey;
            string rowKey       = this._RowKKey;

            // Create a new entity.
            TableStorageEntity tableStorageEntity = new TableStorageEntity(partitionKey, rowKey);

            tableStorageEntity.Clientid = this._Clientid;



            // Construct the query operation for all customer entities where PartitionKey="Smith".
            TableQuery <TableStorageEntity> query = new TableQuery <TableStorageEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, this._PartitionKey));

            int ClientIdCount = table.ExecuteQuery(query).Count();
            int LastEntry     = table.ExecuteQuery(query).Count() - 1;

            //int k = 1;
            //foreach (TableStorageEntity entity in table.ExecuteQuery(query))
            //{


            //    if (LastEntry == k)
            //    {
            //        Console.WriteLine("{0}, UserName={1}\t ClientId={2}", entity.PartitionKey, entity.UserName, entity.Clientid);
            //    }

            //    k++;
            //}

            Console.WriteLine("ClientId Count {0}", ClientIdCount);

            // Create a retrieve operation that takes a TableStorageEntity.
            TableOperation retrieveOperation = TableOperation.Retrieve <TableStorageEntity>(this._PartitionKey, this._RowKKey);

            // Execute the retrieve operation.
            TableResult retrievedResult = table.Execute(retrieveOperation);

            TableStorageEntity TSE = RetrieveRecord(table, this._PartitionKey, this._RowKKey);

            if (TSE != null)
            {
                Console.WriteLine("Record exists");
            }
            else
            {
                Console.WriteLine("Record does not exists");
            }



            // Print the phone number of the result.
            if (retrievedResult.Result != null)
            {
                Console.WriteLine("The entry exists.");
                return(false);
            }
            else
            {
                Console.WriteLine("The entry number could not be retrieved.");
                return(true);
            }

            // Execute the insert operation.
            // table.Execute(insertOperation);
        }