예제 #1
0
        private string BuildAddNewWebPageBody([AllowNull] ChromecastDevice device)
        {
            string name = device != null?device.Name.ToString() : string.Empty;

            string ip = device != null?device.DeviceIP.ToString() : string.Empty;

            string id          = device != null ? device.Id : string.Empty;
            string buttonLabel = device != null ? "Save" : "Add";
            string header      = device != null ? "Edit" : "Add New";
            int    volume      = device != null ? (device.Volume ?? -1) : -1;

            StringBuilder stb = new StringBuilder();

            stb.Append(PageBuilderAndMenu.clsPageBuilder.FormStart("ftmDeviceChange", "IdChange", "Post"));

            stb.Append(@"<div>");
            stb.Append(@"<table class='full_width_table'");
            stb.Append("<tr height='5'><td style='width:25%'></td><td style='width:20%'></td><td style='width:55%'></td></tr>");
            stb.Append(Invariant($"<tr><td class='tableheader' colspan=3>{header}</td></tr>"));
            stb.Append(Invariant($"<tr><td class='tablecell'>Name:</td><td class='tablecell' colspan=2>{HtmlTextBox(NameId, name, @readonly: !string.IsNullOrEmpty(id))}</td></tr>"));
            stb.Append(Invariant($"<tr><td class='tablecell'>DeviceIP:</td><td class='tablecell' colspan=2>{HtmlTextBox(DeviceIPId, ip)}</td></tr>"));
            stb.Append("<tr><td class='tablecell'>Volume:</td><td class='tablecell' colspan=2>");

            var volumeDropDown = new clsJQuery.jqDropList(NameToId(VolumeId), PageName, false)
            {
                toolTip      = "Select Volume of device when Spoken",
                autoPostBack = false,
            };

            volumeDropDown.AddItem("Don't Change", NoValueForVoice, volume == -1);

            foreach (var value in Enumerable.Range(1, 100))
            {
                var stringValue = value.ToString(CultureInfo.InvariantCulture);
                volumeDropDown.AddItem(stringValue, stringValue, volume == value);
            }

            stb.Append(volumeDropDown.Build());
            stb.Append("</td></tr>");
            stb.Append(Invariant($"<tr><td colspan=3>{HtmlTextBox(DeviceIdId, id, type: "hidden")}<div id='{SaveErrorDivId}' style='color:Red'></div></td><td></td></tr>"));
            stb.Append(Invariant($"<tr><td colspan=3>{FormPageButton(SaveDeviceName, buttonLabel)}"));

            if (device != null)
            {
                stb.Append(FormPageButton(DeleteDeviceName, "Delete"));
            }

            stb.Append(FormPageButton(CancelDeviceName, "Cancel"));
            stb.Append(Invariant($"</td><td></td></tr>"));
            stb.Append("<tr height='5'><td colspan=3></td></tr>");
            stb.Append(@" </table>");
            stb.Append(@"</div>");
            stb.Append(PageBuilderAndMenu.clsPageBuilder.FormEnd());

            return(stb.ToString());
        }
예제 #2
0
 public void AddDevice(ChromecastDevice device)
 {
     using (var sync = configLock.WriterLock())
     {
         devices[device.Id] = device;
         SetValue(NameKey, device.Name, device.Id);
         SetValue(IPAddressKey, device.DeviceIP.ToString(), device.Id);
         SetValue(VolumeKey, device.Volume, device.Id);
         SetValue(DeviceIds, devices.Keys.Aggregate((x, y) => x + DeviceIdsSeparator + y));
     }
 }
예제 #3
0
 public void AddDevice(ChromecastDevice device)
 {
     configLock.EnterWriteLock();
     try
     {
         devices[device.Id] = device;
         SetValue(NameKey, device.Name, device.Id);
         SetValue(IPAddressKey, device.DeviceIP.ToString(), device.Id);
         SetValue(VolumeKey, device.Volume, device.Id);
         SetValue(DeviceIds, devices.Keys.Aggregate((x, y) => x + DeviceIdsSeparator + y));
     }
     finally
     {
         configLock.ExitWriteLock();
     }
 }
