public InstrumentPropertiesViewModel(InstrumentComponent instrumentEquipmentComponent)
        {
            mInstrumentComponent = instrumentEquipmentComponent;
            Models = new List<Model>();

            LastInspectedCommand = new DelegateCommand<object>(LastInspectedHandler, CanModify);
            NextInspectionCommand = new DelegateCommand<object>(NextInspectionHandler, CanModify);

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetManufacturersCompleted +=
                (s, e) =>
                    {
                        mManufacturers = e.Result;
                        RaisePropertyChanged("Manufacturers");
                        RaisePropertyChanged("Manufacturer");

                        if (mInstrumentComponent.ManufacturerId.HasValue)
                        {
                            LoadModels(mInstrumentComponent.ManufacturerId.Value);
                        }
                        else if (Loaded != null)
                        {
                            Loaded();
                            Loaded = null;
                        }
                    };
            cmsWebServiceClient.GetManufacturersAsync((int)CommonUtils.EquipmentTypeCode.INSTR);
        }
 public AddEditInstrumentComponentViewModel(InstrumentComponent mc, IList<string> existingComponentNames)
 {
     ExistingComponentNames = existingComponentNames;
     EditingName = mc.Name;
     mInstrumentComponent = mc;
     Initialize();
     InEditMode = true;
 }
 public AddEditInstrumentComponentViewModel(int instrumentEquipmentId, IList<string> existingComponentNames)
 {
     ExistingComponentNames = existingComponentNames;
     Initialize();
     mInstrumentComponent = new InstrumentComponent();
     mInstrumentComponent.InstrumentPropertyValues = new List<InstrumentPropertyValue>();
     mInstrumentComponent.InstrumentId = instrumentEquipmentId;
     InEditMode = false;
 }
예제 #4
0
    private void OnBoundUIOpened(EntityUid uid, InstrumentComponent component, BoundUIOpenedEvent args)
    {
        if (args.UiKey is not InstrumentUiKey)
        {
            return;
        }

        EnsureComp <ActiveInstrumentComponent>(uid);
        Clean(uid, component);
    }
        public AddEditInstrumentComponentDialog(InstrumentComponent electricalEquipmentComponent, IList<string> existingComponentNames)
        {
            // Required to initialize variables
            InitializeComponent();
            Title = "Edit Instrument Component";
            AddEditInstrumentComponentViewModel addEditInstrumentComponentViewModel = new AddEditInstrumentComponentViewModel(electricalEquipmentComponent, existingComponentNames);

            addEditInstrumentComponentViewModel.Loaded += () =>
                {
                    addEditInstrumentComponentViewModel.View = this;
                    DataContext = addEditInstrumentComponentViewModel;
                    Utils.ResetOriginalValues(LayoutRoot);
                };
        }
예제 #6
0
    private void OnBoundUIClosed(EntityUid uid, InstrumentComponent component, BoundUIClosedEvent args)
    {
        if (args.UiKey is not InstrumentUiKey)
        {
            return;
        }

        if (HasComp <ActiveInstrumentComponent>(uid) &&
            _userInterfaceSystem.TryGetUi(uid, args.UiKey, out var bui) &&
            bui.SubscribedSessions.Count == 0)
        {
            RemComp <ActiveInstrumentComponent>(uid);
        }

        Clean(uid, component);
    }
        public InstrumentPropertiesControl(InstrumentComponent controlSystemComponent)
        {
            if (DesignerProperties.IsInDesignTool) { return; }

            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
            mInstrumentComponent = controlSystemComponent;

            ComponentName = mInstrumentComponent.Name;

            mViewModel = new InstrumentPropertiesViewModel(mInstrumentComponent);
            mViewModel.Loaded += () =>
            {
                PopulatePropertyValues(controlSystemComponent);
                DataContext = mViewModel;

                ManufacturerComboBox.ResetOriginalValue();
                ManufacturerComboBox.ControlChanged += ControlChanged;

                ModelComboBox.ResetOriginalValue();
                ModelComboBox.ControlChanged += ControlChanged;
            };
        }
