Example #1
0
        private void Update_host()
        {
            //TODO : Update Drive free spaces

            Dictionary <string, string> data_items = new Dictionary <string, string>()
            {
                { "name", Environment.MachineName }
            };

            var response = Network_Utils.Post_Request(UPDATE_HOST_URL, data_items);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                //Log_Utils.Add_system_event_and_log("aria2c_rpc", "Host update response : " + responseString, EventLogEntryType.Information);

                int error_status = Network_Utils.Check_error(Aria2_Client_Constants.EVENT_SOURCE, JObject.Parse(responseString));

                if (error_status == 0)
                {
                    Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, "Host updated successfully", EventLogEntryType.Information);
                }
                else if (error_status == 2)
                {
                    Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, "Check response, response : " + response, EventLogEntryType.Information);
                }
            }
        }
 public static string Perform(String server, String port, string method, string id, JArray requestParams, string version, String JOSN_RPC_file_name = "jsonrpc", String access_protocol = "http")
 {
     return(Network_Utils.Perform_POST(Request_Utils.get_JSON_RPC_path(server, port, JOSN_RPC_file_name, access_protocol), Request_Utils.Create_request(method, id, requestParams, version)));
 }
Example #3
0
        private void Get_Tasks()
        {
            //Console.WriteLine(Environment.MachineName + " Sync. Started...");
            //Console.WriteLine(API_Wrapper.get_API(API_Wrapper.SELECT_TASKS));
            //var get_response = http_client.Get(API_Wrapper.get_API(API_Wrapper.SELECT_TASKS), new { host = Environment.MachineName });
            //Console.WriteLine("New Tasks : " + get_response.RawText);
            //Console.ReadKey();

            Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, Environment.MachineName + " Sync. Started...", EventLogEntryType.Information);
            var response = Network_Utils.Get_Request(Network_Utils.Get_parametered_URL(API_Wrapper.get_API(Aria2_Remote_API_Constants.SELECT_TASKS), new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("host", Environment.MachineName)
            }));

            Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, "New Tasks Response : " + response.ToString(), EventLogEntryType.Information);

            //TODO : Add No Entry on Error Check

            JArray array = JArray.Parse(response);

            if ((Int32)JObject.Parse(array[0].ToString())["error_status"] == 1)
            {
                Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, "Error : " + array[0]["error"] + " - " + array[0]["error_number"], EventLogEntryType.Information);
            }
            else if ((Int32)JObject.Parse(array[0].ToString())["error_status"] == 2)
            {
                Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, "No Tasks", EventLogEntryType.Information); Console.WriteLine("");
            }
            else if ((Int32)JObject.Parse(array[0].ToString())["error_status"] == 0)
            {
                //List<Task> tasks = new List<Task>();
                //for (int i = 1; i < array.Count; i++)
                //{
                //    JObject json_Task = JObject.Parse(array[i].ToString());
                //    Task current_task = new Task();
                //    current_task.id = (String)json_Task["id"];
                //    current_task.url = (String)json_Task["url"];
                //    tasks.Add(current_task);

                //    Console.WriteLine("ID : " + current_task.id + ", Task : " + current_task.url);
                //    Console.WriteLine("Request : " + Create_json_request_addUri(current_task.url, current_task.id));
                //    //Console.ReadKey();

                //    var add_response = webClient.UploadString("http://localhost:6800/jsonrpc", "POST", Create_json_request_addUri(current_task.url, current_task.id));
                //    Console.WriteLine("Task Addition Response : " + add_response);
                //    //Console.ReadKey();

                //    JObject json_object = JObject.Parse(add_response);

                //    Update_task_gid(current_task.id, json_object["result"].ToString());
                //}

                array.RemoveAt(0);

                Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, "New Tasks : " + array.ToString(), EventLogEntryType.Information);

                //// serialize JSON results into .NET objects
                IList <Aria2_Remote_Task> aria2_tasks = new List <Aria2_Remote_Task>();
                aria2_tasks = array.ToObject <List <Aria2_Remote_Task> >();

                foreach (Aria2_Remote_Task task in aria2_tasks)
                {
                    Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, "ID : " + task.id + ", Task : " + task.url, EventLogEntryType.Information);
                    Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, "Add Uri Response : " + Methods.Add_Uri(task.url, ARIA2_HOST, ARIA2_PORT, ARIA2_JSON_RPC_FILE_NAME, ARIA2_ACCESS_PROTOCOL), EventLogEntryType.Information);
                }

                //return aria2_tasks;
            }
            else
            {
                Log_Utils.Add_system_event_and_log(Aria2_Client_Constants.EVENT_SOURCE, "Check response, response : " + response, EventLogEntryType.Information);
            }
        }