public void UpdateFromItem(EtlPackageMonitorItem item)
 {
     EtlPackageId     = item.EtlPackageId;
     EtlSessionId     = item.EtlSessionId;
     EtlPackageName   = item.EtlPackageName;
     EtlPackageStatus = item.EtlPackageStatus;
     StatusMessage    = item.StatusMessage;
     //EtlSessionStatus = item.EtlSessionStatus;
     EtlSessionDateTime = item.EtlSessionDateTime;
     CanInvoke          = item.CanInvoke;
     ForceRefresh       = item.ForceRefresh;
 }
        private EtlPackageMonitorModel RefreshModel(EtlPackageMonitorModel model)
        {
            // обновляем модель или создаем заново
            var refresh = true;

            if (model == null)
            {
                model = new EtlPackageMonitorModel();

                model.ItemsByColumns = new List<EtlPackageMonitorItem>[SiteConfiguration.MaxCoulmnsToShow];
                for (var columnIndex = 0; columnIndex < SiteConfiguration.MaxCoulmnsToShow; columnIndex++)
                {
                    model.ItemsByColumns[columnIndex] = new List<EtlPackageMonitorItem>();
                }

                refresh = false;
            }

            model.ColumnCount = SiteConfiguration.MaxCoulmnsToShow;

            IEnumerable<EtlPackage> packages = new EtlPackage[0];
            if (model.Items.Count() > 0)
            {
                // идентификаторы пакетов из модели которые необходимо обновить
                var packageIds = model.Items.Where(i => i.ForceRefresh || i.EtlPackageStatus != EtlPackageMonitorItemStatus.Succeeded).Select(i => i.EtlPackageId);
                // сами пакеты
                packages = GetEtlPackages().Where(p => packageIds.Contains(p.Id, StringComparer.OrdinalIgnoreCase));
            }
            else
            {
                packages = GetEtlPackages();
            }

            var agent = SiteConfiguration.GetEtlAgent();
            var logParser = agent.GetEtlLogParser();
            var sessions = logParser.GetLatestEtlSessions(packages.Select(p => p.Id).ToArray());

            model.HasErrors = false;

            var packageIndex = 0;
            foreach (var package in packages)
            {
                var item = new EtlPackageMonitorItem();
                item.EtlPackageId = package.Id;
                item.RunIntervalSeconds = package.RunIntervalSeconds;
                item.EtlPackageName = package.Name;
                item.CanInvoke = true;

                var session = sessions.Where(s => s.EtlPackageId == package.Id).FirstOrDefault();

                if (session != null)
                {
                    item.EtlSessionId = session.EtlSessionId;
                    item.EtlSessionDateTime = session.EndDateTime;
                    item.EtlPackageStatus = EtlPackageMonitorItemStatuses.GetMonitorItemStatus(session, package.RunIntervalSeconds);

                    item.Counters = logParser.GetEtlCounters(package.Id, session.EtlSessionId);

                    var messages = logParser.GetEtlMessages(package.Id, session.EtlSessionId);
                    if (item.EtlPackageStatus == EtlPackageMonitorItemStatus.Failed)
                    {
                        var errorMessage = messages.OrderByDescending(m => m.SequentialId).FirstOrDefault(m => m.MessageType == EtlMessageType.Error);
                        item.StatusMessage = errorMessage == null ? DEFAULT_ERROR_MSG : errorMessage.Text;
                    }

                    if (item.EtlPackageStatus == EtlPackageMonitorItemStatus.TooFar && session.Status == EtlStatus.Started)
                    {
                        item.StatusMessage = PACKAGE_CURRENTLY_RUNNING;
                    }
                }
                else
                {
                    item.EtlPackageStatus = EtlPackageMonitorItemStatus.Never;
                }

                if (item.EtlPackageStatus != EtlPackageMonitorItemStatus.Succeeded)
                {
                    model.HasErrors = true;
                }

                if (refresh)
                {
                    var pack = model.Items.FirstOrDefault(i => String.Equals(i.EtlPackageId, package.Id, StringComparison.OrdinalIgnoreCase));
                    if (pack != null)
                    {
                        pack.UpdateFromItem(item);
                    }
                }
                else
                {
                    var columnIndex = packageIndex % SiteConfiguration.MaxCoulmnsToShow;
                    model.ItemsByColumns[columnIndex].Add(item);
                }

                packageIndex++;
            }

            for (var columnIndex = 0; columnIndex < model.ItemsByColumns.Length; columnIndex++)
            {
                if (model.MaxItemCountInColumn < model.ItemsByColumns[columnIndex].Count)
                {
                    model.MaxItemCountInColumn = model.ItemsByColumns[columnIndex].Count;
                }
            }

            model.LastUpdated = DateTime.Now;

            return model;
        }
 public void UpdateFromItem(EtlPackageMonitorItem item)
 {
     EtlPackageId = item.EtlPackageId;
     EtlSessionId = item.EtlSessionId;
     EtlPackageName = item.EtlPackageName;
     EtlPackageStatus = item.EtlPackageStatus;
     StatusMessage = item.StatusMessage;
     //EtlSessionStatus = item.EtlSessionStatus;
     EtlSessionDateTime = item.EtlSessionDateTime;
     CanInvoke = item.CanInvoke;
     ForceRefresh = item.ForceRefresh;
 }