public static void fncScreenShot() { try { if (GlobalClass.CheckForInternetConnection()) { using (HttpClient client = MachineInfoTracker.GetHttpClient()) { using (var content = new MultipartFormDataContent("---------------------------" + DateTime.Now.Ticks.ToString("x"))) { //Take Screen Shot string activeWindowTitle = GetActiveWindowTitle(); Bitmap img = screenCapture(); var imageFile = new ByteArrayContent(ImageToByte2(img)); // Add file content if (activeWindowTitle != OldTitle && !string.IsNullOrEmpty(activeWindowTitle)) { OldTitle = activeWindowTitle; imageFile.Headers.ContentType = MediaTypeHeaderValue.Parse("image/png"); imageFile.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".png" }; content.Add(imageFile); // Add file content content.Add(new StringContent(Program.MachineId.ToString()), name: "MachineId"); content.Add(new StringContent(MachineInfoTracker.GetUserName()), name: "UserName"); // Make a call to Web API var result = client.PostAsync("api/LiveMonitoringAPI/UploadFiles", content).Result; if (result.StatusCode.ToString() != "OK") { Console.WriteLine(result.StatusCode); GlobalClass.WriteTolog("Save new Screen Shot on server"); } } } } } else { GlobalClass.WriteTolog("server not giving any response in ScreenShot function"); } } catch (Exception ex) { Console.WriteLine("Error In ScreenShot.cs in fncScreenShot Fuction " + ex.Message); GlobalClass.WriteTolog("Error In ScreenShot.cs in fncScreenShot Fuction " + ex.Message); } }
public static void AddMachineInfo() { if (GlobalClass.CheckForInternetConnection()) { try { using (HttpClient client = MachineInfoTracker.GetHttpClient()) { string strMachineName = MachineInfoTracker.GetMachineName(); string strMachineIP = MachineInfoTracker.GetPrimaryAdapterDetails().AdapterIP; string strUserName = MachineInfoTracker.GetUserName(); string strMACAddress = MachineInfoTracker.GetPrimaryAdapterDetails().AdapterMacAddress; int customerID = Constants.CustomerId; MachineDetail model = new MachineDetail { MachineName = strMachineName, CustomerId = customerID, MachineMacAddress = strMACAddress, MachineIP = strMachineIP, UserName = strUserName, CreatedDate = DateTime.Now }; HttpResponseMessage Response = client.PostAsync <MachineDetail>("api/LiveMonitoringAPI/AddMachineDetails", model, new JsonMediaTypeFormatter()).Result; if (Response.IsSuccessStatusCode == true) { var machineID = Response.Content.ReadAsStringAsync().Result; machineID = machineID.Replace("\"", string.Empty).Trim(); string[] result = machineID.Split('_'); MachineId = Convert.ToInt16(result[0]); IsBlocked = Convert.ToBoolean(result[1].ToString()); } else if (Response != null && Response.IsSuccessStatusCode == false) { var result = Response.Content.ReadAsStringAsync().Result; Console.Write("Error Message - " + result); GlobalClass.WriteTolog("Error Message - " + result); } } } catch (Exception ex) { Console.WriteLine("Error In Program.cs in AddMachineInfo Fuction " + ex.Message); GlobalClass.WriteTolog("Error In Program.cs in AddMachineInfo Fuction " + ex.Message); } } else { GlobalClass.WriteTolog("server not giving any response in AddMachineInfo function"); } }