public IActionResult Add(CategoryEntity entity)
        {
            int errorCode = 0;

            try
            {
                if (CacheHelper.GetCategoryList(entity.PartitionKey).Count(cat => cat.NameHash.Equals(entity.NameHash)) > 0)
                {
                    errorCode = Constants.ERROR_CODE_ENTITY_ALREADY_EXISTS;
                }
                else
                {
                    string nextSortNumber = SequenceHelper.GetNextSequence(Constants.SORT, Constants.TABLE_CATEGORY + "_" + entity.PartitionKey, Constants.PADDING_SORT);

                    string nextID = SequenceHelper.GetNextSequence(Constants.ID, Constants.TABLE_CATEGORY, Constants.PADDING_CATEGORYID);

                    entity.RowKey = nextSortNumber + "_" + nextID;


                    TableStorageHelper.InsertOrMergeAsync(Constants.TABLE_CATEGORY, entity).Wait();

                    CacheHelper.ClearCategoryListCache();
                }
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }


            return(RedirectToAction("Index", new { category = entity.PartitionKey, errorCode = errorCode }));
        }
        public IActionResult Edit(CategoryEntity entity)
        {
            int errorCode = 0;

            try
            {
                if (CacheHelper.GetCategoryList(entity.PartitionKey).Count(cat => cat.NameHash.Equals(entity.NameHash) && !cat.ID.Equals(entity.ID)) > 0)
                {
                    errorCode = Constants.ERROR_CODE_ENTITY_ALREADY_EXISTS;
                }
                else
                {
                    TableStorageHelper.MergeAsync(Constants.TABLE_CATEGORY, entity).Wait();

                    CacheHelper.ClearCategoryListCache();
                }
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { category = entity.PartitionKey, errorCode = errorCode }));
        }
        //public IActionResult Delete(CategoryEntity entity)
        //{
        //    int errorCode = 0;

        //    try
        //    {
        //        entity.Visibility = false;
        //        TableStorageHelper.MergeAsync(Constants.TABLE_CATEGORY, entity).Wait();

        //        CacheHelper.ClearCategoryListCache();
        //    }
        //    catch (Exception ex)
        //    {
        //        if (!TableStorageHelper.IsStorageException(ex, out errorCode))
        //        {
        //            errorCode = Constants.ERROR_CODE_COMMON;
        //        }
        //    }

        //    return RedirectToAction("Index", new { category = entity.PartitionKey, errorCode = errorCode });
        //}

        public IActionResult Sort(CategoryEntity up, CategoryEntity down)
        {
            int errorCode = 0;

            try
            {
                CategoryEntity newUp   = new CategoryEntity(up.PartitionKey, up.RowKey);
                CategoryEntity newDown = new CategoryEntity(down.PartitionKey, down.RowKey);

                up.CopyTo(newUp, false);
                down.CopyTo(newDown, false);

                string upSortNumber   = up.RowKey.Split('_')[0];
                string downSortNumber = down.RowKey.Split('_')[0];

                newUp.RowKey   = downSortNumber + "_" + newUp.ID;
                newDown.RowKey = upSortNumber + "_" + newDown.ID;

                TableStorageHelper.BatchAsync(Constants.TABLE_CATEGORY, new CategoryEntity[] { up, down }, new CategoryEntity[] { newUp, newDown }, null).Wait();

                CacheHelper.ClearCategoryListCache();
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { category = up.PartitionKey, errorCode = errorCode }));
        }
Exemplo n.º 4
0
        private string InsertTag(string newTag, string currentTag)
        {
            currentTag = currentTag?.Trim() ?? "";

            bool newTagAdded = false;

            int  nextID     = -1;
            bool nextIDUsed = true;

            if (!string.IsNullOrEmpty(newTag?.Trim()) && newTag.Trim() != "|")
            {
                string[] nt = newTag.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string text in nt)
                {
                    if (!string.IsNullOrEmpty(text?.Trim()))
                    {
                        TagEntity tag = CacheHelper.GetTagList().FirstOrDefault(te => te.RowKey.Trim().ToLower() == text.Trim().ToLower());

                        if (tag == null)
                        {
                            if (nextIDUsed)
                            {
                                nextID = int.Parse(SequenceHelper.GetNextSequence("ID", Constants.TABLE_TAG, null));
                            }
                            tag = new POCO.TagEntity("Tag", text.Trim())
                            {
                                ID = nextID
                            };

                            try
                            {
                                TableStorageHelper.InsertAsync(Constants.TABLE_TAG, tag).Wait();
                                nextIDUsed  = true;
                                newTagAdded = true;
                            }
                            catch (Exception ex)
                            {
                                nextIDUsed = false;
                                CacheHelper.ClearTagListCache();
                                tag = CacheHelper.GetTagList().FirstOrDefault(te => te.RowKey.Trim().ToLower() == text.Trim().ToLower());
                            }
                        }

                        if (tag != null)
                        {
                            currentTag = currentTag + (currentTag.Trim().Length == 0 ? "|" : "") + tag.ID + "|";
                        }
                    }
                }

                if (newTagAdded)
                {
                    CacheHelper.ClearTagListCache();
                }
            }


            return(currentTag);
        }
