Esempio n. 1
0
        public async Task EditTag(CommandContext context, [Description("Tag name")] string key, [Description("Tag value"), RemainingText] string value)
        {
            if (String.IsNullOrEmpty(value))
            {
                throw new ArgumentException();
            }

            await context.TriggerTypingAsync();

            using (var db = new TagContext())
            {
                var tag = db.Tags.FirstOrDefault(t => t.Key.ToLower() == key.ToLower());

                if (tag == null)
                {
                    var error = await context.RespondAsync($"`{key}` is not a valid tag. " +
                                                           $"Type `{Program.AppSettings.CommandPrefix}tag list` for a list of tags.");

                    await Task.Delay(5000)
                    .ContinueWith(t => error.DeleteAsync())
                    .ContinueWith(t => context.Message.DeleteAsync());

                    return;
                }

                tag.Value = value;
                db.Update(tag);
                await db.SaveChangesAsync();
            }

            await context.RespondAsync($"Edited tag `{key}`");
        }
Esempio n. 2
0
        public async Task DeleteTag(CommandContext context, [Description("Tag name")] string key)
        {
            await context.TriggerTypingAsync();

            using (var db = new TagContext())
            {
                var tag = db.Tags.FirstOrDefault(t => t.Key.ToLower() == key.ToLower());

                if (tag == null)
                {
                    var error = await context.RespondAsync($"`{key}` is not a valid tag. " +
                                                           $"Type `{Program.AppSettings.CommandPrefix}tag list` for a list of tags.");

                    await Task.Delay(5000)
                    .ContinueWith(t => error.DeleteAsync())
                    .ContinueWith(t => context.Message.DeleteAsync());

                    return;
                }

                db.Remove(tag);
                await db.SaveChangesAsync();
            }

            await context.RespondAsync($"Deleted tag `{key}`");
        }
Esempio n. 3
0
        public async Task NewTag(CommandContext context, [Description("Tag name")] string key, [Description("Tag value"), RemainingText] string value)
        {
            if (String.IsNullOrEmpty(value))
            {
                throw new ArgumentException();
            }

            await context.TriggerTypingAsync();

            using (var db = new TagContext())
            {
                var tag = db.Tags.FirstOrDefault(t => t.Key.ToLower() == key.ToLower());

                if (tag != null)
                {
                    var error = await context.RespondAsync($"Tag `{key}` already exists");

                    await Task.Delay(5000)
                    .ContinueWith(t => error.DeleteAsync())
                    .ContinueWith(t => context.Message.DeleteAsync());

                    return;
                }

                tag = new Tag {
                    Key = key, Value = value
                };
                db.Add(tag);
                await db.SaveChangesAsync();
            }

            await context.RespondAsync($"Created tag `{key}`");
        }
Esempio n. 4
0
 /// <summary>
 /// 拷贝构造函数
 /// </summary>
 /// <param name="ctx"></param>
 public TagContext(TagContext ctx)
 {
     if (ctx != null)
     {
         Data = ctx.Data;
     }
 }
Esempio n. 5
0
        public int Process(IContext context, string text)
        {
            TagContext tagContext = context as TagContext;

            if (tagContext == null)
            {
                throw new ArgumentException("TagHandler needs TagContext.");
            }

            int tagDelimiter = text.IndexOf('>');

            string[] tagElements = text.Substring(1, tagDelimiter - 1).Split(new char[] { '=', ' ' });

            Tag tag;

            if (tagElements.Length == 1)
            {
                tag = new Tag(tagElements[0]);
            }
            else
            {
                int len       = tagElements[2].Length;
                int attrValue = int.Parse(tagElements[2].Substring(1, len - 2));
                tag = new Tag(tagElements[0], tagElements[1], attrValue);
            }

            tagContext.Push(tag);

            return(tagDelimiter + 1);
        }
        public int Process(IContext context, string text)
        {
            TagContext tagContext = context as TagContext;

            if (tagContext == null)
            {
                throw new ArgumentException("TagHandler needs TagContext.");
            }

            string tagName = text.Substring(2, text.IndexOf('>') - 2);
            Tag    tag;

            try
            {
                tag = (Tag)tagContext.Pop();
            }
            catch (InvalidOperationException e)
            {
                throw new MissingOpeningTagException(tagName, e);
            }

            if (tag.Name != tagName)
            {
                throw new MissingClosingTagException(tagName);
            }

            return(text.Length);
        }
        private async void Filter_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ContextTagsSource == null)
                {
                    return;
                }

                MenuItem itm = sender as MenuItem;

                TagContext filter             = (TagContext)Enum.Parse(typeof(TagContext), itm.Tag.ToString());
                IEnumerable <TagPageSet> tags = await GetContextTagsAsync(filter);

                Tags = from t in tags select t.TagName;
                if (string.IsNullOrEmpty(tagInput.Text))
                {
                    filterPopup.IsOpen = true;
                }
            }
            catch (Exception ex)
            {
                TraceLogger.Log(TraceCategory.Error(), "Applying preset filter failed {0}", ex);
                TraceLogger.ShowGenericErrorBox(Properties.Resources.TagEditor_Filter_Error, ex);
            }
            finally
            {
                e.Handled = true;
            }
        }
