コード例 #1
0
        public static HttpStatusCode replaceCurrentDevice(TeamviewerRootObject oldDevice, string _newAlias, string _description)
        {
            HttpWebRequest request = WebRequest.Create(apiAddress + "/" + oldDevice.Devices[0].deviceID) as HttpWebRequest;

            request.Headers.Set("Authorization", "Bearer " + accessToken);
            request.ContentType = "application/json";
            request.Method      = CallType.DELETE.ToString();

            HttpWebResponse response = null;

            try
            {
                //create a request to get
                response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode == HttpStatusCode.NoContent)
                {
                    var addDeviceResponse = addCurrentDevice(_newAlias, _description, oldDevice.Devices[0].remoteID);
                    return(addDeviceResponse.Item1);
                }
            }
            catch (WebException ex)
            {
                Console.WriteLine("Error getting response : " + ex.Message);
            }

            return(response.StatusCode);
        }
コード例 #2
0
 //when a list of devices is returned, iterate through the list and display it to the user.
 static void ShowDevices(TeamviewerRootObject deviceList)
 {
     for (int i = 0; i <= deviceList.Devices.Count - 1; i++)
     {
         Console.WriteLine("Device # " + (i + 1) + ":");
         Console.WriteLine("Name: " + deviceList.Devices[i].alias);
         Console.WriteLine("Group ID: " + deviceList.Devices[i].groupid);
         Console.WriteLine("Remote ID: " + deviceList.Devices[i].remoteID);
         Console.WriteLine("Device ID: " + deviceList.Devices[i].deviceID);
         Console.WriteLine("Status : " + deviceList.Devices[i].online_state);
         Console.WriteLine("\n\n");
     }
 }
コード例 #3
0
        public static Tuple <HttpStatusCode, TeamviewerRootObject> addCurrentDevice(string _alias, string _description, string clientID)
        {
            //check to see if the device already exists on the account.
            TeamviewerRootObject deviceQuery = getDevices("?remotecontrol_id=" + clientID);

            if (deviceQuery.Devices.Exists(x => x.remoteID == clientID))
            {
                return(Tuple.Create(HttpStatusCode.NotAcceptable, deviceQuery)); //return a status code other than OK to handle later.
            }

            HttpWebRequest request = WebRequest.Create(apiAddress) as HttpWebRequest;

            request.Headers.Set("Authorization", "Bearer " + accessToken);
            request.ContentType = "application/json";
            var postData = new TeamviewerDevice
            {
                remoteID    = clientID,
                groupid     = _groupID, // add your group id here.
                description = _description,
                alias       = _alias
            };

            string postToJson = JsonConvert.SerializeObject(postData);

            request.Method = CallType.POST.ToString();
            try
            {
                using (var postStream = new StreamWriter(request.GetRequestStream()))
                {
                    postStream.Write(postToJson);
                    postStream.Flush();
                    postStream.Close();
                }

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                return(Tuple.Create(response.StatusCode, deviceQuery));
            }
            catch (WebException ex)
            {
                Console.WriteLine(ex.Message);
                return(Tuple.Create(HttpStatusCode.Conflict, deviceQuery));
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            TeamviewerRootObject _deviceList = null;

            Console.WriteLine("Gathering System Information, please wait...");

            //get the remote control id of the client's computer
            string _clientID = "r" + getClientRemoteID();

            System.Threading.Thread.Sleep(1500);
            Console.Clear();

            //user enters information as they would like it seen on their TV contact list.
            Console.WriteLine("Enter the name of the computer as you want it seen on your Teamviewer contact list");
            string _alias = Console.ReadLine();

            Console.WriteLine("(optional) enter the description of the computer as you want it seen on your contact list");
            string _desc = Console.ReadLine();

            Console.Clear();
            Console.WriteLine("Please Wait....");

            Tuple <HttpStatusCode, TeamviewerRootObject> addDeviceResult = TeamviewerAPI.addCurrentDevice(_alias, _desc, _clientID);

            //make the call to the api to add the device, return the status code and act accordingly.
            if (addDeviceResult.Item1 == HttpStatusCode.OK)
            {
                Console.WriteLine("Please wait while your devices are retrieved.");
                _deviceList = TeamviewerAPI.getDevices();
                Console.Clear();
                Console.WriteLine("-----TEAMVIEWER DEVICES ON ACCOUNT --------");
                ShowDevices(_deviceList);
            }
            else if (addDeviceResult.Item1 == HttpStatusCode.NotAcceptable) //this is returned if the device already exists.
            {
                Console.WriteLine("This device already exists as a contact on your list as : " + addDeviceResult.Item2.Devices[0].alias);
                Console.WriteLine("Would you like to replace this with the computer name you entered? (Y/N)");
                string response = Console.ReadLine();

                if (response.ToLower() == "y")
                {
                    Console.WriteLine("Please wait while your computer is renamed on your contact list...");
                    HttpStatusCode replacementStatus = TeamviewerAPI.replaceCurrentDevice(addDeviceResult.Item2, _alias, _desc);
                    if (replacementStatus == HttpStatusCode.OK)
                    {
                        Console.WriteLine("Done!");
                    }
                }
                else
                {
                    Console.WriteLine("Okay. The device has not been changed.");
                }
                Console.WriteLine("Please press any key to continue...");
            }
            else
            {
                Console.WriteLine("There was a problem trying to get your device added to your contact list!");
            }

            Console.ReadKey();
        }