예제 #4
0
        /// <summary>
        /// The user has selected a control on the configuration web page.
        /// The post data is provided to determine the control that initiated the post and the state of the other controls.
        /// </summary>
        /// <param name="data">The post data.</param>
        /// <param name="user">The name of logged in user.</param>
        /// <param name="userRights">The rights of the logged in user.</param>
        /// <returns>Any serialized data that needs to be passed back to the web page, generated by the clsPageBuilder class.</returns>
        public string PostBackProc(string data, [AllowNull] string user, int userRights)
        {
            NameValueCollection parts = HttpUtility.ParseQueryString(data);

            string form = parts["id"];

            if (form == NameToIdWithPrefix(SaveDeviceName))
            {
                StringBuilder results = new StringBuilder();

                // Validate
                IPAddress ipAddress = null;
                if (string.IsNullOrWhiteSpace(parts[DeviceIPId]) ||
                    !IPAddress.TryParse(parts[DeviceIPId], out ipAddress))
                {
                    results.AppendLine("IP Address is not Valid.<br>");
                }

                string name = parts[NameId];
                if (string.IsNullOrWhiteSpace(name))
                {
                    results.AppendLine("Name is not Valid.<br>");
                }

                if (results.Length > 0)
                {
                    divToUpdate.Add(SaveErrorDivId, results.ToString());
                }
                else
                {
                    string deviceId = parts[DeviceIdId];
                    if (string.IsNullOrWhiteSpace(deviceId))
                    {
                        deviceId = name.Replace(' ', '_').Replace('.', '_');
                    }

                    string volumeString = parts[VolumeId];
                    short  volume;

                    if (!short.TryParse(volumeString, NumberStyles.Any, CultureInfo.InvariantCulture, out volume))
                    {
                        volume = -1;
                    }

                    var device = new ChromecastDevice(deviceId, parts[NameId], ipAddress, volume == -1 ? null : (ushort?)volume);

                    pluginConfig.AddDevice(device);
                    pluginConfig.FireConfigChanged();
                    divToUpdate.Add(SaveErrorDivId, RedirectPage(Invariant($"/{HttpUtility.UrlEncode(ConfigPage.Name)}")));
                }
            }
            else if (form == NameToIdWithPrefix(CancelDeviceName))
            {
                divToUpdate.Add(SaveErrorDivId, RedirectPage(Invariant($"/{HttpUtility.UrlEncode(ConfigPage.Name)}")));
            }
            else if (form == NameToIdWithPrefix(DeleteDeviceName))
            {
                pluginConfig.RemoveDevice(parts[DeviceIdId]);
                pluginConfig.FireConfigChanged();
                divToUpdate.Add(SaveErrorDivId, RedirectPage(Invariant($"/{HttpUtility.UrlEncode(ConfigPage.Name)}")));
            }
            else if (form == NameToIdWithPrefix(SaveSettingName))
            {
                StringBuilder results = new StringBuilder();

                // Validate
                IPAddress ipAddress = null;
                if (!string.IsNullOrWhiteSpace(parts[ServerIPAddressId]))
                {
                    if (!IPAddress.TryParse(parts[ServerIPAddressId], out ipAddress))
                    {
                        results.AppendLine("Server IP Address is not Valid.<br>");
                    }
                }

                ushort port = 0;
                if (string.IsNullOrWhiteSpace(parts[ServerPortId]) ||
                    !ushort.TryParse(parts[ServerPortId], NumberStyles.Any, CultureInfo.InvariantCulture, out port))
                {
                    results.AppendLine("Port is not Valid.<br>");
                }

                if (results.Length > 0)
                {
                    divToUpdate.Add(SaveErrorDivId, results.ToString());
                }
                else
                {
                    string sapiVoice = parts[SapiVoiceId];

                    sapiVoice = (sapiVoice == null) || (sapiVoice == NoValueForVoice) ? null : sapiVoice;

                    pluginConfig.WebServerPort      = port;
                    pluginConfig.WebServerIPAddress = ipAddress;
                    pluginConfig.DebugLogging       = parts[NameToId(DebugLoggingId)] == "checked";
                    pluginConfig.ForwardSpeach      = parts[NameToId(FormatSpeechId)] == "checked";
                    pluginConfig.SAPIVoice          = sapiVoice;
                    pluginConfig.FireConfigChanged();
                    divToUpdate.Add(SaveErrorDivId, string.Empty);
                }
            }

            return(base.postBackProc(Name, data, user, userRights));
        }