Esempio n. 8
0
 public HomeController(ILogger <HomeController> logger, TagContext tagContext, ItemContext itemContext, CollectionContext collectionContext)
 {
     _logger            = logger;
     _collectionContext = collectionContext;
     _itemContext       = itemContext;
     _tagContext        = tagContext;
 }
Esempio n. 9
0
        public async Task ListTags(CommandContext context)
        {
            await context.TriggerTypingAsync();

            var tags = new List <Tag>();

            using (var db = new TagContext())
            {
                tags = db.Tags.ToList();
            }

            if (tags.Count == 0)
            {
                var error = await context.RespondAsync("There are no created tags");

                await Task.Delay(5000)
                .ContinueWith(t => error.DeleteAsync())
                .ContinueWith(t => context.Message.DeleteAsync());

                return;
            }

            var embed = new DiscordEmbedBuilder
            {
                Title       = $"Tags",
                Description = String.Join(", ", tags.OrderBy(t => t.Key).Select(t => $"`{t.Key}`"))
            };

            await context.RespondAsync("", false, embed.Build());
        }
Esempio n. 10
0
        public void ProcessTagTestNoAttribute()
        {
            int        result     = 0;
            TagContext tagContext = new TagContext();

            //opening tag
            OpenTagHandler openH = new OpenTagHandler();

            result += openH.Process(tagContext, lineNoAttr);
            Assert.AreEqual(lineNoAttr.IndexOf('>') + 1, result);

            //data handler
            DataContext    dataContext = new DataContext();
            DefaultHandler defaultH    = new DefaultHandler();

            result += defaultH.Process(dataContext, lineNoAttr.Substring(result));
            Assert.AreEqual("Peter", (string)dataContext.Pop());
            Assert.AreEqual(lineNoAttr.LastIndexOf('<'), result);

            //closing tag
            CloseTagHandler closeH = new CloseTagHandler();

            result += closeH.Process(tagContext, lineNoAttr.Substring(result));
            Assert.AreEqual(lineNoAttr.Length, result);
        }
Esempio n. 11
0
 public ManagementServiceImpl(ArticleContext articleContext, ClassificationContext classificationContext
                              , CommentContext commentContext, UserContext userContext, TagContext tagContext)
 {
     _articleContext        = articleContext;
     _classificationContext = classificationContext;
     _commentContext        = commentContext;
     _userContext           = userContext;
     _tagContext            = tagContext;
 }
Esempio n. 12
0
 public ItemController(TagContext tagContext, LikeContext likeContext, ItemContext context, CollectionContext collectionContext, UserManager <User> userManager, CommentContext commentContext)
 {
     _collectionContext = collectionContext;
     _itemContext       = context;
     _userManager       = userManager;
     _commentContext    = commentContext;
     _likeContext       = likeContext;
     _tagContext        = tagContext;
 }
Esempio n. 13
0
        public void Remove_NullKey()
        {
            var tags = new TagContext(new Dictionary <string, string>()
            {
                { K1, V1 }
            });
            var builder = tagger.ToBuilder(tags);

            Assert.Throws <ArgumentNullException>(() => builder.Remove(null));
        }
