Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // 1st we create a new instance of the SonyAPILib
            SonyAPI_Lib mySonyLib = new SonyAPI_Lib();


            #region No parameters
            if (args.Length < 1)
            {
                Console.WriteLine("ERROR: Missing parameters....");
                showhelp();
            }
            #endregion

            #region Logging
            if (args[args.Length - 1] == "/log")
            {
                mySonyLib.LOG.Enable = true;
                mySonyLib.LOG.Level  = "All";
            }
            #endregion

            #region /h and /? Help and Individual Help
            if (args[0] == "/h" | args[0] == "/?")
            {
                showhelp();
            }
            if (args.Length > 1)
            {
                if (args[1] == "/?")
                {
                    showcommandhelp(args[0]);
                }
            }
            #endregion

            #region WOL - Wake-On-Lan
            if (args[0] == "/WOL")
            {
                SonyAPI_Lib.SonyDevice device = mySonyLib.Locator.DeviceLoad(args[1]);
                device.WOL();
            }
            #endregion

            #region /b - Build From Document
            else if (args[0] == "/b")
            {
                try
                {
                    string du = args[1];
                    string pa = args[2] + @"\";
                    SonyAPI_Lib.SonyDevice nDev = new SonyAPI_Lib.SonyDevice();
                    nDev.buildFromDocument(new Uri(du));
                    pa = pa + nDev.Name + ".xml";
                    Console.WriteLine("Saving Device: " + nDev.Name + ".xml to " + pa);
                    mySonyLib.Locator.DeviceSave(pa, nDev);
                }
                catch
                {
                    Console.WriteLine("ERROR: Incorrect parameters....");
                    showhelp();
                }
            }
            #endregion

            #region /l and /ls - Locate and Locate Save
            else if (args[0] == "/l" | args[0] == "/ls")
            {
                try
                {
                    Console.WriteLine("Locating Devices. Please wait.........");
                    List <string> fdev = mySonyLib.Locator.locateDevices();
                    Console.WriteLine("Devices Found: " + fdev.Count);
                    if (fdev.Count > 0)
                    {
                        int i = 1;
                        foreach (string d in fdev)
                        {
                            Console.WriteLine(i + ") " + d);
                            i = i + 1;
                        }
                    }
                    else
                    {
                        Console.WriteLine("NO Devices Found");
                        System.Environment.Exit(0);
                    }
                    if (args[0] == "/ls")
                    {
                        foreach (string dv in fdev)
                        {
                            string pa = args[2] + @"\";
                            SonyAPI_Lib.SonyDevice nDev = new SonyAPI_Lib.SonyDevice();
                            nDev.buildFromDocument(new Uri(dv));
                            pa = pa + nDev.Name + ".xml";
                            Console.WriteLine("Saving Device: " + nDev.Name + ".xml to " + pa);
                            mySonyLib.Locator.DeviceSave(pa, nDev);
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("ERROR: Incorrect parameters....");
                    showhelp();
                }
            }
            #endregion

            #region /r - Register
            else if (args[0] == "/r")
            {
                if (args.Length > 1)
                {
                    string devFile = "";
                    devFile = args[1];
                    SonyAPI_Lib.SonyDevice device = mySonyLib.Locator.DeviceLoad(devFile);
                    bool mySonyReg = false;
                    if (device.Registered == false)
                    {
                        Console.WriteLine(device.Name + ": Performing Registration....");
                        Console.WriteLine("Before continuing, you may need to set the device to Registration Mode,");
                        Console.WriteLine("Confirm Registration or enter the Registration PIN code.");
                        Console.WriteLine("Go to the device and perfrom any step, or be ready to before hitting enter below!");
                        Console.WriteLine("=====================================");
                        Console.WriteLine("Hit enter to Continue....");
                        string c = Console.ReadLine();
                        mySonyReg = device.register();
                        if (device.Registered == false)
                        {
                            if (device.Actionlist.RegisterMode == 3)
                            {
                                string ckii;
                                Console.WriteLine("Enter PIN Code.");
                                ckii = Console.ReadLine();
                                Console.WriteLine("Sending Authitication PIN Code.");
                                mySonyReg = device.sendAuth(ckii);
                            }
                        }
                    }
                    else
                    {
                        mySonyReg = true;
                    }
                    mySonyLib.Locator.DeviceSave(devFile, device);
                }
                else
                {
                    Console.WriteLine("ERROR: missing parameters....");
                    showhelp();
                }
            }
            #endregion

            #region /a - Action
            else if (args[0] == "/a")
            {
                if (args.Length > 4)
                {
                    string devFile    = "";
                    string devService = "";
                    string devAction  = "";
                    string devP       = "";
                    string devP2      = "";
                    devFile    = args[1];
                    devService = args[2];
                    devAction  = args[3];
                    devP       = args[4];
                    SonyAPI_Lib.SonyDevice device = mySonyLib.Locator.DeviceLoad(devFile);
                    if (devService == "IRCC")
                    {
                        if (devAction == "XSendIRCC")
                        {
                            mySonyLib.ircc1.XSendIRCC(device, devP);
                        }
                    }
                    else if (devService == "AVTransport")
                    {
                        if (devAction == "SetAVTransportURI")
                        {
                            if (args.Length > 5)
                            {
                                if (args[5] != "/log")
                                {
                                    devP2 = args[5];
                                }
                                else
                                {
                                    devP2 = null;
                                }
                            }
                            else
                            {
                                devP = null;
                            }
                            mySonyLib.avtransport1.SetAVTransportURI(device, devP, devP2);
                        }
                        if (devAction == "SetNextAVTransportURI")
                        {
                            if (args.Length > 5)
                            {
                                if (args[5] != "/log")
                                {
                                    devP2 = args[5];
                                }
                                else
                                {
                                    devP2 = null;
                                }
                            }
                            else
                            {
                                devP2 = null;
                            }
                            mySonyLib.avtransport1.SetNextAVTransportURI(device, devP, devP2);
                        }
                        if (devAction == "Play")
                        {
                            mySonyLib.avtransport1.Play(device, Convert.ToInt32(devP));
                        }
                        if (devAction == "Stop")
                        {
                            mySonyLib.avtransport1.Stop(device);
                        }
                        if (devAction == "Pause")
                        {
                            mySonyLib.avtransport1.Pause(device);
                        }
                        if (devAction == "Next")
                        {
                            mySonyLib.avtransport1.Next(device);
                        }
                        if (devAction == "Previous")
                        {
                            mySonyLib.avtransport1.Previous(device);
                        }
                    }
                    else if (devService == "ConnectionManager")
                    {
                    }
                    else if (devService == "RenderingControl")
                    {
                        if (devAction == "SetMute")
                        {
                            Boolean p1 = false;
                            if (devP == "true" | devP == "True")
                            {
                                p1 = true;
                            }
                            mySonyLib.renderingcontrol1.SetMute(device, p1);
                        }
                        if (devAction == "SetVolume")
                        {
                            int p1 = 0;
                            p1 = Convert.ToInt32(devP);
                            mySonyLib.renderingcontrol1.SetVolume(device, p1);
                        }
                    }
                    else if (devService == "Party")
                    {
                    }
                }
                else
                {
                    Console.WriteLine("ERROR: missing parameters....");
                    showhelp();
                }
            }
            #endregion
        }