コード例 #1
0
        public async Task <ActionResult> GetAnomalyDetail(int AnomalyId)
        {
            var anomaly = await _prepareService.GetAnomaly(AnomalyId);

            var model = new AnomalyViewModel
            {
                AnomalyId   = anomaly.Id,
                Category    = anomaly.Category,
                Date        = anomaly.Date,
                Description = anomaly.Description,
                HasPhoto    = anomaly.Photo != null ? true : false,
                Photo       = anomaly.Photo == null ? "" : string.Format("data:image/gif;base64,{0}", Convert.ToBase64String(anomaly.Photo)),
                Label       = anomaly.Label,
                Line        = anomaly.Line,
                Machine     = anomaly.Machine,
                Priority    = (int)anomaly.Priority.Value,
                Type        = (int)anomaly.Type,
                TypeLabel   = anomaly.Type.AnomalyTypeToString(),
                TypeColor   = anomaly.Type == AnomalyType.Security ? "green" : anomaly.Type == AnomalyType.Maintenance ? "red" : anomaly.Type == AnomalyType.Operator ? "blue" : "gray"
            };

            model.PriorityLists = new List <Tuple <int, string> >
            {
                new Tuple <int, string>(1, "A"),
                new Tuple <int, string>(2, "B"),
                new Tuple <int, string>(3, "C")
            };

            model.KindItems = new List <IAnomalyKindItem>();
            model.KindItems = Anomalies.GetPossibleAnomalies(anomaly.Type);
            return(PartialView("AnomalyDetail", model));
        }
コード例 #2
0
        private static void ImportAnomalies()
        {
            var context   = new MassDefectContext();
            var json      = File.ReadAllText(AnomaliesPath);
            var anomalies = JsonConvert.DeserializeObject <IEnumerable <AnomalyDTO> >(json);

            foreach (var anomaly in anomalies)
            {
                if (anomaly.OriginPlanet == null || anomaly.TeleportPlanet == null)
                {
                    throw new ArgumentException("Error: Invalid data.");
                    continue;
                }

                var anomalyEntity = new Anomalies()
                {
                    //OriginPlanet = context.Anomalies.Select(orp => orp.OriginPlanet.Name),
                    //TeleportPlanet = context.Anomalies.Select(tpl => tpl.TeleportPlanet.Name)
                };

                context.Anomalies.Add(anomalyEntity);
                System.Console.WriteLine($"Successfully imported {anomalyEntity} {anomalyEntity.OriginPlanet} {anomalyEntity.TeleportPlanet}.");
            }

            context.SaveChanges();
        }
コード例 #3
0
            /// <summary>
            /// Determines whether the given folder contains only the given files, and no others
            /// </summary>
            /// <returns></returns>
            protected bool FolderContainsExclusive(string relFolderPath, IEnumerable<string> filenames, Anomalies anomalies = null)
            {
                var dirPath = Path.Combine(this.TargetDir, relFolderPath);
                var exists = Directory.Exists(dirPath);
                if (!exists)
                {
                    return false;
                }
                else
                {
                    var folderFiles = new DirectoryInfo(dirPath).GetFiles();

                    var filesInFolder = folderFiles.Select(f => f.Name).Except(filenames).ToList();
                    var expectedFiles = filenames.Except(folderFiles.Select(f => f.Name)).ToList();

                    if (anomalies != null)
                    {
                        anomalies.ExpectedFiles.AddRange(expectedFiles);
                        anomalies.UnexpectedFiles.AddRange(filesInFolder);
                    }

                    return !(filesInFolder.Any())
                        && !(expectedFiles.Any());
                }
            }
コード例 #4
0
ファイル: ImportJsonApp.cs プロジェクト: stominmetal/Softuni
        private static void ImportAnomalies()
        {
            var context   = new MassDefectContext();
            var json      = File.ReadAllText(AnomaliesPath);
            var anomalies = JsonConvert.DeserializeObject <IEnumerable <AnomaliesDTO> >(json);

            foreach (var anomaly in anomalies)
            {
                if (anomaly.OriginPlanet == null || anomaly.TeleportPlanet == null)
                {
                    RaiseError();
                    continue;
                }

                var anomalyEntity = new Anomalies
                {
                    OriginPlanet   = GetOriginPlanet(anomaly.OriginPlanet, context),
                    TeleportPlanet = GetTeleportPlanet(anomaly.TeleportPlanet, context)
                };

                if (anomalyEntity.TeleportPlanet == null || anomalyEntity.OriginPlanet == null)
                {
                    RaiseError();
                    continue;
                }

                context.Anomalies.Add(anomalyEntity);

                Console.WriteLine($"Successfully imported anomaly.");
            }
            context.SaveChanges();
        }
