private StockPricesData OnPrependChartData(StockDisplayData displayData) { DateTime ts = DateTimeOperations.OneTickBefore(displayData.TsFrom, displayData.Prices); displayData.TsFrom = ts.AddDays(-1).AddYears(-1); return(_dataProvider.GetPricesData(displayData.Stock, displayData.Prices.Range, 0, displayData.TsFrom, ts)); }
public void OneTickBefore_UndefinedRange__Throws() { Should.Throw <ArgumentException>(() => DateTimeOperations.OneTickBefore(DateTime.Now, new StockPricesData(0) { Range = StockDataRange.Undefined, IntrradayInterval = 0 })); }
public void TrimMilliseconds_DateTime_MillisecondsTrimmed() { // Act var result = DateTimeOperations.TrimMilliseconds(new DateTime(2015, 02, 03, 14, 22, 13, 456)); // Assert Assert.AreEqual(0, result.Millisecond); }
public void OneTickBefore__ReturnsCorrectly(int tsY, int tsM, int tsD, int tsH, int tsMM, StockDataRange stockDataRange, int interadayInterval , int etsY, int etsM, int etsD, int etsH, int etsMM) { DateTimeOperations.OneTickBefore(new DateTime(tsY, tsM, tsD, tsH, tsMM, 0), new StockPricesData(0) { Range = stockDataRange, IntrradayInterval = interadayInterval }) .ShouldBe(new DateTime(etsY, etsM, etsD, etsH, etsMM, 0)); }
public string GetSearchZipCodeSimple(int?supplierId, string userTicket, string zipCode, string productName, string sortedBy) { SimpleSearchReference.Response response; if (string.IsNullOrEmpty(userTicket) || string.IsNullOrEmpty(zipCode) || supplierId == null) { response = new SimpleSearchReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new SimpleSearchReference.StatusResponse { Status = 400, Message = Default.LblHttpStatusCode400, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } if (userTicket.Trim().ToLower() != ConfigurationManager.AppSettings["Token"].Trim().ToLower()) { response = new SimpleSearchReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new SimpleSearchReference.StatusResponse { Status = 401, Message = Default.LblHttpStatusCode401, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } var client = new SimpleSearchReference.SimpleSearchClient(); response = client.Get(new SimpleSearchReference.SimpleSearchRequest { SupplierId = supplierId.Value, ZipCode = zipCode, UserTicket = userTicket, ProductName = productName, SortedBy = (SimpleSearchReference.EnumProduct)SourceProduct(string.IsNullOrEmpty(sortedBy) ? string.Empty : sortedBy), }); return(Serialize(response)); }
public string GetCityStateSortedResults(int?supplierId, string userTicket, string city, string state, string product) { CityStateReference.Response response; if (string.IsNullOrEmpty(userTicket) && (!string.IsNullOrEmpty(city) || !string.IsNullOrEmpty(state)) || supplierId == null) { response = new CityStateReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new CityStateReference.StatusResponse { Status = 400, Message = Default.LblHttpStatusCode400, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } if (userTicket.Trim().ToLower() != ConfigurationManager.AppSettings["Token"].Trim().ToLower()) { response = new CityStateReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new CityStateReference.StatusResponse { Status = 401, Message = Default.LblHttpStatusCode401, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } var client = new CityStateReference.CityStateClient(); response = client.Get(new CityStateReference.CityStateRequest { SupplierId = supplierId.Value, City = city, State = state, SortedBy = (CityStateReference.EnumProduct)SourceProduct(string.IsNullOrEmpty(product) ? string.Empty : product), UserTicket = userTicket }); return(Serialize(response)); }
public string GetLatLongResults(string userTicket, decimal?lattitude, decimal?longitude) { ZipCodeReference.Response response; if (string.IsNullOrEmpty(userTicket) || !lattitude.HasValue || !longitude.HasValue) { response = new ZipCodeReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new ZipCodeReference.StatusResponse { Status = 400, Message = Default.LblHttpStatusCode400, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } if (userTicket.Trim().ToLower() != ConfigurationManager.AppSettings["Token"].Trim().ToLower()) { response = new ZipCodeReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new ZipCodeReference.StatusResponse { Status = 401, Message = Default.LblHttpStatusCode401, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } var zipCode = string.Empty; var client = new ZipCodeReference.ZipCodeClient(); response = client.Get(new ZipCodeReference.ZipCodeRequest { ZipCode = zipCode, UserTicket = userTicket }); return(Serialize(response)); }
public string GetStationListResults(int?supplierId, string userTicket, string idStation) { StationListReference.Response response; if (string.IsNullOrEmpty(userTicket) || string.IsNullOrEmpty(idStation) || supplierId == null) { response = new StationListReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new StationListReference.StatusResponse { Status = 400, Message = Default.LblHttpStatusCode400, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } if (userTicket.Trim().ToLower() != ConfigurationManager.AppSettings["Token"].Trim().ToLower()) { response = new StationListReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new StationListReference.StatusResponse { Status = 401, Message = Default.LblHttpStatusCode401, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } var client = new StationListReference.StationListClient(); response = client.Get(new StationListReference.StationListRequest { SupplierId = supplierId.Value, StationList = idStation, UserTicket = userTicket }); return(Serialize(response)); }
// TODO: Performance improvement if TDNode had its TDNode successors & predecessors retrievable directly. /// <summary> /// Performs a depth-first propagation along a path for which all predecessors' computations are complete, /// adjusting early start & finish according to a PERT methodology. /// </summary> /// <param name="tdNode">The TimingData node.</param> private void PropagateForward(TimingData tdNode) { tdNode.EarlyFinish = tdNode.EarlyStart + tdNode.NominalDuration; foreach (TimingData successor in m_successors(tdNode.Subject).Select(n => TimingDataNodeFor(n))) { if (!successor.IsFixed) { successor.EarlyStart = DateTimeOperations.Max(successor.EarlyStart, tdNode.EarlyFinish); } successor.RegisterPredecessor(); if (successor.AllPredecessorsHaveWeighedIn) { PropagateForward(successor); } } }
/// <summary> /// Performs a depth-first propagation backwards along a path for which all successors' computations /// are complete, adjusting late start & finish according to a PERT methodology. /// </summary> /// <param name="tdNode">The TimingData node.</param> private void PropagateBackward(TimingData tdNode) { tdNode.LateStart = tdNode.LateFinish - tdNode.NominalDuration; foreach (TimingData predecessor in m_predecessors(tdNode.Subject).Select(n => TimingDataNodeFor(n))) { if (!predecessor.IsFixed) { predecessor.LateFinish = DateTimeOperations.Min(predecessor.LateFinish, tdNode.LateStart); } predecessor.RegisterSuccessor(); if (predecessor.AllSuccessorsHaveWeighedIn) { PropagateBackward(predecessor); } } }
/// <summary> /// Gets the file last modification time. /// </summary> /// <param name="relativeFilePath">The relative file path.</param> /// <returns></returns> public DateTime GetFileLastModificationTime(string relativeFilePath) { return(DateTimeOperations.TrimMilliseconds(FileSystem.File.GetLastWriteTimeUtc(relativeFilePath))); }
private static void Propagate() { while (_changedMilestones.Count > 0) { Milestone ms = (Milestone)_changedMilestones.Dequeue(); if (_debug) { _Debug.WriteLine("\tPerforming propagation of change to " + ms.Name); } #region Create a Hashtable of Lists - key is target Milestone, list contains relationships to that ms. Hashtable htol = new Hashtable(); foreach (MilestoneRelationship mr in ms.Relationships) { if (!mr.Enabled) { continue; // Only enabled relationships can effect change. } if (mr.Dependent.Equals(ms)) { continue; // Only relationships where we are the independent can effect change. } //if ( m_debug ) _Debug.WriteLine("\tConsidering " + mr.ToString()); if (!htol.Contains(mr.Dependent)) { htol.Add(mr.Dependent, new ArrayList()); } ((ArrayList)htol[mr.Dependent]).Add(mr); // We now have outbounds, grouped by destination milestone. } #endregion //if ( m_debug ) _Debug.WriteLine("\tPerforming change assessments for relationships that depend on " + ms.Name); // For each 'other' milestone with which this milestone has a relationship, we will // handle all of the relationships that this ms has with that one, as a group. bool fullData = false; foreach (Milestone target in htol.Keys) { if (_debug) { _Debug.WriteLine("\t\tReconciling all relationships between " + ms.Name + " and " + target.Name); // E : RCV Liquid1.Xfer-In.Start and E : RCV Liquid1.Xfer-In.End } IList relationships = (ArrayList)htol[target]; // Gives us a list of parallel relationships to the same downstream. // if ( ms.Name.Equals("B : RCV Liquid1.Xfer-In.Start") && target.Name.Equals("B : RCV Liquid1.Temp-Set.End") ) { // fullData = true; // } if (fullData) { foreach (MilestoneRelationship mr2 in relationships) { _Debug.WriteLine(mr2.ToString()); } } DateTime minDateTime = DateTime.MinValue; DateTime maxDateTime = DateTime.MaxValue; foreach (MilestoneRelationship mr2 in relationships) { /*foreach ( MilestoneRelationship recip in mr2.Reciprocals) { * recip.PushEnabled(false); * m_pushedDisablings.Push(recip); * }*/ if (fullData) { if (_debug) { _Debug.WriteLine("\t\tAdjusting window to satisfy " + mr2); } } DateTime thisMinDt, thisMaxDt; mr2.Reaction(ms.DateTime, out thisMinDt, out thisMaxDt); // Get the relationship's acceptable window. minDateTime = DateTimeOperations.Max(minDateTime, thisMinDt); // Narrow the range from below. maxDateTime = DateTimeOperations.Min(maxDateTime, thisMaxDt); // Narrow the range from above. if (fullData) { if (_debug) { _Debug.WriteLine("\t\t\tThe window is now from " + minDateTime + " to " + maxDateTime + "."); } } } //if ( m_debug ) _Debug.WriteLine("\t\tThe final window is from " + minDateTime + " to " + maxDateTime + "."); if (minDateTime <= maxDateTime) { DateTime newDateTime = GetClosestDateTime(minDateTime, maxDateTime, target.DateTime); if (!target.DateTime.Equals(newDateTime)) { if (_debug) { _Debug.WriteLine("\t\t\tWe will move " + target.Name + " from " + target.DateTime + " to " + newDateTime); } if (!_changedMilestones.Contains(target)) { _changedMilestones.Enqueue(target); } if (!_oldValues.Contains(target)) { _oldValues.Add(target, target.m_dateTime); } if (fullData) { if (_debug) { _Debug.WriteLine("\t\t\tThere are now " + _changedMilestones.Count + " milestones with changes to process."); } } target.m_dateTime = newDateTime; } else { if (_debug) { _Debug.WriteLine("\t\t\t" + target.Name + " stays put."); } } // } else { // if ( m_debug ) _Debug.WriteLine("\t\t\tThis is an unachievable window."); // throw new ApplicationException("Can't find a new datetime value for " + target.ToString()); } fullData = false; } } }
private void RunTest(TimePeriod tpA, TimePeriod tpB, TimePeriod.Relationship relationship, TimePeriodPart moveWhichPart, string ofWhich, TimeSpan byHowMuch) { bool CONSOLE_OUTPUT = false; tpA.AddRelationship(relationship, tpB); DateTime earliest = DateTimeOperations.Min(tpA.StartTime, tpB.StartTime); DateTime left = earliest - new TimeSpan(0, 0, (earliest.Minute % 10), 0, 0); int spaces, width; string A, B; if (CONSOLE_OUTPUT) { Debug.WriteLine(" ....*....|....*....|....*....|....*....|....*....|"); A = "Initial A : "; spaces = (int)((TimeSpan)(tpA.StartTime - left)).TotalMinutes; width = (int)tpA.Duration.TotalMinutes; for (int i = 0; i < spaces; i++) { A += " "; } for (int i = 0; i < width; i++) { A += "a"; } for (int i = (spaces + width); i < 50; i++) { A += " "; } Debug.WriteLine(A + tpA.ToString()); B = "Initial B : "; spaces = (int)((TimeSpan)(tpB.StartTime - left)).TotalMinutes; width = (int)tpB.Duration.TotalMinutes; for (int i = 0; i < spaces; i++) { B += " "; } for (int i = 0; i < width; i++) { B += "b"; } for (int i = (spaces + width); i < 50; i++) { B += " "; } Debug.WriteLine(B + tpB.ToString()); Debug.WriteLine("We'll move " + ofWhich + "." + moveWhichPart.ToString() + " by " + byHowMuch.ToString() + "..."); } int selector = 0; if (ofWhich.Equals("A")) { selector += 0; } if (ofWhich.Equals("B")) { selector += 1; } selector <<= 1; if (moveWhichPart.Equals(TimePeriodPart.StartTime)) { selector += 0; } if (moveWhichPart.Equals(TimePeriodPart.EndTime)) { selector += 1; } tpA.AdjustmentMode = TimeAdjustmentMode.FixedDuration; tpB.AdjustmentMode = TimeAdjustmentMode.FixedDuration; if (CONSOLE_OUTPUT) { Console.WriteLine("3."); foreach (IMilestone ms in new IMilestone[] { tpB.StartMilestone, tpB.EndMilestone }) { Console.WriteLine(ms.Name); foreach (MilestoneRelationship mr in ms.Relationships) { Console.WriteLine(mr.ToString()); } } Console.WriteLine("4."); foreach (IMilestone ms in new IMilestone[] { tpB.StartMilestone, tpB.EndMilestone }) { Console.WriteLine(ms.Name); foreach (MilestoneRelationship mr in ms.Relationships) { Console.WriteLine(mr.ToString()); } } } switch (selector) { case 0: tpA.AdjustmentMode = TimeAdjustmentMode.InferEndTime; tpA.StartTime += byHowMuch; break; case 1: tpA.AdjustmentMode = TimeAdjustmentMode.InferStartTime; tpA.EndTime += byHowMuch; break; case 2: tpB.AdjustmentMode = TimeAdjustmentMode.InferEndTime; tpB.StartTime += byHowMuch; break; case 3: tpB.AdjustmentMode = TimeAdjustmentMode.InferStartTime; tpB.EndTime += byHowMuch; break; } if (CONSOLE_OUTPUT) { A = "Final A : "; spaces = (int)((TimeSpan)(tpA.StartTime - left)).TotalMinutes; width = (int)tpA.Duration.TotalMinutes; for (int i = 0; i < spaces; i++) { A += " "; } for (int i = 0; i < width; i++) { A += "A"; } for (int i = (spaces + width); i < 50; i++) { A += " "; } Debug.WriteLine(A + tpA.ToString()); B = "Final B : "; spaces = (int)((TimeSpan)(tpB.StartTime - left)).TotalMinutes; width = (int)tpB.Duration.TotalMinutes; for (int i = 0; i < spaces; i++) { B += " "; } for (int i = 0; i < width; i++) { B += "B"; } for (int i = (spaces + width); i < 50; i++) { B += " "; } Debug.WriteLine(B + tpB.ToString()); } foreach (TimePeriod tp in new TimePeriod[] { tpA, tpB }) { foreach (IMilestone ms in new IMilestone[] { tp.StartMilestone, tp.EndMilestone }) { foreach (MilestoneRelationship mr in ms.Relationships) { bool b = mr.IsSatisfied(); Console.WriteLine(mr + (b?" is ":" is not ") + "satisfied."); //Assert.IsTrue(b, mr + " is not satisfied!"); } } } }
public string GetLatLongSortedWithDistanceResults(decimal?lattitude, decimal?longitude, string fuelType, decimal?distance) { LattitudeLongitudeReference.Response response; decimal lattitudeValue = 0; decimal longitudeValue = 0; decimal distanceValue = 0; if (!lattitude.HasValue || !longitude.HasValue || string.IsNullOrEmpty(fuelType) || !distance.HasValue || !decimal.TryParse(lattitude.Value.ToString(), out lattitudeValue) || !decimal.TryParse(longitude.Value.ToString(), out longitudeValue) || !decimal.TryParse(distance.Value.ToString(), out distanceValue)) { response = new LattitudeLongitudeReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new LattitudeLongitudeReference.StatusResponse { Status = 400, Message = Default.LblHttpStatusCode400, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } var userName = string.Empty; if (!Validate()) { response = new LattitudeLongitudeReference.Response { IsSuccess = false, ListResult = null, StatusResponse = new LattitudeLongitudeReference.StatusResponse { Status = 401, Message = Default.LblHttpStatusCode401, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(Serialize(response)); } var client = new LattitudeLongitudeReference.LattitudeLongitudeClient(); response = client.Get(new LattitudeLongitudeReference.LatLongRequest { Lattitude = lattitudeValue, Longitude = longitudeValue, FuelType = fuelType, Distance = distanceValue }); return(Serialize(response)); }
public Response GetCityState(CityStateRequest request) { try { _listResult = _repository.GetCityState(request); var numberItems = _listResult.Count; if (numberItems == 0) { _response = new Response { IsSuccess = true, NumberItems = numberItems, //Obsolete = _listResult, StatusResponse = new StatusResponse { Status = 404, Message = Default.LblHttpStatusCode404, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(_response); } _response = new Response { IsSuccess = true, NumberItems = numberItems, //Obsolete = request.SortedBy.HasValue ? Sorting.Sort(_listResult, request.SortedBy.Value) : _listResult, StatusResponse = new StatusResponse { Status = 200, Message = Default.LblHttpStatusCode200, Timestamp = DateTimeOperations.FormatTimeStamp() } }; } catch (Exception exception) { var exceptionLog = new ExceptionLog { ApplicationName = $"{ConfigurationManager.AppSettings["SolutionName"]} - {ConfigurationManager.AppSettings["UserFuelServices"]}", Message = exception.Message }; var exceptionRepository = new ExceptionLogRepository("MetadataConnection"); var exceptionId = exceptionRepository.Add(exceptionLog); _response = new Response { IsSuccess = false, //Obsolete = null, StatusResponse = new StatusResponse { Status = 500, Message = Default.LblHttpStatusCode500, Timestamp = DateTimeOperations.FormatTimeStamp() } }; } return(_response); }
public Response GetLatLongSortedWithDistanceResults(LatLongRequest request) { try { var listResult = _repository.GetLatLongSortedWithDistanceResults(request); var numberItems = listResult.Count; if (numberItems == 0) { _response = new Response { IsSuccess = true, NumberItems = numberItems, ListResult = listResult, StatusResponse = new StatusResponse { Status = 404, Message = Default.LblHttpStatusCode404, Timestamp = DateTimeOperations.FormatTimeStamp() } }; return(_response); } _response = new Response { IsSuccess = true, NumberItems = numberItems, ListResult = listResult, StatusResponse = new StatusResponse { Status = 200, Message = Default.LblHttpStatusCode200 } }; } catch (Exception exception) { var exceptionLog = new ExceptionLog { ApplicationName = $"{ConfigurationManager.AppSettings["SolutionName"]} - {ConfigurationManager.AppSettings["UserFuelServices"]}", Message = exception.Message }; var exceptionRepository = new ExceptionLogRepository("MetadataConnection"); var exceptionId = exceptionRepository.Add(exceptionLog); _response = new Response { IsSuccess = false, ListResult = null, StatusResponse = new StatusResponse { Status = 500, Message = Default.LblHttpStatusCode500, Timestamp = DateTimeOperations.FormatTimeStamp() } }; } return(_response); }