Exemplo n.º 1
0
 private void InitTechnologyCountAnalysisResult()
 {
     technologyCountAnalysisResult = new TechnologyCountAnalysisResult {
         Date      = DateTime.Now,
         TagGroups = TagGroups.GetAllTaggGroups()
     };
 }
Exemplo n.º 2
0
        private static TagGroups ReadTagGroups(string pathToTagGroups)
        {
            var path      = Path.Combine(Directory.GetCurrentDirectory(), pathToTagGroups);
            var tagGroups = new TagGroups();

            var groups = new StreamReader(path)
                         .ReadToEnd()
                         .Split(';')
                         .Where(line => !string.IsNullOrEmpty(line));

            foreach (var group in groups)
            {
                var items = group.Split(' ');
                var name  = items[0];
                var freq  = items[1]
                            .Replace('.', ',')
                            .Split('-')
                            .Select(double.Parse)
                            .ToArray();
                var size = items[2]
                           .Split('x')
                           .Select(int.Parse)
                           .ToArray();
                tagGroups.AddSizeGroup(name, new FrequencyGroup(freq[0], freq[1]), new Size(size[0], size[1]));
            }

            return(tagGroups);
        }
Exemplo n.º 3
0
        public void Should_normalize_tags()
        {
            A.CallTo(() => tagService.GetTagIdsAsync(appId.Id, TagGroups.Schemas(schemaId.Id), A <HashSet <string> > .That.Contains("name1")))
            .Returns(new Dictionary <string, string> {
                ["name1"] = "id1"
            });

            var source = FilterBuilder.Eq("data.tags2.iv", "name1");
            var result = FilterTagTransformer.Transform(source, appId.Id, schema, tagService);

            Assert.Equal("data.tags2.iv == 'id1'", result.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// The main operation filter that will map every <see cref="ApiDefinitionAttribute"/>.
        /// </summary>
        /// <param name="context">The processor context, this is given by the AddOperationFilter method.</param>
        /// <returns>This always return <c>true</c> since it should not remove operations.</returns>
        public static bool OperationFilter(OperationProcessorContext context)
        {
            ApiDefinitionAttribute def = context.ControllerType.GetCustomAttribute <ApiDefinitionAttribute>();
            string name = def?.Name ?? context.ControllerType.Name;

            ApiDefinitionAttribute methodOverride = context.MethodInfo.GetCustomAttribute <ApiDefinitionAttribute>();

            if (methodOverride != null)
            {
                name = methodOverride.Name;
            }

            context.OperationDescription.Operation.Tags.Add(name);
            if (context.Document.Tags.All(x => x.Name != name))
            {
                context.Document.Tags.Add(new OpenApiTag
                {
                    Name        = name,
                    Description = context.ControllerType.GetXmlDocsSummary()
                });
            }

            if (def?.Group == null)
            {
                return(true);
            }

            context.Document.ExtensionData ??= new Dictionary <string, object>();
            context.Document.ExtensionData.TryAdd("x-tagGroups", new List <TagGroups>());
            List <TagGroups> obj      = (List <TagGroups>)context.Document.ExtensionData["x-tagGroups"];
            TagGroups        existing = obj.FirstOrDefault(x => x.Name == def.Group);

            if (existing != null)
            {
                if (!existing.Tags.Contains(def.Name))
                {
                    existing.Tags.Add(def.Name);
                }
            }
            else
            {
                obj.Add(new TagGroups
                {
                    Name = def.Group,
                    Tags = new List <string> {
                        def.Name
                    }
                });
            }

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GroupDialog"/> class.
        /// </summary>
        public GroupDialog()
        {
            InitializeComponent();

            //Add
            foreach (string tagGroup in TagGroups.GetTagGroups())
            {
                tagGroupComboBox.Items.Add(tagGroup);
            }

            //Select
            tagGroupComboBox.SelectedIndex = 0;
        }
Exemplo n.º 6
0
 public void Refresh()
 {
     TagGroups.Clear();
     LocalDatabase.AutoTags.Load();
     LocalDatabase.UserTags.Load();
     LocalDatabase.Aliases.Load();
     LocalDatabase.FavoriteTags.Load();
     LocalDatabase.PageTags.Load();
     TagGroups.Add(GetNode("Auto Tags", LocalDatabase.AutoTags.Local.GroupBy(i => i.Tag, StringComparer.OrdinalIgnoreCase)));
     TagGroups.Add(GetNode("User Tags", LocalDatabase.UserTags.Local.GroupBy(i => i.Tag, StringComparer.OrdinalIgnoreCase)));
     TagGroups.Add(GetNode("Aliases", LocalDatabase.Aliases.Local.GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)));
     TagGroups.Add(GetNodeForFavoriteTags());
 }
Exemplo n.º 7
0
        public override FilterNode <ClrValue>?Visit(CompareFilter <ClrValue> nodeIn)
        {
            if (nodeIn.Value.Value is string stringValue && IsDataPath(nodeIn.Path) && IsTagField(nodeIn.Path))
            {
                var tagNames = Task.Run(() => tagService.GetTagIdsAsync(appId, TagGroups.Schemas(schema.Id), HashSet.Of(stringValue))).Result;

                if (tagNames.TryGetValue(stringValue, out var normalized))
                {
                    return(new CompareFilter <ClrValue>(nodeIn.Path, nodeIn.Operator, normalized));
                }
            }

            return(nodeIn);
        }
Exemplo n.º 8
0
        public override FilterNode Visit(FilterComparison nodeIn)
        {
            if (nodeIn.Rhs.Value is string stringValue && IsDataPath(nodeIn.Lhs) && IsTagField(nodeIn.Lhs))
            {
                var tagNames = Task.Run(() => tagService.GetTagIdsAsync(appId, TagGroups.Schemas(schema.Id), HashSet.Of(stringValue))).Result;

                if (tagNames.TryGetValue(stringValue, out var normalized))
                {
                    return(new FilterComparison(nodeIn.Lhs, nodeIn.Operator, new FilterValue(normalized)));
                }
            }

            return(nodeIn);
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            if (!IsInputCorrect(args))
            {
                return;
            }

            var pathToWords   = args[0];
            var pathToPicture = args[1];

            var tagGroups = new TagGroups();

            if (args.Length > 2)
            {
                tagGroups = ReadTagGroups(args[2]);
            }
            else
            {
                tagGroups.AddSizeGroup("Big", new FrequencyGroup(0.9, 1), new Size(80, 150));
                tagGroups.AddSizeGroup("Average", new FrequencyGroup(0.6, 0.9), new Size(60, 100));
                tagGroups.AddSizeGroup("Small", new FrequencyGroup(0, 0.6), new Size(30, 50));
            }


            var settings = DrawSettings.WordsInRectangles;

            if (args.Length > 3)
            {
                settings = (DrawSettings)(int.Parse(args[3]) % 4);
            }

            var spiral     = new Spiral();
            var cloud      = new CircularCloudLayouter(spiral);
            var visualizer = new CloudVisualizer.CloudVisualizer
            {
                Settings = settings
            };

            var cloudItems = new TagReader(tagGroups)
                             .GetTags(pathToWords)
                             .Select(tag => new CloudItem(tag.Word, cloud.PutNextRectangle(tag.Size)))
                             .ToArray();

            var picture = visualizer.CreatePictureWithItems(cloudItems);

            picture.Save(Path.Combine(Directory.GetCurrentDirectory(), $"{pathToPicture}.png"));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Adds the tag group and calculates the tag indexes.
        /// </summary>
        public void AddGroup(TagGroup tagGroup)
        {
            int tagIndex = deviceTags.Count;

            TagGroups.Add(tagGroup);

            foreach (DeviceTag deviceTag in tagGroup.DeviceTags)
            {
                deviceTag.Index = tagIndex++;
                deviceTags.Add(deviceTag);

                if (!string.IsNullOrEmpty(deviceTag.Code) && !tagByCode.ContainsKey(deviceTag.Code))
                {
                    tagByCode.Add(deviceTag.Code, deviceTag);
                }
            }
        }
Exemplo n.º 11
0
        public async Task Should_normalize_tags_with_old_data()
        {
            var newData = GenerateData("n_raw");
            var oldData = GenerateData("o_raw");

            A.CallTo(() => tagService.NormalizeTagsAsync(appId, TagGroups.Schemas(schemaId),
                                                         A <HashSet <string> > .That.Is("n_raw2_1", "n_raw2_2", "n_raw4"),
                                                         A <HashSet <string> > .That.Is("o_raw2_1", "o_raw2_2", "o_raw4")))
            .Returns(new Dictionary <string, string>
            {
                ["n_raw2_2"] = "id2_2",
                ["n_raw2_1"] = "id2_1",
                ["n_raw4"]   = "id4"
            });

            await tagService.NormalizeAsync(appId, schemaId, schema, newData, oldData);

            Assert.Equal(JsonValue.Array("id2_1", "id2_2"), newData["tags2"] !["iv"]);
Exemplo n.º 12
0
        public async Task Should_denormalize_tags()
        {
            var newData = GenerateData("id");

            A.CallTo(() => tagService.NormalizeTagsAsync(appId, TagGroups.Schemas(schemaId),
                                                         A <HashSet <string> > .That.IsSameSequenceAs("id2_1", "id2_2", "id4"),
                                                         A <HashSet <string> > .That.IsEmpty()))
            .Returns(new Dictionary <string, string>
            {
                ["id2_2"] = "name2_2",
                ["id2_1"] = "name2_1",
                ["id4"]   = "name4"
            });

            await tagService.NormalizeAsync(appId, schemaId, schema, newData, null);

            Assert.Equal(new JArray("name2_1", "name2_2"), newData["tags2"]["iv"], JTokenEqualityComparer);
            Assert.Equal(new JArray("name4"), newData["array"]["iv"][0]["nestedTags2"], JTokenEqualityComparer);
        }
Exemplo n.º 13
0
        public async Task Should_normalize_tags_without_old_data()
        {
            var newData = GenerateData("name");

            A.CallTo(() => tagService.NormalizeTagsAsync(appId, TagGroups.Schemas(schemaId),
                                                         A <HashSet <string> > .That.IsSameSequenceAs("name2_1", "name2_2", "name4"),
                                                         A <HashSet <string> > .That.IsEmpty()))
            .Returns(new Dictionary <string, string>
            {
                ["name2_2"] = "id2_2",
                ["name2_1"] = "id2_1",
                ["name4"]   = "id4"
            });

            await tagService.NormalizeAsync(appId, schemaId, schema, newData, null);

            Assert.Equal(JsonValue.Array("id2_1", "id2_2"), newData["tags2"]["iv"]);
            Assert.Equal(JsonValue.Array("id4"), GetNestedTags(newData));
        }