コード例 #5
0
ファイル: ImportXMLApp.cs プロジェクト: stominmetal/Softuni
        private static void ImportAnomalyAndVictims(XElement anomalyNode, MassDefectContext context)
        {
            var originPlanetName   = anomalyNode.Attribute("origin-planet");
            var teleportPlanetName = anomalyNode.Attribute("teleport-planet");

            if (originPlanetName == null || teleportPlanetName == null)
            {
                RaiseError();
                return;
            }

            //might check the .values tho
            var anomalyEntity = new Anomalies
            {
                OriginPlanet   = GetPlanetByName(originPlanetName.Value, context),
                TeleportPlanet = GetPlanetByName(teleportPlanetName.Value, context)
            };

            if (anomalyEntity.OriginPlanet == null || anomalyEntity.TeleportPlanet == null)
            {
                RaiseError();
            }

            var victims = anomalyNode.XPathSelectElements("victims/victim");

            foreach (var victim in victims)
            {
                ImportVictim(victim, context, anomalyEntity);
            }

            context.SaveChanges();
        }
コード例 #6
0
        // NOT USED
        public async Task <bool> CollectAndSendAnomaly()
        {
            var anomaly = await _prepareService.GetAnomaly(1023);

            if (anomaly == null)
            {
                return(false);
            }
            var model = new WebAdmin.Models.Inspection.AnomalyViewModel
            {
                AnomalyId   = anomaly.Id,
                Category    = anomaly.Category,
                Date        = anomaly.Date,
                Description = anomaly.Description,
                HasPhoto    = anomaly.Photo != null,
                Photo       = anomaly.Photo == null ? string.Empty : string.Format("data:image/gif;base64,{0}", Convert.ToBase64String(anomaly.Photo)),
                Label       = anomaly.Label,
                Line        = anomaly.Line,
                Machine     = anomaly.Machine,
                Priority    = (int)anomaly.Priority.Value,
                Type        = (int)anomaly.Type,
                TypeLabel   = anomaly.Type.AnomalyTypeToString(),
                TypeColor   = anomaly.Type == AnomalyType.Security ? "green" : anomaly.Type == AnomalyType.Maintenance ? "red" : anomaly.Type == AnomalyType.Operator ? "blue" : "gray"
            };

            model.PriorityLists = new List <Tuple <int, string> >
            {
                new Tuple <int, string>(1, "A"),
                new Tuple <int, string>(2, "B"),
                new Tuple <int, string>(3, "C")
            };

            model.KindItems = new List <IAnomalyKindItem>();
            model.KindItems = Anomalies.GetPossibleAnomalies(anomaly.Type);

            model.Items = new List <WebAdmin.Models.Inspection.AnomalyKindItemViewModel>();
            foreach (var item in model.KindItems)
            {
                if (item.GetType().Name == "AnomalyKindItem")
                {
                    var tempItem = (AnomalyKindItem)item;
                    model.Items.Add(new WebAdmin.Models.Inspection.AnomalyKindItemViewModel
                    {
                        Label    = tempItem.Label,
                        Category = tempItem.Category,
                        Number   = tempItem.Number
                    });
                }
            }

            string pdfString = _notificationService.RenderViewToString(model, pdfTemplatePath, "PdfAnomaly.cshtml");

            _notificationService.RenderViewToPdf(pdfString, pdfBase, baseUrl);
            return(true);
        }
コード例 #7
0
        internal async Task <(Anomaly anomaly, Trigger trigger)> AddValue(TValue value)
        {
            var anomaly = Range.Validate(value);

            if (anomaly == Anomaly.None)
            {
                var referenceDate = await AddValueOnReferenceDate(value).ConfigureAwait(false);

                return(anomaly, TriggerSettings.DetermineTrigger(referenceDate, NextCalculationDate, Values.Count));
            }

            Anomalies.Add(value);
            return(anomaly, TriggerSettings.DetermineAnomalyTrigger(Anomalies.Count));
        }
        public bool Read(Stream stream, MatchData matchData)
        {
            if (data == null)
            {
                data = new Anomalies();
            }

            var buffer = string.Empty;
            AnomalousNode foundNode = null;
            var ifFound = false;
            var matchPos = stream.Position;
            int curByte;

            while ((curByte = stream.ReadByte()) >= 0)
            {
                buffer += (char)curByte;

                AnomalousNode node;
                var match = data.Parse(buffer, out node);
                if (match == MatchPrecision.None)
                {
                    break; // No reason to continue reading stream, let's see what we have..
                }

                if (match == MatchPrecision.Exact)
                {
                    matchPos = stream.Position;
                    foundNode = node;
                    ifFound = true;
                }
            }

            if (foundNode != null)
            { // Initialize match data with values from this anomaly
            }

            matchData.Ingredient = foundNode.Ingredient;

            stream.Seek(matchPos, SeekOrigin.Begin);
            return ifFound;
        }
