コード例 #1
0
ファイル: WorkflowActions.cs プロジェクト: lulzzz/WF
        public static void WriteTransitionHistory(Guid processId, string currentStateName, string executedStateName, string commandName, IEnumerable <Guid> identities)
        {
            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processId, currentStateName);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processId, executedStateName);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processId, commandName);

            using (var scope = new TransactionScope())
            {
                using (var context = new DataModelDataContext())
                {
                    GetEmployeesString(identities, context);

                    var historyItem = new DocumentTransitionHistory
                    {
                        Id = Guid.NewGuid(),
                        AllowedToEmployeeNames = GetEmployeesString(identities, context),
                        DestinationState       = nextState,
                        DocumentId             = processId,
                        InitialState           = currentstate,
                        Command = command
                    };
                    context.DocumentTransitionHistories.InsertOnSubmit(historyItem);
                    context.SubmitChanges();
                }

                scope.Complete();
            }
        }
コード例 #2
0
        public void UpdateTransitionHistory(Guid id, string currentState, string nextState, string command, Guid?employeeId)
        {
            var historyItem =
                _sampleContext.DocumentTransitionHistories.FirstOrDefault(
                    h => h.DocumentId == id && !h.TransitionTime.HasValue &&
                    h.InitialState == currentState && h.DestinationState == nextState);

            if (historyItem == null)
            {
                historyItem = new DocumentTransitionHistory
                {
                    Id = Guid.NewGuid(),
                    AllowedToEmployeeNames = string.Empty,
                    DestinationState       = nextState,
                    DocumentId             = id,
                    InitialState           = currentState
                };

                _sampleContext.DocumentTransitionHistories.Add(historyItem);
            }

            historyItem.Command        = command;
            historyItem.TransitionTime = DateTime.Now;
            historyItem.EmployeeId     = employeeId;

            _sampleContext.SaveChanges();
        }
コード例 #3
0
        public static void WriteTransitionHistory(ProcessInstance processInstance, string parameter)
        {
            if (processInstance.IdentityIds == null)
                return;

            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand);

            using (var context = new DataModelDataContext())
            {
                GetEmployeesString(processInstance.IdentityIds, context);

                var historyItem = new DocumentTransitionHistory
                                      {
                                          Id = Guid.NewGuid(),
                                          AllowedToEmployeeNames = GetEmployeesString(processInstance.IdentityIds, context),
                                          DestinationState = nextState,
                                          DocumentId = processInstance.ProcessId,
                                          InitialState = currentstate,
                                          Command = command
                                      };
                context.DocumentTransitionHistories.InsertOnSubmit(historyItem);
                context.SubmitChanges();
            }
        }
コード例 #4
0
        public static void WriteTransitionHistory(ProcessInstance processInstance, string parameter)
        {
            if (processInstance.IdentityIds == null)
            {
                return;
            }

            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand);

            using (var context = new DataModelDataContext())
            {
                GetEmployeesString(processInstance.IdentityIds, context);

                var historyItem = new DocumentTransitionHistory
                {
                    Id = Guid.NewGuid(),
                    AllowedToEmployeeNames = GetEmployeesString(processInstance.IdentityIds, context),
                    DestinationState       = nextState,
                    DocumentId             = processInstance.ProcessId,
                    InitialState           = currentstate,
                    Command = command
                };
                context.DocumentTransitionHistories.InsertOnSubmit(historyItem);
                context.SubmitChanges();
            }
        }