Exemplo n.º 5
0
        // GET: /<controller>/
        public IActionResult Index([FromQuery] string CurrentCategoryID, [FromQuery] int?Priority, [FromQuery] int?Top, [FromQuery] string Tag, [FromQuery] string errorCode)
        {
            DashboardModel data = new DashboardModel();

            data.StyleIDForTags = new HashSet <string>();

            data.Categories    = CacheHelper.GetCategoryList(Constants.BASE_CATEGORY).Where(cat => cat.Visibility == (int)Visibility.True);
            data.Technologies  = new Dictionary <string, IEnumerable <TechnologyEntity> >();
            data.Subcategories = new Dictionary <string, IEnumerable <CategoryEntity> >();

            foreach (CategoryEntity category in data.Categories)
            {
                data.Technologies.Add(category.ID, TableStorageHelper.RetrieveByRangeAsync <TechnologyEntity>(Constants.TABLE_TECHNOLOGY, category.ID, "ge", "T", "lt", "U").Result.Where(tech => tech.Visibility == (int)Visibility.True));

                data.Subcategories.Add(category.ID, CacheHelper.GetCategoryList(category.ID).Where(cat => cat.Visibility == (int)Visibility.True));
            }

            data.TagList = CacheHelper.GetTagList();


            data.CurrentCategoryID = data.Categories.FirstOrDefault(c => c.ID.Equals(CurrentCategoryID?.Trim() ?? ""))?.ID ?? data.Categories.FirstOrDefault()?.ID ?? "";

            data.Priority = Priority ?? 0;

            data.Top = Top?.ToString() ?? "";

            data.Tag = Tag?.Trim() ?? "";

            if (!string.IsNullOrEmpty(errorCode))
            {
                ViewData["errorCode"] = errorCode;
            }

            return(View(data));
        }
        public async Task <ActionResult> DeleteTodoItem(string id)
        {
            _logger.LogInformation($"Deleting Todo item, id: {id}");

            var table = TableStorageHelper.GetTableReference(_storageConnectionString, _tableName);

            var deleteOp = TableOperation.Delete(new TableEntity
            {
                PartitionKey = TodoItemMapper.TablePartitionKey,
                RowKey       = id,
                ETag         = "*"
            });

            try
            {
                var deleteResult = await table.ExecuteAsync(deleteOp);
            }
            catch (StorageException ex)
            {
                if (ex.RequestInformation.HttpStatusCode == StatusCodes.Status404NotFound)
                {
                    return(new NotFoundResult());
                }
            }

            return(new NoContentResult());
        }
        public async Task <ActionResult <TodoItem> > UpdateTodoItem(string id, TodoItem todoItem)
        {
            _logger.LogInformation($"Updating Todo item, id: {id}");

            if (todoItem == null || id != todoItem.Id || string.IsNullOrWhiteSpace(todoItem.Name))
            {
                return(new BadRequestResult());
            }

            var table = TableStorageHelper.GetTableReference(_storageConnectionString, _tableName);

            var findOp     = TableOperation.Retrieve <TodoItemEntity>(TodoItemMapper.TablePartitionKey, id);
            var findResult = await table.ExecuteAsync(findOp);

            if (findResult.Result == null)
            {
                return(new NotFoundResult());
            }

            var todoEntity = (TodoItemEntity)findResult.Result;

            todoEntity.Name        = todoItem.Name;
            todoEntity.IsCompleted = todoItem.IsCompleted;

            var replaceOp = TableOperation.Replace(todoEntity);
            await table.ExecuteAsync(replaceOp);

            return(new OkObjectResult(todoEntity.ToModel()));
        }
