示例#1
0
        private static void SetOrdinalAndGroupOnControlTypeTestingProperty(ARTEntities art, CmsEntities cee, TestResult testResult, ControlModule cm, ControlSystem controlSystem)
        {
            //get the number for this testresult to use on the ControlSystemTypeTestingProperty.Number
            var tp = (from x in cee.ControlSystemTestingProperties where x.Description.Equals(testResult.Test.Description, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
            if (tp == null)
            {
                //log error
                Logger.Out(string.Format("Control {0} - Trying to set ordinal. No matchng ControlSystemTestingProperty found in CMS using Description = '{1}'.", cm.Tag, testResult.Test.Description));
                return;
            }

            var controlSystemTypeTestingProperty = (from x in cee.ControlSystemTypeTestingProperties
                                                    where x.ControlSystemTypeId == controlSystem.ControlSystemTypeId
                                                          && x.TestPropertyId == tp.Id
                                                    select x).FirstOrDefault();

            if (controlSystemTypeTestingProperty == null)
            {
                Logger.Out(string.Format("Control {0} - Trying to set ordinal. No matchng ControlSystemTypeTestingProperty found in CMS using ControlSystemTypeId = '{1}' and TestPropertyId = {2}.", cm.Tag, controlSystem.ControlSystemTypeId, tp.Id));
                return;
            }

            //matchGroup
            if (testResult.Test == null)
            {
                Logger.Out(string.Format("Control {0} - Trying to set Group Id. No Tests exist on TestResult.Test. ", cm.Tag));
                return;
            }

            if (controlSystemTypeTestingProperty.Ordinal == 0)
            {
                //not been set before.
                controlSystemTypeTestingProperty.GroupOrdinal = testResult.Number;
            }

            Stage stage = (from x in art.Stages where x.Id == testResult.Test.StageId select x).FirstOrDefault();

            if (stage != null)
            {
                if (controlSystemTypeTestingProperty.Ordinal == 0)
                {
                    //not been set before.
                    if (stage.Description.Equals("Stage 2", StringComparison.CurrentCultureIgnoreCase))
                    {
                        controlSystemTypeTestingProperty.Ordinal = 1;
                    }
                    else if (stage.Description.Equals("Stage 3", StringComparison.CurrentCultureIgnoreCase))
                    {
                        controlSystemTypeTestingProperty.Ordinal = 2;
                    }
                    else if (stage.Description.Equals("Stage 4", StringComparison.CurrentCultureIgnoreCase))
                    {
                        controlSystemTypeTestingProperty.Ordinal = 3;
                    }
                }

                //check if we have cee.Group.
                ComponentTypeGroup typeGroup = (from x in cee.ComponentTypeGroups
                                                where x.Name.Equals(stage.Description, StringComparison.InvariantCultureIgnoreCase)
                                                    && x.ComponentPropertyType.Equals(CommonUtils.EquipmentPropertyType.SystemTestingProperty.ToString(), StringComparison.InvariantCultureIgnoreCase)
                                                select x).FirstOrDefault();

                if (typeGroup == null)
                {
                    //CREATE GROUP
                    typeGroup = new ComponentTypeGroup
                    {
                        Name = stage.Description,
                        ComponentPropertyType = CommonUtils.EquipmentPropertyType.SystemTestingProperty.ToString()
                    };

                    cee.ComponentTypeGroups.Add(typeGroup);
                    cee.SaveChanges();
                    Logger.Out(string.Format("Control {0} - Created new CMS ComponentTypeGroup '{1}'. ", cm.Tag, typeGroup.Name));

                }

                controlSystemTypeTestingProperty.ComponentTypeGroupId = typeGroup.Id;
            }
        }
示例#2
0
        public void Run()
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            var dt = DateTime.Now;

            Console.WriteLine("Started Run at " + dt.ToString(DATE_FORMAT));

            try
            {
                if (AbortSetStartUpOptions()) return;

                List<int> controlModuleIdList;
                int count;
                using (var art = new ARTEntities())
                {
                    controlModuleIdList = (from x in art.ControlModules select x.Id).ToList();
                    //controlModuleIdList = (from x in art.ControlModules where x.Tag == "HV631442" select x.Id).ToList();
                    count = art.ControlModules.Count();
                }

                var index = 0;
                foreach (var id in controlModuleIdList)
                {
                    using (var art = new ARTEntities())
                    {

                        art.Database.CommandTimeout = 360;
                        using (var cee = new CmsEntities())
                        {

                            var artCm = (from x in art.ControlModules
                                .Include("Elements")
                                .Include("Elements.ElementTypical")
                                .Include("ControlModuleTypical")
                                         where x.Id == id
                                         select x).FirstOrDefault();

                            index++;

                            UpdateStatus(string.Format("{0} of {1})", index, count));

                            //Match ControlSystemType
                            ControlSystemType controlSystemType;
                            if (MatchControlSystemTypeFailed(cee, artCm, out controlSystemType)) continue;

                            //Match ControlSystem
                            ControlSystem controlSystem;
                            if (MatchControlSystemFailed(cee, artCm, controlSystemType, out controlSystem)) continue;

                            //Check Default View Exists in Elements
                            List<Element> defaultViewElements;
                            if (GetDefaultViewElementFailed(artCm, out defaultViewElements)) continue;

                            artCm = (from x in art.ControlModules
                                .Include("Elements")
                                .Include("Elements.ElementTypical")
                                .Include("ControlModuleTypical")
                                .Include("ControlModuleTypical.TestSets")
                                     where x.Id == id
                                     select x).FirstOrDefault();

                            if (!artCm.ControlModuleTypical.TestSets.Any())
                            {
                                Logger.Out(string.Format("Control {0} - No TestSets exist.", artCm.Tag));
                                continue;
                            }

                            artCm = (from x in art.ControlModules
                                .Include("Elements")
                                .Include("Elements.ElementTypical")
                                .Include("ControlModuleTypical")
                                .Include("ControlModuleTypical.TestSets")
                                .Include("ControlModuleTypical.TestSets.Test")
                                     where x.Id == id
                                     select x).FirstOrDefault();

                            List<ControlSystemTestingProperty> associatedProperties;
                            if (BuildTestPropertiesFailed(artCm.ControlModuleTypical.TestSets.ToList(), cee, out associatedProperties)) continue;

                            foreach (var property in associatedProperties)
                            {
                                var pair = new KeyValuePair<int, int>(property.Id, controlSystem.ControlSystemTypeId);

                                if (!mControlTypePropertyPairsDictionary.ContainsKey(pair))
                                {
                                    //insert new comp type propertid record.
                                    mControlTypePropertyPairsDictionary.Add(pair, artCm.Id);

                                    ControlSystemTypeTestingProperty typeTestingProperty = (from x in cee.ControlSystemTypeTestingProperties where x.TestPropertyId == property.Id && x.ControlSystemTypeId == controlSystem.ControlSystemTypeId select x).FirstOrDefault();

                                    if (typeTestingProperty == null)
                                    {
                                        var cptp = new ControlSystemTypeTestingProperty
                                        {
                                            TestPropertyId = property.Id,
                                            ControlSystemTypeId = controlSystem.ControlSystemTypeId,
                                            Ordinal = 0
                                        };

                                        cee.ControlSystemTypeTestingProperties.Add(cptp);

                                        //+++ SAVE +++
                                        cee.SaveChanges();
                                    }
                                }
                            }

                            var testResults = (from x in art.TestResults
                                                   .Include("Test")
                                                   .Include("ControlModule")
                                                   .Include("ControlModule.ControlModuleTypical")
                                               where x.ControlModuleId == id
                                               select x).ToList();

                            if (!testResults.Any())
                            {
                                Logger.Out(string.Format("Control {0} - No matchng TestResult.Test found in ART.TestResults using ControlModuleId = '{1}'.", artCm.Tag, artCm.Id));
                                continue;
                            }

                            //build property values and set ordinal on ControlSystemTypeTestingProperty
                            var k = 0;
                            foreach (var testResult in testResults)
                            {
                                if (testResult.TestId == null)
                                {
                                    continue;
                                }

                                //Match Test
                                Test test;
                                if (MatchTestFailed(art, testResult, artCm, out test)) continue;

                                //Match ControlSystemTestingProperty
                                ControlSystemTestingProperty testingProperty;
                                if (MatchTestingPropertyFailed(cee, test, artCm, out testingProperty)) continue;

                                //Build ControlSystemTestingPropertyValue
                                ControlSystemTestingPropertyValue pv;
                                if (BuildPropertyValueFailed(controlSystem, testingProperty, testResult, cee, artCm, out pv)) continue;

                                k++;
                                cee.ControlSystemTestingPropertyValues.Add(pv);

                                SetOrdinalAndGroupOnControlTypeTestingProperty(art, cee, testResult, artCm, controlSystem);
                            }

                            // +++ SAVE +++
                            cee.SaveChanges();
                            Logger.Out(string.Format("{0}: Saved {1} Property Values.", controlSystem.Name, k));

                        }//end using
                    }//end using
                }//end control module loop

            }
            catch (Exception ex)
            {
                Logger.Out("");
                Logger.Out("{0}\n\r\n\r{1}", ex.Message, ex.InnerException != null ? ex.InnerException.ToString() : string.Empty);
            }
            finally
            {
                Logger.WriteToFile();
                Logger.Out("");

                sw.Stop();
                Console.WriteLine("Time taken: {0} minutes, {1} secs", sw.Elapsed.Minutes, sw.Elapsed.Seconds);
                Logger.Out("Press Enter to continue...");
                Console.ReadLine();

            }
        }
示例#3
0
 private static bool MatchTestFailed(ARTEntities art, TestResult testResult, ControlModule cm, out Test test)
 {
     test = (from x in art.Tests where x.Id == testResult.TestId select x).FirstOrDefault();
     if (test == null)
     {
         //log error
         Logger.Out(string.Format("Control {0} - No matchng TestResult.Test found in ART using Test.Id = '{1}'.", cm.Tag, testResult.TestId));
         return true;
     }
     return false;
 }