Ejemplo n.º 1
0
        /// <summary>
        /// Prepares the Document Map
        /// </summary>
        public static string AnalysizePercentDocumentated(DocumentModel model)
        {
            var totalMatches = 0;
            // ReSharper disable LoopCanBeConvertedToQuery
            var index = 0;

            foreach (var line in model.File.RawText)
            // ReSharper restore LoopCanBeConvertedToQuery
            {
                var property = PropertyService.GetProperty(new LineArgs
                {
                    Path  = model.File.Path,
                    iLine = index,
                    Line  = line
                });

                if (property is PropertyLookup)
                {
                    totalMatches++;
                }
                index++;
            }
            return(totalMatches == 0
                       ? "There is no documentation for this log."
                       : $"{(totalMatches / (float) model.File.RawText.Count) * 100:F}% of the log is documentated");
        }
        /// <summary>
        /// Returns the properties for the current item
        /// </summary>
        public static List <SimpleProperty> GetCurrentLineValues(LineArgs item)
        {
            var property = PropertyService.GetProperty(item);
            var result   = property.Properties.Select(prop => new SimpleProperty
            {
                Name  = prop.Name,
                Value = (string)prop.Value ?? "",
                Type  = "EventPattern"
            }).ToList();

            result = result.OrderBy(n => n.Name).ToList();

            var file    = XmlDal.CacheModel.GetFile(item.Path);
            var result2 = file.FileValues.Where(n => n.FileInfo).Select(fileInfo => new SimpleProperty
            {
                Name  = fileInfo.Name,
                Value = fileInfo.Value ?? "",
                Type  = "FileData"
            }).ToList();

            result2 = result2.OrderBy(n => n.Name).ToList();
            result.AddRange(result2);

            return(result);
        }
        /// <summary>
        /// Returns a list of EventPattern and FileData values
        /// </summary>
        public static List <SimpleProperty> GetPropertyValues(LineArgs model)
        {
            var result = new List <SimpleProperty>();
            var file   = XmlDal.CacheModel.GetFile(model.Path);

            var unload = false;

            try
            {
                if (!file.IsLoaded)
                {
                    file.Load(true);
                    unload = true;
                }

                var property = PropertyService.GetProperty(model);

                result.AddRange(property.Properties.Select(prop => new SimpleProperty
                {
                    Name  = prop.Name,
                    Value = (string)prop.Value ?? "",
                    Type  = "EventPattern"
                }));

                result = result.OrderBy(n => n.Name).ToList();
                var result2 = file.FileValues.Where(n => n.FileInfo).Select(item => new SimpleProperty
                {
                    Name  = item.Name,
                    Value = item.Value ?? "",
                    Type  = "FileData"
                }).ToList();

                result2 = result2.OrderBy(n => n.Name).ToList();
                result.AddRange(result2);

                return(result);
            }
            finally
            {
                if (unload)
                {
                    file.UnLoad();
                }
            }
        }