예제 #8
0
        private void DeleteInstrumentComponent(InstrumentComponent instrumentComponent)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                var instrumentPropertyValues = (from x in cee.InstrumentPropertyValues
                                                where x.InstrumentComponentId == instrumentComponent.Id
                                                select x).ToList();

                foreach (var instrumentPropertyValue in instrumentPropertyValues)
                {
                    cee.InstrumentPropertyValues.Remove(instrumentPropertyValue);
                }

                var q = (from x in cee.InstrumentComponents
                         where x.Id == instrumentComponent.Id
                         select x).FirstOrDefault();
                if (q != null)
                {
                    cee.InstrumentComponents.Remove(q);
                    cee.SaveChanges();
                }
            }
        }
        private InstrumentPropertyValue GetPropertyValue(InstrumentComponent controlSystemComponent,
            InstrumentComponentTypeProperty controlSystemComponentProperty)
        {
            var propertyValue = (from x in controlSystemComponent.InstrumentPropertyValues
                                 where x.InstrumentPropertyId == controlSystemComponentProperty.InstrumentPropertyId &&
                                       x.InstrumentComponentId == controlSystemComponent.Id
                                 select x).FirstOrDefault();

            if (propertyValue == null)
            {
                propertyValue = new InstrumentPropertyValue
                {
                    InstrumentComponentId = controlSystemComponent.Id,
                    InstrumentPropertyId = controlSystemComponentProperty.InstrumentPropertyId,
                    Value = controlSystemComponentProperty.InstrumentProperty.DefaultValue
                };

                controlSystemComponent.InstrumentPropertyValues.Add(propertyValue);
            }
            return propertyValue;
        }
        private void PopulatePropertyValues(InstrumentComponent instrumentComponent)
        {
            var controlSystemComponentProperies = instrumentComponent.InstrumentComponentType.InstrumentComponentTypeProperties.OrderBy(x => x.Ordinal).ToList();

            if (controlSystemComponentProperies.Any(x => x.InstrumentProperty.SystemComboType == CommonUtils.SystemComboBoxType.PandIdDocuments.ToString() ||
                                                         x.InstrumentProperty.SystemComboType == CommonUtils.SystemComboBoxType.SpecificationDocuments.ToString()))
            {
                Task<List<QuickDocument>> getPidDocumentsTask = null;
                Task<List<QuickDocument>> getSpecDocumentsTask = null;

                getPidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode);
                getSpecDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypeFuncspecCode);

                List<Task> tasks = new List<Task> { getPidDocumentsTask, getSpecDocumentsTask };
                Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
                {
                    CMS.UiFactory.StartNew(() =>
                    {

                        CreateAndBindDynamicProperties(instrumentComponent, getPidDocumentsTask.Result.Select(d => d.Name).ToList(), getSpecDocumentsTask.Result.Select(d => d.Name).ToList());
                    });
                });

            }
            CreateAndBindDynamicProperties(instrumentComponent, null, null);
        }
        private bool ChangeManufacturerModel(InstrumentComponentDataAdapter adapter, InstrumentComponent newComponent)
        {
            //CHANGING Manufacturer
            if (!string.IsNullOrEmpty(adapter.Manufacturer))
            {
                if (adapter.Manufacturer.ToLower() != "null")
                {

                    var manufactuer = (from x in mExistingManufacturers where x.Name.ToLower() == adapter.Manufacturer.ToLower() select x).FirstOrDefault();

                    if (manufactuer == null)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("Manufacturer", adapter.Manufacturer, adapter.RowNumber)));
                        return false;
                    }

                    newComponent.Manufacturer = manufactuer;
                    newComponent.ManufacturerId = manufactuer.Id;

                    if (adapter.Model.ToLower() != "null")
                    {
                        //CHANGING Model
                        if (!string.IsNullOrEmpty(adapter.Model))
                        {
                            var model = (from x in manufactuer.Models where x.Name.ToLower() == adapter.Model.ToLower() select x).FirstOrDefault();

                            if (model == null)
                            {
                                RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("Model", adapter.Model, adapter.RowNumber)));
                                return false;
                            }

                            newComponent.Model = model;
                            newComponent.ModelId = model.Id;
                        }
                    }
                    else
                    {
                        newComponent.Model = null;
                        newComponent.ModelId = null;
                    }
                }
                else
                {
                    newComponent.Manufacturer = null;
                    newComponent.ManufacturerId = null;
                    newComponent.Model = null;
                    newComponent.ModelId = null;
                }
            }
            return false;
        }
 private void InstrumentNeedsClean(EntityUid uid, InstrumentComponent component, ActivatableUIPlayerChangedEvent ev)
 {
     Clean(uid, component);
 }
        private bool GetInstrumentComponentType(string typeName, InstrumentComponent component, int rowIndex)
        {
            InstrumentComponentType componentType = (from x in mExistingComponentTypes
                                                     where string.Compare(typeName, x.Name, true, CultureInfo.CurrentCulture) == 0
                                                           && !string.IsNullOrEmpty(x.Name)
                                                     select x).FirstOrDefault();

            if (componentType != null)
            {
                component.InstrumentComponentType = componentType;
                component.InstrumentComponentTypeId = componentType.Id;
            }
            else
            {
                if (CanCreateProperties)
                {
                    string code = typeName.Replace(" ", "_").ToUpper();
                    componentType = new InstrumentComponentType { Name = typeName, Code = code, Description = typeName + " (created by importer)", IsActive = true };
                    mExistingComponentTypes.Add(componentType);
                    component.InstrumentComponentType = componentType;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Could not find InstrumentComponentType '{2}' in database. Skipping this row.", WorkSheetName, rowIndex, typeName));
                    return true;
                }
            }

            return false;
        }
        private bool GetInstrument(string tag, InstrumentComponent newComponent, int rowIndex)
        {
            bool skipRow = false;

            //Check if the Area exist in the database
            Instrument equipment = (from x in Cee.Instruments
                                    where string.Compare(tag, x.Name, true, CultureInfo.CurrentCulture) == 0
                                          && !string.IsNullOrEmpty(x.Name)
                                    select x).FirstOrDefault();

            if (equipment != null)
            {
                newComponent.Instrument = equipment;
                newComponent.InstrumentId = equipment.Id;
            }
            else
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Could not find Equipment '{2}' in database. Skipping this row.", WorkSheetName, rowIndex, tag));
                skipRow = true;
            }

            return skipRow;
        }
        private InstrumentComponent CloneComponent(InstrumentComponent selectedComponent)
        {
            InstrumentComponent clone = new InstrumentComponent();
            clone.Id = selectedComponent.Id;
            clone.InstrumentId = selectedComponent.InstrumentId;
            clone.Instrument = selectedComponent.Instrument;
            clone.InstrumentComponentTypeId = selectedComponent.InstrumentComponentTypeId;
            clone.Name = selectedComponent.Name;
            clone.Description = selectedComponent.Description;
            clone.Ordinal = selectedComponent.Ordinal;
            clone.LastModifiedById = selectedComponent.LastModifiedById;
            clone.LastModifiedDate = selectedComponent.LastModifiedDate;
            clone.LastInspectedById = selectedComponent.LastInspectedById;
            clone.NextInspectionDate = selectedComponent.NextInspectionDate;
            clone.LastInspectedDate = selectedComponent.LastInspectedDate;

            clone.InstrumentPropertyValues = new List<InstrumentPropertyValue>();

            foreach (var instrumentPropertyValue in selectedComponent.InstrumentPropertyValues)
            {
                clone.InstrumentPropertyValues.Add(new InstrumentPropertyValue
                {
                    Id = instrumentPropertyValue.Id,
                    InstrumentPropertyId = instrumentPropertyValue.InstrumentPropertyId,
                    InstrumentComponentId = instrumentPropertyValue.InstrumentComponentId,
                    Value = instrumentPropertyValue.Value
                });
            }

            return clone;
        }
        private void InsertData(IList<InstrumentComponentDataAdapter> adapters)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();

            for (int index = 0; index < adapters.Count; index++)
            {
                InstrumentComponentDataAdapter adapter = adapters[index];
                if (!adapter.IsValid())
                {
                    continue;
                }

                IList<string> componentNames = (from x in adapters select x.ComponentName).ToList();
                if (DuplicateItemNameFoundInExcell(adapter.ComponentName, componentNames, adapter.RowNumber))
                {
                    continue;
                }

                componentNames = (from x in Cee.InstrumentComponents select x.Name).ToList();
                if (DuplicateItemNameFoundInDatabase(adapter.ComponentName, componentNames, adapter.RowNumber))
                {
                    continue;
                }

                InstrumentComponent newComponent = new InstrumentComponent
                {
                    LastModifiedDate = DateTime.Now,
                    LastModifiedById = MetaData.UserId,
                    Name = adapter.ComponentName,
                    Description = adapter.ComponentDescription
                };

                if (GetInstrument(adapter.Tag, newComponent, adapter.RowNumber)) continue;
                if (GetInstrumentComponentType(adapter.ComponentType, newComponent, adapter.RowNumber)) continue;

                InstrumentComponent existing = (from x in Cee.InstrumentComponents
                                                where string.Compare(x.Name, adapter.Tag, true, CultureInfo.CurrentCulture) == 0
                                                    && x.InstrumentComponentTypeId == newComponent.InstrumentComponentTypeId
                                                select x).FirstOrDefault();
                if (existing != null)
                {
                    //error - should not already exist
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': '{2}' with a component type of '{3}' already exists in the database.  Skipping.",
                        WorkSheetName, adapter.RowNumber, adapter.Tag, newComponent.InstrumentComponentType.Name));
                    continue;
                }

                var skipRow = ChangeManufacturerModel(adapter, newComponent);

                if (skipRow) continue;

                BuildPropertyValues(newComponent, adapter);

                Cee.InstrumentComponents.Add(newComponent);
                mSavedResults.Add(newComponent);

                const decimal incrediment = 0.001m;
                decimal revision = new decimal(1.000);

                List<decimal> foo = (from x in Cee.InstrumentRevisionHistories where x.InstrumentId == newComponent.InstrumentId orderby x.Revision descending select x.Revision).ToList();

                if (foo.Count > 0)
                {
                    revision = foo[0] + incrediment;
                }

                newComponent.Instrument.InstrumentRevisionHistories.Add(new InstrumentRevisionHistory
                {
                    Date = DateTime.Now,
                    InstrumentId = newComponent.InstrumentId,
                    UserId = MetaData.UserId,
                    Description = BuildRevisionHistoryInsertComment(MetaData.RevisionHistoryComment),
                    IsSystemMessage = true,
                    Revision = revision
                });
            }

            if (mSavedResults.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Info, string.Format("No Components were processed from this worksheet '{0}'.", WorkSheetName));
            }
            else
            {
                Cee.SaveChanges();
            }

            foreach (InstrumentComponent result in mSavedResults)
            {
                RaiseMessage(CommonUtils.MessageType.Added, string.Format("Added Instrument Component '{0}' from worksheet {1}.", result.Name, WorkSheetName));
            }
        }
        private InstrumentRevisionHistory BuildRevisionHistory(InstrumentComponent existingComponent)
        {
            const decimal incrediment = 0.001m;
            decimal revision = new decimal(1.000);

            List<decimal> foo = (from x in Cee.InstrumentRevisionHistories where x.InstrumentId == existingComponent.InstrumentId orderby x.Revision descending select x.Revision).ToList();

            if (foo.Count > 0)
            {
                revision = foo[0] + incrediment;
            }

            InstrumentRevisionHistory rvh = new InstrumentRevisionHistory
                                                {
                                                    Date = DateTime.Now,
                                                    InstrumentId = existingComponent.InstrumentId,
                                                    UserId = MetaData.UserId,
                                                    Description = BuildRevisionHistoryUpdateComment(MetaData.RevisionHistoryComment),
                                                    Revision = revision,
                                                    IsSystemMessage = true
                                                };
            return rvh;
        }
        private void CreateAndBindDynamicProperties(InstrumentComponent instrumentComponent, List<String> pidDocuments, List<String> specDocuments)
        {
            int rowCount = 5;

            var controlSystemComponentProperies = instrumentComponent.InstrumentComponentType.InstrumentComponentTypeProperties.OrderBy(x => x.Ordinal).ToList();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAllPropertyListsCompleted += (s, e) =>
            {

                foreach (var controlSystemComponentProperty in controlSystemComponentProperies.Where(x => x.InstrumentProperty.IsVisible))
                {

                    Label label = new Label();

                    Binding labelBinding = new Binding("Name")
                    {
                        Mode = BindingMode.OneTime,
                        Source = controlSystemComponentProperty.InstrumentProperty
                    };

                    label.SetBinding(ContentControl.ContentProperty, labelBinding);
                    label.VerticalAlignment = VerticalAlignment.Center;
                    label.Margin = new Thickness(1);

                    PropertiesGrid.Children.Add(label);
                    Grid.SetRow(label, rowCount);
                    Grid.SetColumn(label, 0);

                    var propertyValue = GetPropertyValue(instrumentComponent, controlSystemComponentProperty);

                    var element = Utils.BindElement(controlSystemComponentProperty.InstrumentProperty, propertyValue, e.Result,
                        ComponentPropertyWrapViewModels, ControlChanged, pidDocuments, specDocuments);

                    PropertiesGrid.Children.Add(element);
                    Grid.SetRow((FrameworkElement)element, rowCount);
                    Grid.SetColumn((FrameworkElement)element, 1);

                    PropertiesGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(element.Height + 2) });

                    rowCount++;
                }

                LastInspectedTextBox.ResetOriginalValue();
                LastInspectedTextBox.ControlChanged += ControlChanged;

                NextInspectionTextBox.ResetOriginalValue();
                NextInspectionTextBox.ControlChanged += ControlChanged;

            };
            cmsWebServiceClient.GetAllPropertyListsAsync();
        }