コード例 #5
0
ファイル: DocumentRepository.cs プロジェクト: lestrage/WF3.5
 public void CheckAndInsertHistoryTimer(Guid CurrentUserId, Guid ToUserId, string nameTimer, Guid documentId, string currentState, string nextState)
 {
     try
     {
         var doc = _sampleContext.Documents.FirstOrDefault(x => x.Id == documentId);
         doc.Comment = "Timer tự động chuyển";
         var historyItem = new DocumentTransitionHistory
         {
             Id = Guid.NewGuid(),
             AllowedToEmployeeNames = string.Empty,
             DestinationState       = nextState,
             DocumentId             = documentId,
             InitialState           = currentState,
             InitialTime            = DateTime.Now,
             FromUser       = CurrentUserId,
             ToUser         = ToUserId,
             Command        = "Timer",
             TransitionTime = DateTime.Now,
             EmployeeId     = CurrentUserId,
             Comment        = "Quy trình tự động chuyển"
         };
         _sampleContext.DocumentTransitionHistories.Add(historyItem);
         _sampleContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #6
0
ファイル: DocumentRepository.cs プロジェクト: lestrage/WF3.5
        public void UpdateTransitionHistory(Guid id, string currentState, string nextState, string command, Guid?employeeId)
        {
            if (command != "Timer")
            {
                var docs     = _sampleContext.Documents.FirstOrDefault(x => x.Id == id);
                var intState = WorkflowInit.Runtime.GetInitialState(docs.SchemeName);
                if (currentState == intState.Name)
                {
                }

                var sComment = (from Doc in _sampleContext.Documents where Doc.Id == id select Doc.Comment).FirstOrDefault();

                var historyItem =
                    _sampleContext.DocumentTransitionHistories.FirstOrDefault(
                        h => h.DocumentId == id && !h.TransitionTime.HasValue &&
                        h.InitialState == currentState && h.DestinationState == nextState);

                if (historyItem == null)
                {
                    var s = (from time in _sampleContext.DocumentTransitionHistories
                             where (time.DestinationState == currentState) &&
                             (time.DocumentId == id) &&
                             time.TransitionTime != null
                             orderby time.Order descending
                             select time.TransitionTime).FirstOrDefault();

                    historyItem = new DocumentTransitionHistory
                    {
                        Id = Guid.NewGuid(),
                        AllowedToEmployeeNames = string.Empty,
                        DestinationState       = nextState,
                        DocumentId             = id,
                        InitialState           = currentState,
                        InitialTime            = s
                    };

                    _sampleContext.DocumentTransitionHistories.Add(historyItem);
                }

                historyItem.Command        = (!string.IsNullOrWhiteSpace(command)) ? command : "";
                historyItem.TransitionTime = DateTime.Now;

                if (string.IsNullOrWhiteSpace(employeeId.ToString()))
                {
                    historyItem.EmployeeId = null;
                }
                else
                {
                    historyItem.EmployeeId = employeeId;
                }
                historyItem.Comment    = sComment;
                historyItem.EmployeeId = employeeId;
                historyItem.FromUser   = employeeId;

                _sampleContext.SaveChanges();
            }
        }
コード例 #7
0
        public static void UpdateTransitionHistory(ProcessInstance processInstance, string parameter)
        {
            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand);

            var isTimer = !string.IsNullOrEmpty(processInstance.ExecutedTimer);

            using (var session = Workflow.WorkflowInit.Provider.Store.OpenSession())
            {
                var document = session.Load <Document>(processInstance.ProcessId);
                if (document == null)
                {
                    return;
                }

                var historyItem =
                    document.TransitionHistories.FirstOrDefault(
                        h => !h.TransitionTime.HasValue &&
                        h.InitialState == currentstate && h.DestinationState == nextState);

                if (historyItem == null)
                {
                    historyItem = new DocumentTransitionHistory
                    {
                        Id = Guid.NewGuid(),
                        AllowedToEmployeeNames = string.Empty,
                        DestinationState       = nextState,
                        InitialState           = currentstate
                    };
                    document.TransitionHistories.Add(historyItem);
                }
                historyItem.Command        = !isTimer ? command : string.Format("Timer: {0}", processInstance.ExecutedTimer);
                historyItem.TransitionTime = DateTime.Now;
                if (string.IsNullOrWhiteSpace(processInstance.IdentityId))
                {
                    historyItem.EmployeeId   = null;
                    historyItem.EmployeeName = string.Empty;
                }
                else
                {
                    historyItem.EmployeeId   = new Guid(processInstance.IdentityId);
                    historyItem.EmployeeName = EmployeeHelper.EmployeeCache.First(c => c.Id == historyItem.EmployeeId).Name;
                }

                session.SaveChanges();
            }
        }
コード例 #8
0
ファイル: DocumentRepository.cs プロジェクト: lestrage/WF3.5
        public void WriteTransitionHistory(Guid id, string currentState, string nextState, string command, IEnumerable <string> identities)
        {
            if (command != "Timer")
            {
                var doc      = _sampleContext.Documents.FirstOrDefault(x => x.Id == id);
                var intState = WorkflowInit.Runtime.GetInitialState(doc.SchemeName);

                if (identities == null)
                {
                    return;
                }

                if (currentState == intState.Name)
                {
                    var historyItem = new DocumentTransitionHistory
                    {
                        Id = Guid.NewGuid(),
                        AllowedToEmployeeNames = GetEmployeesString(identities),
                        DestinationState       = nextState,
                        DocumentId             = id,
                        InitialState           = currentState,
                        Command     = command,
                        InitialTime = DateTime.Now
                    };
                    _sampleContext.DocumentTransitionHistories.Add(historyItem);
                    _sampleContext.SaveChanges();
                }
                else
                {
                    var s = (from time in _sampleContext.DocumentTransitionHistories
                             where (time.DestinationState == currentState) &&
                             (time.DocumentId == id)
                             orderby time.Order descending
                             select time.TransitionTime).FirstOrDefault();

                    var historyItem = new DocumentTransitionHistory
                    {
                        Id = Guid.NewGuid(),
                        AllowedToEmployeeNames = GetEmployeesString(identities),
                        DestinationState       = nextState,
                        DocumentId             = id,
                        InitialState           = currentState,
                        Command     = command,
                        InitialTime = s
                    };
                    _sampleContext.DocumentTransitionHistories.Add(historyItem);
                    _sampleContext.SaveChanges();
                }
            }
        }
コード例 #9
0
        public static void UpdateTransitionHistory(ProcessInstance processInstance, string parameter)
        {
            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState);
            var nextState    = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState);
            var command      = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand);
            var isTimer      = !string.IsNullOrEmpty(processInstance.ExecutedTimer);

            var dbcoll   = WorkflowInit.Provider.Store.GetCollection <Document>("Document");
            var document = dbcoll.Find(x => x.Id == processInstance.ProcessId).FirstOrDefault();

            if (document == null)
            {
                return;
            }

            var historyItem =
                document.TransitionHistories.FirstOrDefault(
                    h => !h.TransitionTime.HasValue &&
                    h.InitialState == currentstate && h.DestinationState == nextState);

            if (historyItem == null)
            {
                historyItem = new DocumentTransitionHistory
                {
                    Id = Guid.NewGuid(),
                    AllowedToEmployeeNames = string.Empty,
                    DestinationState       = nextState,
                    InitialState           = currentstate
                };
                document.TransitionHistories.Add(historyItem);
            }

            historyItem.Command        = !isTimer ? command : string.Format("Timer: {0}", processInstance.ExecutedTimer);
            historyItem.TransitionTime = DateTime.Now;

            if (string.IsNullOrWhiteSpace(processInstance.IdentityId))
            {
                historyItem.EmployeeId   = null;
                historyItem.EmployeeName = string.Empty;
            }
            else
            {
                historyItem.EmployeeId   = new Guid(processInstance.IdentityId);
                historyItem.EmployeeName = EmployeeHelper.EmployeeCache.First(c => c.Id == historyItem.EmployeeId).Name;
            }

            dbcoll.ReplaceOne(x => x.Id == document.Id, document, new UpdateOptions {
                IsUpsert = true
            });
        }
