private void Data_sender_do_work(object sender, DoWorkEventArgs e) { string Network_Traffic_String = null; HTTP_web_request = (HttpWebRequest)WebRequest.Create(IP_address); if (First_send == true) { First_send = false; } byte[] Data_sender_data; string Data_sender_post_string = null; Data_sender_post_string += "secret=" + Properties.Settings.Default.Secret_key; Data_sender_post_string += "&petname=" + Properties.Settings.Default.Server_petname; Data_sender_post_string += "&email=" + Properties.Settings.Default.Contact_e_mail; Data_sender_post_string += "&agent_version=" + System.Windows.Forms.Application.ProductVersion; Data_sender_post_string += "&company=" + Properties.Settings.Default.Company_name; Data_sender_post_string += "&host=" + Properties.Settings.Default.Server_host; Data_sender_post_string += "&cpu=" + To_Base_64("{\"cpu_used\": " + Fix_decimal_point(CPU_last_value) + ", \"cpu_user\": 0, \"cpu_system\": " + Fix_decimal_point(CPU_last_value) + ", \"cpu_free\": " + Fix_decimal_point(100-CPU_last_value) + "}"); Data_sender_post_string += "&server_uptime=" + Format_time(Get_server_uptime()); Data_sender_post_string += "&memory=" + To_Base_64("{\"mem_used\": "+Fix_decimal_point(RAM_last_value)+", \"mem_user\": 0, \"mem_system\": "+Fix_decimal_point(RAM_last_value)+", \"mem_free\": "+Fix_decimal_point(100-RAM_last_value)+"}"); Data_sender_post_string += "&loadavg=" + To_Base_64("{\"load_one\": 0, \"load_five\": 0, \"load_fifteen\": 0}"); Data_sender_post_string += "&OS=" + To_Base_64("{\"version\": (\"" + Operation_system_version + "\",\"" + Operation_system_architecture + "\"),\"cpu_cores\": " + CPU_cores + ",\"machine\": \"" + CPU_architecture + "\",\"processor\": \"" + CPU_type + "\",\"platform\": \"" + Platform + "\"}"); Data_sender_post_string += "&windows_info=" + To_Base_64("{\"battery_status\": " + Battery_status + ", \"design_capacity\": " + Design_capacity + ", \"estimated_charge_remaining\": " + Battery_power_percent + ",\"estimated_run_time\": " + Estimated_run_time + ",\"full_charge_capacity\": " + Full_charge_capacity + ",\"time_on_battery\": " + Time_on_battery + ",\"time_to_full_charge\": " + Time_to_full_charge + "}"); Network_Traffic_String += "{"; for (uint Instances_count = 0; Instances_count < Network_instances.Length; Instances_count++) { if (Network_Download_Last_values.Count > 0 && Network_Upload_Last_values.Count > 0) { try { Network_Traffic_String += "'en" + Instances_count + "': (" + (uint)Network_Download_Last_values[(int)Instances_count] + ", " + (uint)Network_Upload_Last_values[(int)Instances_count] + "), "; } catch { Network_Traffic_String += "'en0': (0, 0), "; }; } else { Network_Traffic_String += "'en" + Instances_count + "': (0, 0), "; } } Network_Traffic_String += "'all': (" + (uint)Network_Download_Last_value_all + ", " + (uint)Network_Upload_Last_value_all + ")}"; Data_sender_post_string += "&networktraffic=" + To_Base_64(Network_Traffic_String); Data_sender_data = Encoding.UTF8.GetBytes(Data_sender_post_string); HTTP_web_request.Method = "POST"; HTTP_web_request.ContentType = "application/x-www-form-urlencoded"; HTTP_web_request.ContentLength = Data_sender_data.Length; try { Stream Data_sender_stream = HTTP_web_request.GetRequestStream(); Data_sender_stream.Write(Data_sender_data, 0, Data_sender_data.Length); Data_sender_stream.Close(); using (WebResponse Data_sender_response = HTTP_web_request.GetResponse()) { Data_sender_stream = Data_sender_response.GetResponseStream(); StreamReader Data_sender_stream_reader = new StreamReader(Data_sender_stream); string Data_sender_response_from_server = Data_sender_stream_reader.ReadToEnd(); switch (Data_sender_response_from_server) { case "streaming off": if (!Timer_Streaming_Timeout.IsEnabled) { Streaming = Streaming_enum.Off; Debug.WriteLine("Timer is not running"); Debug.WriteLine("OFF"); } else { Debug.WriteLine("Timer is running"); } break; case "streaming on": if (!Timer_Streaming_Timeout.IsEnabled) { Streaming = Streaming_enum.On; Debug.WriteLine("Timer is not running"); Debug.WriteLine("ON"); } else { Debug.WriteLine("Timer is running"); } break; case "stop": Sending_toggle(); break; //case "update": //Form updater_form = new Updater(); //SendingToggle(true); //updater_form.ShowDialog(); //Process.Start("Cloudiff updater.exe"); //break; } Data_sender_stream_reader.Close(); Data_sender_stream.Close(); Data_sender_response.Close(); } } catch (Exception Exception) { } Sending_count++; }
private void Streaming_toggle(string Value) { switch (Value) { case "on": Streaming = Streaming_enum.On; Timer_sender_interval = 2; Label_streaming_status.Content = "Streaming ON"; Image_Streaming.Source = ImageSource_from_file("Streaming ON.png"); Image_Streaming_StatusBar.Source = ImageSource_from_file("Streaming ON.png"); break; case "off": Streaming = Streaming_enum.Off; Timer_sender_interval = 15; Label_streaming_status.Content = "Streaming OFF"; Image_Streaming.Source = ImageSource_from_file("Streaming OFF.png"); Image_Streaming_StatusBar.Source = ImageSource_from_file("Streaming OFF.png"); break; } Timer_sender.Interval = new TimeSpan(0, 0, (int)Timer_sender_interval); }