public int DeleteDevice(string id) { int count = operations.Device.DevicePlanCount(WebUtilities.DecryptId(WebUtility.UrlDecode(id), GetUserName(), GetOrganizationId()), GetOrganizationId()); if (count > 0) { TempData["Notification"] = WebUtilities.InsertNotification("Cihaza bağlı planlar olduğu için silinemez."); return(-1); } DeviceInsertModel model = operations.Device.GetDeviceById(GetOrganizationId(), WebUtilities.DecryptId(WebUtility.UrlDecode(id), GetUserName(), GetOrganizationId())); operations.Device.DeleteDevice(WebUtilities.DecryptId(WebUtility.UrlDecode(id), GetUserName(), GetOrganizationId()), GetOrganizationId()); List <string> stringModel = new List <string>(); if (!String.IsNullOrEmpty(model.BakcupJobId)) { stringModel.Add(model.BakcupJobId); } if (!String.IsNullOrEmpty(model.CheckOnlineJobId)) { stringModel.Add(model.CheckOnlineJobId); } if (!String.IsNullOrEmpty(model.FileListJobId)) { stringModel.Add(model.FileListJobId); } HangfireProvider.DeleteHangFireJobs(stringModel); return(1); }
public HttpResponseMessage CheckOnlineDevice([FromBody] CheckModel data) { DpOperations db = new DpOperations(); var device = db.Device.GetApiAccessAndSecretKeyDevice(data.apiAccessKey, data.apiSecretKey); if (device != null) { if (String.IsNullOrEmpty(device.CpuId) || String.IsNullOrEmpty(device.MacAddress) || String.IsNullOrEmpty(device.DiskSeriNo)) { data.deviceId = device.Id; db.Device.UpdateDeviceInformation(data); DevicePlanLog lg = new DevicePlanLog() { CreatedDate = DateTime.Now, Description = "Cihaz ekleme başarılı bir şekilde gerçekleşmiştir. Cihaz aktif", DeviceId = device.Id, OrganizationId = device.OrganizationId }; db.Log.InsertLog(lg); HangfireProvider.ScheduleRecurringCheckOnline(DateTime.Now, device.Id, "0 */3 * * *", device.OrganizationId); //HangfireProvider.ScheduleRecurringFileList(DateTime.Now, device.Id, "0 */12 * * *", device.OrganizationId); //HangfireProvider.InsertJobOneTimeFileList(DateTime.Now, device.Id, device.OrganizationId); HangfireProvider.InsertJobOneTimeCheckOnline(DateTime.Now, device.Id, device.OrganizationId); } else { if (data.updateData) { data.deviceId = device.Id; db.Device.UpdateDeviceInformation(data); DevicePlanLog lg = new DevicePlanLog() { CreatedDate = DateTime.Now, Description = "Cihaz ekleme başarılı bir şekilde gerçekleşmiştir. Cihaz aktif", DeviceId = device.Id, OrganizationId = device.OrganizationId }; db.Log.InsertLog(lg); } else { DevicePlanLog lg = new DevicePlanLog() { CreatedDate = DateTime.Now, Description = "Cihaz kontrolü başarılı bir şekilde gerçekleşmiştir. Cihaz aktif", DeviceId = device.Id, OrganizationId = device.OrganizationId }; db.Log.InsertLog(lg); } } return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)); } else { return(new HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized)); } }
public bool DeleteDevicePlan(string id) { var model = operations.DevicePlan.GetDevicePlanById(GetOrganizationId(), WebUtilities.DecryptId(WebUtility.UrlDecode(id), GetUserName(), GetOrganizationId())); HangfireProvider.DeleteHangFireJobs(new List <string> { model.BackgroundJobId }); operations.DevicePlan.DeleteDevicePlan(WebUtilities.DecryptId(WebUtility.UrlDecode(id), GetUserName(), GetOrganizationId()), GetOrganizationId()); return(true); }
public JsonResult GetParentDirectoryListing(string directoryId, string deviceId, string cloudId) { var sList = new List <object>(); if (String.IsNullOrEmpty(cloudId)) { DpOperations db = new DpOperations(); int realDeviceId = WebUtilities.DecryptId(WebUtility.HtmlDecode(WebUtility.UrlDecode(deviceId)), GetUserName(), GetOrganizationId()); string directoryName = db.Device.GetDirectoryById(Convert.ToInt32(directoryId), GetOrganizationId()); HangfireProvider.SendFileListCommand(realDeviceId, GetOrganizationId(), directoryId); directoryId = directoryId.Replace(@"\\", @"\"); for (int i = 0; i <= 20; i++) { double second = db.Device.IsFileListIncoming(realDeviceId, GetOrganizationId(), directoryName); if (second > 2 && second < 60 && second != 0) { var list = db.Device.GetFileList(realDeviceId, GetOrganizationId(), directoryName); foreach (var item in list) { sList.Add(new { id = item.Id, text = item.Directory, parent = directoryId, children = true }); } break; } System.Threading.Thread.Sleep(3000); } } else { int realplanId = WebUtilities.DecryptId(WebUtility.UrlDecode(cloudId), GetUserName(), GetOrganizationId()); var planData = operations.Plan.GetPlanById(GetOrganizationId(), realplanId); List <FileListModel> list = new List <FileListModel>(); if (planData.Type == Database.Enum.PlanType.GoogleDrive) { list = GetGoogleDriveList(realplanId, directoryId, planData); } else if (planData.Type == Database.Enum.PlanType.AmazonS3) { list = GetAmazonS3List(realplanId, directoryId, planData); } foreach (var item in list) { sList.Add(new { id = item.CloudId, text = item.Directory, parent = directoryId, children = true }); } } return(Json(sList)); }
public IActionResult NewJob(DevicePlanInsertModel model) { SetNewJobViewBag(); model.CloseModal = false; if (String.IsNullOrEmpty(model.Name)) { TempData["Notification"] = WebUtilities.InsertNotification("İsim boş geçilemez"); return(View(model)); } if (String.IsNullOrEmpty(model.Description)) { TempData["Notification"] = WebUtilities.InsertNotification("Açıklama boş geçilemez"); return(View(model)); } if (String.IsNullOrEmpty(model.LocalSource)) { TempData["Notification"] = WebUtilities.InsertNotification("Kaynak bilgisayar boş geçilemez"); return(View(model)); } if (String.IsNullOrEmpty(model.RemoteSource)) { TempData["Notification"] = WebUtilities.InsertNotification("Hedef bilgisayar boş geçilemez"); return(View(model)); } if (String.IsNullOrEmpty(model.BackupStartDate)) { TempData["Notification"] = WebUtilities.InsertNotification("Başlangıç tarihi boş geçilemez"); return(View(model)); } if (String.IsNullOrEmpty(model.BackupStartTime)) { TempData["Notification"] = WebUtilities.InsertNotification("Başlangıç saati boş geçilemez"); return(View(model)); } try { string[] dateArray = model.BackupStartDate.Split('-'); string[] timeArray = model.BackupStartTime.Split(':'); model.RealInsertBackupStartDate = new DateTime(Convert.ToInt32(dateArray[2]), Convert.ToInt32(dateArray[1]), Convert.ToInt32(dateArray[0]), Convert.ToInt32(timeArray[0]), Convert.ToInt32(timeArray[1]), 0); } catch { TempData["Notification"] = WebUtilities.InsertNotification("Lütfen tarih ve saat bilgisini kontrol ediniz."); return(View(model)); } model.PlanId = WebUtilities.DecryptId(WebUtility.UrlDecode(model.HashedPlanId), GetUserName(), GetOrganizationId()); model.DeviceId = WebUtilities.DecryptId(model.DeviceHashedId, GetUserName(), GetOrganizationId()); model.OrganizationId = GetOrganizationId(); if (String.IsNullOrEmpty(model.HashedDevicePlanId)) { int returnValue = operations.DevicePlan.InsertDevicePlan(model); if (returnValue > 0) { model.Id = returnValue; TriggerHangfireJob(model); model.HashedDevicePlanId = WebUtilities.EncryptId(returnValue, GetUserName(), GetOrganizationId()); TempData["Notification"] = WebUtilities.InsertNotification("Cihaz planı başarılı bir şekilde eklenmiştir."); model.CloseModal = true; return(View(model)); } else { TempData["Notification"] = WebUtilities.InsertNotification("Ekleme sırasında bir hata oluştu lütfen sistem yöneticisine başvurunuz."); model.CloseModal = false; return(View(model)); } } else { int realId = WebUtilities.DecryptId(WebUtility.UrlDecode(model.HashedDevicePlanId), GetUserName(), GetOrganizationId()); if (realId > 0) { model.CloseModal = true; model.Id = realId; operations.DevicePlan.UpdateDevicePlan(model, GetOrganizationId()); List <string> list = new List <string>(); list.Add(operations.DevicePlan.GetDevicePlanById(GetOrganizationId(), realId).BackgroundJobId); HangfireProvider.DeleteHangFireJobs(list); TriggerHangfireJob(model); return(View(model)); } else { TempData["Notification"] = WebUtilities.InsertNotification("Hatalı işlem lütfen pencereyi kapatıp tekrar deneyiniz."); model.CloseModal = false; return(View(model)); } } // return View(); }
public void TriggerHangfireJob(DevicePlanInsertModel model) { model.RealInsertBackupStartDate = model.RealInsertBackupStartDate.Value.AddHours(-3); if (model.RetryPlan == Database.Enum.RetryPlan.OneTime) { HangfireProvider.InsertJobOneTimeBackup(model.RealInsertBackupStartDate.Value, model.Id, model.DeviceId, GetOrganizationId()); } else { string retryPlan = ""; if (model.RetryPlan == Database.Enum.RetryPlan.Minute30) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + "/30 * * * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Hour1) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + "/1 * * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Hour3) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + "/3 * * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Hour6) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + "/6 * * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Hour12) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + "/12 * * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day1) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 1) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day2) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 2) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day3) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 3) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day4) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 4) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day5) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 5) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day6) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 6) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day7) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 7) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day8) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 8) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day9) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 9) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Day10) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + DailyCron(model.RealInsertBackupStartDate.Value.Day, 10) + " * *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Month1) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + model.RealInsertBackupStartDate.Value.Day + " " + MonthCron(model.RealInsertBackupStartDate.Value.Month, 1) + " *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Month2) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + model.RealInsertBackupStartDate.Value.Day + " " + MonthCron(model.RealInsertBackupStartDate.Value.Month, 2) + " *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Month3) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + model.RealInsertBackupStartDate.Value.Day + " " + MonthCron(model.RealInsertBackupStartDate.Value.Month, 3) + " *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Month4) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + model.RealInsertBackupStartDate.Value.Day + " " + MonthCron(model.RealInsertBackupStartDate.Value.Month, 4) + " *"; } else if (model.RetryPlan == Database.Enum.RetryPlan.Year1) { retryPlan = "" + model.RealInsertBackupStartDate.Value.Minute + " " + model.RealInsertBackupStartDate.Value.Hour + " " + model.RealInsertBackupStartDate.Value.Day + " " + model.RealInsertBackupStartDate.Value.Month + " *"; } HangfireProvider.InsertJobTimePlanBackup(model.Id, retryPlan, model.DeviceId, GetOrganizationId()); } }