Пример #1
0
        public static void WriteMachineIdleTime(int IdleTimemin)
        {
            int IdleTimeSec = (IdleTimemin * 60);

            if (IdleTimeSec >= Program.Idle_MinTime && CheckForInternetConnection())
            {
                using (HttpClient client = MachineInfoTracker.GetHttpClient())
                {
                    MachineIdle model = new MachineIdle {
                        MachineDetailId = Program.MachineId, IdleTime = IdleTimeSec, CreatedDate = DateTime.Now
                    };
                    HttpResponseMessage Response = client.PostAsync <MachineIdle>("api/LiveMonitoringAPI/AddMachineIdleTime", model, new JsonMediaTypeFormatter()).Result;

                    if (Response.IsSuccessStatusCode == true)
                    {
                        var result = Response.Content.ReadAsStringAsync().Result;
                        if (result.Contains("OK"))
                        {
                            Console.WriteLine("Record (Idle Time is :- " + lastIdleMinute + ") saved successfully.");
                            GlobalClass.lastIdleMinute = 0;
                            GlobalClass.LastIdletime   = GlobalClass.ApplicationNowTime;
                        }
                        else if (result.Contains("Invalid"))
                        {
                            Program.AddMachineInfo();
                        }
                    }
                    else if (Response != null && Response.IsSuccessStatusCode == false)
                    {
                        var result = Response.Content.ReadAsStringAsync().Result;
                        Console.Write("Error Message - " + result);
                    }
                }
            }
        }