Esempio n. 14
0
        public void Put_NullKey()
        {
            var tags = new TagContext(new Dictionary <TagKey, TagValue>()
            {
                { K1, V1 }
            });
            var builder = tagger.ToBuilder(tags);

            Assert.Throws <ArgumentNullException>(() => builder.Put(null, V2));
        }
Esempio n. 15
0
        public void Put_NullValue()
        {
            var tags = new TagContext(new Dictionary <string, string>()
            {
                { K1, V1 }
            });
            var builder = tagger.ToBuilder(tags);

            Assert.Throws <ArgumentNullException>(() => builder.Put(K2, null));
        }
        public void Remove_NullKey()
        {
            TagContext tags = new TagContext(new Dictionary <TagKey, TagValue>()
            {
                { K1, V1 }
            });
            ITagContextBuilder builder = tagger.ToBuilder(tags);

            Assert.Throws <ArgumentNullException>(() => builder.Remove(null));
        }
Esempio n. 17
0
        public async Task <IEnumerable <TagValue> > GetTagsAsync()
        {
            if (_db == null)
            {
                _db = new TagContext();
            }
            await _db.Database.EnsureCreatedAsync();

            return(_db.Tags);
        }
Esempio n. 18
0
        public void Put_NullValue()
        {
            TagContext tags = new TagContext(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }
            });
            ITagContextBuilder builder = tagger.ToBuilder(tags);

            Assert.Throws <ArgumentNullException>(() => builder.Put(K2, null));
        }
Esempio n. 19
0
        public void Remove_DifferentKey()
        {
            var tags = new TagContext(new Dictionary <string, string>()
            {
                { K1, V1 }
            });

            Assert.Equal(new Dictionary <string, string>()
            {
                { K1, V1 }
            }, ((TagContext)tagger.ToBuilder(tags).Remove(K2).Build()).Tags);
        }
Esempio n. 20
0
        public void getTags_nonEmpty()
        {
            var tags = new TagContext(new Dictionary <string, string>()
            {
                { K1, V1 }, { K2, V2 }
            });

            Assert.Equal(new Dictionary <string, string>()
            {
                { K1, V1 }, { K2, V2 }
            }, tags.Tags);
        }
Esempio n. 21
0
 public static void Initialize(TagContext context)
 {
     context.Database.EnsureCreated();
     if (!context.Groups.Any())
     {
         context.Groups.Add(new Group()
         {
             Name = "Default"
         });
     }
     context.SaveChanges();
 }
Esempio n. 22
0
 public ArticleServiceImpl(ArticleContext articleContext, ClassificationContext classificationContext
                           , CommentContext commentContext, TagContext tagContext
                           , UserContext userContext
                           , ReplyContext replyContext)
 {
     _articleContext        = articleContext;
     _classificationContext = classificationContext;
     _commentContext        = commentContext;
     _tagContext            = tagContext;
     _userContext           = userContext;
     _replyContext          = replyContext;
 }
Esempio n. 23
0
        public void Remove_DifferentKey()
        {
            TagContext tags = new TagContext(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }
            });

            Assert.Equal(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }
            }, ((TagContext)tagger.ToBuilder(tags).Remove(K2).Build()).Tags);
        }
Esempio n. 24
0
        public void getTags_nonEmpty()
        {
            TagContext tags = new TagContext(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }, { K2, V2 }
            });

            Assert.Equal(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }, { K2, V2 }
            }, tags.Tags);
        }
Esempio n. 25
0
        public void Remove_ExistingKey()
        {
            TagContext tags = new TagContext(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }, { K2, V2 }
            });

            Assert.Equal(new Dictionary <ITagKey, ITagValue>()
            {
                { K2, V2 }
            }, ((TagContext)tagger.ToBuilder(tags).Remove(K1).Build()).Tags);
        }
Esempio n. 26
0
        public void Put_NewKey()
        {
            TagContext tags = new TagContext(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }
            });

            Assert.Equal(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }, { K2, V2 }
            },
                         ((TagContext)tagger.ToBuilder(tags).Put(K2, V2).Build()).Tags);
        }