Exemplo n.º 8
0
 public DeviceGroupMigration(TableStorageHelper tableStorageClient, TenantConnectionHelper tenantConnectionHelper, ILogger logger, AppConfig appConfig)
 {
     this.tableStorageClient     = tableStorageClient;
     this.tenantConnectionHelper = tenantConnectionHelper;
     this.logger    = logger;
     this.appConfig = appConfig;
 }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var connectString = ConfigurationManager.AppSettings["AzureStorage"];
            var storageHelper = new TableStorageHelper(connectString);

            //insert
            //var member = new Member("Hong", "Long2")
            //{
            //    Address = "HongKung",
            //    Phone = "123456"
            //};
            //var result = storageHelper.Insert("KyleTest", member);


            //query
            //var result = storageHelper.Query<Member>("KyleTest", x => x.PartitionKey == "Lin");
            //var data = result.data;

            //query first
            //var obj = storageHelper.Query<Member>("KyleTest", "Lin", "Hue");
            //obj.entity.Phone = "99999";
            //var result = storageHelper.Update("KyleTest", obj.entity);

            //delete
            storageHelper.Delte <Member>("KyleTest", "Lin", "Hue");
        }
Exemplo n.º 10
0
        public IActionResult Edit(TechnologyEntity technology, string OriginalNameHash, bool isSubcategoryInQuery)
        {
            int errorCode = 0;

            try
            {
                technology.Description = technology.Description ?? "";

                technology.Tag = InsertTag(technology.NewTag, technology.Tag);

                if (OriginalNameHash.Equals(technology.NameHash))
                {
                    TableStorageHelper.MergeAsync(Constants.TABLE_TECHNOLOGY, technology).Wait();
                }
                else
                {
                    DuplicateCheckEntity duplicateCheckOriginalDelete = new DuplicateCheckEntity(technology.PartitionKey, technology.SubcategoryID + "_" + OriginalNameHash);
                    duplicateCheckOriginalDelete.ETag = "*";

                    DuplicateCheckEntity duplicateCheckNewAdd = new DuplicateCheckEntity(technology.PartitionKey, technology.SubcategoryID + "_" + technology.NameHash);

                    TableStorageHelper.BatchAsync(Constants.TABLE_TECHNOLOGY, new DuplicateCheckEntity[] { duplicateCheckOriginalDelete }, new DuplicateCheckEntity[] { duplicateCheckNewAdd }, new TechnologyEntity[] { technology }).Wait();
                }
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode, category = technology.PartitionKey, subcategory = ((isSubcategoryInQuery) ? technology.SubcategoryID : ""), technology = technology.ID }));
        }
Exemplo n.º 11
0
        public IActionResult Edit(UserEntity user)
        {
            int errorCode = 0;

            try
            {
                if ((HttpContext?.User?.Identity?.Name ?? "").Trim().ToLower().Equals((user?.RowKey?.Trim()?.ToLower() ?? "Q!@QQW@!")) ||
                    (HttpContext?.User?.Identity?.Name ?? "") == "sachin")
                {
                    user.ETag = "*";
                    TableStorageHelper.MergeAsync(Constants.TABLE_USER, user).Wait();

                    CacheHelper.ClearUsersCache();
                }
                else
                {
                    errorCode = Constants.ERROR_CODE_ACCESS_DENIED;
                }
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode }));
        }
Exemplo n.º 12
0
        private static async Task Main(string[] args)
        {
            var     appConfig = InitializeAppConfig();
            ILogger logger    = LoggerSetup();

            try
            {
                AppConfigHelper        appConfigHelper        = new AppConfigHelper(appConfig.AppConfigurationConnectionString);
                TableStorageHelper     tableStorageHelper     = new TableStorageHelper(appConfig);
                TenantConnectionHelper tenantConnectionHelper = new TenantConnectionHelper(appConfigHelper);
                DeviceGroupMigration   deviceGroupMigration   = new DeviceGroupMigration(tableStorageHelper, tenantConnectionHelper, logger, appConfig);
                logger.LogInformation("Device Group Migration Started");
                await deviceGroupMigration.Start();

                logger.LogInformation("Device Group Migration Completed");

                DeviceTwinMigration deviceTwinMigration = new DeviceTwinMigration(tableStorageHelper, tenantConnectionHelper, logger);
                logger.LogInformation("Device Twin Migration Started");
                await deviceTwinMigration.Start();

                logger.LogInformation("Device Twin Migration Completed");
            }
            catch (System.Exception ex)
            {
                logger.LogError(ex, "Migration Failed");
            }
        }
