Beispiel #1
0
        private void InsertApi(string VehicleNo, string Lat, string Long, string Kecepatan, string Suhu, string Mesin, string AC, string Provinsi, string Kabupaten, string Alamat, DateTime CreatedDate, string geofence, string provider)
        {
            ContextModel context = new ContextModel();

            if (context.HistoryGps.Where(d => d.VehicleNo == VehicleNo && d.Lat == Lat && d.Long == Long && d.CreatedDate == CreatedDate).Count() == 0)
            {
                VehicleNo = VehicleNo.TrimStart();
                VehicleNo = VehicleNo.TrimEnd();
                Suhu      = Suhu == null || Suhu == "" ? Suhu = "0" : Suhu;
                HistoryGps dbitem = new HistoryGps()
                {
                    VehicleNo   = VehicleNo,
                    Lat         = Lat,
                    Long        = Long,
                    Speed       = double.Parse(Kecepatan),
                    Temp        = float.Parse(Suhu),
                    Mesin       = Mesin,
                    Ac          = AC,
                    Provinsi    = Provinsi,
                    Kabupaten   = Kabupaten,
                    Alamat      = Alamat,
                    CreatedDate = CreatedDate,
                    Geofence    = geofence,
                    Provider    = provider
                };

                context.HistoryGps.Add(dbitem);
                context.SaveChanges();
            }
            context.Dispose();
        }
