private async void DropDownSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox CBox = sender as ComboBox;

            Models.Param parameter = (Models.Param)GetParamByName(CBox.Name);
            await Camera.SetParamValue(CBox.Name, CBox.SelectedItem.ToString(), parameter.permission);
        }
        /// <summary>
        /// Populate a combobox with the possible values
        /// </summary>
        public async void PopulateValues(ComboBox CBox)
        {
            if (CBox.Items.Count == 1)
            {
                string currentValue = CBox.SelectedItem.ToString();

                // To avoid ComboBox closing:
                // Deselect the current Item
                CBox.SelectedItem = null;

                //Get the Values
                CamGetParamValuesMessage Param = await Camera.GetParamValues(CBox.Name);

                // Get the Param and update its values with reflexion
                Models.Param parameter = (Models.Param)GetParamByName(CBox.Name);

                foreach (var item in Param.options)
                {
                    parameter.Values.Add(item);
                }

                // Remove the first one (so it isn't repeated)
                parameter.Values.RemoveAt(0);

                // Select the value again
                parameter.currentValue = currentValue;

                parameter.permission = Param.permission;

                // Now set the handler for SelectionChanged
                CBox.SelectionChanged += DropDownSelectionChanged;
            }
        }
Beispiel #3
0
		/// <summary>
		/// Initializes the module. This method should be used for
		/// ensuring runtime resources and registering hooks.
		/// </summary>
		public void Init() {
			using (var api = new Api()) {
				// Ensure configuration params
				var param = api.Params.GetSingle(where: p => p.Name == "akismet_apikey");
				if (param == null) {
					param = new Models.Param() { 
						Name = "akismet_apikey"
					};
					api.Params.Add(param);
				}
				param = api.Params.GetSingle(where: p => p.Name == "akismet_siteurl");
				if (param == null) {
					param = new Models.Param() { 
						Name = "akismet_siteurl",
					};
					api.Params.Add(param);
				}

				// Save changes
				api.SaveChanges();
			}

			// Add configuration to the manager
			Manager.Config.Blocks.Add(new Manager.Config.ConfigBlock("Blogging", "Akismet", new List<Manager.Config.ConfigRow>() {
				new Manager.Config.ConfigRow(new List<Manager.Config.ConfigColumn>() {
					new Manager.Config.ConfigColumn(new List<Manager.Config.ConfigItem>() {
						new Manager.Config.ConfigString() {
							Name = "API-key", Param = "akismet_apikey", Value = Config.Akismet.ApiKey
						}
					}),
					new Manager.Config.ConfigColumn(new List<Manager.Config.ConfigItem>() {
						new Manager.Config.ConfigString() {
							Name = "Site URL", Param = "akismet_siteurl", Value = Config.Akismet.SiteUrl
						}
					})
				})
			}));

			// Add model hooks
			Hooks.Models.Comment.OnSave += (c) => {
				if (!String.IsNullOrWhiteSpace(Config.Akismet.ApiKey)) {
					//
					// TODO: Maybe check if the comment exists in the database
					//
					if (akismet.VerifyKey()) {
						if (akismet.CommentCheck(c)) {
							App.Logger.Log(Log.LogLevel.WARNING, "Akismet: Comment was marked as spam by Akismet");
							c.IsSpam = true;
						}
					} else {
						App.Logger.Log(Log.LogLevel.ERROR, "Akismet: ApiKey verification failed.");
					}
				} else {
					App.Logger.Log(Log.LogLevel.INFO, "Akismet: No api key configured. Skipping comment validation.");
				}
			};
		}
Beispiel #4
0
        /// <summary>
        /// Test the param repository.
        /// </summary>
        protected void Run()
        {
            using (var api = new Api()) {
                // Add new model
                var model = new Models.Param()
                {
                    Name  = "my_param",
                    Value = "23"
                };
                api.Params.Add(model);
                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Get model
                var model = api.Params.GetSingle(where : p => p.Name == "my_param");

                Assert.IsNotNull(model);
                Assert.AreEqual("23", model.Value);

                // Update model
                model.Value = "32";
                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Verify update
                var model = api.Params.GetSingle(where : p => p.Name == "my_param");

                Assert.IsNotNull(model);
                Assert.AreEqual("32", model.Value);

                // Remove model
                api.Params.Remove(model);
                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Verify remove
                var model = api.Params.GetSingle(where : p => p.Name == "my_param");
                Assert.IsNull(model);
            }
        }
