Ejemplo n.º 1
0
        /// <summary>
        /// Обновляет информацию
        /// </summary>
        public void UpdateInformation()
        {
            DirectiveCollection primarySubDirectives = GlobalObjects.DirectiveCore.GetDirectives(_baseComponent, DirectiveType.AirworthenessDirectives);
            //List<BaseDetailDirective> engineeringOrdersDirectives = GlobalObjects.CasEnvironment.;
            DirectiveCollection sbStatusDirectives = GlobalObjects.DirectiveCore.GetDirectives(_baseComponent, DirectiveType.SB);

            /* for (int i = 0; i < directives.Length; i++)
             *   {
             *           switch (directives[i].DirectiveType.ID)
             *           {
             *                   case (int)DirectiveTypeID.ADDirectiveTypeID:
             *                           ADDirectives.Add(directives[i]);
             *                           break;
             *                   case (int)DirectiveTypeID.EngeneeringOrdersDirectiveTypeID:
             *                           engineeringOrdersDirectives.Add(directives[i]);
             *                           break;
             *                   case (int)DirectiveTypeID.SBDirectiveTypeID:
             *                           SBStatusDirectives.Add(directives[i]);
             *                           break;
             *           }
             *   }*/
            _linkAdStatus.Status = GetStatus(primarySubDirectives);
            //linkDiscrepancies.Status = (Statuses)baseDetail.ConditionState;
            //linkEngineeringOrders.Status = GetStatus(engineeringOrdersDirectives);
            //DetailCollectionFilter filter = new DetailCollectionFilter(baseDetail.ContainedDetails, new DetailFilter[] { new LLPFilter() });
            //linkLLPDiskSheetStatus.Status = GetStatus(filter.GatherDetails());
            _linkSbStatus.Status = GetStatus(sbStatusDirectives);

            primarySubDirectives.Clear();
            sbStatusDirectives.Clear();
        }
