Beispiel #1
0
 private void Buildbut_Click(object sender, EventArgs e)
 {
     dataGridView1.Refresh();
     if (dataGridView1.Rows.Count > 0)
     {
         foreach (DataGridViewRow r in dataGridView1.Rows)
         {
             if (r.Cells[3].Value != null)
             {
                 if (r.Cells[0].Value == null)
                 {
                     APILibrary.SonyDevice nDev = new APILibrary.SonyDevice();
                     if (r.Cells[3].Value != null)
                     {
                         nDev.DocumentUrl = r.Cells[3].Value.ToString();
                         nDev.BuildFromDocument(new Uri(r.Cells[3].Value.ToString()));
                         r.Cells[0].Value = nDev.Name;
                         r.Cells[1].Value = nDev.IPAddress;
                         r.Cells[2].Value = nDev.Actionlist.RegisterMode;
                         Program.fDev.Add(nDev);
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 private void devList_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (fDev.Count > 0)
     {
         curDev = fDev[devList.SelectedIndex];
         UpdateLog(LogPath.Text, LogName.Text);
         UpdateDevice();
     }
 }
Beispiel #3
0
        private void Device_SelectedIndexChanged(object sender, EventArgs e)

        {

            curDev = Program.fDev[Device.SelectedIndex];

            showDevice(curDev);

            this.Refresh();

        }
Beispiel #4
0
        private void showDevice(APILibrary.SonyDevice cDev)
        {
            devName.Text           = cDev.Name;
            devIP.Text             = cDev.IPAddress;
            devPort.Text           = cDev.Port.ToString();
            devMac.Text            = cDev.MacAddress;
            devGen.Text            = cDev.Actionlist.RegisterMode.ToString();
            devCommands.Text       = cDev.Commands.Count().ToString();
            devSName.Text          = cDev.ServerName;
            devSMac.Text           = cDev.ServerMacAddress;
            devReg.Text            = cDev.Registered.ToString();
            Commands.DataSource    = cDev.Commands;
            Commands.DisplayMember = "Name";
            Commands.ValueMember   = "Name";
            string hCH = curDev.GetCommandString("ChannelUp");

            if (hCH != "")
            {
                devType           = "TV";
                pictureBox1.Image = Sony_Forms_Example.Properties.Resources.TV_icon1;
                ChanUp.Visible    = true;
                ChanDown.Visible  = true;
                Chanlabel.Visible = true;
                Guide.Visible     = true;
                Yellow.Visible    = true;
                Red.Visible       = true;
                Blue.Visible      = true;
                Green.Visible     = true;
            }
            else
            {
                devType           = "other";
                pictureBox1.Image = Sony_Forms_Example.Properties.Resources.Stereo_Icon;
                ChanUp.Visible    = false;
                ChanDown.Visible  = false;
                Chanlabel.Visible = false;
                Guide.Visible     = false;
                Yellow.Visible    = false;
                Red.Visible       = false;
                Blue.Visible      = false;
                Green.Visible     = false;
            }
            if (curDev.Registered == true)
            {
                regButton.Visible = false;
            }
            else
            {
                regButton.Visible = true;
            }
            this.Refresh();
        }
Beispiel #5
0
        private void Load_but_Click(object sender, EventArgs e)
        {
            APILibrary.SonyDevice sDev = new APILibrary.SonyDevice();
            DataGridViewRow       ro   = dataGridView1.CurrentRow;
            OpenFileDialog        ofd  = new OpenFileDialog();

            ofd.Filter           = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            ofd.FilterIndex      = 1;
            ofd.InitialDirectory = Application.StartupPath;
            ofd.RestoreDirectory = true;
            DataGridViewRow nr = new DataGridViewRow();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //deserialize
                string fpth = ofd.FileName;
                sDev = Program.mySonyLib.Locator.DeviceLoad(fpth);
                ofd.Dispose();
                dataGridView1.Refresh();
                if (dataGridView1.Rows.Count < 1)
                {
                    dataGridView1.Rows.Insert(0, 1);
                    nr = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                    dataGridView1.Rows.RemoveAt(0);
                }
                else
                {
                    nr = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                }
                nr.Cells[0].Value = sDev.Name;
                nr.Cells[1].Value = sDev.IPAddress;
                nr.Cells[2].Value = sDev.Actionlist.RegisterMode;
                nr.Cells[3].Value = sDev.DocumentUrl;
                dataGridView1.Rows.Add(nr);
                dataGridView1.Refresh();
                Program.fDev.Add(sDev);
            }
            if (dataGridView1.Rows.Count > 0)
            {
                Delete_But.Enabled = true;
                Save_but.Enabled   = true;
                OK_but.Enabled     = true;
            }
            else
            {
                Delete_But.Enabled = false;;
                Save_but.Enabled   = false;;
                OK_but.Enabled     = false;
            }
        }
Beispiel #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <string> fDevices = Program.mySonyLib.Locator.LocateDevices();

            if (fDevices.Count > 0)
            {
                foreach (string doc in fDevices)
                {
                    APILibrary.SonyDevice nDev = new APILibrary.SonyDevice();
                    nDev.DocumentUrl = doc;
                    nDev.BuildFromDocument(new Uri(nDev.DocumentUrl));
                    Program.fDev.Add(nDev);
                }
                Form dRemote = new Form3();
                dRemote.ShowDialog();
            }
            else
            {
                MessageBox.Show("No Devices were found!", "No Devices", MessageBoxButtons.OK);
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            mySonyLib.Log.Enable           = true;
            mySonyDevice                   = mySonyLib.Locator.DeviceLoad(@"C:\myDevices\STR-DN840.xml");
            myEventServer.IpAddress        = "192.168.0.2";
            myEventServer.Port             = 8080;
            myEventServer.CallBackUrl      = @"http://192.168.0.2:" + myEventServer.Port;
            myEventServer.PropertyChanged += EventServerOnChange;
            myEventServer.Start();

            while (true)
            {
                Console.WriteLine("Enter the command to send and hit Enter.");
                Console.WriteLine("Or type ‘End’ and hit Enter to Quit.");
                string cki = Console.ReadLine();

                if (cki == "End")
                {
                    ShutDown(myEventServer);
                }
                else if (cki == "Sub")
                {
                    myEventServer.SubscribeToEvents(mySonyDevice, mySonyDevice.RenderingControl.ServiceIdentifier, 1800);
                }
                else if (cki == "Resub")
                {
                    myEventServer.ReSubscribeToEvents(mySonyDevice.Name, mySonyDevice.RenderingControl.ServiceIdentifier);
                }
                else if (cki == "Unsub")
                {
                    myEventServer.UnSubscribeToEvents(mySonyDevice.Name, mySonyDevice.RenderingControl.ServiceIdentifier);
                }
                else
                {
                    string results = mySonyDevice.Ircc.SendIRCC(mySonyDevice, mySonyDevice.GetCommandString(cki));
                }
            }
        }
Beispiel #8
0
        private void LoadBut_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            ofd.FilterIndex      = 1;
            ofd.InitialDirectory = Application.StartupPath;
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                ShowWait1();
                //deserialize
                string fpth = ofd.FileName;
                curDev = mySonyLib.Locator.DeviceLoad(fpth);
                ofd.Dispose();
                fDev.Add(curDev);
                UpdateLog(LogPath.Text, LogName.Text);
                UpdateDevice();
                UpdateDeviceList();
                SaveBut.Enabled = true;
                HideWait1();
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            APILibrary mySonyLib = new APILibrary();                       // Create an Instance of the Library

            mySonyLib.Log.Enable = false;                                  // Set to NO logging
            APILibrary.SonyDevice mySonyDev = new APILibrary.SonyDevice(); // Create a new instance of a Device Object

            // Now there are 2 ways you can complete the next part.
            // You can build the Device from the Device's Description Document

            // Like This:
            //mySonyDev.buildFromDocument(new Uri("http://192.168.0.100:52323/dmr.xml"));

            //Or, if you have created a Device File, then you can load and use it.
            //This is the prefered method, as it would be the fastest.

            //Like This:
            mySonyDev = mySonyLib.Locator.DeviceLoad(@"c:\MyDevices\Bravia55.xml");

            string cmd = mySonyDev.GetCommandString("PowerOff");      //Get the Command String value
            //string results = mySonyLib.Ircc.SendIRCC(mySonyDev, cmd);  //Send Command Value to device using the IRCC:1 Service
            string results = mySonyDev.Ircc.SendIRCC(mySonyDev, cmd); //Send Command Value to device using the IRCC:1 Service
        }
Beispiel #10
0
 private void Save_but_Click(object sender, EventArgs e)
 {
     dataGridView1.Refresh();
     APILibrary.SonyDevice sDev = new APILibrary.SonyDevice();
     if (dataGridView1.Rows.Count > 0)
     {
         DataGridViewRow ro = dataGridView1.CurrentRow;
         if (Program.fDev.Count > 0)
         {
             sDev = Program.fDev[ro.Index];
             SaveFileDialog sfd = new SaveFileDialog();
             sfd.Filter           = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
             sfd.FilterIndex      = 1;
             sfd.InitialDirectory = Application.StartupPath;
             sfd.RestoreDirectory = true;
             sfd.FileName         = sDev.Name + ".xml";
             if (sfd.ShowDialog() == DialogResult.OK)
             {
                 string fpth = sfd.FileName;
                 sfd.Dispose();
                 try
                 {
                     Program.mySonyLib.Locator.DeviceSave(fpth, sDev);
                 }
                 catch
                 {
                     MessageBox.Show("Error. File Not Saved!", "File Error", MessageBoxButtons.OK);
                 }
             }
         }
         else
         {
             MessageBox.Show("Error. No Device to Save!", "File Error", MessageBoxButtons.OK);
         }
     }
 }
Beispiel #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("SonyAPILib v5.3 by: Kirk Herron");
            Console.WriteLine("Starting Console Example Program");
            Console.WriteLine("================================");

            // 1st we create a new instance of the SonyAPILib
            APILibrary mySonyLib = new APILibrary();

            // Now create new instances of the UPnP/DLNA services
            //SonyAPI_Lib.IRCC1 ircc1 = new SonyAPI_Lib.IRCC1();  // Only required if you plan to use this service
            //SonyAPI_Lib.AVTransport1 avtransport1 = new SonyAPI_Lib.AVTransport1(); // Only required if you plan to use this service
            //SonyAPI_Lib.ConnectionManager1 connectionmanager1 = new SonyAPI_Lib.ConnectionManager1(); // Only required if you plan to use this service
            //SonyAPI_Lib.RenderingControl1 renderingcontrol1 = new SonyAPI_Lib.RenderingControl1(); // Only required if you plan to use this service
            //SonyAPI_Lib.Party1 party1 = new SonyAPI_Lib.Party1(); // Only required if you plan to use this service

            #region Set Logging
            // Next Set the API logging information.
            // Enable Logging: default is set to FALSE.
            mySonyLib.Log.Enable = true;

            // Set Logging Level.
            // Set to "Basic" to only Log Minimum information
            // Set to "All" for all Logging information
            // Default is set to "Basic"
            mySonyLib.Log.Level = "All";

            // Set where the logging file will be saved.
            // Folder will be created if it does not exist!
            // Set to Null to use Default
            // Default is set to C:\ProgramData\Sony
            mySonyLib.Log.Path = null;

            // Set the name of the Logging file.
            // Default is set to SonyAPILib_LOG.txt
            mySonyLib.Log.Name = "SonyAPILib_LOG.txt";

            // Clears the existing log file and starts a new one
            // Send Null as the param to just clear the file and start a new one
            // Enter a new File name as the param, and log file will be copied to new name before it is cleared.
            // Example: mySonyLib.LOG.clearlog(datestamp + "_Old_Sony_Log_File.txt");
            mySonyLib.Log.ClearLog(null);
            #endregion

            #region Device Locator
            // Perform a Discovery to find all/any compatiable devices on the LAN.
            // Returns a list of all Devices found through the UPnP Broadcast
            // Return value is a list containg the Description.xml file for each Device object discovered.
            // Each returned object will contain the full URL to the devices Description.xml file

            Console.WriteLine("Searching for Devices...");
            List <string> foundDevices = mySonyLib.Locator.LocateDevices();
            #endregion

            // foundDevices.Count will return the number of devices found
            #region Console Output
            Console.WriteLine("Device Count: " + foundDevices.Count);
            Console.WriteLine("---------------------------------");
            int i = 0;
            foreach (string fd in foundDevices)
            {
                Console.WriteLine(i + " - " + fd.ToString());
                i = i + 1;
            }
            Console.WriteLine("---------------------------------");
            #endregion

            // TODO: Here you can perform task or other code as to which device to select or use.
            // You could also do a For Next loop and go through each one.
            // Or save the Description.xml URL for later use!

            // This example makes sure that there is at least one object returned in the list, if not then it will Exit.
            if (foundDevices.Count > 0)
            {
                // Allow User to select from the devices found which one to test
                Console.WriteLine("Enter the Device # to Test");
                string cki;
                cki = Console.ReadLine();

                // 1st create a new Device Object
                APILibrary.SonyDevice mySonyDevice = new APILibrary.SonyDevice();

                // Here you can save the device information to a database or text file.
                // This will allow you to Initialize a device WITHOUT having to run the sonyDiscover() method every time.
                // Once you have discovered the devices, saving their information will speed up your application the next time you run it!

                // You can Initialize a device with only the following minimimal information:
                //     1) The Device Name - MUST Match what the device returns as it's name. (selDev.Name)
                //     2) The IP address of the device. (selDev.Device_IP_Address)

                // Now we build the new sonyDevice object with the selected device above.
                #region Build Device from Description.xml file
                // The buildFromDocument() method will retrieve the devices Description file, and build/populate the device object.

                // From above, selDev or each item in the list foundDevices[] is a SonyDevice object.

                // To build the device with the default information retrieved from locateDevices, use the following method:
                // mySonyDevice.DocumentURL = foundDevices[0].ToString(); or set the array to the device you want.
                // mySonyDevice.buildFromDocument(new Uri(mySonyDevice.DocumentURL));

                // This example will use the first method to initialize the device chosen by the user.
                Console.WriteLine("");
                Console.WriteLine(foundDevices[Convert.ToInt16(cki)].ToString() + ": Building Device....");

                // Set the devices DocumentUrl property first
                mySonyDevice.DocumentUrl = foundDevices[Convert.ToInt16(cki)].ToString();

                // Then build the device from the document
                mySonyDevice.BuildFromDocument(new Uri(mySonyDevice.DocumentUrl));

                #endregion

                // Next we will check the status of the device.
                #region Check Status

                //The following will return the current status of the device
                //The value returned is: status_name:value
                //An example would be: viewing:TV
                //An emplty string "" will be returned if there is no response from the device. This could also mean the device is off.
                //Also, this method requires the device to be registered on Generation 1 and 2 devices.
                Console.WriteLine(mySonyDevice.Name + ": Checking Device Status....");
                // Without a response: mySonyLib.ircc1.XGetStatus(mySonyDevice);
                string status = mySonyDevice.Ircc.GetStatus(mySonyDevice);
                // Use the Device State Variable: if (mySonyDevice.Ircc.CurrentStatus == "" | mySonyDevice.Ircc.CurrentStatus == null)
                if (status == "" | status == null)
                {
                    // NO Response!!
                }
                else
                {
                    #region Console Output
                    Console.WriteLine("");
                    Console.WriteLine("Get Status returned: " + status);
                    Console.WriteLine("---------------------------------");
                    Console.WriteLine("");
                    #endregion
                }

                #endregion

                // Now we must register with the device
                #region register

                bool mySonyReg = false;

                // first check to see if the Build process determined the registration value.
                if (mySonyDevice.Registered == false)
                {
                    Console.WriteLine(mySonyDevice.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, and be ready before hitting enter below!");
                    Console.WriteLine("=====================================");
                    Console.WriteLine("Hit any key to continue");
                    Console.ReadKey();
                    // The next method is very IMPORTANT.

                    // YOU MUST RUN THE FOLLOWING METHOD AND RECEIVE A SUCCESSFUL RETURN at least ONCE!
                    // Before you can send any IRCC commands or receive and data back from the device!

                    // The very first time this is executed, you will need to be at your device (TV, Blue Ray)
                    // to confim the registration. Also, some devices (Blue Ray, Home Theater Tuners) require you to put
                    // the device in to "Registration" mode, before you try to register this application as
                    // a controlling device. (Registration uses the MAC address of the computer/device trying
                    //to gain control). If installed on more than 1 computer, each one will require registration.

                    // Register as Controller
                    // Returns true if successful
                    // Returns false if not successful

                    mySonyReg = mySonyDevice.Register();

                    // Check if register returned false
                    if (mySonyDevice.Registered == false)
                    {
                        //Check if Generaton 4. If yes, prompt for pin code
                        if (mySonyDevice.Actionlist.RegisterMode > 2)
                        {
                            string ckii;
                            Console.WriteLine("Enter PIN Code.");
                            ckii = Console.ReadLine();
                            // Send PIN code to TV to create Autorization cookie
                            Console.WriteLine("Sending Authitication PIN Code.");
                            mySonyReg = mySonyDevice.SendAuth(ckii);
                        }
                    }
                }
                else
                {
                    mySonyReg = true;
                }
                #endregion

                //TODO: Add more code in case of false, or true
                #region Console Output
                Console.WriteLine("Registration returned: " + mySonyReg.ToString());
                Console.WriteLine("---------------------------------");
                Console.WriteLine("");
                #endregion

                // This example will: If true, display device information
                #region Console Output
                if (mySonyReg)
                {
                    Console.WriteLine("Device Information");
                    Console.WriteLine("Mame: " + mySonyDevice.Name);
                    Console.WriteLine("Mac Address: " + mySonyDevice.MacAddress);
                    Console.WriteLine("IP Address: " + mySonyDevice.IPAddress);
                    Console.WriteLine("Port: " + mySonyDevice.Port);
                    Console.WriteLine("Registration Mode: " + mySonyDevice.Actionlist.RegisterMode);
                    Console.WriteLine("Registration: " + mySonyDevice.Registered.ToString());
                    Console.WriteLine("Server Name: " + mySonyDevice.ServerName);
                    Console.WriteLine("Server Mac: " + mySonyDevice.ServerMacAddress);
                    Console.WriteLine("Action List URL: " + mySonyDevice.ActionListUrl);
                    Console.WriteLine("---------------------------------");
                    Console.WriteLine("");
                }
                else
                {
                    // Display this if NOT true
                    Console.WriteLine("There was an error");
                    Console.WriteLine("---------------------------------");
                    Console.WriteLine("");
                }
                #endregion

                // Get the IRCC command list from the device so we know it's capabilities.
                #region get_remote_command_list
                // The next command is used to retrieve the IRCC command list from the device.
                // ### You must register before this method will return any data ###
                // This method will populate the Commands list in the SonyDevice object when executed.
                // This Methed also returnes a string that contains the contents of the Devices Command List XML file for your own use.
                Console.WriteLine(mySonyDevice.Name + ": Retrieving Remote Command List");
                string CmdList = mySonyDevice.GetRemoteCommandList();

                // TODO: Parse this information as your application requires.
                // convert to an XMLDocument or dataset for your own use
                #endregion

                // Checks if the list contains any data
                #region Console Output
                if (CmdList != "")
                {
                    Console.WriteLine("Retrieved Command List Successful");
                    Console.WriteLine("---------------------------------");
                    Console.WriteLine("");
                }
                else
                {
                    Console.WriteLine("ERROR Retrieving Command List");
                    Console.WriteLine("---------------------------------");
                    Console.WriteLine("");
                }
                #endregion

                // Get the IRCC command value by searching the command name
                #region GetCommandString
                // The next method is used to search for an IRCC Command String that matches the param.

                // param is a string containing the command name to search for.
                // Returns a string containing the command's value (If Successful)
                // Returns a Null if the search command is not found in the devices IRCC command list

                // This example will search for the command "VolumeUp"
                Console.WriteLine(mySonyDevice.Name + ": Retrieving Command Value for: VolumeUp");
                string irccCmd = mySonyDevice.GetCommandString("VolumeUp");

                //Check if command was found
                if (irccCmd == "")
                {
                    Console.WriteLine("Command Not Found: VolumeUp");
                }
                else
                {
                    #endregion

                    // Displays the IRCC command value retrieved
                    #region Console Output
                    // Show the IRCC_Command value found information
                    Console.WriteLine("Found Command: VolumeUp");
                    Console.WriteLine("Command Value: " + irccCmd);
                    Console.WriteLine("---------------------------------");
                    Console.WriteLine("");
                    Console.WriteLine("Now we are ready to try to send a few IRCC commands to the device");
                    Console.WriteLine("Hit any key to continue");
                    Console.ReadKey();
                }
                #endregion

                // Next are 4 examples of how you can send the IRCC commands to the device
                #region Example 1
                // This first example will send a "VolumeUp" command value to the device
                // it asumes we already know the value to send to the device.
                // We will use the Command String we retrieved above in the GetCommandString method.
                Console.WriteLine(mySonyDevice.Name + ": Sending Command Value " + irccCmd + " to device");
                string results = mySonyDevice.Ircc.SendIRCC(mySonyDevice, irccCmd);
                System.Threading.Thread.Sleep(500);  // give the device time to react before sending another command

                #region Console Output
                // Show the IRCC_Command value found information
                Console.WriteLine("Sent Command: VolumeUp:" + irccCmd);
                Console.WriteLine("Hit any key to continue");
                Console.WriteLine("---------------------------------");
                Console.ReadKey();
                #endregion
                #endregion

                #region Example 2
                // The next example will use the getIRCCcommandString("CommandName") method to get the command value for "VolumeDown".
                // Then send it to the device
                Console.WriteLine(mySonyDevice.Name + ": Sending Command VolumeDown to device");
                String mycommand = mySonyDevice.GetCommandString("VolumeDown");
                results = mySonyDevice.Ircc.SendIRCC(mySonyDevice, mycommand);
                System.Threading.Thread.Sleep(500);  // give the device time to react before sending another command

                #region Console Output
                // Show the IRCC_Command value found information
                Console.WriteLine("Sent Command: VolumeDown:" + mycommand);
                Console.WriteLine("Hit any key to continue");
                Console.WriteLine("---------------------------------");
                Console.ReadKey();
                #endregion
                #endregion

                #region Example 3
                // The next example will use a combination of both examples above for the command "VolumeUp".
                Console.WriteLine(mySonyDevice.Name + ": Sending Command VolumeUp to device again");
                mySonyDevice.Ircc.SendIRCC(mySonyDevice, mySonyDevice.GetCommandString("VolumeUp"));
                System.Threading.Thread.Sleep(500);  // give the device time to react before sending another command

                #region Console Output
                // Show the IRCC_Command value found information
                Console.WriteLine("Sent Command: VolumeUp:" + mycommand);
                Console.WriteLine("Hit any key to continue");
                Console.WriteLine("---------------------------------");
                Console.ReadKey();
                #endregion
                #endregion

                #region Example 5
                Console.WriteLine("");
                Console.WriteLine("Now You Try.");
                Console.WriteLine("Here are the Commands: Hit any key to Continue.");
                Console.WriteLine("---------------------------------");
                Console.ReadKey();
                foreach (APILibrary.SonyCommands cmd in mySonyDevice.Commands)
                {
                    Console.WriteLine(cmd.name);
                }
                Console.WriteLine("---------------------------------");
                Console.WriteLine("Enter a command from the list above.");
                cki     = Console.ReadLine();
                results = mySonyDevice.Ircc.SendIRCC(mySonyDevice, mySonyDevice.GetCommandString(cki));
                #endregion

                #region Example 6
                Console.WriteLine("---------------------------------");
                Console.WriteLine("Now, using your TV remote control, navigate to a search screen.");
                Console.WriteLine("This can be Pandora, Youtube or any search where you enter TEXT.");
                Console.WriteLine("Now, enter the text here to send.");
                cki     = Console.ReadLine();
                results = mySonyDevice.SendText(cki);
                Console.WriteLine("---------------------------------");
                #endregion

                Console.WriteLine("That's about it for now. Hit enter to Quit.");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Error: No Devices were found!");
                Console.ReadKey();
            }
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            // 1st we create a new instance of the SonyAPILib
            APILibrary mySonyLib = new APILibrary();


            #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")
            {
                APILibrary.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] + @"\";
                    APILibrary.SonyDevice nDev = new APILibrary.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] + @"\";
                            APILibrary.SonyDevice nDev = new APILibrary.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];
                    APILibrary.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];
                    APILibrary.SonyDevice device = mySonyLib.Locator.DeviceLoad(devFile);
                    if (devService == "IRCC")
                    {
                        if (devAction == "XSendIRCC")
                        {
                            device.Ircc.SendIRCC(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;
                            }
                            device.AVTransport.SetAVTransportURI(device, devP, devP2);
                        }
                        if (devAction == "SetNextAVTransportURI")
                        {
                            if (args.Length > 5)
                            {
                                if (args[5] != "/log")
                                {
                                    devP2 = args[5];
                                }
                                else
                                {
                                    devP2 = null;
                                }
                            }
                            else
                            {
                                devP2 = null;
                            }
                            device.AVTransport.SetNextAVTransportURI(device, devP, devP2);
                        }
                        if (devAction == "Play")
                        {
                            device.AVTransport.Play(device, Convert.ToInt32(devP));
                        }
                        if (devAction == "Stop")
                        {
                            device.AVTransport.Stop(device);
                        }
                        if (devAction == "Pause")
                        {
                            device.AVTransport.Pause(device);
                        }
                        if (devAction == "Next")
                        {
                            device.AVTransport.Next(device);
                        }
                        if (devAction == "Previous")
                        {
                            device.AVTransport.Previous(device);
                        }
                    }
                    else if (devService == "ConnectionManager")
                    {
                    }
                    else if (devService == "RenderingControl")
                    {
                        if (devAction == "SetMute")
                        {
                            Boolean p1 = false;
                            if (devP == "true" | devP == "True")
                            {
                                p1 = true;
                            }
                            device.RenderingControl.SetMute(device, p1);
                        }
                        if (devAction == "SetVolume")
                        {
                            int p1 = 0;
                            p1 = Convert.ToInt32(devP);
                            device.RenderingControl.SetVolume(device, p1);
                        }
                    }
                    else if (devService == "Party")
                    {
                    }
                }
                else
                {
                    Console.WriteLine("ERROR: missing parameters....");
                    showhelp();
                }
            }
            #endregion
        }