Beispiel #2
0
        private string DateTimeApi(string id)
        {
            ContextModel context        = new ContextModel();
            string       DateTimeNowApi = "";

            if (context.HistoryGps.Where(d => d.VehicleNo == id).Count() > 0)
            {
                var data = context.HistoryGps.Where(d => d.VehicleNo == id).Max(d => d.CreatedDate);

                TimeSpan start = TimeSpan.Parse(data.ToString("HH:mm:ss"));
                TimeSpan end   = TimeSpan.Parse("23:59:59");

                if (start < end)
                {
                    data = data.AddSeconds(1);
                }

                DateTimeNowApi = data.ToString("yyyy-MM-dd'%'20HH:mm:ss");
            }
            else
            {
                DateTimeNowApi = DateTime.Today.ToString("yyyy-MM-dd'%'2000:00:00");
            }

            context.Dispose();
            return(DateTimeNowApi);
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Beispiel #4
0
        public void Dispose()
        {
            if (transaction != null)
            {
                transaction.Dispose();
            }

            if (contextDB != null)
            {
                contextDB.Dispose();
            }
        }
Beispiel #5
0
        public void UpdateDataTrukMonitoring()
        {
            ContextModel context = new ContextModel();

            var grpGps = context.HistoryGps.GroupBy(g => g.VehicleNo).Select(grp => grp.ToList()).ToList();


            foreach (var item in grpGps)
            {
                DateTime endDate     = item.Max(d => d.CreatedDate).AddMinutes(-3);
                var      dataHistory = item.OrderByDescending(d => d.CreatedDate).FirstOrDefault();
                var      dummyItem   = item.Where(d => d.CreatedDate >= endDate).OrderByDescending(d => d.CreatedDate).ToList();
                double   avgSpedd    = 0;
                if (dummyItem.Sum(s => s.Speed) > 0)
                {
                    avgSpedd = dummyItem.Average(s => s.Speed);
                }
                string rangSuhu = "0 to 0";
                float  AvgSuhu  = 0;
                if (dummyItem.Count > 0)
                {
                    rangSuhu = dummyItem.Min(s => s.Temp).ToString() + " to " + dummyItem.Max(s => s.Temp).ToString();
                    AvgSuhu  = dummyItem.Average(s => s.Temp);
                }

                var truk = context.MonitoringVehicle.Where(t => t.VehicleNo == dataHistory.VehicleNo).FirstOrDefault();
                if (truk != null)
                {
                    truk.Gps        = "ON";
                    truk.Engine     = dataHistory.Mesin;
                    truk.Kecepatan  = dataHistory.Speed;
                    truk.Ac         = dataHistory.Ac;
                    truk.Suhu       = dataHistory.Temp.ToString();
                    truk.LatNew     = dataHistory.Lat;
                    truk.LongNew    = dataHistory.Long;
                    truk.Provinsi   = dataHistory.Provinsi;
                    truk.Kabupaten  = dataHistory.Kabupaten;
                    truk.Alamat     = dataHistory.Alamat;
                    truk.Zone       = dataHistory.Geofence;
                    truk.RangeAc    = rangSuhu;
                    truk.AvgSpeed   = avgSpedd;
                    truk.LastUpdate = dataHistory.CreatedDate;
                    truk.AvgSuhu    = AvgSuhu;

                    context.MonitoringVehicle.Attach(truk);
                    var entry = context.Entry(truk);
                    entry.State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
            context.Dispose();
        }
Beispiel #6
0
        public void UpdateDataTrukMonitoringTrim()
        {
            ContextModel context = new ContextModel();

            var dataTruck = context.DataTruck.ToList();

            foreach (var item in dataTruck)
            {
                item.VehicleNo = item.VehicleNo.Trim();
                context.DataTruck.Attach(item);
                var entry = context.Entry(item);
                entry.State = EntityState.Modified;
                context.SaveChanges();
            }
            context.Dispose();
        }
Beispiel #7
0
        public void InsertDataTrukMonitoring()
        {
            ContextModel context = new ContextModel();

            var dataMonitoring = context.MonitoringVehicle.Select(d => d.VehicleNo).ToList();
            var dataTruck      = context.DataTruck.ToList();

            dataTruck = dataTruck.Where(d => !dataMonitoring.Contains(d.VehicleNo)).ToList();

            foreach (var item in dataTruck)
            {
                context.MonitoringVehicle.Add(new MonitoringVehicle()
                {
                    VehicleNo = item.VehicleNo, Type = item.JenisTrucks.StrJenisTruck, LastUpdate = DateTime.Now
                });
                context.SaveChanges();
            }
            context.Dispose();
        }
 public void Dispose()
 {
     ctx.Dispose();
 }
Beispiel #9
0
        private void ProsesNotif()
        {
            ContextModel dbcontext     = new ContextModel();
            string       baseUrl       = System.Configuration.ConfigurationManager.AppSettings["baseUrl"];
            var          hubConnection = new HubConnection(baseUrl + "signalr", useDefaultUrl: false);
            IHubProxy    alphaProxy    = hubConnection.CreateHubProxy("NotificationHub");

            hubConnection.Start().Wait();

            var data      = dbcontext.HistoryGps.GroupBy(v => v.VehicleNo).Select(grp => grp.ToList()).ToList();
            var dataTruck = dbcontext.DataTruck.ToList();

            foreach (var item in data)
            {
                foreach (var setting in dbcontext.SettingGeneral.Where(d => d.status).ToList())
                {
                    DateTime endDate = item.Max(d => d.CreatedDate);
                    DateTime strDate = DateTime.Now;
                    if (setting.overSatuan == "Menit")
                    {
                        strDate = endDate.AddMinutes(setting.over * -1);
                    }
                    else if (setting.overSatuan == "Jam")
                    {
                        strDate = endDate.AddHours(setting.over * -1);
                    }
                    else if (setting.overSatuan == "Hari")
                    {
                        strDate = endDate.AddDays(setting.over * -1);
                    }

                    var dataSpeed = item.Where(d => d.CreatedDate >= strDate && d.CreatedDate <= endDate);
                    var truk      = dataTruck.Where(d => d.VehicleNo == dataSpeed.FirstOrDefault().VehicleNo).FirstOrDefault();
                    var avgSpeed  = dataSpeed.Average(k => k.Speed);

                    if (setting.idProses == "Speed Alert")
                    {
                        if ((avgSpeed > truk.MaxSpeed) && (truk.MaxSpeed != 0))
                        {
                            foreach (var user in setting.idUserAlert.Split(','))
                            {
                                if (setting.AlertPopup)
                                {
                                    alphaProxy.Invoke("SendNotifications", "Kecepatan " + truk.VehicleNo + " " + avgSpeed + "KM/Jam ( Limit " + truk.MaxSpeed + " KM/Jam).", user).Wait();
                                }
                                if (setting.AlertEmail)
                                {
                                    string BodyEmail = string.Format(
                                        "<p>Kecepatan " + truk.VehicleNo + " " + avgSpeed + "KM/Jam ( Limit " + truk.MaxSpeed + " KM/Jam)..</p>" +
                                        "<BR/><BR/><BR/> Regards,<BR/><BR/> TMS MKA Team");
                                    int IdUser = int.Parse(user);
                                    var users  = dbcontext.User.Find(IdUser);
                                    alphaProxy.Invoke("SendNotificationEmail", users.Email, "Speed Alert TMS MKA", BodyEmail);
                                }
                                if (setting.AlertSound)
                                {
                                    alphaProxy.Invoke("SendNotificationSound", user);
                                }
                            }
                        }
                    }
                    if (setting.idProses == "Parking Alert")
                    {
                        //if (avgSpeed == 0 && item.FirstOrDefault().MonitoringDetailSoId != 0)
                        //{
                        //    if ((avgSpeed > decimal.Parse(truk.MaxSpeed.ToString())) && (truk.MaxSpeed != 0))
                        //    {
                        //        foreach (var user in setting.idUserAlert.Split(','))
                        //        {
                        //            if (setting.AlertPopup)
                        //                alphaProxy.Invoke("SendNotifications", "Truk dengan Nopol " + truk.VehicleNo + " melebihi batas kecepatan.", user).Wait();
                        //            else if (setting.AlertEmail)
                        //            { }
                        //            else if (setting.AlertSound)
                        //            { }
                        //        }
                        //    }
                        //}
                    }
                }
            }
            dbcontext.Dispose();
        }
Beispiel #10
0
        private void ProsesTimeAlertNotif()
        {
            ContextModel dbcontext     = new ContextModel();
            string       baseUrl       = System.Configuration.ConfigurationManager.AppSettings["baseUrl"];
            var          hubConnection = new HubConnection(baseUrl + "signalr", useDefaultUrl: false);
            IHubProxy    alphaProxy    = hubConnection.CreateHubProxy("NotificationHub");

            hubConnection.Start().Wait();

            var dataNotif = dbcontext.ListNotif.Where(d => !d.IsSend).ToList();

            foreach (var item in dataNotif)
            {
                List <TimeAlert> dataAlert = dbcontext.TimeAlert.Where(d => d.idProses == item.Type && d.status).ToList();
                foreach (var itemAlert in dataAlert)
                {
                    DateTime currDateNotif = DateTime.Now;
                    if (itemAlert.overSatuan == "Menit")
                    {
                        currDateNotif = item.CreateDate.AddMinutes(itemAlert.over);
                    }
                    else if (itemAlert.overSatuan == "Jam")
                    {
                        currDateNotif = item.CreateDate.AddHours(itemAlert.over);
                    }
                    else if (itemAlert.overSatuan == "Hari")
                    {
                        currDateNotif = item.CreateDate.AddDays(itemAlert.over);
                    }

                    if (currDateNotif <= DateTime.Now)
                    {
                        foreach (var user in itemAlert.idUserAlert.Split(','))
                        {
                            if (itemAlert.AlertPopup)
                            {
                                alphaProxy.Invoke("SendNotifications", item.PopupMsg, user);
                            }
                            if (itemAlert.AlertEmail)
                            {
                                int idUser = int.Parse(user);
                                var users  = dbcontext.User.Find(idUser);
                                if (users.Email != null && users.Email != "")
                                {
                                    alphaProxy.Invoke("SendNotificationEmail", users.Email, "Alert TMS MKA", item.EmailMsg);
                                }
                            }
                            if (itemAlert.AlertSound)
                            {
                                alphaProxy.Invoke("SendNotificationSound", user);
                            }
                        }

                        item.IsSend = true;
                        dbcontext.ListNotif.Attach(item);
                        var entry = dbcontext.Entry(item);
                        entry.State = EntityState.Modified;
                        dbcontext.SaveChanges();
                    }
                }
            }
            dbcontext.Dispose();
        }
Beispiel #11
0
        private void process_ApiIntellitrac()
        {
            ContextModel context = new ContextModel();

            try
            {
                //var hubConnection = new HubConnection("http://localhost:15401/signalr", useDefaultUrl: false);
                //IHubProxy alphaProxy = hubConnection.CreateHubProxy("NotificationHub");

                //hubConnection.Start().Wait();
                // Invoke method on hub

                //* # Alur Proses #
                //*
                //* 1. Membuat list ID Devices GPS yang digunakan oleh MKA pada vendor Intellitrac, yang mana digunakan untuk looping permintaan data
                //* 2. Mengecek apakah tanggal jam sudah tersedia, jika sudah lewati jika belum simpan ke database
                //* 3. Untuk pengecekan awal akan di list data dari jam 00:00:00 hingga 23:59:59, selanjutnya di list hanya dari jam terakhir pada database hingga 23:59:59

                #region Api
                string urlApi    = System.Configuration.ConfigurationManager.AppSettings["urlApiIntellitrac"];
                string idApi     = System.Configuration.ConfigurationManager.AppSettings["idApiIntellitrac"];
                int    RealId    = int.Parse(idApi);
                var    dataTruck = context.DataGPS.Where(d => d.IdVendor == RealId).ToList();
                foreach (var truck in dataTruck)
                {
                    string  DateTimeNowApi = DateTimeApi(truck.DataTruck.VehicleNo);
                    string  urlApiIdData   = urlApi + "/history.php?username=mka_api&password=m4ngg4l4API&start_datetime=" + DateTimeNowApi + "& end_datetime=" + DateTimeNow + "%2023:59:59&devices=" + truck.NoDevice + "& filter=ignition_status;speed;temperature_2;location;longitude;latitude;geofences;input;temperature";
                    dynamic getDeviceData  = getDataApi(urlApiIdData);
                    if (getDeviceData["status"] == "OK")
                    {
                        if (getDeviceData["data"][truck.NoDevice]["history"] != null)
                        {
                            int    contData = getDeviceData["data"][truck.NoDevice]["history"].Count;
                            string longitude, latitude, location, provinsi, kabupaten, alamat, kecepatan, suhu, mesin, ac, createddate, geofence;
                            for (int j = 0; j <= (contData - 1); j++)
                            {
                                longitude = getDeviceData["data"][truck.NoDevice]["history"][j]["longitude"];
                                latitude  = getDeviceData["data"][truck.NoDevice]["history"][j]["latitude"];
                                location  = getDeviceData["data"][truck.NoDevice]["history"][j]["location"];
                                location  = location.Replace("'", "''");

                                string[] words = location.Split(',');

                                provinsi  = words[2];
                                kabupaten = words[1];
                                alamat    = words[0];

                                kecepatan   = getDeviceData["data"][truck.NoDevice]["history"][j]["speed"];
                                suhu        = getDeviceData["data"][truck.NoDevice]["history"][j]["temperature_2"];
                                mesin       = getDeviceData["data"][truck.NoDevice]["history"][j]["ignition_status"];
                                ac          = getDeviceData["data"][truck.NoDevice]["history"][j]["input"]["02"] == 1 ? "ON" : "OFF";
                                createddate = getDeviceData["data"][truck.NoDevice]["history"][j]["local_datetime"];
                                geofence    = getDeviceData["data"][truck.NoDevice]["history"][j]["geofence"];
                                InsertApi(truck.DataTruck.VehicleNo, latitude, longitude, kecepatan, suhu, mesin, ac, provinsi, kabupaten, alamat, DateTime.Parse(createddate), geofence, "Intellitrac");
                            }
                        }
                    }
                }
                #endregion Api
            }
            catch (Exception e)
            {
            }
            context.Dispose();
        }
        public void process_ApiSolofleet()
        {
            ContextModel context = new ContextModel();

            //* # Alur Proses #
            //*
            //* 1. Membuat list ID Devices GPS yang digunakan oleh MKA pada vendor Solofleet, yang mana digunakan untuk looping permintaan data
            //* 2. Mengecek apakah tanggal jam sudah tersedia, jika sudah lewati jika belum simpan ke database
            //* 3. Untuk pengecekan awal akan di list data dari jam 00:00:00 hingga 23:59:59, selanjutnya di list hanya dari jam terakhir pada database hingga 23:59:59
            #region Api
            string urlApi    = System.Configuration.ConfigurationManager.AppSettings["urlApiSolofleet"];
            string idApi     = System.Configuration.ConfigurationManager.AppSettings["idApiSolofleet"];
            int    RealId    = int.Parse(idApi);
            var    dataTruck = context.DataGPS.Where(d => d.IdVendor == RealId).ToList();

            foreach (var truk in dataTruck)
            {
                try
                {
                    string devicesId      = truk.NoDevice;
                    string vehicleno      = truk.DataTruck.VehicleNo;
                    string DateTimeNowApi = DateTimeApi(vehicleno);
                    DateTimeNowApi = DateTimeNowApi.Replace("%20", "T");
                    string  urlApiIdData  = urlApi + "/api/jsondailyreport?username=mkasolo286&password=mkajson&gprsid=" + devicesId + "&filterStartDate=" + DateTimeNowApi + ".070Z&filterEndDate=" + DateTimeNow + "T23:59:59.070Z&type=json";
                    dynamic getDeviceData = getDataApiArray(urlApiIdData);
                    int     contData      = getDeviceData.Count;
                    if (contData >= 1)
                    {
                        for (int j = 0; j <= (contData - 1); j++)
                        {
                            string longitude = getDeviceData[j]["longtitude"];
                            string latitude  = getDeviceData[j]["latitude"];

                            string provinsi = getDeviceData[j]["province"] != "" ? getDeviceData[j]["province"] + ", " : "";
                            provinsi = provinsi.Replace("'", "''");

                            string kabupaten = getDeviceData[j]["city"] != "" ? getDeviceData[j]["city"] + ", " : "";
                            kabupaten = kabupaten.Replace("'", "''");

                            string alamat = getDeviceData[j]["district"] != "" ? getDeviceData[j]["district"] + ", " : "";
                            alamat = alamat.Replace("'", "''");

                            string kecepatan = getDeviceData[j]["speed"];
                            string suhu      = getDeviceData[j]["temperature1"];
                            string mesin     = getDeviceData[j]["engineStatus"];
                            string ac        = getDeviceData[j]["iP4Compressor"];

                            DateTime dtenow      = getDeviceData[j]["gpstime"];
                            string   createddate = dtenow.ToString("yyyy-MM-dd H:mm:ss");

                            InsertApi(vehicleno, latitude, longitude, kecepatan, suhu, mesin, ac, provinsi, kabupaten, alamat, DateTime.Parse(createddate), "", "Soloflet");
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            #endregion Api
            context.Dispose();
        }