Exemplo n.º 13
0
        public IActionResult SetDefaultUpdateByForStatusHistory(string username)
        {
            try
            {
                username = username?.Trim() ?? "";
                if (HttpContext.User.Identity.Name.Equals("sachin") && username.Length > 0)
                {
                    foreach (CategoryEntity category in CacheHelper.GetCategoryList(Constants.BASE_CATEGORY))
                    {
                        IEnumerable <TechnologyStatusEntity> statuses = TableStorageHelper.RetrieveByRangeAsync <TechnologyStatusEntity>(Constants.TABLE_TECHNOLOGY, category.ID, "ge", "S", "lt", "T").Result;
                        foreach (TechnologyStatusEntity status in statuses)
                        {
                            if (string.IsNullOrEmpty(status?.Username?.Trim()))
                            {
                                status.Username = username;
                            }
                        }

                        TableStorageHelper.BatchAsync(Constants.TABLE_TECHNOLOGY, null, null, statuses.ToArray()).Wait();
                    }
                    ViewData["ExecutionStatus"] = "Succeed.";
                }
                else
                {
                    ViewData["ExecutionStatus"] = "Failed.";
                }
            }
            catch
            {
                ViewData["ExecutionStatus"] = "Failed.";
            }

            return(View());
        }
Exemplo n.º 14
0
        public IActionResult Add(TechnologyEntity technology, string StatusRemarks, bool isSubcategoryInQuery)
        {
            int    errorCode = 0;
            string nextID    = "";

            try
            {
                nextID = SequenceHelper.GetNextSequence(Constants.ID, Constants.TABLE_TECHNOLOGY, Constants.PADDING_TECHNOLOGYID);

                technology.RowKey = technology.RowKey + "_" + nextID;

                technology.Description = technology.Description ?? "";

                technology.Tag = InsertTag(technology.NewTag, technology.Tag);

                DuplicateCheckEntity duplicateCheck = new DuplicateCheckEntity(technology.PartitionKey, technology.SubcategoryID + "_" + technology.NameHash);

                TechnologyStatusEntity technologyStatus = GetTechnologyStatusEntity(technology.PartitionKey, nextID, technology.Status, StatusRemarks);

                TableStorageHelper.InsertBatchAsync(Constants.TABLE_TECHNOLOGY, duplicateCheck, technology, technologyStatus).Wait();
            }
            catch (Exception ex)
            {
                nextID = "";
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode, category = technology.PartitionKey, subcategory = ((isSubcategoryInQuery) ? technology.SubcategoryID : ""), technology = nextID }));
        }
Exemplo n.º 15
0
        public TableStorageClientsStore(IOptions <CloudConfiguration> cloudConfig)
        {
            var storageConnectionString = cloudConfig.Value.StorageConnectionString;
            var account            = TableStorageHelper.CreateStorageAccountFromConnectionString(storageConnectionString);
            var tableStorageClient = account.CreateCloudTableClient();

            _table = tableStorageClient.GetTableReference(TableNames.Clients);
        }
Exemplo n.º 16
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            [Table(nameof(SomeEntity), SomeEntity.PARTITION_KEY, Connection = "scs")] CloudTable table,
            ILogger log)
        {
            // The instance of CloudTable in this case has a reference to the entities in the specified partition of the table.
            var result = await TableStorageHelper.GetEntitiesFromTable <SomeEntity>(table);

            return(new OkObjectResult(result));
        }
        public async Task <IActionResult> GetHealthCheck()
        {
            _logger.LogInformation("Checking Health of Application");

            var table = TableStorageHelper.GetTableReference(_storageConnectionString, _tableName);

            var tableExists = await table.ExistsAsync();

            return(tableExists ? new OkResult() : new StatusCodeResult((int)HttpStatusCode.ServiceUnavailable));
        }
