public ActionResult Create(string farmName) { // Validate request var userName = this.User.Identity.Name; if (string.IsNullOrWhiteSpace(userName)) { throw new NullReferenceException(); } var farm = TableStorageService.Insert(userName, farmName); return(View("Index", farm)); }
public bool Save(DeviceInput entity) { //List<Entity.BaseNoSqlEntity> lst = new List<Entity.BaseNoSqlEntity>(); //entity.RowKey = entity.ID.ToString(); //entity.PartitionKey = ApartmentConstants.PartitionKey; //entity.TableName = "Device"; //lst.Add(entity); //Entity.Address address = entity.Address; //address.PartitionKey = ApartmentConstants.PartitionKey; //address.TableName = "Address"; //address.RowKey = address.ID.ToString(); //lst.Add(address); //return SaveBatch(lst); TableStorageService <BaseAzureTableStorage> StorageService = new TableStorageService <BaseAzureTableStorage>(DeviceInputDataConstants.TableName); StorageService.CreateTable(); return(StorageService.Insert(entity)); }
public static async Task ReceiveFeedbackAsync(string terraConnString) { IHelper _helper = new Helper(ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"].ToString()); ITableStorageService _cloudTableManager = new TableStorageService(); ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(ConfigurationManager.ConnectionStrings["IoTHubConnectionString"].ToString()); var feedbackReceiver = serviceClient.GetFeedbackReceiver(); DateTime time = DateTime.Now; string feedback = String.Empty; try { while (true) { var feedbackBatch = await feedbackReceiver.ReceiveAsync(); if (feedbackBatch != null) { _helper.WriteInformation("Inside while loop " + DateTime.Now); foreach (FeedbackRecord feedbackBatchRecord in feedbackBatch.Records) { string temp = $"Device Id:{feedbackBatchRecord.DeviceId}-Status:{feedbackBatchRecord.StatusCode} - Message Id :{feedbackBatchRecord.OriginalMessageId}"; feedback += $"|{temp}|"; var messageToTerra = new { statusCode = (int)feedbackBatchRecord.StatusCode, description = feedbackBatchRecord.Description }; // var eventData = new EventData(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(messageToTerra))); IDictionary <string, string> appValues = new Dictionary <string, string>(); appValues.Add("DeviceId", feedbackBatchRecord.DeviceId); appValues.Add("DeviceGeneratedId", feedbackBatchRecord.DeviceGenerationId); appValues.Add("MessageId", feedbackBatchRecord.OriginalMessageId); appValues.Add("EnqueuedTimeUtc", feedbackBatchRecord.EnqueuedTimeUtc.ToString()); //eventData.Properties.Add("DeviceId", feedbackBatchRecord.DeviceId); //eventData.Properties.Add("DeviceGeneratedId", feedbackBatchRecord.DeviceGenerationId); //eventData.Properties.Add("MessageId", feedbackBatchRecord.OriginalMessageId); //eventData.Properties.Add("EnqueuedTimeUtc", feedbackBatchRecord.EnqueuedTimeUtc.ToString()); //Sending to Terra // var hubClient = EventHubClient.CreateFromConnectionString(terraConnString); // await hubClient.SendAsync(eventData); // store in table await _cloudTableManager.Insert <WOADeviceFeedbackEntity>("DeviceFeedbacks", feedbackBatchRecord.DeviceId, feedbackBatchRecord.OriginalMessageId, new WOADeviceFeedbackEntity() { DeviceStatus = feedbackBatchRecord.Description }); } await feedbackReceiver.CompleteAsync(feedbackBatch); } } } catch (Exception ex) { _helper.SendException(ex); _helper.WriteInformation("Feedback process unsuccessful.."); } }