コード例 #10
0
        public void WriteTransitionHistory(Guid id, string currentState, string nextState, string command, IEnumerable <string> identities)
        {
            var historyItem = new DocumentTransitionHistory
            {
                Id = Guid.NewGuid(),
                AllowedToEmployeeNames = GetEmployeesString(identities),
                DestinationState       = nextState,
                DocumentId             = id,
                InitialState           = currentState,
                Command = command
            };

            _sampleContext.DocumentTransitionHistories.Add(historyItem);
            _sampleContext.SaveChanges();
        }
コード例 #11
0
ファイル: WorkflowActions.cs プロジェクト: lulzzz/WF
        public static void UpdateTransitionHistory(Guid processId, string currentStateName, string executedStateName, string commandName, Guid identityId, Guid impersonatedIdentityId, string comment)
        {
            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processId, currentStateName);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processId, executedStateName);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processId, commandName);

            using (var scope = new TransactionScope())
            {
                using (var context = new DataModelDataContext())
                {
                    var document = context.Documents.FirstOrDefault(d => d.Id == processId);
                    if (document == null)
                    {
                        return;
                    }

                    document.State = nextState;

                    var historyItem =
                        context.DocumentTransitionHistories.FirstOrDefault(
                            h => h.DocumentId == processId && !h.TransitionTime.HasValue &&
                            h.InitialState == currentstate && h.DestinationState == nextState);

                    if (historyItem == null)
                    {
                        historyItem = new DocumentTransitionHistory
                        {
                            Id = Guid.NewGuid(),
                            AllowedToEmployeeNames = string.Empty,
                            DestinationState       = nextState,
                            DocumentId             = processId,
                            InitialState           = currentstate
                        };

                        context.DocumentTransitionHistories.InsertOnSubmit(historyItem);
                    }

                    historyItem.Command        = command;
                    historyItem.TransitionTime = DateTime.Now;
                    historyItem.EmployeeId     = identityId;

                    context.SubmitChanges();
                }
                scope.Complete();
            }
        }
コード例 #12
0
ファイル: WorkflowActions.cs プロジェクト: jiguixin/WF
        public static void UpdateTransitionHistory(Guid processId, string currentStateName, string executedStateName, string commandName, Guid identityId, Guid impersonatedIdentityId, string comment)
        {
            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processId, currentStateName);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processId, executedStateName);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processId, commandName);

            using (var scope = new TransactionScope())
            {
                using (var context = new DataModelDataContext())
                {
                    var document = context.Documents.FirstOrDefault(d => d.Id == processId);
                    if (document == null)
                        return;

                     document.State = nextState;

                    var historyItem =
                        context.DocumentTransitionHistories.FirstOrDefault(
                            h => h.DocumentId == processId && !h.TransitionTime.HasValue &&
                                 h.InitialState == currentstate && h.DestinationState == nextState);

                    if (historyItem == null)
                    {
                        historyItem = new DocumentTransitionHistory
                                          {
                                              Id = Guid.NewGuid(),
                                              AllowedToEmployeeNames = string.Empty,
                                              DestinationState = nextState,
                                              DocumentId = processId,
                                              InitialState = currentstate
                                          };

                         context.DocumentTransitionHistories.InsertOnSubmit(historyItem);

                    }

                    historyItem.Command = command;
                    historyItem.TransitionTime = DateTime.Now;
                    historyItem.EmployeeId = identityId;

                    context.SubmitChanges();

                }
                scope.Complete();
            }
        }
コード例 #13
0
        public static void UpdateTransitionHistory(ProcessInstance processInstance, string parameter)
        {
            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand);

            var isTimer = !string.IsNullOrEmpty(processInstance.ExecutedTimer);

            using (var context = new DataModelDataContext())
            {
                var historyItem =
                    context.DocumentTransitionHistories.FirstOrDefault(
                        h => h.DocumentId == processInstance.ProcessId && !h.TransitionTime.HasValue &&
                        h.InitialState == currentstate && h.DestinationState == nextState);

                if (historyItem == null)
                {
                    historyItem = new DocumentTransitionHistory
                    {
                        Id = Guid.NewGuid(),
                        AllowedToEmployeeNames = string.Empty,
                        DestinationState       = nextState,
                        DocumentId             = processInstance.ProcessId,
                        InitialState           = currentstate
                    };

                    context.DocumentTransitionHistories.InsertOnSubmit(historyItem);
                }

                historyItem.Command        = !isTimer ? command : string.Format("Timer: {0}", processInstance.ExecutedTimer);
                historyItem.TransitionTime = DateTime.Now;

                if (string.IsNullOrWhiteSpace(processInstance.IdentityId))
                {
                    historyItem.EmployeeId = null;
                }
                else
                {
                    historyItem.EmployeeId = new Guid(processInstance.IdentityId);
                }

                context.SubmitChanges();
            }
        }
コード例 #14
0
ファイル: WorkflowReport.cs プロジェクト: weitalu/HRM
        public async static Task <object> Generate(DateTime?datefrom, DateTime?dateto)
        {
            var res = new Dictionary <string, WorkflowReportItem>();

            var filter  = Filter.Empty;
            var filter2 = Filter.Empty;

            if (datefrom.HasValue)
            {
                filter  = Filter.And.GreaterOrEqual(datefrom.Value, "Date");
                filter2 = Filter.And.GreaterOrEqual(datefrom.Value, "DocumentDate");
            }

            if (dateto.HasValue)
            {
                filter  = filter.Merge(Filter.And.LessOrEqual(dateto.Value, "Date"));
                filter2 = filter2.Merge(Filter.And.LessOrEqual(dateto.Value, "DocumentDate"));
            }

            var documents = await Document.SelectAsync(filter);

            filter2 = filter2.Merge(Filter.And.NotEqual(Null.Value, "TransitionTime"));
            var documentTransitions = await DocumentTransitionHistory.SelectAsync(filter2);

            var stats = new Dictionary <string, List <TimeSpan> >();

            foreach (var d in documents)
            {
                if (!res.ContainsKey(d.Type))
                {
                    res[d.Type] = new WorkflowReportItem()
                    {
                        Type = d.Type
                    }
                }
                ;

                res[d.Type].Count++;

                if (DraftStates.Contains(d.State))
                {
                    res[d.Type].DraftDocCount += 1;
                }
                else if (FinalStates.Contains(d.State))
                {
                    res[d.Type].FinalDocCount += 1;
                    var history = documentTransitions.Where(c => c.DocumentId == d.Id && c.EmployeeId.HasValue);
                    var minDate = history.Min(c => c.TransitionTime);
                    var maxDate = history.Max(c => c.TransitionTime);
                    if (minDate.HasValue && maxDate.HasValue)
                    {
                        var delta = (maxDate - minDate).Value;
                        if (!stats.ContainsKey(d.Type))
                        {
                            stats[d.Type] = new List <TimeSpan>();
                        }

                        stats[d.Type].Add(delta);

                        if (res[d.Type].MinApprovalTime == null || res[d.Type].MinApprovalTime.Ticks == 0 || res[d.Type].MinApprovalTime > delta)
                        {
                            res[d.Type].MinApprovalTime = delta;
                        }

                        if (res[d.Type].MaxApprovalTime == null || res[d.Type].MaxApprovalTime < delta)
                        {
                            res[d.Type].MaxApprovalTime = delta;
                        }
                    }
                }
                else
                {
                    res[d.Type].OtherDocCount += 1;
                }
            }

            foreach (var s in stats)
            {
                var sumSpan = new TimeSpan();
                s.Value.ForEach(c => { sumSpan += c; });
                res[s.Key].AvrApprovalTime = new TimeSpan((long)(sumSpan.Ticks / s.Value.Count));

                res[s.Key].MinApprovalStr = TimeSpanFormat(res[s.Key].MinApprovalTime);
                res[s.Key].MaxApprovalStr = TimeSpanFormat(res[s.Key].MaxApprovalTime);
                res[s.Key].AvrApprovalStr = TimeSpanFormat(res[s.Key].AvrApprovalTime);
            }

            return(res.OrderBy(c => c.Key).Select(c => c.Value).ToList());
        }
コード例 #15
0
        public static void UpdateTransitionHistory(ProcessInstance processInstance, string parameter)
        {
            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand);

            var isTimer = !string.IsNullOrEmpty(processInstance.ExecutedTimer);

            using (var context = new DataModelDataContext())
            {
                var historyItem =
                    context.DocumentTransitionHistories.FirstOrDefault(
                        h => h.DocumentId == processInstance.ProcessId && !h.TransitionTime.HasValue &&
                             h.InitialState == currentstate && h.DestinationState == nextState);

                if (historyItem == null)
                {
                    historyItem = new DocumentTransitionHistory
                    {
                        Id = Guid.NewGuid(),
                        AllowedToEmployeeNames = string.Empty,
                        DestinationState = nextState,
                        DocumentId = processInstance.ProcessId,
                        InitialState = currentstate
                    };

                    context.DocumentTransitionHistories.InsertOnSubmit(historyItem);

                }

                historyItem.Command = !isTimer ? command : string.Format("Timer: {0}",processInstance.ExecutedTimer);
                historyItem.TransitionTime = DateTime.Now;

                if (string.IsNullOrWhiteSpace(processInstance.IdentityId))
                    historyItem.EmployeeId = null;
                else
                    historyItem.EmployeeId = new Guid(processInstance.IdentityId);

                context.SubmitChanges();
            }
        }
コード例 #16
0
ファイル: WorkflowActions.cs プロジェクト: jiguixin/WF
        public static void WriteTransitionHistory(Guid processId, string currentStateName, string executedStateName, string commandName, IEnumerable<Guid> identities)
        {
            var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processId, currentStateName);

            var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processId, executedStateName);

            var command = WorkflowInit.Runtime.GetLocalizedCommandName(processId, commandName);

            using (var scope = new TransactionScope())
            {
                using (var context = new DataModelDataContext())
                {
                    GetEmployeesString(identities, context);

                    var historyItem = new DocumentTransitionHistory
                                          {
                                              Id = Guid.NewGuid(),
                                              AllowedToEmployeeNames =  GetEmployeesString(identities, context),
                                              DestinationState = nextState,
                                              DocumentId = processId,
                                              InitialState = currentstate,
                                              Command = command
                                          };
                    context.DocumentTransitionHistories.InsertOnSubmit(historyItem);
                    context.SubmitChanges();
                }

                scope.Complete();
            }
        }