Exemple #1
0
        public TagInformation GetTagValue(int key)
        {
            TagInformation result;

            if (this.RegisteredTags.TryGetValue(key, out result))
            {
                return(result);
            }
            else
            {
                var tag = new TagInformation()
                {
                    Name = key.ToString(), Shortcut = ""
                };
                this.RegisteredTags.TryAdd(key, tag);
                this.IsEdited = true;
                return(tag);
            }
        }
Exemple #2
0
        public int SetTag(TagInformation newTag)
        {
            var existingTag = this.RegisteredTags
                              .FirstOrNull(x => x.Value.Name.Equals(newTag.Name));

            if (existingTag != null)           //.Count > 0)
            {
                return(existingTag.Value.Key); //.First().Key;
            }


            this.RegisteredTags
            .Where(x =>
            {
                return(x.Value.Shortcut != null &&
                       x.Value.Shortcut.Length > 0 &&
                       x.Value.Shortcut.Equals(newTag.Shortcut,
                                               StringComparison.OrdinalIgnoreCase));
            })
            .ForEach(x => x.Value.Shortcut = "_" + x.Value.Shortcut);

            var newKey = this.RegisteredTags.Count + 1;

            while (this.RegisteredTags.ContainsKey(newKey))
            {
                newKey++;
            }


            //this.RegisteredTags.Add(newKey, newTag);
            var result = this.RegisteredTags.TryAdd(newKey, newTag);

            //Task.Run(async () => await SaveSettingsAsync());
            //this.SaveSettingsAsync().FireAndForget();
            this.IsEdited = true;

            return(newKey);
        }