Esempio n. 27
0
        public void ProcessTagTestWithAttribute()
        {
            TagContext     context = new TagContext();
            OpenTagHandler handler = new OpenTagHandler();
            int            result  = handler.Process(context, lineWithAttr);

            Tag tag = (Tag)context.Pop();

            Assert.AreEqual("name", tag.Name);
            Assert.AreEqual("attr", tag.Attribute);
            Assert.AreEqual(1, tag.Value);
            Assert.AreEqual(lineWithAttr.IndexOf('>') + 1, result);
        }
 public PostController(
     UserManager <UserIndentity> userManager,
     SignInManager <UserIndentity> signInManager,
     ILogger <AutheficationController> logger,
     PostContext postContext,
     TagContext tagContext)
 {
     this._userManager   = userManager;
     this._signInManager = signInManager;
     this._logger        = logger;
     this._postContext   = postContext;
     this._tagContext    = tagContext;
 }
Esempio n. 29
0
        public void Put_ExistingKey()
        {
            var tags = new TagContext(new Dictionary <string, string>()
            {
                { K1, V1 }
            });

            Assert.Equal(new Dictionary <string, string>()
            {
                { K1, V2 }
            },
                         ((TagContext)tagger.ToBuilder(tags).Put(K1, V2).Build()).Tags);
        }
Esempio n. 30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TaggerSettingsWindow"/> class.
        /// </summary>
        public TaggerSettingsWindow()
        {
            InitializeComponent();

            // Initialize data contexts
            var globalSettingsViewModel = new GlobalSettingsViewModel();
            var tagViewModel = new HotkeyViewModel(this.TagHotkeyControl);
            var appearanceViewModel = new HotkeyViewModel(this.SettingsHotkeyControl);
            var trayIconViewModel = new TrayIconViewModel();
            this.TrayIconControl.DataContext = trayIconViewModel;
            this.DataContext = globalSettingsViewModel;

            // Restore previous settings state
            tagViewModel.ModifierKeys = (ModifierKeys)Settings.Default.TagHotkey_Modifiers;
            tagViewModel.Key = (Key)Settings.Default.TagHotkey_Keys;
            appearanceViewModel.ModifierKeys = (ModifierKeys)Settings.Default.AppearanceHotkey_Modifiers;
            appearanceViewModel.Key = (Key)Settings.Default.AppearanceHotkey_Keys;

            // Restore registration state
            tagViewModel.RegisterHotkey();
            appearanceViewModel.RegisterHotkey();

            // Do not tag global settings window
            this.Loaded += delegate { RegistrationManager.RegisterException(this); };

            // Exit application on window close
            this.Closed += delegate { Application.Current.Shutdown(); };

            // Save settings on program deactivation (app exit included)
            Application.Current.Deactivated += delegate
            {
                Settings.Default.TagHotkey_Modifiers = (int)tagViewModel.ModifierKeys;
                Settings.Default.TagHotkey_Keys = (int)tagViewModel.Key;
                Settings.Default.AppearanceHotkey_Modifiers = (int)appearanceViewModel.ModifierKeys;
                Settings.Default.AppearanceHotkey_Keys = (int)appearanceViewModel.Key;
                Settings.Default.Save();
            };

            // Dispose all on exit
            Application.Current.Exit += delegate
            {
                tagViewModel.Dispose();
                appearanceViewModel.Dispose();
                trayIconViewModel.Dispose();
                globalSettingsViewModel.Dispose();
            };

            // Pre-compiling JIT code to speadup first tag appearance
            var context = new TagContext();
            context.Dispose();
        }
 public AjaxApiPostController(
     UserManager <UserIndentity> userManager,
     SignInManager <UserIndentity> signInManager,
     ILogger <AjaxApiPostController> logger,
     PostContext postContext,
     TagContext tagContext,
     LikeContext LikeContext)
 {
     this._userManager   = userManager;
     this._signInManager = signInManager;
     this._logger        = logger;
     this._postContext   = postContext;
     this._tagContext    = tagContext;
     this._likeContext   = LikeContext;
 }