コード例 #9
0
        public bool Read(Stream stream, MatchData matchData)
        {
            if (data == null)
            {
                data = new Anomalies();
            }

            var buffer = string.Empty;
            AnomalousNode foundNode = null;
            var matchFound = false;
            var matchPos = stream.Position;
            int curByte;

            while ((curByte = stream.ReadByte()) >= 0)
            {
                buffer += (char)curByte;

                AnomalousNode node;
                var match = data.Parse(buffer, out node);
                if (match == MatchPrecision.None)
                {
                    break;
                }

                if (match == MatchPrecision.Exact)
                {
                    matchPos = stream.Position;
                    foundNode = node;
                    matchFound = true;
                }
            }

            if (foundNode != null)
            {
                matchData.Ingredient = foundNode.Ingredient;
            }

            stream.Seek(matchPos, SeekOrigin.Begin);
            return matchFound;
        }
コード例 #10
0
        public bool Read(Stream stream, MatchData matchData)
        {
            if (data == null)
            {
                data = new Anomalies();
            }

            var           buffer    = String.Empty;
            AnomalousNode foundNode = null;
            var           fFound    = false;
            var           matchPos  = stream.Position;
            int           curByte;

            while ((curByte = stream.ReadByte()) >= 0)
            {
                buffer += (char)curByte;

                AnomalousNode node;
                var           match = data.Parse(buffer, out node);
                if (match == MatchPrecision.None)
                {
                    break; //No reason to continue reading stream, let's see what we have..
                }

                if (match == MatchPrecision.Exact)
                {
                    matchPos  = stream.Position;
                    foundNode = node;
                    fFound    = true;
                }
            }

            if (foundNode != null) //Initialize match data with values from this anomaly
            {
                matchData.Ingredient = foundNode.Ingredient;
            }

            stream.Seek(matchPos, SeekOrigin.Begin);
            return(fFound);
        }
コード例 #11
0
        /// <summary>
        /// Initializes the context and loads necessary data into memory through the configured database adapter.
        /// This must be done before the context is usable.
        /// </summary>
        public virtual void Initialize()
        {
            if (Adapter == null)
            {
                throw new InvalidConfigurationException("DBContext requires a configured database adapter.  Please check your configuration.");
            }

            // Initiaze NHibernate session
            Adapter.Initialize(this);

            new Thread(delegate()
            {
                using (InitLock.WriteLock())
                {
                    // Initialize ingredient parser
                    ingParser           = new IngredientParser();
                    var ingredientIndex = Adapter.LoadIngredientsForIndex();
                    ingParser.CreateIndex(ingredientIndex);

                    // Initialize modeler
                    modeler = new ModelerProxy(this);
                    modeler.LoadSnapshot();

                    // Initialize natural language parsing
                    IngredientSynonyms.InitIndex(Adapter.IngredientLoader);
                    UnitSynonyms.InitIndex(Adapter.UnitLoader);
                    FormSynonyms.InitIndex(Adapter.FormLoader);
                    PrepNotes.InitIndex(Adapter.PrepLoader);
                    Anomalies.InitIndex(Adapter.AnomalyLoader);
                    NumericVocab.InitIndex();

                    parser = new Parser();
                    LoadTemplates();
                }
            }).Start();

            Thread.Sleep(500); // Provides time for initialize thread to start and acquire InitLock
        }
コード例 #12
0
ファイル: ImportXMLApp.cs プロジェクト: stominmetal/Softuni
        private static void ImportVictim(XElement victimNode, MassDefectContext context, Anomalies anomaly)
        {
            var name = victimNode.Attribute("name");

            if (name == null)
            {
                RaiseError();
            }

            var perssonEntity = GetPersonName(name.Value, context);

            if (perssonEntity.Name == null)
            {
                RaiseError();
            }

            anomaly.Person.Add(perssonEntity);
        }
コード例 #13
0
ファイル: AnomaliesFacts.cs プロジェクト: Perfvane/Example
 public void Multimodal()
 {
     Anomalies.Multimodal();
 }
コード例 #14
0
            /// <summary>
            /// Determines if the given file exists in the given folder
            /// </summary>
            /// <returns></returns>
            protected bool FolderNotEmpty(string relFolderPath, string fileTypes = "*.*", Anomalies anomalies = null)
            {
                var dirPath = Path.Combine(this.TargetDir, relFolderPath);
                var exists = Directory.Exists(dirPath);
                if (!exists)
                {
                    if (anomalies != null)
                    {
                        anomalies.ExpectedFiles.Add(relFolderPath);
                    }

                    return false;
                }
                else
                {
                    var filesInFolder = new DirectoryInfo(dirPath).GetFiles(fileTypes);
                    if (!filesInFolder.Any())
                    {
                        if (anomalies != null)
                        {
                            anomalies.ExpectedFiles.Add(fileTypes);
                        }
                    }

                    return filesInFolder.Any();
                }
            }
