protected override int Execute(DateTime when) { int result; PostAssetRequest sampleLoad = SampleFactory.BuildLoad(when); // build a search request based on the load to be posted CreateSearchRequest searchRequest = SampleFactory.BuildSearch(sampleLoad); SessionFacade session1; SessionFacade session2; if (Account1FailsLogin(out session1) || Account2FailsLogin(out session2)) { result = Result.Invalid; } else { session1.Post(sampleLoad); session2.Search(searchRequest); result = Result.Success; } return(result); }
public static PostAssetRequest BuildTruckWithAlarm(PostAssetRequest loadRequest) { PostAssetOperation loadOperation = loadRequest.postAssetOperations[0]; var load = loadOperation.Item as Shipment; var equipment = new Equipment { origin = new Place { Item = load.origin.Item }, destination = new EquipmentDestination { Item = new Place { Item = load.destination.Item } }, equipmentType = load.equipmentType }; Availability availability = loadOperation.availability; Dimensions dimensions = loadOperation.dimensions; var alarm = new AlarmSearchCriteria { ageLimitMinutes = 90, originRadius = new Mileage { method = MileageType.Road, miles = 50 }, destinationRadius = new Mileage { method = MileageType.Road, miles = 50 } }; var operation = new PostAssetOperation { availability = availability, alarm = alarm, count = loadOperation.count, countSpecified = true, dimensions = dimensions, Item = equipment, includeAsset = true, includeAssetSpecified = true }; if (loadOperation.stopsSpecified) { operation.stops = loadOperation.stops; operation.stopsSpecified = true; } if (loadOperation.ltlSpecified) { operation.ltl = loadOperation.ltl; operation.ltlSpecified = true; } return(new PostAssetRequest { postAssetOperations = new[] { operation } }); }
private static Availability DeriveAvailability(PostAssetRequest assetRequest) { Availability availability = assetRequest.postAssetOperations[0].availability; DateTime timeEarlierThanLoadsEarliest = availability.earliest.AddHours(-1); return(new Availability { earliest = timeEarlierThanLoadsEarliest, earliestSpecified = true, latest = availability.latest, latestSpecified = true }); }
private static Dimensions DeriveDimensions(PostAssetRequest assetRequest) { Dimensions assetDimensions = assetRequest.postAssetOperations[0].dimensions; return(new Dimensions { heightInches = assetDimensions.heightInches, heightInchesSpecified = true, lengthFeet = assetDimensions.lengthFeet + 10, lengthFeetSpecified = true, volumeCubicFeet = 0, volumeCubicFeetSpecified = false, weightPounds = assetDimensions.weightPounds, weightPoundsSpecified = true }); }
public async Task <ActionResult> PostAsync([FromBody] PostAssetRequest asset) { var result = _validationService.Validate <PostAssetRequest, AssetValidator>(asset); if (result.IsValid) { var id = await _assetService.CreateAsync(_mapper.Map <AssetDto>(asset)); return(Created($"{Url.ActionLink(action: "Post", controller:"Asset")}/{id}", await _assetService.GetAsync(id))); } else { _logger.LogWarning("Failed validation: {0}", result.Errors.FormatErrors()); return(BadRequest(result.Errors.FormatErrors())); } }
public static CreateSearchRequest BuildSearch(PostAssetRequest assetRequest) { Availability derivedAvailability = DeriveAvailability(assetRequest); Dimensions derivedDimensions = DeriveDimensions(assetRequest); var origin = new SearchArea { stateProvinces = new[] { StateProvince.CA, StateProvince.IL } }; var destination = new SearchArea { zones = new[] { Zone.MidAtlantic } }; var searchCriteria = new SearchCriteria { ageLimitMinutes = 90, ageLimitMinutesSpecified = true, assetType = AssetType.Shipment, availability = derivedAvailability, destination = new GeoCriteria { Item = destination }, equipmentClasses = new[] { EquipmentClass.Flatbeds, EquipmentClass.Reefers }, includeFulls = true, includeFullsSpecified = true, includeLtls = true, includeLtlsSpecified = true, limits = derivedDimensions, origin = new GeoCriteria { Item = origin } }; var createSearchOperation = new CreateSearchOperation { criteria = searchCriteria, includeSearch = true, includeSearchSpecified = true, sortOrder = SortOrder.Closest, sortOrderSpecified = true }; return(new CreateSearchRequest { createSearchOperation = createSearchOperation }); }
/// <summary> /// Calls <see cref="TfmiFreightMatchingPortTypeClient.PostAsset" /> method and writes result to console. /// </summary> /// <param name="postAssetRequest"> </param> public void Post(PostAssetRequest postAssetRequest) { /* pass a local variable as a "ref" parameter, rather than passing the field itself, so * the service can't modify what the field refers to */ CorrelationHeader correlationHeader = _correlationHeader; SessionHeader sessionHeader = _sessionHeader; WarningHeader warningHeader; PostAssetResponse postAssetResponse; _client.PostAsset(_applicationHeader, ref correlationHeader, ref sessionHeader, postAssetRequest, out warningHeader, out postAssetResponse); Console.WriteLine("===============Post Results==============="); if (postAssetResponse != null) { foreach (PostAssetResult postAssetResult in postAssetResponse.postAssetResults) { var postAssetSuccessData = postAssetResult.Item as PostAssetSuccessData; if (postAssetSuccessData == null) { var serviceError = postAssetResult.Item as ServiceError; serviceError.Display(); } else { postAssetSuccessData.Display(); } } } }
protected override int Execute(DateTime when) { int result; PostAssetRequest load = SampleFactory.BuildLoad(when); PostAssetRequest truckWithAlarm = SampleFactory.BuildTruckWithAlarm(load); DateTime deadline = DateTime.Now + Timeout; SessionFacade session1; SessionFacade session2; if (Account1FailsLogin(out session1) || Account2FailsLogin(out session2)) { result = Result.Failure; } else { session1.DeleteAllAssets(); string alarmUrl = AlarmUrl.AbsoluteUri + "/"; session1.UpdateAlarm(alarmUrl); session1.Post(truckWithAlarm); // listener implements IDisposable to allow cleanup of HTTP ports using (var listener = new Listener(AlarmUrl, deadline)) { var cancellableWaitForAlarm = new CancellationTokenSource(); // task for getting the listener started Task startListener = Task.Factory.StartNew(() => listener.Start()); // task for returning an HTTP request, if any Task <HttpListenerRequest> receiveAlarm = startListener.ContinueWith(p => listener.GetRequest(), cancellableWaitForAlarm.Token); // if task completes before timeout, post a search that should trigger the alarm if (startListener.Wait(Timeout)) { if (startListener.IsCanceled) { Console.WriteLine("Background task canceled before listening began."); return(Result.Failure); } if (startListener.IsFaulted) { Console.WriteLine("Background task faulted before listening began."); return(Result.Failure); } if (!startListener.IsCompleted) { Console.WriteLine("Unspecified error with starting listener in background task."); return(Result.Failure); } Console.WriteLine("Background task is listening for alarm."); session2.Post(load); } else { Console.WriteLine("Background listener was not ready within {0}ms.", Timeout.TotalMilliseconds); cancellableWaitForAlarm.Cancel(); return(Result.Failure); } // if receive an alarm before the timeout, print it to console if (receiveAlarm.Wait(Timeout)) { if (receiveAlarm.IsCanceled) { Console.WriteLine("Background task canceled before any alarm was received."); return(Result.Failure); } if (receiveAlarm.IsFaulted) { Console.WriteLine("Background task faulted before any alarm was received."); return(Result.Failure); } if (!receiveAlarm.IsCompleted) { Console.WriteLine("Unspecified error with listener awaiting alarm in background task."); return(Result.Failure); } Console.WriteLine("Background task completed."); HttpListenerRequest request = receiveAlarm.Result; Console.WriteLine("HTTP requested host name and port: " + request.UserHostName); Console.WriteLine("HTTP requested IP address and port: " + request.UserHostAddress); Console.WriteLine("HTTP raw url: " + request.RawUrl); Console.WriteLine("HTTP method: " + request.HttpMethod); Console.WriteLine("HTTP content type: " + request.ContentType); if (request.HasEntityBody) { Console.WriteLine("HTTP body: "); using (var streamReader = new StreamReader(request.InputStream)) { Console.WriteLine(streamReader.ReadToEnd()); } } Console.WriteLine("IP address and port of requester: " + request.RemoteEndPoint); } else { Console.WriteLine("Background task timed out after {0}ms.", Timeout.TotalMilliseconds); return(Result.Failure); } } result = Result.Success; } return(result); }