Exemplo n.º 1
0
        public void RowKey()
        {
            var item = new DataManagerLog(this.GetType());

            Assert.IsFalse(string.IsNullOrWhiteSpace(item.RowKey));
            Assert.AreNotEqual <Guid>(Guid.Empty, Guid.Parse(item.RowKey));
        }
Exemplo n.º 2
0
        public void PartitionKey()
        {
            var startDate = DateTime.UtcNow;
            var item      = new DataManagerLog(this.GetType());

            Assert.AreEqual <string>(string.Format("{0}{1}{2}", this.GetType(), startDate.Year, startDate.Month), item.PartitionKey);
        }
Exemplo n.º 3
0
        public void Successful()
        {
            var item = new DataManagerLog(this.GetType());

            Assert.IsFalse(item.Successful);
            item.Successful = true;
            Assert.IsTrue(item.Successful);
        }
Exemplo n.º 4
0
        public void StartTime()
        {
            var item = new DataManagerLog(this.GetType());
            var data = DateTime.UtcNow;

            item.StartTime = data;
            Assert.AreEqual <DateTime>(data, item.StartTime);
        }
        /// <summary>
        /// Execute
        /// </summary>
        protected override void Execute(object state)
        {
            using (new PerformanceMonitor())
            {
                try
                {
                    var item = new DataManagerLog(this.GetType());

                    var table  = new AzureTable <DataManagerLog>(ServerConfiguration.Default);
                    var latest = (from data in table.QueryByPartition(item.PartitionKey).ToList()
                                  orderby data.StartTime
                                  select data).FirstOrDefault();

                    // Check if there's any task to execute
                    var performTask = null == latest || (latest.CompletionTime.HasValue ?
                                                         DateTime.UtcNow.Subtract(latest.CompletionTime.Value) >= period || !latest.Successful :
                                                         DateTime.UtcNow.Subtract(latest.StartTime) >= retryInterval);

                    if (performTask)
                    {
                        log.Log(string.Format("{0} Task Started.", DateTime.UtcNow));

                        item.StartTime = DateTime.UtcNow;

                        table.AddEntity(item);

                        // Start the backup
                        try
                        {
                            this.Execute();
                            item.Successful = true;
                        }
                        catch (Exception ex)
                        {
                            log.Log(ex, EventTypes.Critical, (int)ServiceFault.Unknown);
                            item.Successful = false;
                        }
                        finally
                        {
                            item.CompletionTime = DateTime.UtcNow;
                        }

                        // Update entry in table
                        table.AddOrUpdateEntity(item);
                        log.Log(string.Format("{0} Task Completed. Success: {1}", DateTime.UtcNow, item.Successful));
                    }
                    else
                    {
                        log.Log(string.Format("{0} No Action Required.", DateTime.UtcNow));
                    }
                }
                catch (Exception ex)
                {
                    log.Log(ex, EventTypes.Error, (int)ServiceFault.Unknown);
                }
            }
        }
Exemplo n.º 6
0
        public void CompletionTime()
        {
            var item = new DataManagerLog(this.GetType());

            Assert.IsNull(item.CompletionTime);
            var data = DateTime.UtcNow;

            item.CompletionTime = data;
            Assert.AreEqual <DateTime?>(data, item.CompletionTime);
        }