Beispiel #5
0
		/// <summary>
		/// Test the param repository.
		/// </summary>
		protected void Run() {
			using (var api = new Api()) {
				// Add new model
				var model = new Models.Param() {
					Name = "my_param",
					Value = "23"
				};
				api.Params.Add(model);
				api.SaveChanges();
			}

			using (var api = new Api()) {
				// Get model
				var model = api.Params.GetSingle(where: p => p.Name == "my_param");

				Assert.IsNotNull(model);
				Assert.AreEqual("23", model.Value);

				// Update model
				model.Value = "32";
				api.SaveChanges();
			}

			using (var api = new Api()) {
				// Verify update
				var model = api.Params.GetSingle(where: p => p.Name == "my_param");

				Assert.IsNotNull(model);
				Assert.AreEqual("32", model.Value);

				// Remove model
				api.Params.Remove(model);
				api.SaveChanges();
			}

			using (var api = new Api()) {
				// Verify remove
				var model = api.Params.GetSingle(where: p => p.Name == "my_param");
				Assert.IsNull(model);
			}
		}
Beispiel #6
0
		/// <summary>
		/// Initializes the module. This method should be used for
		/// ensuring runtime resources and registering hooks.
		/// </summary>
		public void Init() {
			using (var api = new Api()) {
				// Ensure configuration params
				var param = api.Params.GetSingle(where: p => p.Name == "feed_pagesize");
				if (param == null) {
					param = new Models.Param() { 
						Name = "feed_pagesize",
						Value = "10"
					};
					api.Params.Add(param);
				}
				param = api.Params.GetSingle(where: p => p.Name == "feed_sitefeedtitle");
				if (param == null) {
					param = new Models.Param() { 
						Name = "feed_sitefeedtitle",
						Value = "{SiteTitle} > Feed"
					};
					api.Params.Add(param);
				}
				param = api.Params.GetSingle(where: p => p.Name == "feed_archivefeedtitle");
				if (param == null) {
					param = new Models.Param() { 
						Name = "feed_archivefeedtitle",
						Value = "{SiteTitle} > {PostType} Archive Feed"
					};
					api.Params.Add(param);
				}
				param = api.Params.GetSingle(where: p => p.Name == "feed_commentfeedtitle");
				if (param == null) {
					param = new Models.Param() { 
						Name = "feed_commentfeedtitle",
						Value = "{SiteTitle} > Comments Feed"
					};
					api.Params.Add(param);
				}
				param = api.Params.GetSingle(where: p => p.Name == "feed_postfeedtitle");
				if (param == null) {
					param = new Models.Param() { 
						Name = "feed_postfeedtitle",
						Value = "{SiteTitle} > {PostTitle} Comments Feed"
					};
					api.Params.Add(param);
				}

				// Save changes
				api.SaveChanges();
			}

			// Add configuration to the manager
			Manager.Config.Blocks.Add(new Manager.Config.ConfigBlock("Blogging", "Feed", new List<Manager.Config.ConfigRow>() {
				new Manager.Config.ConfigRow(new List<Manager.Config.ConfigColumn>() {
					new Manager.Config.ConfigColumn(new List<Manager.Config.ConfigItem>() {
						new Manager.Config.ConfigString() {
							Name = "Site title", Param = "feed_sitefeedtitle", Value = Config.Feed.SiteFeedTitle
						},
						new Manager.Config.ConfigString() {
							Name = "Archive title", Param = "feed_archivefeedtitle", Value = Config.Feed.ArchiveFeedTitle
						},
						new Manager.Config.ConfigInteger() {
							Name = "Page size", Param = "feed_pagesize", Value = Config.Feed.PageSize.ToString()
						}
					}),
					new Manager.Config.ConfigColumn(new List<Manager.Config.ConfigItem>() {
						new Manager.Config.ConfigString() {
							Name = "Comment title", Param = "feed_commentfeedtitle", Value = Config.Feed.CommentFeedTitle
						},
						new Manager.Config.ConfigString() {
							Name = "Post title", Param = "feed_postfeedtitle", Value = Config.Feed.PostFeedTitle
						}
					})
				})
			}));

			// Add the feed handler
			App.Handlers.Add("feed", new FeedHandler());

			// Add UI rendering
			Hooks.UI.Head.Render += (sb) => {
				// Get current
				var current = App.Env.GetCurrent();

				// Render base feeds
				var sTitle = HttpUtility.HtmlEncode(Config.Feed.SiteFeedTitle
					.Replace("{SiteTitle}", Config.Site.Title));

				var cTitle = HttpUtility.HtmlEncode(Config.Feed.CommentFeedTitle
					.Replace("{SiteTitle}", Config.Site.Title));

				sb.Append(String.Format(LINK_TAG, "alternate", "application/rss+xml", sTitle,
					App.Env.AbsoluteUrl("~/feed")));
				sb.Append(String.Format(LINK_TAG, "alternate", "application/rss+xml", cTitle,
					App.Env.AbsoluteUrl("~/feed/comments")));

				if (current.Type == ContentType.Archive) {
					using (var api = new Api()) {
						var type = api.PostTypes.GetSingle(current.Id);

						var title = HttpUtility.HtmlEncode(Config.Feed.ArchiveFeedTitle
							.Replace("{SiteTitle}", Config.Site.Title)
							.Replace("{PostType}", type.ArchiveTitle));

						sb.Append(String.Format(LINK_TAG, "alternate", "application/rss+xml", title,
							App.Env.AbsoluteUrl("~/feed/blog")));
					}
				} else if (current.Type == ContentType.Post) {
					var post = Client.Models.PostModel.GetById(current.Id);

					var title = HttpUtility.HtmlEncode(Config.Feed.PostFeedTitle
						.Replace("{SiteTitle}", Config.Site.Title)
						.Replace("{PostTitle}", post.Title));

					sb.Append(String.Format(LINK_TAG, "alternate", "application/rss+xml", title,
						App.Env.AbsoluteUrl("~/feed/" + post.Type + "/" + post.Slug)));
				}
			};
		}
Beispiel #7
0
        /// <summary>
        /// Initializes the module. This method should be used for
        /// ensuring runtime resources and registering hooks.
        /// </summary>
        public void Init()
        {
            using (var api = new Api()) {
                // Ensure configuration params
                var param = api.Params.GetSingle(where : p => p.Name == "feed_pagesize");
                if (param == null)
                {
                    param = new Models.Param()
                    {
                        Name  = "feed_pagesize",
                        Value = "10"
                    };
                    api.Params.Add(param);
                }
                param = api.Params.GetSingle(where : p => p.Name == "feed_sitefeedtitle");
                if (param == null)
                {
                    param = new Models.Param()
                    {
                        Name  = "feed_sitefeedtitle",
                        Value = "{SiteTitle} > Feed"
                    };
                    api.Params.Add(param);
                }
                param = api.Params.GetSingle(where : p => p.Name == "feed_archivefeedtitle");
                if (param == null)
                {
                    param = new Models.Param()
                    {
                        Name  = "feed_archivefeedtitle",
                        Value = "{SiteTitle} > {PostType} Archive Feed"
                    };
                    api.Params.Add(param);
                }
                param = api.Params.GetSingle(where : p => p.Name == "feed_commentfeedtitle");
                if (param == null)
                {
                    param = new Models.Param()
                    {
                        Name  = "feed_commentfeedtitle",
                        Value = "{SiteTitle} > Comments Feed"
                    };
                    api.Params.Add(param);
                }
                param = api.Params.GetSingle(where : p => p.Name == "feed_postfeedtitle");
                if (param == null)
                {
                    param = new Models.Param()
                    {
                        Name  = "feed_postfeedtitle",
                        Value = "{SiteTitle} > {PostTitle} Comments Feed"
                    };
                    api.Params.Add(param);
                }

                // Save changes
                api.SaveChanges();
            }

            // Add configuration to the manager
            Manager.Config.Blocks.Add(new Manager.Config.ConfigBlock("Blogging", "Feed", new List <Manager.Config.ConfigRow>()
            {
                new Manager.Config.ConfigRow(new List <Manager.Config.ConfigColumn>()
                {
                    new Manager.Config.ConfigColumn(new List <Manager.Config.ConfigItem>()
                    {
                        new Manager.Config.ConfigString()
                        {
                            Name = "Site title", Param = "feed_sitefeedtitle", Value = Config.Feed.SiteFeedTitle
                        },
                        new Manager.Config.ConfigString()
                        {
                            Name = "Archive title", Param = "feed_archivefeedtitle", Value = Config.Feed.ArchiveFeedTitle
                        },
                        new Manager.Config.ConfigInteger()
                        {
                            Name = "Page size", Param = "feed_pagesize", Value = Config.Feed.PageSize.ToString()
                        }
                    }),
                    new Manager.Config.ConfigColumn(new List <Manager.Config.ConfigItem>()
                    {
                        new Manager.Config.ConfigString()
                        {
                            Name = "Comment title", Param = "feed_commentfeedtitle", Value = Config.Feed.CommentFeedTitle
                        },
                        new Manager.Config.ConfigString()
                        {
                            Name = "Post title", Param = "feed_postfeedtitle", Value = Config.Feed.PostFeedTitle
                        }
                    })
                })
            }));

            // Add the feed handler
            App.Handlers.Add("feed", new FeedHandler());

            // Add UI rendering
            Hooks.UI.Head.Render += (sb) => {
                // Get current
                var current = App.Env.GetCurrent();

                // Render base feeds
                var sTitle = HttpUtility.HtmlEncode(Config.Feed.SiteFeedTitle
                                                    .Replace("{SiteTitle}", Config.Site.Title));

                var cTitle = HttpUtility.HtmlEncode(Config.Feed.CommentFeedTitle
                                                    .Replace("{SiteTitle}", Config.Site.Title));

                sb.Append(String.Format(LINK_TAG, "alternate", "application/rss+xml", sTitle,
                                        App.Env.AbsoluteUrl("~/feed")));
                sb.Append(String.Format(LINK_TAG, "alternate", "application/rss+xml", cTitle,
                                        App.Env.AbsoluteUrl("~/feed/comments")));

                if (current.Type == ContentType.Archive)
                {
                    using (var api = new Api()) {
                        var type = api.PostTypes.GetSingle(current.Id);

                        var title = HttpUtility.HtmlEncode(Config.Feed.ArchiveFeedTitle
                                                           .Replace("{SiteTitle}", Config.Site.Title)
                                                           .Replace("{PostType}", type.ArchiveTitle));

                        sb.Append(String.Format(LINK_TAG, "alternate", "application/rss+xml", title,
                                                App.Env.AbsoluteUrl("~/feed/blog")));
                    }
                }
                else if (current.Type == ContentType.Post)
                {
                    var post = Client.Models.PostModel.GetById(current.Id);

                    var title = HttpUtility.HtmlEncode(Config.Feed.PostFeedTitle
                                                       .Replace("{SiteTitle}", Config.Site.Title)
                                                       .Replace("{PostTitle}", post.Title));

                    sb.Append(String.Format(LINK_TAG, "alternate", "application/rss+xml", title,
                                            App.Env.AbsoluteUrl("~/feed/" + post.Type + "/" + post.Slug)));
                }
            };
        }
        /// <summary>
        /// Initializes the module. This method should be used for
        /// ensuring runtime resources and registering hooks.
        /// </summary>
        public void Init()
        {
            using (var api = new Api()) {
                // Ensure configuration params
                var param = api.Params.GetSingle(where : p => p.Name == "akismet_apikey");
                if (param == null)
                {
                    param = new Models.Param()
                    {
                        Name = "akismet_apikey"
                    };
                    api.Params.Add(param);
                }
                param = api.Params.GetSingle(where : p => p.Name == "akismet_siteurl");
                if (param == null)
                {
                    param = new Models.Param()
                    {
                        Name = "akismet_siteurl",
                    };
                    api.Params.Add(param);
                }

                // Save changes
                api.SaveChanges();
            }

            // Add configuration to the manager
            Manager.Config.Blocks.Add(new Manager.Config.ConfigBlock("Blogging", "Akismet", new List <Manager.Config.ConfigRow>()
            {
                new Manager.Config.ConfigRow(new List <Manager.Config.ConfigColumn>()
                {
                    new Manager.Config.ConfigColumn(new List <Manager.Config.ConfigItem>()
                    {
                        new Manager.Config.ConfigString()
                        {
                            Name = "API-key", Param = "akismet_apikey", Value = Config.Akismet.ApiKey
                        }
                    }),
                    new Manager.Config.ConfigColumn(new List <Manager.Config.ConfigItem>()
                    {
                        new Manager.Config.ConfigString()
                        {
                            Name = "Site URL", Param = "akismet_siteurl", Value = Config.Akismet.SiteUrl
                        }
                    })
                })
            }));

            // Add model hooks
            Hooks.Models.Comment.OnSave += (c) => {
                if (!String.IsNullOrWhiteSpace(Config.Akismet.ApiKey))
                {
                    //
                    // TODO: Maybe check if the comment exists in the database
                    //
                    if (akismet.VerifyKey())
                    {
                        if (akismet.CommentCheck(c))
                        {
                            App.Logger.Log(Log.LogLevel.WARNING, "Akismet: Comment was marked as spam by Akismet");
                            c.IsSpam = true;
                        }
                    }
                    else
                    {
                        App.Logger.Log(Log.LogLevel.ERROR, "Akismet: ApiKey verification failed.");
                    }
                }
                else
                {
                    App.Logger.Log(Log.LogLevel.INFO, "Akismet: No api key configured. Skipping comment validation.");
                }
            };
        }
		public void ParamRepository() {
			var id = Guid.Empty;

			// Insert param
			using (var api = new Api()) {
				var param = new Models.Param() {
					InternalId = "MY_PARAM",
					Name = "My param",
					Value = "23"
				};
				api.Params.Add(param);

				Assert.AreEqual(param.Id.HasValue, true);
				Assert.IsTrue(api.SaveChanges() > 0);

				id = param.Id.Value;
			}

			// Get by internal id
			using (var api = new Api()) {
				var param = api.Params.GetByInternalId("MY_PARAM");

				Assert.IsNotNull(param);
				Assert.AreEqual(param.Value, "23");
			}

			// Update param
			using (var api = new Api()) {
				var param = api.Params.GetByInternalId("MY_PARAM");

				Assert.IsNotNull(param);

				param.Value = "24";
				api.Params.Add(param);

				Assert.IsTrue(api.SaveChanges() > 0);
			}

			// Get by id
			using (var api = new Api()) {
				var param = api.Params.GetById(id);

				Assert.IsNotNull(param);
				Assert.AreEqual(param.Value, "24");
			}

			// Remove param
			using (var api = new Api()) {
				var param = api.Params.GetByInternalId("MY_PARAM");

				api.Params.Remove(param);

				Assert.IsTrue(api.SaveChanges() > 0);
			}

			// Remove system param
			using (var api = new Api()) {
				var param = api.Params.GetByInternalId("ARCHIVE_PAGE_SIZE");

				try {
					api.Params.Remove(param);

					// The above statement should throw an exception and this
					// this assertion should not be reached.
					Assert.IsTrue(false);
				} catch (Exception ex) {
					Assert.IsTrue(ex is UnauthorizedAccessException);
				}
			}
		}