Beispiel #1
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);
            }
        }
Beispiel #2
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);
            }
        }