Ejemplo n.º 1
0
        public HomeModule()
        {
            Get["/"] = p => {
                var configuration = Nancy.TinyIoc.TinyIoCContainer.Current.Resolve<ServantConfiguration>();

                var latestErrors = EventLogHelper.GetByDateTimeDescending(5).ToList();
                latestErrors = EventLogHelper.AttachSite(latestErrors, Page.Sites);
                Model.UnhandledExceptions = latestErrors;
                Model.HaveSeenNewsletter = configuration.HaveSeenNewsletter;
                return View["Index", Model];
            };

            Post["/subscribetonewsletter"] = p => {
                var email = Request.Form.Email;
                var firstname = Request.Form.Firstname;
                var lastname = Request.Form.Lastname;

                try
                {
                    new System.Net.Mail.MailAddress(email);
                }
                catch
                {
                    AddPropertyError("email", "Looks like the email is not valid.");
                }

                var serializer = new Nancy.Json.JavaScriptSerializer();

                if (HasErrors)
                {
                    return new { Type = MessageType.Error.ToString(), Errors = serializer.Serialize(Model.Errors) }; ;
                }

                var response = MailchimpHelper.Subscribe(email, firstname, lastname);

                if (response != "true")
                {
                    MailchimpResponse result = serializer.Deserialize<MailchimpResponse>(response);

                    if (result.Code == 214)
                    {
                        SetNewsletterRead();
                    }

                    if (result.Code == 502)
                    {
                        AddPropertyError("email", "Looks like the email is not valid.");
                        return new { Type = MessageType.Error, Errors = serializer.Serialize(Model.Errors) };
                    }

                    return new { Message = result.Error, Type = MessageType.Error.ToString() };
                }

                SetNewsletterRead();

                return new { Message = response, Type = MessageType.Success.ToString() };
            };
        }
Ejemplo n.º 2
0
        public HomeModule()
        {
            Get["/"] = p => {
                var configuration = Nancy.TinyIoc.TinyIoCContainer.Current.Resolve <ServantConfiguration>();

                var latestErrors = EventLogHelper.GetByDateTimeDescending(5).ToList();
                latestErrors = EventLogHelper.AttachSite(latestErrors, Page.Sites);
                Model.UnhandledExceptions = latestErrors;
                Model.HaveSeenNewsletter  = configuration.HaveSeenNewsletter;
                return(View["Index", Model]);
            };

            Post["/subscribetonewsletter"] = p => {
                var email     = Request.Form.Email;
                var firstname = Request.Form.Firstname;
                var lastname  = Request.Form.Lastname;

                try
                {
                    new System.Net.Mail.MailAddress(email);
                }
                catch
                {
                    AddPropertyError("email", "Looks like the email is not valid.");
                }

                var serializer = new Nancy.Json.JavaScriptSerializer();

                if (HasErrors)
                {
                    return(new { Type = MessageType.Error.ToString(), Errors = serializer.Serialize(Model.Errors) });;
                }

                var response = MailchimpHelper.Subscribe(email, firstname, lastname);

                if (response != "true")
                {
                    MailchimpResponse result = serializer.Deserialize <MailchimpResponse>(response);

                    if (result.Code == 214)
                    {
                        SetNewsletterRead();
                    }

                    if (result.Code == 502)
                    {
                        AddPropertyError("email", "Looks like the email is not valid.");
                        return(new { Type = MessageType.Error, Errors = serializer.Serialize(Model.Errors) });
                    }

                    return(new { Message = result.Error, Type = MessageType.Error.ToString() });
                }

                SetNewsletterRead();

                return(new { Message = response, Type = MessageType.Success.ToString() });
            };
        }
Ejemplo n.º 3
0
        public static ServantConfiguration GetConfigurationFromDisk()
        {
            if (!System.IO.File.Exists(ConfigFilePath))
            {
                return(new ServantConfiguration());
            }

            var configContent = System.IO.File.ReadAllText(ConfigFilePath);
            var configuration = Serializer.Deserialize <ServantConfiguration>(configContent);

            var fileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location).FileVersion.Split('.');
            var version     = string.Join(".", fileVersion.Take(2));

            // Updates configuration file to new version
            if (configuration.Version != version)
            {
                configuration.Version = version;
                UpdateConfiguration(configuration);
            }

            return(configuration);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// get channel list from HDHomeRunPlus (from first device in list)
        /// </summary>
        /// <param name="ipaddr"></param>
        /// <returns>List of cChannels</returns>
        public static List<cChannels> getChannels(List<cHDHomeRunPlus> HDHDRPs)
        {
            try
            {
                List<cChannels> channels = new List<cChannels>();
                String json = string.Empty;

                //use webclient to request channel JSON from HDHomeRunPLus
                using (var client = new WebClient())
                {
                    //get channels using first HDHomeRunPlus device
                    json = client.DownloadString("http://" + HDHDRPs[0].IP + "/lineup.json");
                }
                //deserialize JSON into cChannel
                var serializer = new Nancy.Json.JavaScriptSerializer();
                channels = serializer.Deserialize<List<cChannels>>(json);

                return channels;
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("cChannel.getChannels, Error: {0}", ex.Message));
            }
        }