public IActionResult AddNewSchedule([FromBody] CreateScheduleRequest newSchedule) { if (newSchedule.Date.Equals("") || newSchedule.Time.Equals("") || newSchedule.MovieId.Equals("")) { return(BadRequest("Missing or invalid data!")); } else { if (scheduleRepository.FindExistingSchedule(newSchedule.Date, newSchedule.Time)) { return(Conflict("Schedule with this date and time existing in database!")); } else { Movie movie = movieRepository.GetById(newSchedule.MovieId); DateTime dateTime = DateTime.ParseExact(newSchedule.Time, "HH:mm:ss", CultureInfo.InvariantCulture); DateTime max = DateTime.ParseExact("23:00:00", "HH:mm:ss", CultureInfo.InvariantCulture); DateTime min = DateTime.ParseExact("08:00:00", "HH:mm:ss", CultureInfo.InvariantCulture); if (dateTime.AddMinutes(movie.Duration) > max || dateTime < min) { return(BadRequest("Bad time")); } else { scheduleRepository.Create(newSchedule.returnSchedule()); return(Ok(new ApiResponse("Schedule was added successfully!"))); } } } }
protected override void ProcessRecord() { base.ProcessRecord(); CreateScheduleRequest request; try { request = new CreateScheduleRequest { WorkspaceId = WorkspaceId, ApplicationKey = ApplicationKey, CreateScheduleDetails = CreateScheduleDetails, OpcRequestId = OpcRequestId, OpcRetryToken = OpcRetryToken }; response = client.CreateSchedule(request).GetAwaiter().GetResult(); WriteOutput(response, response.Schedule); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
public async Task CreateScheduleTest() { var commandState = HueRequestBuilder.Modify.Light(7).TurnOn().Build(); var newSchedule = new GetScheduleResponse { AutoDelete = true, Name = "new Timer", Description = "testing that scheduling", Timing = ScheduleTiming.CreateNew(ScheduleTimingTypes.Alarm), Command = new Command(commandState), Status = ScheduleStatus.Enabled }; newSchedule.Timing.BaseDate = DateTime.Now.AddDays(1); IHueRequest request = new CreateScheduleRequest { NewSchedule = newSchedule }; var response = await _client.GetResponseAsync(request); Assert.True(response is SuccessResponse); OnLog(response); Assert.True(newSchedule.Id > 0); await DeleteTemporarySchedule(newSchedule.Id); }
public async Task ShouldCreateScheduleWhenRequested() { var scheduleWebApiClient = new JsonServiceClient(ScheduleWebApiBaseUrl); var maintenanceWindowServiceLocation = new ServiceLocation { Location = new Uri("http://localhost:5678") }; _mockServer.Given( Request.Create().UsingGet().WithPath("/MaintenanceWindowService")) .RespondWith( Response.Create().WithSuccess().WithBodyAsJson(maintenanceWindowServiceLocation)); var maintenanceWindows = Any.Instance <MaintenanceWindow>(); _mockServer.Given( Request.Create().UsingGet().WithPath("/Planned")) .RespondWith( Response.Create().WithSuccess().WithBodyAsJson(maintenanceWindows)); var workloadItems = new List <WorkloadItem> { Any.Instance <WorkloadItem>(), Any.Instance <WorkloadItem>() }; var createScheduleRequest = new CreateScheduleRequest { WorkloadItems = workloadItems }; var result = await scheduleWebApiClient.PostAsync(createScheduleRequest).ConfigureAwait(false); result.Id.Should().NotBe(Guid.Empty); }
public Schedule GetSchedule() { DemandPermissionsBackup(); ScheduleResponse response; response = BackupService.GetSchedule(GetCurrentTenantId()); if (response == null) { return(null); } var schedule = new Schedule { StorageType = response.StorageType, StorageParams = response.StorageParams.ToDictionary(r => r.Key, r => r.Value) ?? new Dictionary <string, string>(), CronParams = new CronParams(response.Cron), BackupMail = response.BackupMail.NullIfDefault(), BackupsStored = response.NumberOfBackupsStored.NullIfDefault(), LastBackupTime = response.LastBackupTime }; if ((BackupStorageType)response.StorageType == BackupStorageType.CustomCloud) { var amazonSettings = CoreConfiguration.GetSection <AmazonS3Settings>(); var consumer = ConsumerFactory.GetByKey <DataStoreConsumer>("S3"); if (!consumer.IsSet) { consumer["acesskey"] = amazonSettings.AccessKeyId; consumer["secretaccesskey"] = amazonSettings.SecretAccessKey; consumer["bucket"] = amazonSettings.Bucket; consumer["region"] = amazonSettings.Region; } schedule.StorageType = BackupStorageType.ThirdPartyConsumer; schedule.StorageParams = consumer.AdditionalKeys.ToDictionary(r => r, r => consumer[r]); schedule.StorageParams.Add("module", "S3"); var Schedule = new CreateScheduleRequest { TenantId = TenantManager.GetCurrentTenant().TenantId, BackupMail = schedule.BackupMail != null && (bool)schedule.BackupMail, Cron = schedule.CronParams.ToString(), NumberOfBackupsStored = schedule.BackupsStored == null ? 0 : (int)schedule.BackupsStored, StorageType = schedule.StorageType, StorageParams = schedule.StorageParams }; BackupService.CreateSchedule(Schedule); } else if ((BackupStorageType)response.StorageType != BackupStorageType.ThirdPartyConsumer) { schedule.StorageParams["folderId"] = response.StorageBasePath; } return(schedule); }
public async Task <object> CreateSchedule(CreateScheduleRequest request) { var response = new CreateScheduleResponse { //Id = await _scheduleStorage.SaveScheduleAsync(CalculateScheduleFor(request.WorkloadItems, plannedMaintenanceWindow)) }; return(response); }
public async Task <IActionResult> ModifySchedule( [FromRoute] Guid facilityId, [FromRoute] Guid scheduleId, [FromBody] CreateScheduleRequest request) { var id = await mediator.Send(new ModifyScheduleCommand(facilityId, scheduleId, request.Name, request.StartDate, request.EndDate, request.Availabilities, request.CreatorId)); return(Ok(id)); }
public async Task ShouldRetrieveCreatedSchedule() { var scheduleWebApiClient = new JsonServiceClient(ScheduleWebApiBaseUrl); var maintenanceWindowServiceLocation = new ServiceLocation { Location = new Uri("http://localhost:5678") }; _mockServer.Given( Request.Create().UsingGet().WithPath("/MaintenanceWindowService")) .RespondWith( Response.Create().WithSuccess().WithBodyAsJson(maintenanceWindowServiceLocation)); var maintenanceWindows = new MaintenanceWindow { LengthInHours = 5 }; _mockServer.Given( Request.Create().UsingGet().WithPath("/Planned")) .RespondWith( Response.Create().WithSuccess().WithBodyAsJson(maintenanceWindows)); var workloadItems = new List <WorkloadItem> { new WorkloadItem { Identifier = Guid.NewGuid(), DurationInHours = 7 }, new WorkloadItem { Identifier = Guid.NewGuid(), DurationInHours = 3 } }; var createScheduleRequest = new CreateScheduleRequest { WorkloadItems = workloadItems }; var createScheduleResponse = await scheduleWebApiClient.PostAsync(createScheduleRequest).ConfigureAwait(false); var getScheduleByIdRequest = new GetScheduleByIdRequest { ScheduleId = createScheduleResponse.Id }; var getScheduleByIdResponse = await scheduleWebApiClient.GetAsync(getScheduleByIdRequest).ConfigureAwait(false); getScheduleByIdResponse.Schedule.Count.Should().Be(2); getScheduleByIdResponse.Schedule.Should().Contain(x => x.Identifier == workloadItems[0].Identifier && x.Order == 2); getScheduleByIdResponse.Schedule.Should().Contain(x => x.Identifier == workloadItems[1].Identifier && x.Order == 1); }
public async Task <IActionResult> Post([FromBody] CreateScheduleRequest request) { var command = new CreateScheduleCommand(request.Day, request.Hour, request.CustomerId, request.ServiceId); var result = await createScheduleService.Process(command); return(Ok(new ApiReturnItem <ScheduleResult> { Item = result, Success = true })); }
public void CreateSchedule(CreateScheduleRequest request) { BackupStorageFactory.GetBackupRepository().SaveBackupSchedule( new Schedule(request.TenantId) { Cron = request.Cron, BackupMail = request.BackupMail, NumberOfBackupsStored = request.NumberOfBackupsStored, StorageType = request.StorageType, StorageBasePath = request.StorageBasePath }); }
public void CreateSchedule(CreateScheduleRequest request) { BackupRepository.SaveBackupSchedule( new BackupSchedule() { TenantId = request.TenantId, Cron = request.Cron, BackupMail = request.BackupMail, BackupsStored = request.NumberOfBackupsStored, StorageType = request.StorageType, StorageBasePath = request.StorageBasePath, StorageParams = JsonConvert.SerializeObject(request.StorageParams) }); }
/// <summary> /// Allows the user to create new schedules. The bridge can store up to 100 schedules. /// /// Starting 1.17, creations of schedules with PUT is deprecated.PUT on existing schedules is still allowed. /// </summary> /// <param name="request">Create Schedule request</param> /// <param name="cancellationToken"></param> /// <returns>Contains a list with a single item that details whether the schedule was added successfully.</returns> public async Task <List <GenericSuccessResponseItem> > CreateScheduleAsync(CreateScheduleRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var json = JsonSerializer.Serialize(request, _jsonSerializerOptions); var requestContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync($"/api/{_userName}/schedules", requestContent, cancellationToken); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <List <GenericSuccessResponseItem> >(content, _jsonSerializerOptions)); } return(null); }
public void CreateSchedule(BackupStorageType storageType, StorageParams storageParams, int backupsStored, CronParams cronParams, bool backupMail) { DemandPermissionsBackup(); DemandSize(); if (!SetupInfo.IsVisibleSettings("AutoBackup")) { throw new InvalidOperationException(Resource.ErrorNotAllowedOption); } ValidateCronSettings(cronParams); var scheduleRequest = new CreateScheduleRequest { TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId, BackupMail = backupMail, Cron = cronParams.ToString(), NumberOfBackupsStored = backupsStored, StorageType = storageType }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: scheduleRequest.StorageBasePath = storageParams.FolderId; break; case BackupStorageType.CustomCloud: ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region); CoreContext.Configuration.SaveSection( new AmazonS3Settings { AccessKeyId = storageParams.AccessKeyId, SecretAccessKey = storageParams.SecretAccessKey, Bucket = storageParams.Bucket, Region = storageParams.Region }); break; } using (var service = new BackupServiceClient()) { service.CreateSchedule(scheduleRequest); } }
public void CreateSchedule(BackupStorageType storageType, Dictionary <string, string> storageParams, int backupsStored, CronParams cronParams, bool backupMail) { DemandPermissionsBackup(); DemandSize(); if (!SetupInfo.IsVisibleSettings("AutoBackup")) { throw new InvalidOperationException(Resource.ErrorNotAllowedOption); } ValidateCronSettings(cronParams); var scheduleRequest = new CreateScheduleRequest { TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId, BackupMail = backupMail, Cron = cronParams.ToString(), NumberOfBackupsStored = backupsStored, StorageType = storageType, StorageParams = storageParams }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: scheduleRequest.StorageBasePath = storageParams["folderId"]; break; case BackupStorageType.Local: if (!CoreContext.Configuration.Standalone) { throw new Exception("Access denied"); } scheduleRequest.StorageBasePath = storageParams["filePath"]; break; } using (var service = new BackupServiceClient()) { service.CreateSchedule(scheduleRequest); } }
public async Task <object> Post(CreateScheduleRequest request) { _logger.LogInformation("Create schedule requested."); using var httpClient = _httpClientFactory.CreateClient(); var getMaintenanceWindowServiceUriRequest = new HttpRequestMessage(HttpMethod.Get, $"{_configuration["ServiceLocatorBaseAddress"]}/MaintenanceWindowService"); var maintenanceWindowServiceUriResponse = await httpClient.SendAsync(getMaintenanceWindowServiceUriRequest).ConfigureAwait(false); var maintenanceWindowServiceUri = JsonConvert.DeserializeObject <ServiceLocation>(await maintenanceWindowServiceUriResponse.Content.ReadAsStringAsync() .ConfigureAwait(false)); var getPlannedMaintenanceWindowRequest = new HttpRequestMessage(HttpMethod.Get, $"{maintenanceWindowServiceUri.Location}Planned"); var plannedMaintenanceWindowResponse = await httpClient.SendAsync(getPlannedMaintenanceWindowRequest).ConfigureAwait(false); var plannedMaintenanceWindow = JsonConvert.DeserializeObject <MaintenanceWindow>(await plannedMaintenanceWindowResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); var response = new CreateScheduleResponse { Id = await _scheduleStorage.SaveScheduleAsync(CalculateScheduleFor(request.WorkloadItems, plannedMaintenanceWindow)) }; return(response); }
private async Task <int> CreateTemporarySchedule() { var request = new CreateScheduleRequest(); var commandState = HueRequestBuilder.Modify.Light(7).TurnOn().Build(); var newSchedule = new GetScheduleResponse { AutoDelete = true, Name = "temporary schedule", Description = "temporary schedule description", Timing = ScheduleTiming.CreateNew(ScheduleTimingTypes.Alarm), Command = new Command(commandState), Status = ScheduleStatus.Enabled }; newSchedule.Timing.BaseDate = DateTime.Now.AddDays(1); request.NewSchedule = newSchedule; var response = await _client.GetResponseAsync(request); Assert.True(response is SuccessResponse, "response is SuccessResponse"); OnLog(response); Assert.True(newSchedule.Id > 0, "new ID set"); return(newSchedule.Id); }
public async Task <IActionResult> Post([FromBody] CreateScheduleRequest request) { var result = await _scheduleAppService.Create(request); return(Ok(result)); }
public Task <BaseResponse> Create(CreateScheduleRequest request) { var response = new BaseResponse(); try { #region Tao dữ liệu routes var idsInvoice = new List <int>(); List <ScheduleCommand.Route> lstRoute = new List <ScheduleCommand.Route>(); foreach (var route in request.Routes) { // lay du lieu customer ung voi 1 route List <ScheduleCommand.CustomerInfo> customerInfos = new List <ScheduleCommand.CustomerInfo>(); route.Customers.ForEach(x => { idsInvoice.AddRange(x.Invoices); ScheduleCommand.CustomerInfo customerInfo = new ScheduleCommand.CustomerInfo() { CustomerID = x.CustomerID, Invoices = string.Join(',', x.Invoices), Lat = x.Address.Lat.Value.ToString(), Lng = x.Address.Lng.Value.ToString(), Status = x.Status, Weight = x.Weight }; customerInfos.Add(customerInfo); }); ScheduleCommand.Route routeData = new ScheduleCommand.Route() { EstimatedDistance = route.EstimatedDistance, EstimatedDuration = route.EstimatedDuration, DepotLat = route.Depot.Lat.Value.ToString(), DepotAddress = route.Depot.Address, DepotLng = route.Depot.Lng.Value.ToString(), DriverID = route.DriverID, WarehouseId = route.Depot.WarehouseId, Weight = route.Weight.Value, Status = route.Status.Value, CustomerInfos = customerInfos }; lstRoute.Add(routeData); } #endregion CreateScheduleCommand createCommand = new CreateScheduleCommand() { EstimatedDistance = request.EstimatedDistance, EstimatedDuration = request.EstimatedDuration, Name = request.Name, Note = request.Note, NumberOfCustomers = request.NumberOfCustomers, Weight = request.Weight, Status = request.Status, RouteManagerType = request.RouteManagerType, DeliveredAt = DateTime.ParseExact(request.Name, "dd-MM-yyyy", null), Routes = lstRoute }; var result = _bus.SendCommand(createCommand); Task <object> status = result as Task <object>; bool isCreate = (bool)status.Result; if (isCreate) { var ipValue = "192.168.43.51"; IBus rabbitBusControl = Bus.Factory.CreateUsingRabbitMq( rabbit => { IRabbitMqHost rabbitMqHost = rabbit.Host(new Uri($"rabbitmq://{ipValue}/"), settings => { settings.Username("tuandv"); settings.Password("tuandv"); }); } ); var invoices = _invoiceService.GetInvoices(idsInvoice); foreach (var item in invoices) { rabbitBusControl.Publish <InvoiceReadModel>(item); } } return(Task.FromResult(new BaseResponse { })); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }