Exemplo n.º 1
0
        public List<ProcessOverviewViewModel> createProcessOverview()
        {
            List<ProcessOverviewViewModel> processOverview = new List<ProcessOverviewViewModel>();
            var processes = _inflowDb.P_Processes.ToList();
            foreach(var i in processes)
            {
                ProcessOverviewViewModel m = new ProcessOverviewViewModel() { Id = i.Id, Name = i.WS_Project.Name, Version = i.WS_Project_Version, Info = i.ProcessInfo, InstancesTotal = 0, InstancesRunning = 0, InstancesCompleted = 0 };

                var c =
                    from pi in _inflowDb.P_ProcessInstance
                    where pi.Ended == true && pi.P_Process_Id == m.Id
                    select new { Id = pi.P_Process_Id, CycleTime = DbFunctions.DiffSeconds( pi.DateStarted.Value , pi.DateEnded.Value)};

                var r =
                    from pi in _inflowDb.P_ProcessInstance
                    where pi.Ended == false && pi.P_Process_Id == m.Id
                    select pi.Id;

                var completed = c.ToList();
                var running = r.ToList();

                m.InstancesCompleted = completed.Count;
                m.InstancesRunning = running.Count;
                m.InstancesTotal = m.InstancesRunning + m.InstancesCompleted;
                if (m.InstancesCompleted > 0)
                {
                    m.MaxCycleTime = new TimeSpan(0,0, 0, (int)completed.Max(x => x.CycleTime));
                    m.MinCycleTime = new TimeSpan(0,0, 0, (int)completed.Min(x => x.CycleTime));
                    m.AverageCycleTime = new TimeSpan(0,0, 0, (int)completed.Average(x => x.CycleTime));
                }
               
                processOverview.Add(m);
            }
            return processOverview;
        }