예제 #19
0
        public DbOperationResult SaveInstrumentComponents(List<InstrumentComponent> instrumentComponents, int userId)
        {
            DbOperationResult result = new DbOperationResult();

            using (CmsEntities cee = new CmsEntities())
            {
                try
                {
                    foreach (var instrumentComponent in instrumentComponents)
                    {
                        var q = (from x in cee.InstrumentComponents
                                 where x.Id == instrumentComponent.Id
                                 select x).FirstOrDefault();

                        if (q != null)
                        {

                            if (q.LastInspectedDate != instrumentComponent.LastInspectedDate)
                            {
                                InstrumentRevisionHistory rv = new InstrumentRevisionHistory
                                {
                                    InstrumentId = instrumentComponent.InstrumentId,
                                    Date = DateTime.Now,
                                    UserId = userId,
                                    Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", instrumentComponent.Name, q.LastInspectedDate, instrumentComponent.LastInspectedDate),
                                    IsSystemMessage = true
                                };
                                AddInstrumentRevisionHistoryInternal(rv, cee);
                            }

                            //Update Instrument Componet
                            cee.Entry(q).CurrentValues.SetValues(instrumentComponent);
                        }
                        else
                        {
                            q = new InstrumentComponent();
                            q.InstrumentId = instrumentComponent.InstrumentId;
                            q.InstrumentComponentTypeId = instrumentComponent.InstrumentComponentTypeId;
                            q.Name = instrumentComponent.Name;
                            q.Ordinal = instrumentComponent.Ordinal;
                            q.NextInspectionDate = instrumentComponent.NextInspectionDate;
                            q.LastInspectedById = instrumentComponent.LastInspectedById;
                            q.LastInspectedDate = instrumentComponent.LastInspectedDate;
                            q.LastModifiedById = instrumentComponent.LastModifiedById;
                            q.LastModifiedDate = instrumentComponent.LastModifiedDate;
                            q.Description = instrumentComponent.Description;
                            q.ManufacturerId = instrumentComponent.ManufacturerId;
                            q.ModelId = instrumentComponent.ModelId;

                            //Add new Instrument Component
                            cee.InstrumentComponents.Add(q);
                        }

                        foreach (var instrumentComponentPropertyValue in instrumentComponent.InstrumentPropertyValues)
                        {
                            var qq = (from x in cee.InstrumentPropertyValues
                                      where x.Id == instrumentComponentPropertyValue.Id
                                      select x).FirstOrDefault();

                            if (qq != null)
                            {
                                cee.Entry(qq).CurrentValues.SetValues(instrumentComponentPropertyValue);
                            }
                            else
                            {
                                cee.InstrumentPropertyValues.Add(instrumentComponentPropertyValue);
                            }
                        }
                        cee.SaveChanges();
                    }
                }
                catch (Exception ex)
                {

                    result.ServerErrorMessages.Add(String.Format("Error moving components: {0}", ex.Message));
                }
            }
            return result;
        }
        private void MoveComponentHandler(object parameter)
        {
            if (SelectedComponent != null)
            {
                AddIssueInstrumentDialog dialog = new AddIssueInstrumentDialog("Select Destination Tag", true, SelectedComponent.InstrumentId);
                dialog.Show();

                //Select the component as user might have changed the component type
                //and this needs to reload the component type properties
                dialog.Closed += (s1, e1) =>
                                     {
                                         if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                                         {
                                             if (dialog.SelectedEquipment != null)
                                             {
                                                 SelectedComponent.InstrumentId = dialog.SelectedEquipment.Id;

                                                 //need to CLONE due to the line "RaisePropertyChanged("Components");"
                                                 var movedInstrumentComponent = CloneComponent(SelectedComponent);
                                                 movedInstrumentComponent.Instrument = new Instrument
                                                                                           {
                                                                                               Id = dialog.SelectedEquipment.Id,
                                                                                               Name = dialog.SelectedEquipment.Name
                                                                                           };

                                                 MovedComponents.Add(movedInstrumentComponent);

                                                 //remove
                                                 mInstrument.InstrumentComponents.Remove(SelectedComponent);
                                                 RaiseChangeEvent();
                                                 OnCollectionChanged();
                                                 mSelectedComponent = null;

                                                 RaisePropertyChanged("Components");
                                             }
                                         }
                                     };
            }
        }
        private void EditComponentHandler(object parameter)
        {
            if (SelectedComponent != null)
            {
                CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

                cmsWebServiceClient.GetInstrumentComponentsCompleted +=
                    (s, e) =>
                    {

                        InstrumentComponent clone = new InstrumentComponent();
                        CommonUtils.CloneObject(clone, SelectedComponent, "");
                        clone.InstrumentComponentType = SelectedComponent.InstrumentComponentType;//not done by CloneObject method.

                        IList<string> existingComponentNames = (from x in Components select x.Name).ToList();
                        AddEditInstrumentComponentDialog dialog = new AddEditInstrumentComponentDialog(SelectedComponent, existingComponentNames);
                        dialog.Show();

                        //Select the component as user might have changed the component type
                        //and this needs to reload the component type properties
                        dialog.Closed += (s1, e1) =>
                            {
                                if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                                {
                                    SelectedComponent = dialog.Component;
                                    Utils.OnCollectionChanged(EventAggregator, mInstrument, PROPERTYNAME, true);
                                }
                                else
                                {
                                    SelectedComponent.Name = clone.Name;
                                    SelectedComponent.InstrumentComponentType = clone.InstrumentComponentType;
                                    SelectedComponent.Description = clone.Description;
                                }
                                RaisePropertyChanged("Components");
                            };
                    };
                cmsWebServiceClient.GetInstrumentComponentsAsync();

            }
        }