Ejemplo n.º 2
0
        protected override void AnimatedThreadWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            GlobalObjects.ComponentCore.ReloadActualStateRecordForBaseComponents(_currentComponent.ParentAircraftId);

            #region Загрузка элементов

            AnimatedThreadWorker.ReportProgress(0, "load component");
            try
            {
                if (_currentComponent.ItemId > 0)
                {
                    if (_currentComponent is BaseComponent)
                    {
                        if (AnimatedThreadWorker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        _currentComponent = GlobalObjects.ComponentCore.GetFullBaseComponent(_currentComponent.ItemId);

                        var types = new[] { SmartCoreType.BaseComponent.ItemId, SmartCoreType.ComponentDirective.ItemId };
                        if (AnimatedThreadWorker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        //Загрузка документов
                        var documents = GlobalObjects.CasEnvironment.Loader.GetObjectList <Document>(new ICommonFilter[]
                        {
                            new CommonFilter <int>(Document.ParentIdProperty, _currentComponent.ItemId),
                            new CommonFilter <int>(Document.ParentTypeIdProperty, FilterType.In, types)
                        });

                        _currentComponent.ChangeLLPCategoryRecords.Clear();
                        _currentComponent.ChangeLLPCategoryRecords
                        .AddRange(GlobalObjects.CasEnvironment.NewLoader
                                  .GetObjectList <ComponentLLPCategoryChangeRecordDTO, ComponentLLPCategoryChangeRecord>(
                                      new Filter("ParentId", _currentComponent.ItemId), true));

                        _workParams = GlobalObjects.CasEnvironment.NewLoader
                                      .GetObjectList <ComponentWorkInRegimeParamDTO, ComponentWorkInRegimeParams>(
                            new List <Filter>()
                        {
                            new Filter("ComponentId", _currentComponent.ItemId)
                        });


                        if (documents.Count > 0)
                        {
                            var crs = GlobalObjects.CasEnvironment.GetDictionary <DocumentSubType>()
                                      .GetByFullName("Component CRS Form") as DocumentSubType;
                            var shipping =
                                GlobalObjects.CasEnvironment.GetDictionary <DocumentSubType>()
                                .GetByFullName("Shipping document") as DocumentSubType;

                            var docShipping = documents.FirstOrDefault(d =>
                                                                       d.ParentId == _currentComponent.ItemId &&
                                                                       d.ParentTypeId == SmartCoreType.BaseComponent.ItemId &&
                                                                       d.DocumentSubType.ItemId == shipping.ItemId);
                            if (docShipping != null)
                            {
                                _currentComponent.Document        = docShipping;
                                _currentComponent.Document.Parent = _currentComponent;
                            }

                            var docCrs = documents.FirstOrDefault(d =>
                                                                  d.ParentId == _currentComponent.ItemId &&
                                                                  d.ParentTypeId == SmartCoreType.BaseComponent.ItemId &&
                                                                  d.DocumentSubType.ItemId == crs.ItemId);
                            if (docCrs != null)
                            {
                                _currentComponent.DocumentCRS        = docCrs;
                                _currentComponent.DocumentCRS.Parent = _currentComponent;
                            }
                        }

                        if (_currentComponent.ComponentDirectives.Count > 0)
                        {
                            var directivesIds  = _currentComponent.ComponentDirectives.Select(d => d.ItemId);
                            var itemsRelations = GlobalObjects.ItemsRelationsDataAccess.GetRelations(directivesIds,
                                                                                                     SmartCoreType.ComponentDirective.ItemId);

                            foreach (var directive in _currentComponent.ComponentDirectives)
                            {
                                var docCd = documents.FirstOrDefault(d =>
                                                                     d.ParentId == directive.ItemId &&
                                                                     d.ParentTypeId == SmartCoreType.ComponentDirective.ItemId);
                                if (docCd != null)
                                {
                                    directive.Document        = docCd;
                                    directive.Document.Parent = directive;
                                }

                                if (itemsRelations.Count > 0)
                                {
                                    //Сделан такой костыль для того что был когда то баг что записи не грузились и создавалось несколько связок и вылетало предупреждение
                                    if (itemsRelations.Count > 1)
                                    {
                                        var max     = itemsRelations.Max(i => i.Updated);
                                        var deleted = new List <ItemsRelation>();
                                        foreach (var relation in itemsRelations)
                                        {
                                            if (max.Equals(relation.Updated))
                                            {
                                                continue;
                                            }

                                            GlobalObjects.NewKeeper.Delete(relation);
                                            deleted.Add(relation);
                                        }

                                        foreach (var itemsRelation in deleted)
                                        {
                                            itemsRelations.Remove(itemsRelation);
                                        }
                                    }

                                    directive.ItemRelations.Clear();
                                    directive.ItemRelations.AddRange(itemsRelations.Where(i =>
                                                                                          i.FirstItemId == directive.ItemId ||
                                                                                          i.SecondItemId ==
                                                                                          directive.ItemId)); //TODO:(Evgenii Babak)не использовать Where
                                }
                            }
                        }
                    }
                    else
                    {
                        if (AnimatedThreadWorker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }
                        _currentComponent = GlobalObjects.ComponentCore.GetComponentById(_currentComponent.ItemId);
                    }
                }
            }
            catch (Exception ex)
            {
                Program.Provider.Logger.Log("Error while loading component", ex);
            }

            if (AnimatedThreadWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
            #endregion

            #region Калькуляция состояния директив

            AnimatedThreadWorker.ReportProgress(40, "calculation of component");

            var conditionState = GlobalObjects.PerformanceCalculator.GetConditionState(_currentComponent);

            foreach (var directive in _currentComponent.ComponentDirectives)
            {
                GlobalObjects.MTOPCalculator.CalculateDirectiveNew(directive);
            }

            Invoke(new Action <ConditionState>(cs => statusControl.ConditionState = cs), conditionState);

            if (AnimatedThreadWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            if (_baseComponentHeaderControl != null && _currentComponent is BaseComponent)
            {
                #region Проверка состояния компонентов

                if (_baseComponentComponents != null)
                {
                    _baseComponentComponents.Clear();
                }
                _baseComponentComponents = GlobalObjects.ComponentCore.GetComponents((BaseComponent)_currentComponent);
                if (_baseComponentComponents.Count == 0)
                {
                    _baseComponentHeaderControl.ComponentsStatus    = Statuses.NotActive;
                    _baseComponentHeaderControl.ComponentsLLPStatus = Statuses.NotActive;
                }
                else
                {
                    #region проверка Component Status

                    if (AnimatedThreadWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    AnimatedThreadWorker.ReportProgress(47, "Check Components: Component Status");

                    Statuses allComponentStatus = Statuses.NotActive;
                    foreach (Component detail in _baseComponentComponents)
                    {
                        ConditionState directiveCond = GlobalObjects.PerformanceCalculator.GetConditionState(detail);
                        if (directiveCond == ConditionState.NotEstimated && allComponentStatus == Statuses.NotActive)
                        {
                            allComponentStatus = Statuses.NotActive;
                        }
                        if (directiveCond == ConditionState.Satisfactory && allComponentStatus != Statuses.Notify)
                        {
                            allComponentStatus = Statuses.Satisfactory;
                        }
                        if (directiveCond == ConditionState.Notify)
                        {
                            allComponentStatus = Statuses.Notify;
                        }
                        if (directiveCond == ConditionState.Overdue)
                        {
                            allComponentStatus = Statuses.NotSatisfactory;
                            break;
                        }
                    }
                    _baseComponentHeaderControl.ComponentsStatus = allComponentStatus;

                    #endregion

                    #region проверка LLP Status

                    if (AnimatedThreadWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    AnimatedThreadWorker.ReportProgress(51, "Check Components: LLP Status");

                    IEnumerable <Component> llp = _baseComponentComponents
                                                  .Where(d => d.ParentBaseComponent != null && d.ParentBaseComponent.BaseComponentTypeId == BaseComponentType.Engine.ItemId);//TODO:(Evgenii Babak) заменить на использование ComponentCore
                    Statuses bdComponentLLPStatus = Statuses.NotActive;
                    foreach (Component llpDetail in llp)
                    {
                        ConditionState directiveCond = GlobalObjects.PerformanceCalculator.GetConditionState(llpDetail);
                        if (directiveCond == ConditionState.NotEstimated && bdComponentLLPStatus == Statuses.NotActive)
                        {
                            bdComponentLLPStatus = Statuses.NotActive;
                        }
                        if (directiveCond == ConditionState.Satisfactory && bdComponentLLPStatus != Statuses.Notify)
                        {
                            bdComponentLLPStatus = Statuses.Satisfactory;
                        }
                        if (directiveCond == ConditionState.Notify)
                        {
                            bdComponentLLPStatus = Statuses.Notify;
                        }
                        if (directiveCond == ConditionState.Overdue)
                        {
                            bdComponentLLPStatus = Statuses.NotSatisfactory;
                            break;
                        }
                    }
                    _baseComponentHeaderControl.ComponentsStatus = bdComponentLLPStatus;

                    #endregion
                }

                if (AnimatedThreadWorker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                #endregion

                #region Проверка состояния директив

                AnimatedThreadWorker.ReportProgress(55, "Check Directives");
                DirectiveCollection directives = GlobalObjects.DirectiveCore.GetDirectives((BaseComponent)_currentComponent, DirectiveType.All);
                if (directives.Count == 0)
                {
                    _baseComponentHeaderControl.ADStatus = Statuses.NotActive;
                    _baseComponentHeaderControl.EOStatus = Statuses.NotActive;
                    _baseComponentHeaderControl.SBStatus = Statuses.NotActive;
                }
                else
                {
                    #region проверка ADStatus

                    if (AnimatedThreadWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    AnimatedThreadWorker.ReportProgress(55, "Check Directives: AD Status");

                    Statuses allADStatus        = Statuses.NotActive;
                    IEnumerable <Directive> ads =
                        directives.Where(p => p.DirectiveType == DirectiveType.AirworthenessDirectives);

                    foreach (Directive primaryDirective in ads)
                    {
                        ConditionState directiveCond = GlobalObjects.PerformanceCalculator.GetConditionState(primaryDirective);
                        if (directiveCond == ConditionState.NotEstimated && allADStatus == Statuses.NotActive)
                        {
                            allADStatus = Statuses.NotActive;
                        }
                        if (directiveCond == ConditionState.Satisfactory && allADStatus != Statuses.Notify)
                        {
                            allADStatus = Statuses.Satisfactory;
                        }
                        if (directiveCond == ConditionState.Notify)
                        {
                            allADStatus = Statuses.Notify;
                        }
                        if (directiveCond == ConditionState.Overdue)
                        {
                            allADStatus = Statuses.NotSatisfactory;
                            break;
                        }
                    }
                    _baseComponentHeaderControl.ADStatus = allADStatus;

                    #endregion

                    #region проверка EO Status

                    if (AnimatedThreadWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    AnimatedThreadWorker.ReportProgress(61, "Check Directives: Engineering order Status");

                    Statuses allEOStatus        = Statuses.NotActive;
                    IEnumerable <Directive> eos =
                        directives.Where(p => p.DirectiveType == DirectiveType.EngineeringOrders ||
                                         p.EngineeringOrders != "" ||
                                         p.EngineeringOrderFile != null);
                    foreach (Directive primaryDirective in eos)
                    {
                        ConditionState directiveCond = GlobalObjects.PerformanceCalculator.GetConditionState(primaryDirective);
                        if (directiveCond == ConditionState.NotEstimated && allEOStatus == Statuses.NotActive)
                        {
                            allEOStatus = Statuses.NotActive;
                        }
                        if (directiveCond == ConditionState.Satisfactory && allEOStatus != Statuses.Notify)
                        {
                            allEOStatus = Statuses.Satisfactory;
                        }
                        if (directiveCond == ConditionState.Notify)
                        {
                            allEOStatus = Statuses.Notify;
                        }
                        if (directiveCond == ConditionState.Overdue)
                        {
                            allEOStatus = Statuses.NotSatisfactory;
                            break;
                        }
                    }
                    _baseComponentHeaderControl.EOStatus = allEOStatus;

                    #endregion

                    #region проверка SB Status

                    if (AnimatedThreadWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    AnimatedThreadWorker.ReportProgress(66, "Check Directives: Service bulletins Status");

                    Statuses allSBStatus        = Statuses.NotActive;
                    IEnumerable <Directive> sbs =
                        directives.Where(p => p.DirectiveType == DirectiveType.SB ||
                                         p.ServiceBulletinNo != "" ||
                                         p.ServiceBulletinFile != null);
                    foreach (Directive primaryDirective in sbs)
                    {
                        ConditionState directiveCond = GlobalObjects.PerformanceCalculator.GetConditionState(primaryDirective);
                        if (directiveCond == ConditionState.NotEstimated && allSBStatus == Statuses.NotActive)
                        {
                            allSBStatus = Statuses.NotActive;
                        }
                        if (directiveCond == ConditionState.Satisfactory && allSBStatus != Statuses.Notify)
                        {
                            allSBStatus = Statuses.Satisfactory;
                        }
                        if (directiveCond == ConditionState.Notify)
                        {
                            allSBStatus = Statuses.Notify;
                        }
                        if (directiveCond == ConditionState.Overdue)
                        {
                            allSBStatus = Statuses.NotSatisfactory;
                            break;
                        }
                    }

                    _baseComponentHeaderControl.SBStatus = allSBStatus;

                    #endregion
                }
                //Очистка коллекции для предотвращения утечек памяти
                directives.Clear();

                #endregion
            }

            if (AnimatedThreadWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            #endregion

            #region Сравнение с рабочими пакетами

            AnimatedThreadWorker.ReportProgress(90, "comparison with the Work Packages");

            if (AnimatedThreadWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
            #endregion

            AnimatedThreadWorker.ReportProgress(100, "Complete");
        }