コード例 #1
0
        public void DbMakeChangesTest()
        {
            var context = new D2SLogContext(DeployDatabaseIfNotExist: true);
            var a       = context.RunLogEntries;
            var b       = context.taskLogEntries;

            RunLogEntry entry = new RunLogEntry()
            {
                Source      = "Test",
                Target      = "Test",
                UserName    = "******",
                Status      = "Running",
                StartTime   = DateTime.Now,
                MachineName = "Test",
                Tasks       = new List <TaskLogEntry>()
                {
                    new TaskLogEntry()
                    {
                        TaskName  = "Test",
                        Target    = "Test",
                        Status    = "Running",
                        StartTime = DateTime.Now,
                    }
                }
            };

            a.Add(entry);
            context.SaveChanges();
        }
コード例 #2
0
        public void UndesiredDatabaseMigrationPreventionTest()
        {
            //drop the DB first, or at least make sure its gone
            var c = new D2SLogContext(true);

            c.Database.Delete();
            c.SaveChanges();
            c.Dispose();

            var context = new D2SLogContext(false);

            Assert.ThrowsException <EntityException>(() => addTask(context));
        }
コード例 #3
0
        /// <summary>
        /// Closes the previously opened logentry with either a success or failure code.
        /// </summary>
        /// <remarks>
        /// If this method  is not called, any log entries written will be lost.
        /// </remarks>
        /// <param name="processWasSuccessfull">A bool indicating if the process has completed successfully</param>
        public void CloseLogEntry(bool processWasSuccessfull)
        {
            if (!SqlLogEnabled)
            {
                return;
            }
            if (!_hasOpenLogEntry)
            {
                var outputMessage = "Attempted to close a log entry when no log entry was open";
                LogService.Instance.Error(outputMessage);
                throw new InvalidOperationException(outputMessage);
            }
            else
            {
                DateTime endTime = DateTime.Now;
                string   status  = processWasSuccessfull ? "SUCCESS" : "FAILED";

                try
                {
                    _runLogEntry.Status  = status;
                    _runLogEntry.EndTime = endTime;
                    D2SLogContext context = new D2SLogContext(false);
                    context.RunLogEntries.Add(_runLogEntry);
                    context.SaveChanges();
                }
                catch (SqlException sqlEx)
                {
                    LogService.Instance.Error(sqlEx);
                    throw;
                }
                catch (Exception ex)
                {
                    LogService.Instance.Error(ex);
                    throw;
                }

                _hasOpenLogEntry = false;
            }
        }
コード例 #4
0
 private void addTask(D2SLogContext c)
 {
     c.RunLogEntries.Add(new RunLogEntry());
     c.SaveChanges();
 }