Ejemplo n.º 4
0
        private static void SearchForLookupValue(LookupArgs args)
        {
            var file = XmlDal.CacheModel.GetFile(args.FilePath);

            if (args.LookupValue.OnlyNetworkValues)
            {
                lock (file.Network)
                {
                    foreach (var networkMessageInfo in file.Network.NetworkMessages)
                    {
                        if (networkMessageInfo.Source.iLine == args.SourceProperty.iLine)
                        {
                            continue;
                        }

                        bool?success = null;
                        foreach (var criteria in args.LookupValue.Criteria)
                        {
                            var targetValue = networkMessageInfo.Source.FindEventValue(criteria.TargetName);
                            switch (criteria.CriteriaType)
                            {
                            case LookupTargetType.Value:
                                switch (criteria.Operator)
                                {
                                case Keywords.EQUAL:
                                    success = String.Equals(criteria.TargetValue ?? "", targetValue ?? "",
                                                            StringComparison.CurrentCultureIgnoreCase);
                                    break;

                                case Keywords.NOT_EQUAL:
                                    success =
                                        !String.Equals(criteria.TargetValue ?? "", targetValue ?? "",
                                                       StringComparison.CurrentCultureIgnoreCase);
                                    break;
                                }
                                break;

                            case LookupTargetType.Name:
                                var sourceProperty = args.SourceProperty.FindProperty(criteria.SourceName);
                                success =
                                    String.Equals(
                                        sourceProperty.Value == null ? "" : sourceProperty.Value.ToString(),
                                        targetValue, StringComparison.CurrentCultureIgnoreCase);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }
                            if ((bool)!success)
                            {
                                break;
                            }
                        }
                        if (success == null || !(bool)success)
                        {
                            continue;
                        }

                        foreach (var valueName in args.LookupValue.ValueNames)
                        {
                            var sourceProperty = args.SourceProperty.FindProperty(valueName.Name);
                            if (sourceProperty == null)
                            {
                                continue;
                            }

                            var targetProperty = networkMessageInfo.Source.FindEventValue(valueName.Name);
                            if (targetProperty == null)
                            {
                                continue;
                            }

                            sourceProperty.Name = string.Format("_{0}", sourceProperty.Name);

                            var category = args.LookupValue.UseCategory
                                ? args.LookupValue.Category
                                : sourceProperty.Category;
                            args.SourceProperty.Properties.Add(new DynamicProperty(category, sourceProperty.Desc,
                                                                                   valueName.Name, targetProperty));
                        }
                        break;
                    }
                }
            }
            else
            {
                switch (args.LookupValue.LookupDirection)
                {
                case LookupDirection.Prior:
                    for (var i = args.SourceProperty.iLine - 1; i >= 0; i--)
                    {
                        var searchProperty = PropertyService.GetProperty(new LineArgs {
                            iLine = i, Path = args.FilePath
                        });

                        bool?success = null;
                        foreach (var criteria in args.LookupValue.Criteria)
                        {
                            var targetValue = FindFirstEventValue(file.GetLine(i), criteria.TargetName);
                            if (targetValue == null)
                            {
                                continue;
                            }

                            switch (criteria.CriteriaType)
                            {
                            case LookupTargetType.Value:

                                success = String.Equals(criteria.TargetValue, targetValue, StringComparison.CurrentCultureIgnoreCase);
                                break;

                            case LookupTargetType.Name:
                                var sourceProperty = args.SourceProperty.FindProperty(criteria.SourceName);
                                success = String.Equals(sourceProperty.Value.ToString(), targetValue, StringComparison.CurrentCultureIgnoreCase);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }

                            if ((bool)!success)
                            {
                                break;
                            }
                        }
                        if (success == null || !(bool)success)
                        {
                            continue;
                        }

                        foreach (var valueName in args.LookupValue.ValueNames)
                        {
                            var sourceProperty = args.SourceProperty.FindProperty(valueName.Name);
                            if (sourceProperty == null)
                            {
                                continue;
                            }

                            var targetProperty = searchProperty.FindProperty(valueName.Name);
                            if (targetProperty == null)
                            {
                                continue;
                            }

                            sourceProperty.Name = string.Format("_{0}", sourceProperty.Name);

                            var category = args.LookupValue.UseCategory ? args.LookupValue.Category : sourceProperty.Category;
                            args.SourceProperty.Properties.Add(new DynamicProperty(category, sourceProperty.Desc, valueName.Name, sourceProperty.Value));
                        }
                        break;
                    }

                    break;

                case LookupDirection.Next:
                case LookupDirection.TopDown:
                case LookupDirection.BottomUp:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
        public static CriteriaMatchModel GetCriteriaMatches(int networkMapId, LineArgs source, LineArgs target, bool noNetworkMessages)
        {
            var matches = new List <CriteriaMatch>();

            var map = XmlDal.DataModel.GetNetworkMap(networkMapId);

            var sourceMessage = XmlDal.CacheModel.GetFile(source.Path).GetNetworkMessage(source.iLine);

            if (sourceMessage == null)
            {
                Log.WriteError("sourceMessage should never be null!!!!", typeof(NetworkMapService).FullName, MethodBase.GetCurrentMethod().Name);
                return(new CriteriaMatchModel());
            }
            var targetMessage = XmlDal.CacheModel.GetFile(target.Path).GetNetworkMessage(target.iLine);

            foreach (var criteria in map.Criteria)
            {
                var match = IsMatch(criteria, sourceMessage, targetMessage, target.Path);

                if (criteria.UseSourceValue)
                {
                    match.SourceValue = $"=={match.CriteriaSourceValue} [{match.SourceValue}]";
                }
                if (criteria.UseTargetValue)
                {
                    match.TargetValue = $"=={match.CriteriaTargetValue} [{match.TargetValue}]";
                }
                if (criteria.TimeConditionMs != null)
                {
                    match.TargetValue = $"{match.TargetValue} tc:{criteria.TimeConditionMs}";
                }

                matches.Add(new CriteriaMatch
                {
                    Enabled     = criteria.Enabled,
                    IsMatch     = match.IsMatch,
                    Operator    = criteria.Operator,
                    SourceName  = criteria.SourceName,
                    SourceType  = criteria.SourceType.ToString(),
                    SourceValue = match.SourceValue,
                    TargetName  = criteria.TargetName,
                    TargetType  = criteria.TargetType.ToString(),
                    TargetValue = match.TargetValue
                });
            }

            LogPropertyBaseModel targetProperty = null;

            if (!noNetworkMessages)
            {
                targetProperty = PropertyService.GetProperty(target);
            }
            var sourceProperty     = PropertyService.GetProperty(source);
            var dateTimeDifference = CalculateDateTimeDifference(targetProperty, sourceProperty);

            return(new CriteriaMatchModel
            {
                DateTimeDifference = dateTimeDifference,
                Matches = matches
            });
        }