Ejemplo n.º 1
0
        private void dowork(object o, DoWorkEventArgs args)
        {
            try
            {
                var client = new WeMoService.BasicServicePortTypeClient();
                client.Endpoint.Address = new EndpointAddress(string.Format("http://{0}:{1}/upnp/control/basicevent1", ip, port));

                var state = client.GetBinaryState(new WeMoService.GetBinaryState());
                Console.WriteLine("Switch is current set to: {0}", state.BinaryState);

                if (state.BinaryState == "0")
                {
                    state.BinaryState = "1";
                }
                else
                {
                    state.BinaryState = "0";
                }

                var msg = new WeMoService.SetBinaryState {
                    BinaryState = state.BinaryState
                };
                client.SetBinaryState(msg);
            }
            catch (Exception ex)
            {
                WebPage.DisplayWebPage("Wemo Command Error", ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void dowork(object o, DoWorkEventArgs args)
        {
            BackgroundWorker b = o as BackgroundWorker;

            StringBuilder sb           = new StringBuilder();
            var           finder       = new UPnPDeviceFinder();
            var           foundDevices = new List <UPnPDevice>();

            var deviceType = "upnp:rootdevice";
            var devices    = finder.FindByType(deviceType, 1);

            foreach (UPnPDevice upnpDevice in devices)
            {
                sb.AppendHtmlLine("FriendlyName: " + upnpDevice.FriendlyName);
                sb.AppendHtmlLine("Description: " + upnpDevice.Description);
                sb.AppendHtmlLine("PresentationURL: " + upnpDevice.PresentationURL);


                string port    = new Uri(upnpDevice.PresentationURL).Port.ToString();
                string baseUrl = new Uri(upnpDevice.PresentationURL).DnsSafeHost.ToString();

                sb.AppendHtmlLine("Type: " + upnpDevice.Type);
                sb.AppendHtmlLine("Port: " + port);
                sb.AppendHtmlLine("baseUrl: " + baseUrl);

                sb.AppendLine("<hr/>");
            }

            WebPage.DisplayWebPage("Universal Plug and Play devices", sb.ToString());
        }
Ejemplo n.º 3
0
        override public bool Execute(string[] args)
        {
            string text       = Clipboard.GetText();
            string formatText = "";
            string delimiter  = "word";

            if (args.Length > 1 && !string.IsNullOrWhiteSpace(args[1]))
            {
                formatText = args[1];
            }

            if (args.Length > 2 && !string.IsNullOrWhiteSpace(args[2]))
            {
                if (string.Compare(args[2].Trim(), "line", true) == 0)
                {
                    delimiter = "line";
                }
                else if (string.Compare(args[2].Trim(), "tab", true) == 0)
                {
                    delimiter = "tab";
                }
            }

            if (!string.IsNullOrWhiteSpace(text))
            {
                StringBuilder sb = new StringBuilder();

                List <string> lines = text.SplitLines();

                StringBuilder errorText = new StringBuilder();

                foreach (var line in lines)
                {
                    try
                    {
                        if (delimiter == "word")
                        {
                            string   cleanline = line.Trim();
                            string[] words     = cleanline.Split(' ');
                            for (int i = 0; i < words.Length; i++)
                            {
                                words[i] = words[i].Trim();
                            }
                            sb.AppendLine(string.Format(formatText, words));
                        }
                        else if (delimiter == "tab")
                        {
                            string[] words = line.Split('\t');
                            for (int i = 0; i < words.Length; i++)
                            {
                                words[i] = words[i].Trim();
                            }
                            sb.AppendLine(string.Format(formatText, words));
                        }
                        else if (delimiter == "line")
                        {
                            sb.AppendLine(string.Format(formatText, line));
                        }
                    }
                    catch (Exception e)
                    {
                        string errorMessage = $"Format failed this line '{line}' for delimiter {delimiter} and format string {formatText} with error '{e.Message}'";
                        errorText.AppendHtmlLine(errorMessage);
                    }
                }

                if (errorText.Length > 0)
                {
                    WebPage.DisplayWebPage("Format Command Error", formatText + "<hr/>" + errorText.ToString());
                }

                try
                {
                    Clipboard.SetText(sb.ToString(), TextDataFormat.Text);
                }
                catch (Exception) { }
            }
            return(true); // hide command window
        }