Exemplo n.º 18
0
        public void Notify(string deviceID, string message)
        {
            var context = GlobalHost.ConnectionManager.GetConnectionContext <MyEndPoint>();

            TableStorageHelper tableStorage = new TableStorageHelper();
            var    devEntity = tableStorage.Get("device", deviceID);
            string connID    = devEntity.ConnectionID;

            context.Connection.Send(connID, message);
            //context.Connection.Broadcast(message);
        }
        public async Task <ActionResult <IEnumerable <TodoItem> > > GetTodoItems()
        {
            _logger.LogInformation("Getting array of all Todo items");

            var table = TableStorageHelper.GetTableReference(_storageConnectionString, _tableName);

            var query   = new TableQuery <TodoItemEntity>();
            var segment = await table.ExecuteQuerySegmentedAsync(query, null);

            var items = segment.Select(TodoItemMapper.ToModel);

            return(new OkObjectResult(items));
        }
Exemplo n.º 20
0
        protected override Task OnConnected(IRequest request, string connectionId)
        {
            string deviceID = request.QueryString["deviceId"].ToLowerInvariant();

            TableStorageHelper tableStorage = new TableStorageHelper();
            var devEntity = new DeviceEntity("device", deviceID)
            {
                ConnectionID = connectionId
            };

            tableStorage.AddOfUpdateDevice(devEntity);

            return(Connection.Broadcast("Connection " + connectionId + " connected"));
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            var connectString = ConfigurationManager.AppSettings["AzureStorage"];
            var storageHelper = new TableStorageHelper(connectString);

            var rand = new Random();
            var temp = rand.Next(1, 13);
            //insert
            var member = new Member("Hong", temp.ToString())
            {
                Date = DateTime.UtcNow.AddHours(8)
            };
            var result = storageHelper.Insert("KyleTest", member);
        }
Exemplo n.º 22
0
        public IActionResult StatusHistory(string PartitionKey, string RowKey)
        {
            ViewData["divID"] = (PartitionKey ?? "") + "_" + (RowKey ?? "");

            string technologyID = (RowKey ?? "T_ASDF_-12345").Split('_')[2];

            string value1 = "S_" + technologyID;

            string value2 = "S_" + (int.Parse(technologyID) + 1).ToString(Constants.PADDING_TECHNOLOGYID);

            IEnumerable <TechnologyStatusEntity> statusList = TableStorageHelper.RetrieveByRangeAsync <TechnologyStatusEntity>(Constants.TABLE_TECHNOLOGY, PartitionKey ?? "", "ge", value1, "lt", value2).Result;


            return(PartialView(statusList));
        }
Exemplo n.º 23
0
        public IActionResult Index([FromQuery] int?category, [FromQuery] int?subcategory, [FromQuery] int?technology, [FromQuery] string errorCode)
        {
            TechnologyViewModel data = new POCO.TechnologyViewModel();

            data.CategoryID    = category?.ToString(Constants.PADDING_CATEGORYID);
            data.SubcategoryID = subcategory?.ToString(Constants.PADDING_CATEGORYID);
            data.TechnologyID  = technology?.ToString(Constants.PADDING_TECHNOLOGYID);

            if (category != null)
            {
                string value1 = (subcategory != null ? "T_" + ((int)subcategory).ToString(Constants.PADDING_CATEGORYID) : "T");

                string value2 = (subcategory != null ? "T_" + ((int)subcategory + 1).ToString(Constants.PADDING_CATEGORYID) : "U");

                data.Technologies = TableStorageHelper.RetrieveByRangeAsync <TechnologyEntity>(Constants.TABLE_TECHNOLOGY, ((int)category).ToString(Constants.PADDING_CATEGORYID), "ge", value1, "lt", value2).Result;

                data.Subcategories = CacheHelper.GetCategoryList(((int)category).ToString(Constants.PADDING_CATEGORYID));

                data.TagList = CacheHelper.GetTagList();

                data.Active = new Microsoft.AspNetCore.Mvc.Rendering.SelectListGroup()
                {
                    Name = "Active"
                };
                data.Inactive = new Microsoft.AspNetCore.Mvc.Rendering.SelectListGroup()
                {
                    Name = "Inactive"
                };

                data.CategoryName = CacheHelper.GetCategoryList(Constants.BASE_CATEGORY).FirstOrDefault(cat => cat.ID.Equals(((int)category).ToString(Constants.PADDING_CATEGORYID)))?.Name ?? "";

                if (subcategory != null)
                {
                    data.SubcategoryName = CacheHelper.GetCategoryList(((int)category).ToString(Constants.PADDING_CATEGORYID)).FirstOrDefault(cat => cat.ID.Equals(((int)subcategory).ToString(Constants.PADDING_CATEGORYID)))?.Name ?? "";
                }
            }

            data.Categories = CacheHelper.GetCategoryList(Constants.BASE_CATEGORY);


            if (!string.IsNullOrEmpty(errorCode))
            {
                ViewData["errorCode"] = errorCode;
            }

            return(View(data));
        }