예제 #22
0
 private void OnShutdown(EntityUid uid, InstrumentComponent component, ComponentShutdown args)
 {
     EndRenderer(uid, false, component);
 }
        private void BuildPropertyValues(InstrumentComponent componentIn, InstrumentComponentDataAdapter adapter)
        {
            foreach (KeyValuePair<string, string> pair in adapter.PropertyValues)
            {
                //DOES PROPERTY EXIST?
                InstrumentProperty property = (from x in mExistingProperties where x.Name.ToLower() == pair.Key.ToLower() select x).FirstOrDefault();
                if (property == null)
                {
                    if (CanCreateProperties)
                    {
                        property = new InstrumentProperty { Name = pair.Key, DefaultValue = pair.Value, Description = " (created by importer)." };
                        mExistingProperties.Add(property);//update cache
                    }
                    else
                    {
                        //ERROR!
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1} Tag {2} Component Name {3}' : The property does not exist.",
                            WorkSheetName, adapter.RowNumber, adapter.Tag, adapter.ComponentName));
                        continue;
                    }
                }

                //CHECK InstrumentComponentTypeProperty Exists
                InstrumentComponentTypeProperty equipmentComponentTypeProperty = null;
                if (mExistingEquipmentComponentTypeProperty.Any())
                {
                    equipmentComponentTypeProperty =
                        (from x in mExistingEquipmentComponentTypeProperty
                         where x.InstrumentComponentType.Name.ToLower() == componentIn.InstrumentComponentType.Name.ToLower()
                         && x.InstrumentProperty.Name.ToLower() == property.Name.ToLower()
                         select x).FirstOrDefault();
                }

                if (equipmentComponentTypeProperty == null)
                {
                    if (CanCreateProperties)
                    {
                        //CREATE JOIN ROW
                        equipmentComponentTypeProperty = new InstrumentComponentTypeProperty
                        {
                            InstrumentComponentType = componentIn.InstrumentComponentType,
                            InstrumentProperty = property
                        };
                        mExistingEquipmentComponentTypeProperty.Add(equipmentComponentTypeProperty);//update cache
                    }
                    else
                    {
                        //ERROR!
                        RaiseMessage(CommonUtils.MessageType.Warning, string.Format("WorkSheet '{0}' Row '{1} Tag {2} Component Type {3}' : The property {4} does not belong to the Component Type.",
                            WorkSheetName, adapter.RowNumber, adapter.Tag, componentIn.InstrumentComponentType.Name, property.Name));
                        continue;
                    }
                }
                property.InstrumentComponentTypeProperties.Add(equipmentComponentTypeProperty);

                //CHECK PROPERTYVALUE EXISTS
                InstrumentPropertyValue propertyValue = null;
                //if (mCee.InstrumentPropertyValues.Any())
                //{

                propertyValue = (from x in Cee.InstrumentPropertyValues
                                 where x.InstrumentComponent.Name.ToLower() == componentIn.Name.ToLower()
                                       && x.InstrumentProperty.Name.ToLower() == property.Name.ToLower()
                                 select x).FirstOrDefault();
                //}

                if (propertyValue == null)
                {
                    propertyValue = new InstrumentPropertyValue
                    {
                        InstrumentComponent = componentIn,
                        InstrumentProperty = property
                    };
                    //mExistingPropertyValues.Add(propertyValue);//update cache
                }

                //set value
                if (!string.IsNullOrEmpty(pair.Value))
                {
                    propertyValue.Value = pair.Value.ChangeNullToEmptyString();
                }
                componentIn.InstrumentPropertyValues.Add(propertyValue);
            }
        }