public JsonRequestModel GetJsonInformation() { Persistence persistence = new Persistence(); JsonRequestModel result = persistence.ReadFormInformation(); return(result); }
// Add real time scheduler for options: seconds, minutes, hours. private void AddRealTimeScheduler(JsonRequestModel jsonRequestModel, DateTime startDate, TaskDefinition td, bool isWindowsInitialize) { DailyTrigger daily = new DailyTrigger(); if (jsonRequestModel.RealTimeBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Hours))) { startDate = startDate.AddHours(jsonRequestModel.RealTimeBackupModel.BackupInterval); using (TaskService ts = new TaskService()) { AddTrigger(daily, startDate, td, isWindowsInitialize); } } if (jsonRequestModel.RealTimeBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Minutes))) { startDate = startDate.AddMinutes(jsonRequestModel.RealTimeBackupModel.BackupInterval); using (TaskService ts = new TaskService()) { AddTrigger(daily, startDate, td, isWindowsInitialize); } } if (jsonRequestModel.RealTimeBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Seconds))) { startDate = startDate.AddSeconds(jsonRequestModel.RealTimeBackupModel.BackupInterval); using (TaskService ts = new TaskService()) { AddTrigger(daily, startDate, td, isWindowsInitialize); } } }
public void SaveBackupFormInfo(List <BackupModel> backupModelList, bool isNewTask) { if (backupModelList.Any()) { CheckIfJsonFileExist(); var jsonText = File.ReadAllText(_persistancePath); var request = JsonConvert.DeserializeObject <JsonRequestModel>(jsonText); if (request == null) { request = new JsonRequestModel(); request.BackupModelList = backupModelList; WriteJsonRequestModel(request); } else { if (request.BackupModelList != null) { foreach (var backupModelItem in backupModelList) { var existingBackupModelItem = request.BackupModelList.FirstOrDefault(b => b.BackupName == backupModelItem.BackupName); if (existingBackupModelItem == null) { request.BackupModelList.Add(backupModelItem); WriteJsonRequestModel(request); } else { if (!isNewTask) { // update model with the updated values request.BackupModelList.Remove(existingBackupModelItem); request.BackupModelList.Add(backupModelItem); WriteJsonRequestModel(request); } else { // task is new and informative message is displayed MessageBox.Show(Constants.TaskSchedulerAlreadyExist, Constants.InformativeMessage, MessageBoxButtons.OK); } } } } else { request.BackupModelList = backupModelList; WriteJsonRequestModel(request); } } } }
public void SaveDetailsFormInfo(List <BackupDetailsModel> backupDetailsModelList) { if (backupDetailsModelList.Any()) { CheckIfJsonFileExist(); var jsonText = File.ReadAllText(_persistancePath); var request = JsonConvert.DeserializeObject <JsonRequestModel>(jsonText); if (request == null) { request = new JsonRequestModel(); request.BackupDetailsModelList = backupDetailsModelList; var json = JsonConvert.SerializeObject(request); File.WriteAllText(_persistancePath, json); } else { if (request.BackupDetailsModelList.Any()) { foreach (var backupItem in backupDetailsModelList) { var existingBackupItem = request.BackupDetailsModelList.Where(b => b.BackupAction == backupItem.BackupAction && b.BackupType == backupItem.BackupType && b.BackupPattern == backupItem.BackupPattern) .FirstOrDefault(); if (existingBackupItem == null) { request.BackupDetailsModelList.Add(backupItem); var json = JsonConvert.SerializeObject(request); File.WriteAllText(_persistancePath, json); } else { MessageBox.Show(Constants.ActionAlreadyExist, Constants.InformativeMessage, MessageBoxButtons.OK); } } } else { request.BackupDetailsModelList = backupDetailsModelList; var json = JsonConvert.SerializeObject(request); File.WriteAllText(_persistancePath, json); } } } }
public void SaveDetailsFormInfo(List <BackupDetailsModel> backupDetailsModelList, string taskName) { if (backupDetailsModelList != null) { foreach (var item in backupDetailsModelList) { item.BackupName = taskName; item.TrimmedBackupName = string.Concat(taskName.Where(c => !char.IsWhiteSpace(c))); } CheckIfJsonFileExist(); var jsonText = File.ReadAllText(_persistancePath); var request = JsonConvert.DeserializeObject <JsonRequestModel>(jsonText); if (request == null) { request = new JsonRequestModel(); request.BackupDetailsModelList = backupDetailsModelList; WriteJsonRequestModel(request); } else { if (request.BackupDetailsModelList != null) { foreach (var backupItem in backupDetailsModelList) { var existingBackupItem = request.BackupDetailsModelList.FirstOrDefault(b => b.BackupName.Equals(taskName) && b.BackupAction.Equals(backupItem.BackupAction) && b.BackupPattern.Equals(backupItem.BackupPattern) && b.BackupType.Equals(backupItem.BackupType)); if (existingBackupItem == null) { request.BackupDetailsModelList.Add(backupItem); WriteJsonRequestModel(request); } else { MessageBox.Show(Constants.ActionAlreadyExist, Constants.InformativeMessage, MessageBoxButtons.OK); } } } else { request.BackupDetailsModelList = backupDetailsModelList; WriteJsonRequestModel(request); } } } }
// Add periodic time scheduler depending on user setup. private void AddPeriodicTimeScheduler(JsonRequestModel jsonRequestModel, DateTime startDate, TaskDefinition td, bool isWindowsInitialize) { DailyTrigger daily = new DailyTrigger(); if (jsonRequestModel.PeriodicBackupModel.IsRunOption) { startDate = DateTime.Now; using (TaskService ts = new TaskService()) { AddTrigger(daily, startDate, td, isWindowsInitialize); } } else { DateTime atScheduleTime = DateTime.Parse(jsonRequestModel.PeriodicBackupModel.BackupAt, CultureInfo.InvariantCulture); startDate = jsonRequestModel.PeriodicBackupModel.FirstBackup.Date + new TimeSpan(atScheduleTime.Hour, atScheduleTime.Minute, atScheduleTime.Second); if (jsonRequestModel.PeriodicBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Hours))) { startDate = startDate.AddHours(jsonRequestModel.PeriodicBackupModel.BackupInterval); using (TaskService ts = new TaskService()) { AddTrigger(daily, startDate, td, isWindowsInitialize); } } if (jsonRequestModel.PeriodicBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Minutes))) { startDate = startDate.AddMinutes(jsonRequestModel.PeriodicBackupModel.BackupInterval); using (TaskService ts = new TaskService()) { AddTrigger(daily, startDate, td, isWindowsInitialize); } } if (jsonRequestModel.PeriodicBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Seconds))) { startDate = startDate.AddSeconds(jsonRequestModel.PeriodicBackupModel.BackupInterval); using (TaskService ts = new TaskService()) { AddTrigger(daily, startDate, td, isWindowsInitialize); } } } }
public void SaveBackupFormInfo(BackupModel backupModel) { CheckIfJsonFileExist(); var jsonText = File.ReadAllText(_persistancePath); var request = JsonConvert.DeserializeObject <JsonRequestModel>(jsonText); if (request == null) { request = new JsonRequestModel(); } request.BackupModel = backupModel; var json = JsonConvert.SerializeObject(request); File.WriteAllText(_persistancePath, json); }
public void SaveChangeSettings(ChangeSettingsModel changeSettingsModel) { CheckIfJsonFileExist(); var jsonText = File.ReadAllText(_persistancePath); var request = JsonConvert.DeserializeObject <JsonRequestModel>(jsonText); if (request == null) { request = new JsonRequestModel(); } request.ChangeSettingsModel = changeSettingsModel; var json = JsonConvert.SerializeObject(request); File.WriteAllText(_persistancePath, json); }
/// <summary> /// Run manually task/tasks /// </summary> private void RunManuallyTasks() { try { var persistence = new Persistence(); var service = new Service(); var backupInfo = new Dictionary <string, bool>(); var dictionaryBackup = new Dictionary <string, bool>(); _jsonRquestModel = persistence.ReadFormInformation(); if (dataGridView1.SelectedRows.Count > 0) { // Run selected backup tasks foreach (DataGridViewRow row in dataGridView1.SelectedRows) { dictionaryBackup = SetManuallyTasksInfo(persistence, service, row); foreach (var entry in dictionaryBackup) { backupInfo.Add(entry.Key, entry.Value); } } AddInfoIntoJson(persistence, service, backupInfo); } else { // Run all manually backup tasks foreach (DataGridViewRow row in dataGridView1.Rows) { dictionaryBackup = SetManuallyTasksInfo(persistence, service, row); foreach (var entry in dictionaryBackup) { backupInfo.Add(entry.Key, entry.Value); } } AddInfoIntoJson(persistence, service, backupInfo); } GetBackupTasks(); } catch (Exception ex) { Logger.Error($"{Constants.RunManuallyTasks} {ex.Message} \n {ex.StackTrace}"); } }
public void SavePeriodicBackupInfo(List <PeriodicBackupModel> periodicBackupModelList, string taskName) { if (periodicBackupModelList != null) { CheckIfJsonFileExist(); var jsonText = File.ReadAllText(_persistancePath); var request = JsonConvert.DeserializeObject <JsonRequestModel>(jsonText); if (request == null) { request = new JsonRequestModel(); request.PeriodicBackupModelList = periodicBackupModelList; WriteJsonRequestModel(request); } else { if (request.PeriodicBackupModelList != null && request.PeriodicBackupModelList.Count > 0 && request.PeriodicBackupModelList[0] != null) { foreach (var periodicBackupModelItem in periodicBackupModelList) { var existingperiodicBackupModelItem = request.PeriodicBackupModelList.FirstOrDefault(b => b.BackupName == periodicBackupModelItem.BackupName); if (existingperiodicBackupModelItem == null) { request.PeriodicBackupModelList.Add(periodicBackupModelItem); WriteJsonRequestModel(request); } else { // Update json request model with the updated values request.PeriodicBackupModelList.Remove(existingperiodicBackupModelItem); request.PeriodicBackupModelList.Add(periodicBackupModelItem); WriteJsonRequestModel(request); } } } else { request.PeriodicBackupModelList = periodicBackupModelList; WriteJsonRequestModel(request); } } } }
private ReadOnlyUrl LinkedInApiLogIn(AuthenticationStatus expectedStatus, JsonRequestModel profile) { // Ensure element is on the screen. Assert.IsNotNull(Browser.CurrentHtml.DocumentNode.SelectSingleNode("//div/script[@type='in/Login']")); // Extract the urls to redirect to. const string find = "window.location = data.Status == \"Authenticated\" ? \""; var pos = Browser.CurrentPageText.IndexOf(find); Assert.AreNotEqual(-1, pos); pos = pos + find.Length; var endPos = Browser.CurrentPageText.IndexOf("\"", pos, StringComparison.CurrentCultureIgnoreCase); Assert.AreNotEqual(-1, endPos); var authenticatedUrl = Browser.CurrentPageText.Substring(pos, endPos - pos); pos = endPos + 1; endPos = Browser.CurrentPageText.IndexOf("\"", pos, StringComparison.CurrentCultureIgnoreCase); Assert.AreNotEqual(-1, endPos); pos = endPos + 1; endPos = Browser.CurrentPageText.IndexOf("\"", pos, StringComparison.CurrentCultureIgnoreCase); Assert.AreNotEqual(-1, endPos); var accountUrl = Browser.CurrentPageText.Substring(pos, endPos - pos); // Login. var response = Deserialize <LinkedInAuthenticationModel>(Post(_apiLoginUrl, JsonContentType, Serialize(profile))); AssertJsonSuccess(response); var status = (AuthenticationStatus)Enum.Parse(typeof(AuthenticationStatus), response.Status); Assert.AreEqual(expectedStatus, status); return(expectedStatus == AuthenticationStatus.Authenticated ? new ReadOnlyApplicationUrl(authenticatedUrl) : new ReadOnlyApplicationUrl(accountUrl)); }
// Add periodic time scheduler depending on user setup. private void AddPeriodicTimeScheduler(JsonRequestModel jsonRequestModel, DateTime startDate, TaskDefinition td, Trigger tr) { DateTime atScheduleTime = DateTime.Parse(jsonRequestModel.PeriodicBackupModel.BackupAt, CultureInfo.InvariantCulture); tr.StartBoundary = jsonRequestModel.PeriodicBackupModel.FirstBackup.Date + new TimeSpan(atScheduleTime.Hour, atScheduleTime.Minute, atScheduleTime.Second); SetupRealDateTime(tr); if (jsonRequestModel.PeriodicBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Hours))) { tr.Repetition.Interval = TimeSpan.FromHours(jsonRequestModel.PeriodicBackupModel.BackupInterval); AddTrigger(tr, td); } if (jsonRequestModel.PeriodicBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Minutes))) { tr.Repetition.Interval = TimeSpan.FromMinutes(jsonRequestModel.PeriodicBackupModel.BackupInterval); AddTrigger(tr, td); } }
/// <summary> /// Run manually task/tasks /// </summary> private void RunManuallyTasks() { var persistence = new Persistence(); var service = new Service(); var backupInfo = new Dictionary <string, bool>(); var dictionaryBackup = new Dictionary <string, bool>(); _jsonRquestModel = persistence.ReadFormInformation(); if (dataGridView1.SelectedRows.Count > 0) { // Run selected backup tasks foreach (DataGridViewRow row in dataGridView1.SelectedRows) { dictionaryBackup = SetManuallyTasksInfo(persistence, service, row); foreach (var entry in dictionaryBackup) { backupInfo.Add(entry.Key, entry.Value); } } AddInfoIntoJson(persistence, service, backupInfo); } else { // Run all manually backup tasks foreach (DataGridViewRow row in dataGridView1.Rows) { dictionaryBackup = SetManuallyTasksInfo(persistence, service, row); foreach (var entry in dictionaryBackup) { backupInfo.Add(entry.Key, entry.Value); } } AddInfoIntoJson(persistence, service, backupInfo); } GetBackupTasks(); }
// Add periodic time scheduler depending on user setup. private void AddPeriodicTimeScheduler(JsonRequestModel jsonRequestModel, TaskDefinition td, Trigger tr, string backupName) { var periodicBackupModel = jsonRequestModel?.PeriodicBackupModelList?.FirstOrDefault(p => p.BackupName.Equals(backupName)); if (periodicBackupModel != null) { DateTime atScheduleTime = DateTime.Parse(periodicBackupModel.BackupAt, CultureInfo.InvariantCulture); tr.StartBoundary = periodicBackupModel.FirstBackup.Date + new TimeSpan(atScheduleTime.Hour, atScheduleTime.Minute, atScheduleTime.Second); SetupRealDateTime(tr, periodicBackupModel.IsNowPressed); if (periodicBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Hours))) { tr.Repetition.Interval = TimeSpan.FromHours(periodicBackupModel.BackupInterval); AddTrigger(tr, td, backupName, periodicBackupModel.TrimmedBackupName); } if (periodicBackupModel.TimeType.Equals(Enums.GetDescription(TimeTypes.Minutes))) { tr.Repetition.Interval = TimeSpan.FromMinutes(periodicBackupModel.BackupInterval); AddTrigger(tr, td, backupName, periodicBackupModel.TrimmedBackupName); } } }
private async Task <List <HoteisFormatados> > CreateHotelAsync(Criteria criteria, Credential credential) { JsonResultModel hoteisRetorno = null; JsonRequestModel hotels = new JsonRequestModel { Credential = credential, Criteria = criteria }; using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://pp.cangooroo.net/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.PostAsJsonAsync("ws/rest/hotel.svc/Search", hotels); response.EnsureSuccessStatusCode(); if (response.IsSuccessStatusCode) { var jsonResult = response.Content.ReadAsStringAsync().Result; hoteisRetorno = JsonConvert.DeserializeObject <JsonResultModel>(jsonResult); } } List <Hotel> hoteis = new List <Hotel>(); foreach (var item in hoteisRetorno.Hotels) { hoteis.Add(item); } List <HoteisFormatados> hoteisFormatados = new HoteisFormatados().GetHoteisFormatados(hoteis, criteria.DestinationId); return(hoteisFormatados); }
/// <summary> /// Run disabled task/tasks /// </summary> private void RunDisabledTasks() { try { var backupInfo = new Dictionary <string, bool>(); var persistence = new Persistence(); var service = new Service(); var taskNames = new List <string>(); _jsonRquestModel = persistence.ReadFormInformation(); using (var ts = new TaskService()) { var tasks = ts.AllTasks.Where(t => t.State.Equals(TaskState.Disabled)).ToList(); if (dataGridView1.SelectedRows.Count > 0) { // Run selected disabled tasks foreach (var task in tasks) { if (task.Name.Contains(Constants.TaskDetailValue)) { var index = task.Name.IndexOf(" ") + 1; var taskName = task.Name.Substring(index); taskNames.Add(taskName); } } foreach (DataGridViewRow row in dataGridView1.SelectedRows) { var selectedTaskName = taskNames.FirstOrDefault(t => t.Equals(row.Cells[0].Value.ToString())); var backupModel = _jsonRquestModel.BackupModelList.FirstOrDefault(b => b.BackupName.Equals(selectedTaskName)); if (backupModel != null) { backupInfo.Add(backupModel.BackupName, false); persistence.RemoveDataFromJson(backupModel.BackupName); } } AddInfoIntoJson(persistence, service, backupInfo); } else { // Run all disabled tasks foreach (var task in tasks) { if (task.Name.Contains(Constants.TaskDetailValue)) { var index = task.Name.IndexOf(" ") + 1; var taskName = task.Name.Substring(index); var backupModel = _jsonRquestModel.BackupModelList.FirstOrDefault(b => b.BackupName.Equals(taskName)); if (backupModel != null) { backupInfo.Add(backupModel.BackupName, false); persistence.RemoveDataFromJson(backupModel.BackupName); } } } AddInfoIntoJson(persistence, service, backupInfo); } GetBackupTasks(); } } catch (Exception ex) { Logger.Error($"{Constants.RunDisabledTasks} {ex.Message} \n {ex.StackTrace}"); } }
protected static string Serialize(JsonRequestModel model, params JavaScriptConverter[] converters) { return(CreateSerializer(converters).Serialize(model)); }
public void WriteJsonRequestModel(JsonRequestModel request) { var json = JsonConvert.SerializeObject(request); File.WriteAllText(_persistancePath, json); }
public static dynamic ReadSheet(string spreadSheetId) { // Specifying Column Range for reading... var range = $"{sheet}!A:Z"; SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(spreadSheetId, range); // Ecexuting Read Operation... var response = request.Execute(); // Getting all records from Column A to E... IList <IList <object> > values = response.Values; //String jsonString = "["; int count = 0; IList <object> rowTitle = null; string ticketId = ""; List <JsonRequestModel> listJson = new List <JsonRequestModel>(); if (values != null && values.Count > 0) { foreach (var row in values) { JsonRequestModel jsonRequest = new JsonRequestModel(); if (count == 0) { rowTitle = row; count++; } else { string jsonString = "{"; for (int i = 0; i < row.Count; i++) { if (i == 0 || i == 1) { if (rowTitle[i].Equals("Ticket ID")) { ticketId = row[i] + ""; jsonRequest.TicketId = row[i] + ""; } } else { jsonString += "\"" + rowTitle[i] + "\":" + "\"" + row[i] + "\","; } } int lastIndex = jsonString.LastIndexOf(","); jsonString = jsonString.Substring(0, lastIndex); jsonString += "}"; jsonRequest.JsonInformation = jsonString; listJson.Add(jsonRequest); } // Print columns A to F, which correspond to indices 0 and 4. } //int last = jsonString.LastIndexOf(","); //jsonString = jsonString.Substring(0, last); //jsonString += "]"; return(listJson); } return(null); }