public async Task AddLogAsync(IOperationLog log)
        {
            var logEntity = OperationLogEntity.Create(log, _dateService.Now());

            using (var conn = new SqlConnection(_connectionString))
            {
                await conn.ExecuteAsync(
                    $"insert into {_tableName} ({GetColumns}) values ({GetFields})", logEntity);
            }
        }
Example #2
0
        private object userData;                    // Application specific information

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="id">The base transaction <see cref="Guid" />.</param>
        /// <param name="manager">The <see cref="TransactionManager" /> responsible for this transaction.</param>
        internal BaseTransaction(Guid id, TransactionManager manager)
            : base()
        {
            manager.Trace(0, "Begin BASE transaction", "ID=" + id.ToString());

            this.syncLock     = manager.SyncRoot;
            this.id           = id;
            this.manager      = manager;
            this.operationLog = manager.Log.CreateOperationLog(id);
            this.userData     = null;
        }
 public static OperationLogEntity Create(IOperationLog src)
 {
     return(new OperationLogEntity
     {
         PartitionKey = GeneratePartitionKey(src.AccountId, src.Name),
         Name = src.Name,
         Input = src.Input,
         Data = src.Data,
         AccountId = src.AccountId,
     });
 }
Example #4
0
 public static OperationLogEntity Create(IOperationLog src, DateTime time)
 {
     return(new OperationLogEntity
     {
         DateTime = time,
         Name = src.Name,
         Input = src.Input,
         Data = src.Data,
         AccountId = src.AccountId
     });
 }
Example #5
0
        /// <summary>
        /// Closes an <see cref="IOperationLog" />.
        /// </summary>
        /// <param name="operationLog">The <see cref="IOperationLog" />.</param>
        /// <exception cref="TransactionException">Thrown if the log is not open.</exception>
        public void CloseOperationLog(IOperationLog operationLog)
        {
            using (TimedLock.Lock(syncLock))
            {
                if (!isOpen)
                {
                    throw new TransactionException(NotOpenMsg);
                }

                ((FileOperationLog)operationLog).Close();
            }
        }
Example #6
0
        /// <summary>
        /// Sets an <see cref="IOperationLog" />'s mode to <see cref="OperationLogMode.Redo" />
        /// and then closes the log.
        /// </summary>
        /// <param name="operationLog">The <see cref="IOperationLog" />.</param>
        /// <remarks>
        /// This is called when the base transaction is committed and all of the
        /// operations that compose the transaction have been persisted to the
        /// log.  The method sets the operation log mode to <see cref="OperationLogMode.Redo" />
        /// so that the operations will be reapplied after a process crash.
        /// </remarks>
        public void CommitOperationLog(IOperationLog operationLog)
        {
            using (TimedLock.Lock(syncLock))
            {
                if (!isOpen)
                {
                    throw new TransactionException(NotOpenMsg);
                }

                ((MemoryOperationLog)operationLog).Mode = OperationLogMode.Redo;
            }
        }
Example #7
0
        /// <summary>
        /// Performs a best efforts recovery of orphaned transactions.
        /// </summary>
        private void Recover()
        {
            var        orphans = log.GetOrphanTransactions();
            var        context = new UpdateContext(this, true, false, false, Guid.Empty);
            IOperation operation;

            SysLog.LogWarning("Recovering [{0}] transactions for [{1}].", orphans.Count, resource.Name);

            Trace(0, "Begin Recovery", null);
            resource.BeginRecovery(context);

            for (int i = 0; i < orphans.Count; i++)
            {
                IOperationLog opLog = log.OpenOperationLog(orphans[i]);

                context.TransactionID = opLog.TransactionID;
                if (opLog.Mode == OperationLogMode.Redo)
                {
                    if (resource.BeginRedo(context))
                    {
                        foreach (ILogPosition pos in opLog.GetPositions(false))
                        {
                            operation = opLog.Read(resource, pos);
                            Trace(0, "Redo: " + operation.Description, "ID=" + context.TransactionID.ToString());
                            resource.Redo(context, operation);
                        }
                    }

                    resource.EndRedo(context);
                }
                else
                {
                    if (resource.BeginUndo(context))
                    {
                        foreach (ILogPosition pos in opLog.GetPositions(true))
                        {
                            operation = opLog.Read(resource, pos);
                            Trace(0, "Undo: " + operation.Description, "ID=" + context.TransactionID.ToString());
                            resource.Undo(context, opLog.Read(resource, pos));
                        }
                    }

                    resource.EndUndo(context);
                }

                log.CloseOperationLog(opLog);
            }

            context.TransactionID = Guid.Empty;
            resource.EndRecovery(context);
            Trace(0, "End Recovery", null);
        }
Example #8
0
        public OperationLog() : base()
        {
            if (isMultiDatabase)
            {
                base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, dicmultiDatabase[this.GetType().Name].ToString());
            }
            else
            {
                base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
            }

            dal = baseDal as IOperationLog;
        }