Пример #2
0
        static void WriteMachineIdleTime(int IdleTimeSec)
        {
            try
            {
                using (HttpClient client = MachineInfoTracker.GetHttpClient())
                {
                    MachineIdle model = new MachineIdle {
                        MachineDetailId = Program.MachineId, IdleTime = IdleTimeSec, CreatedDate = DateTime.Now
                    };
                    HttpResponseMessage Response = client.PostAsync <MachineIdle>("api/LiveMonitoringAPI/AddMachineIdleTime", model, new JsonMediaTypeFormatter()).Result;

                    if (Response.IsSuccessStatusCode == true)
                    {
                        var result = Response.Content.ReadAsStringAsync().Result;
                        if (result.Contains("OK"))
                        {
                            Console.WriteLine("Record saved successfully.");
                        }
                        else if (result.Contains("Invalid"))
                        {
                            Program.AddMachineInfo();
                        }
                    }
                    else if (Response != null && Response.IsSuccessStatusCode == false)
                    {
                        var result = Response.Content.ReadAsStringAsync().Result;
                        Console.Write("Error Message - " + result);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        public static bool InsertNewSessionEntry(DateTime StartDate, DateTime EndDate)
        {
            bool returnData = false;

            try
            {
                if (CheckForInternetConnection() && Program.MachineId > 0)
                {
                    using (HttpClient client = MachineInfoTracker.GetHttpClient())
                    {
                        MachineSession model = new MachineSession {
                            MachineDetailId = Program.MachineId, SessionStart = StartDate, SessionEnd = EndDate
                        };
                        HttpResponseMessage Response = client.PostAsync <MachineSession>("api/LiveMonitoringAPI/AddMachineSession", model, new JsonMediaTypeFormatter()).Result;

                        if (Response.IsSuccessStatusCode == true)
                        {
                            var result = Response.Content.ReadAsStringAsync().Result;
                            if (Convert.ToInt32(result) > 0)
                            {
                                // reset any value is here
                                // Console.Clear();
                                GlobalClass.RuningMachineSessionId = Convert.ToInt32(result);
                                GlobalClass.WriteTolog("Saved New Session insert entry in database" + GlobalClass.RuningMachineSessionId + "Start Time : " + StartDate.ToString("MM/dd/yyyy HH:mm") + " End Date is : " + EndDate.ToString("MM/dd/yyyy HH:mm"));
                                Console.WriteLine("Saved New Session insert entry in database" + GlobalClass.RuningMachineSessionId + "Start Time : " + StartDate.ToString("MM/dd/yyyy HH:mm") + " End Date is : " + EndDate.ToString("MM/dd/yyyy HH:mm"));
                                returnData = true;
                            }
                            else if (Convert.ToInt32(result) == 0)
                            {
                                Program.AddMachineInfo();
                                return(false);
                            }
                        }
                        else if (Response != null && Response.IsSuccessStatusCode == false)
                        {
                            var result = Response.Content.ReadAsStringAsync().Result;
                            Console.Write("Error Message - " + result);
                        }
                    }
                }
                return(returnData);
            }
            catch (Exception)
            {
                return(returnData);
            }
        }
Пример #5
0
 static void WriteBrowserData(string Title, string Url, string BrowserName, string Version)
 {
     if (GlobalClass.CheckForInternetConnection())
     {
         try
         {
             if (!(Title.Contains("New Tab") || Title.Contains("Speed Dial") || Title.Contains("\"")))
             {
                 using (HttpClient client = MachineInfoTracker.GetHttpClient())
                 {
                     BrowserDetail model = new BrowserDetail {
                         MachineDetailId = Program.MachineId, BrowserName = BrowserName, BrowserVersion = Version, Title = Title, URL = Url, CreatedDate = DateTime.Now
                     };
                     HttpResponseMessage Response = client.PostAsync <BrowserDetail>("api/LiveMonitoringAPI/AddBrowserDetails", model, new JsonMediaTypeFormatter()).Result;
                     if (Response.IsSuccessStatusCode == true)
                     {
                         var result = Response.Content.ReadAsStringAsync().Result;
                         if (result.Contains("OK"))
                         {
                             Console.WriteLine("Record saved successfully.");
                             GlobalClass.WriteTolog("Record saved successfully.");
                         }
                         else if (result.Contains("Invalid"))
                         {
                             Program.AddMachineInfo();
                         }
                     }
                     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 BrowserUrlTracker.cs in WriteBrowserData Fuction " + ex.Message);
             GlobalClass.WriteTolog("Error In BrowserUrlTracker.cs in WriteBrowserData Fuction " + ex.Message);
         }
     }
     else
     {
         GlobalClass.WriteTolog("server not giving any response");
     }
 }
Пример #6
0
        public static void addKeyLoggerInfo(string LogText, string Type)
        {
            if (LogText != "" && CheckForInternetConnection())
            {
                try
                {
                    using (HttpClient client = MachineInfoTracker.GetHttpClient())
                    {
                        KeyLogging model = new KeyLogging {
                            MachineDetailId = Program.MachineId, Text = LogText, TextType = Type, CreatedDate = DateTime.Now
                        };
                        HttpResponseMessage Response = client.PostAsync <KeyLogging>("api/LiveMonitoringAPI/AddKeyLoggings", model, new JsonMediaTypeFormatter()).Result;

                        if (Response.IsSuccessStatusCode == true)
                        {
                            var result = Response.Content.ReadAsStringAsync().Result;
                            if (result.Contains("OK"))
                            {
                                if (Type == "KL")
                                {
                                    KeyBordText = "";
                                }
                                // Console.Clear();
                                Console.WriteLine("Record (" + Type + ") saved successfully.");
                                GlobalClass.WriteTolog("Record (" + Type + ") saved successfully.");
                            }
                            else if (result.Contains("Invalid"))
                            {
                                Program.AddMachineInfo();
                            }
                        }
                        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 GlobalClass.cs in addKeyLoggerInfo Fuction " + ex.Message);
                    GlobalClass.WriteTolog("Error In GlobalClass.cs in addKeyLoggerInfo Fuction " + ex.Message);
                }
            }
        }
Пример #7
0
        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");
            }
        }
Пример #8
0
        public static bool UpdateSession(DateTime SessionEndDate, int PrimaryKey)
        {
            bool ReturnUpdate = false;

            try
            {
                if (CheckForInternetConnection() && PrimaryKey != 0)
                {
                    using (HttpClient client = MachineInfoTracker.GetHttpClient())
                    {
                        MachineSession model = new MachineSession {
                            MachineSessionId = PrimaryKey, MachineDetailId = Program.MachineId, SessionEnd = SessionEndDate, SessionStart = SessionEndDate
                        };
                        HttpResponseMessage Response = client.PostAsync <MachineSession>("api/LiveMonitoringAPI/UpdateMachineSession", model, new JsonMediaTypeFormatter()).Result;

                        if (Response.IsSuccessStatusCode == true)
                        {
                            var result = Response.Content.ReadAsStringAsync().Result;
                            if (Convert.ToInt32(result) == PrimaryKey)
                            {
                                Console.WriteLine("Update id is :- " + PrimaryKey + " and End Time Is" + SessionEndDate);
                                GlobalClass.WriteTolog("Update id is :- " + PrimaryKey + " and End Time Is" + SessionEndDate);
                                // reset any value is here
                                // Console.Clear();
                                ReturnUpdate = true;
                            }
                            else if (Convert.ToInt32(result) == 0)
                            {
                                Program.AddMachineInfo();
                            }
                        }
                        else if (Response != null && Response.IsSuccessStatusCode == false)
                        {
                            var result = Response.Content.ReadAsStringAsync().Result;
                            Console.Write("Error Message - " + result);
                        }
                    }
                }
                return(ReturnUpdate);
            }
            catch (Exception)
            {
                return(ReturnUpdate);
            }
        }
Пример #9
0
 public static void GetCofigrationSettings()
 {
     if (GlobalClass.CheckForInternetConnection())
     {
         try
         {
             using (HttpClient client = MachineInfoTracker.GetHttpClient())
             {
                 int customerID = Constants.CustomerId;
                 HttpResponseMessage Response = client.GetAsync("api/LiveMonitoringAPI/GetCofigrationSettings?customerId=" + customerID).Result;
                 if (Response.IsSuccessStatusCode == true)
                 {
                     JObject jResponse = JObject.Parse(Response.Content.ReadAsStringAsync().Result);
                     Screenshot_Interval = Convert.ToInt16(jResponse["ScreenShot_Interval"].ToString());
                     Idle_Interval       = Convert.ToInt16(jResponse["MachineIdle_Interval"].ToString());
                     KeyLogger_Interval  = Convert.ToInt16(jResponse["KeyLogger_Interval"].ToString());
                     App_Interval        = Convert.ToInt16(jResponse["AppTracker_Interval"].ToString());
                     KeyLogger_MinTime   = Convert.ToInt16(jResponse["KeyLogger_MinTime"].ToString());
                     Idle_MinTime        = Convert.ToInt16(jResponse["MachineIdle_MinTime"].ToString());
                     IsSendBlockData     = Convert.ToBoolean(jResponse["IsSendBlockData"].ToString());
                     SetallIntervalsInSeconds();
                 }
                 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 GetCofigrationSettings Fuction " + ex.Message);
             GlobalClass.WriteTolog("Error In Program.cs in GetCofigrationSettings Fuction " + ex.Message);
         }
     }
     else
     {
         GlobalClass.WriteTolog("error in GetCofigrationSettings function server not availble");
     }
 }
Пример #10
0
        private static void WriteData(string Title, string appexe)
        {
            if (GlobalClass.CheckForInternetConnection())
            {
                try
                {
                    using (HttpClient client = MachineInfoTracker.GetHttpClient())
                    {
                        AppDetail model = new AppDetail {
                            MachineDetailId = Program.MachineId, AppName = appexe, Title = Title, CreatedDate = DateTime.Now
                        };
                        HttpResponseMessage Response = client.PostAsync <AppDetail>("api/LiveMonitoringAPI/AddAppDetails", model, new JsonMediaTypeFormatter()).Result;

                        if (Response.IsSuccessStatusCode == true)
                        {
                            var result = Response.Content.ReadAsStringAsync().Result;
                            if (result.Contains("OK"))
                            {
                                Console.WriteLine("Record (AppTraker) saved successfully.");
                            }
                            else if (result.Contains("Invalid"))
                            {
                                Program.AddMachineInfo();
                            }
                        }
                        else if (Response != null && Response.IsSuccessStatusCode == false)
                        {
                            var result = Response.Content.ReadAsStringAsync().Result;
                            Console.Write("Error Message - " + result);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error In AppTracker.cs in WriteData Fuction " + ex.Message);
                }
            }
        }