コード例 #15
0
ファイル: AnomaliesFacts.cs プロジェクト: Perfvane/Example
 public void Changepoint2()
 {
     Anomalies.Changepoint2();
 }
コード例 #16
0
ファイル: AnomaliesFacts.cs プロジェクト: Perfvane/Example
 public void Bimodal()
 {
     Anomalies.Bimodal();
 }
コード例 #17
0
            /// <summary>
            /// Asserts whether if the given file exists in the given folder, and reports the difference
            /// </summary>
            protected void AssertFolderNotEmpty(string relFolderPath, string fileTypes = "*.*")
            {
                var anomalies = new Anomalies();

                Assert.IsTrue(FolderNotEmpty(relFolderPath, fileTypes, anomalies), anomalies.Format());
            }
コード例 #18
0
            /// <summary>
            /// Determines if the given file exists in the given folder
            /// </summary>
            /// <returns></returns>
            protected bool FolderNotEmpty(string relFolderPath, string fileTypes = "*.*", Anomalies anomalies = null)
            {
                var dirPath = Path.Combine(this.TargetDir, relFolderPath);
                var exists  = Directory.Exists(dirPath);

                if (!exists)
                {
                    if (anomalies != null)
                    {
                        anomalies.ExpectedFiles.Add(relFolderPath);
                    }

                    return(false);
                }
                else
                {
                    var filesInFolder = new DirectoryInfo(dirPath).GetFiles(fileTypes);
                    if (!filesInFolder.Any())
                    {
                        if (anomalies != null)
                        {
                            anomalies.ExpectedFiles.Add(fileTypes);
                        }
                    }

                    return(filesInFolder.Any());
                }
            }
コード例 #19
0
ファイル: AnomaliesFacts.cs プロジェクト: Perfvane/Example
 public void Degradation()
 {
     Anomalies.Degradation();
 }
コード例 #20
0
 internal void AddAnomaly(TValue value)
 {
     Anomalies.Add(value);
 }
コード例 #21
0
 /// <summary>
 /// Asserts whether the given folder contains only the given files, and no others, and reports the difference
 /// </summary>
 protected void AssertFolderContainsExclusive(string relFolderPath, IEnumerable<string> filenames)
 {
     var anomalies = new Anomalies();
     Assert.IsTrue(FolderContainsExclusive(relFolderPath, filenames, anomalies), anomalies.Format());
 }
コード例 #22
0
            /// <summary>
            /// Asserts whether the given folder contains only the given files, and no others, and reports the difference
            /// </summary>
            protected void AssertFolderContainsExclusive(string relFolderPath, IEnumerable <string> filenames)
            {
                var anomalies = new Anomalies();

                Assert.IsTrue(FolderContainsExclusive(relFolderPath, filenames, anomalies), anomalies.Format());
            }
コード例 #23
0
 /// <summary>
 /// Asserts whether if the given file exists in the given folder, and reports the difference
 /// </summary>
 protected void AssertFolderNotEmpty(string relFolderPath, string fileTypes = "*.*")
 {
     var anomalies = new Anomalies();
     Assert.IsTrue(FolderNotEmpty(relFolderPath, fileTypes, anomalies), anomalies.Format());
 }
コード例 #24
0
            /// <summary>
            /// Determines whether the given folder contains only the given files, and no others
            /// </summary>
            /// <returns></returns>
            protected bool FolderContainsExclusive(string relFolderPath, IEnumerable <string> filenames, Anomalies anomalies = null)
            {
                var dirPath = Path.Combine(this.TargetDir, relFolderPath);
                var exists  = Directory.Exists(dirPath);

                if (!exists)
                {
                    return(false);
                }
                else
                {
                    var folderFiles = new DirectoryInfo(dirPath).GetFiles();

                    var filesInFolder = folderFiles.Select(f => f.Name).Except(filenames).ToList();
                    var expectedFiles = filenames.Except(folderFiles.Select(f => f.Name)).ToList();

                    if (anomalies != null)
                    {
                        anomalies.ExpectedFiles.AddRange(expectedFiles);
                        anomalies.UnexpectedFiles.AddRange(filesInFolder);
                    }

                    return(!(filesInFolder.Any()) &&
                           !(expectedFiles.Any()));
                }
            }
コード例 #25
0
ファイル: AnomaliesFacts.cs プロジェクト: Perfvane/Example
 public void Acceleration()
 {
     Anomalies.Acceleration();
 }