Exemplo n.º 24
0
        public IActionResult Add(UserEntity user)
        {
            int errorCode = 0;

            try
            {
                TableStorageHelper.InsertAsync(Constants.TABLE_USER, user).Wait();

                CacheHelper.ClearUsersCache();
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode }));
        }
        public async Task <ActionResult <TodoItem> > GetTodoItem(string id)
        {
            _logger.LogInformation($"Getting Todo item, id: {id}");

            var table = TableStorageHelper.GetTableReference(_storageConnectionString, _tableName);

            var findOp     = TableOperation.Retrieve <TodoItemEntity>(TodoItemMapper.TablePartitionKey, id);
            var findResult = await table.ExecuteAsync(findOp);

            if (findResult.Result == null)
            {
                return(new NotFoundResult());
            }

            var todoEntity = (TodoItemEntity)findResult.Result;

            var todoItem = TodoItemMapper.ToModel(todoEntity);

            return(new OkObjectResult(todoItem));
        }
Exemplo n.º 26
0
        public IActionResult UpdateStatus(TechnologyEntity technology, string StatusRemarks, bool isSubcategoryInQuery)
        {
            int errorCode = 0;

            try
            {
                technology.Description = technology.Description ?? "";

                TechnologyStatusEntity technologyStatus = GetTechnologyStatusEntity(technology.PartitionKey, technology.ID, technology.Status, StatusRemarks);

                TableStorageHelper.BatchAsync(Constants.TABLE_TECHNOLOGY, null, new TechnologyStatusEntity[] { technologyStatus }, new TechnologyEntity[] { technology }).Wait();
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode, category = technology.PartitionKey, subcategory = ((isSubcategoryInQuery) ? technology.SubcategoryID : ""), technology = technology.ID }));
        }
        public async Task <ActionResult <TodoItem> > CreateTodoItem(TodoItem todoItem)
        {
            _logger.LogInformation($"Creating new Todo item");

            if (todoItem == null || string.IsNullOrWhiteSpace(todoItem.Name))
            {
                return(new BadRequestResult());
            }

            var table = TableStorageHelper.GetTableReference(_storageConnectionString, _tableName);

            var newTodoItem = new TodoItem {
                Name = todoItem.Name, IsCompleted = false
            };
            // Create the InsertOrReplace table operation
            TableOperation insertOp = TableOperation.Insert(TodoItemMapper.ToEntity(newTodoItem));

            // Execute the operation.
            TableResult result = await table.ExecuteAsync(insertOp);

            return(CreatedAtAction(nameof(GetTodoItem), new { id = newTodoItem.Id }, newTodoItem));
        }
        /// <summary>
        /// Listens to queue and gets messages; messages are not deleted;
        /// Messages will appear in queue again in 5 seconds
        /// </summary>
        /// <param name="queue">Cloud queue to listen</param>
        public void Listen(CloudQueue queue)
        {
            while (true)
            {
                // Get message frim queue; message will be invisible for 5 seconds
                CloudQueueMessage message = queue.GetMessage(new TimeSpan(0, 0, 10));

                // if there are no more messages
                if (message == null)
                {
                    continue;
                }

                var fileInfo = JsonConvert.DeserializeObject <FileInfo>(message.AsString);

                // some operation here is performed

                TableStorageHelper.AddTableLog(OperationType.Products, fileInfo.BlobPath, fileInfo.ProcessingType, OperationResult.Success);

                Console.WriteLine("Message successfully processed. Blob path {0}", fileInfo.BlobPath);
            }
        }
Exemplo n.º 29
0
 public DeviceTwinMigration(TableStorageHelper tableStorageClient, TenantConnectionHelper tenantConnectionHelper, ILogger logger)
 {
     this.tableStorageClient     = tableStorageClient;
     this.tenantConnectionHelper = tenantConnectionHelper;
     this.logger = logger;
 }
 public LoggingService()
 {
     _loggingRepository = new TableStorageHelper<LogEntry>();
 }