Example #9
0
        /// <summary>
        /// Closes and deletes an <see cref="IOperationLog" />.
        /// </summary>
        /// <param name="operationLog">The <see cref="IOperationLog" />.</param>
        /// <remarks>
        /// This is called after the all of the transactions have been applied to
        /// the underlying resource and the log is no longer necessary.
        /// </remarks>
        public void RemoveOperationLog(IOperationLog operationLog)
        {
            using (TimedLock.Lock(syncLock))
            {
                if (!isOpen)
                {
                    throw new TransactionException(NotOpenMsg);
                }

                if (transactions.ContainsKey(operationLog.TransactionID))
                {
                    transactions.Remove(operationLog.TransactionID);
                }
            }
        }
Example #10
0
        /// <summary>
        /// Sets an <see cref="IOperationLog" />'s mode to <see cref="OperationLogMode.Redo" />
        /// and then closes the log.
        /// </summary>
        /// <param name="operationLog">The <see cref="IOperationLog" />.</param>
        /// <remarks>
        /// This is called when the base transaction is committed and all of the
        /// operations that compose the transaction have been persisted to the
        /// log.  The method sets the operation log mode to <see cref="OperationLogMode.Redo" />
        /// so that the operations will be reapplied after a process crash.
        /// </remarks>
        /// <exception cref="TransactionException">Thrown if the log is not open.</exception>
        public void CommitOperationLog(IOperationLog operationLog)
        {
            using (TimedLock.Lock(syncLock))
            {
                if (!isOpen)
                {
                    throw new TransactionException(NotOpenMsg);
                }

                var fileLog = (FileOperationLog)operationLog;

                fileLog.Mode = OperationLogMode.Redo;
                fileLog.Close();
            }
        }
Example #11
0
        /// <summary>
        /// Closes and deletes an <see cref="IOperationLog" />.
        /// </summary>
        /// <param name="operationLog">The <see cref="IOperationLog" />.</param>
        /// <remarks>
        /// This is called after the all of the transactions have been applied to
        /// the underlying resource and the log is no longer necessary.
        /// </remarks>
        /// <exception cref="TransactionException">Thrown if the log is not open.</exception>
        public void RemoveOperationLog(IOperationLog operationLog)
        {
            using (TimedLock.Lock(syncLock))
            {
                if (!isOpen)
                {
                    throw new TransactionException(NotOpenMsg);
                }

                var fileLog = (FileOperationLog)operationLog;
                var path    = fileLog.FullPath;

                fileLog.Close();
                File.Delete(path);
            }
        }
        protected override void prepareLogEntry(IOperationLog log, IEngineContext context){
            log.ObjectType = "report";
            log.OperationType = "render";

            var def = myapp.conversation.Current.Data["ioc.getdefinition"] as IReportDefinition;
            log.Xml = new XElement("parameters",
                                   from p in def.Parameters
                                   select new XElement(p.Key,
                                                       new XText(p.Value.toStr())
                                       )
                ).ToString();
            var code = "?";
            if (def != null){
                code = def.Code;
            }

            log.ObjectCode = code;
        }
        public static OperationLogData ToModel(this IOperationLog log, bool withDetails = false)
        {
            if (log == null)
            {
                return(null);
            }
            var data = new OperationLogData()
            {
                Id        = log.Id, CreatedOn = log.CreatedOn, UserName = log.UserName,
                WebCallId = log.WebCallId, UserSessionId = log.UserSessionId, Message = log.Message
            };

            if (withDetails)
            {
            }
            data.AssignCommon(log);
            return(data);
        }
 public OperationsController(IOperationLog operationLog, IStateRepository stateRepository)
 {
     this.operationLog    = operationLog;
     this.stateRepository = stateRepository;
 }
Example #15
0
 /// <summary>
 /// Closes an <see cref="IOperationLog" />.
 /// </summary>
 /// <param name="operationLog">The <see cref="IOperationLog" />.</param>
 public void CloseOperationLog(IOperationLog operationLog)
 {
 }
 public async Task AddLogAsync(IOperationLog logEntity)
 {
     var entity = OperationLogEntity.Create(logEntity);
     await _tableStorage.InsertAndGenerateRowKeyAsTimeAsync(entity, DateTime.UtcNow);
 }
Example #17
0
 public AdminController(IStateRepository stateRepository, IStorage storage, IOperationLog operationLog)
 {
     this.stateRepository = stateRepository;
     this.storage         = storage;
     this.operationLog    = operationLog;
 }
Example #18
0
 public Storage(IOperationLog operationLog, IComparer <Value> valueComparer)
 {
     this.operationLog  = operationLog;
     this.valueComparer = valueComparer;
 }
 protected abstract void prepareLogEntry(IOperationLog log, IEngineContext context);
Example #20
0
 public async Task AddLogAsync(IOperationLog logEntity)
 {
     await _log.WriteInfoAsync(nameof(SerilogOperationsLogRepository), logEntity.Name,
                               logEntity.Input, logEntity.Data);
 }