private static TrackingData getSim2TrackingData() { var td = new TrackingData(); td.UsageRequirements = "The simulation tracker is for internal use only"; td.TrackerName = "Simulation Tracker"; td.EstimatedDelivery = DateTime.Parse("1-7-15"); td.Activity = new List<Activity>(); DateTime baseTime = DateTime.Now; baseTime = baseTime.AddMinutes(-baseTime.Minute); var activity = new Activity(); activity.Timestamp = baseTime.AddHours(-1); activity.ShortDescription = string.Format("Simulated activity at {0}", activity.Timestamp); activity.LocationDescription = "Simulated, SI"; td.Activity.Add(activity); activity = new Activity(); activity.Timestamp = baseTime; activity.ShortDescription = string.Format("Simulated activity at {0}", activity.Timestamp); activity.LocationDescription = "Simulated, SI"; td.Activity.Add(activity); return td; }
public void GetFormattedBody_Verify_Html_Contents() { var activity = new Activity(); activity.Timestamp = DateTime.Parse("2/5/06"); activity.ShortDescription = "Picked Up"; activity.LocationDescription = "Orlando, FL"; _stf = new SimpleTrackingRssBodyFormatter(); string body = _stf.GetFormattedBody(activity); Assert.AreEqual( "Date/Time: 2/5/2006 12:00:00 AM<br />Location: Orlando, FL<hr /><a href=\"http://www.SimpleTracking.com?source=feed-footer-click\"><img src=\"http://www.SimpleTracking.com/Images/Rss-Footer-Image.gif\" alt=\"Powered by SimpleTracking.com\" /></a>", body); }
private static TrackingData getSim1TrackingData() { var td = new TrackingData(); td.UsageRequirements = "The simulation tracker is for internal use only"; td.TrackerName = "Simulation Tracker"; td.EstimatedDelivery = DateTime.Parse("1-7-15"); td.Activity = new List<Activity>(); var activity = new Activity(); activity.Timestamp = DateTime.Parse("1-6-15 1:30 am"); activity.ShortDescription = "Picked Up"; activity.LocationDescription = "Atlanta, GA"; td.Activity.Add(activity); activity = new Activity(); activity.Timestamp = DateTime.Parse("1-6-15 2:53 pm"); activity.ShortDescription = "Processed"; activity.LocationDescription = "Richmond, VA"; td.Activity.Add(activity); return td; }
public void SetUp() { _a = new Activity(); }
private static Activity getPickupActivity(XmlNode xmlDoc) { XmlNode node = xmlDoc.SelectSingleNode("//Pickup/Date/text()"); if (node == null) return null; string dateString = node.Value; node = xmlDoc.SelectSingleNode("//Pickup/Time/text()"); if(node != null) dateString += " " + node.Value; var activity = new Activity(); activity.Timestamp = DateTime.Parse(dateString); activity.ShortDescription = "Picked up by DHL."; return activity; }
private static Activity getActivityFromScanNode(XmlNode scanNode) { var activity = new Activity(); XmlNode currNode; var dateString = scanNode.SelectSingleNode("Date/text()").Value; dateString += " " + scanNode.SelectSingleNode("Time/text()").Value; activity.Timestamp = DateTime.Parse(dateString); activity.ShortDescription = scanNode.SelectSingleNode("StatusDesc/text()").Value; string city = null, state = null, country = null; currNode = scanNode.SelectSingleNode("Location/City/text()"); if(currNode != null) city = currNode.Value; currNode = scanNode.SelectSingleNode("Location/State/text()"); if (currNode != null) state = currNode.Value; currNode = scanNode.SelectSingleNode("Location/Country/text()"); if (currNode != null) country = currNode.Value; var location = Location.GetLocationString(city, state, country); activity.LocationDescription = location; return activity; }
/// <summary> /// Converts a "Scan" node in the XML document into an <see cref="Activity"/>. /// </summary> /// <param name="scanNode"> /// The <see cref="XmlNode"/> that represents a "scan" node. /// </param> /// <returns> /// An activity that contains the data from the scan. /// </returns> private static Activity getActivityFromScanNode(XmlNode scanNode) { var activity = new Activity(); var dateString = scanNode.SelectSingleNode("Date/text()").Value; var timeString = scanNode.SelectSingleNode("Time/text()").Value; var date = UpsFormatConversions.parseUpsDate(dateString); var time = UpsFormatConversions.parseUpsTime(timeString); activity.Timestamp = date.Add(time.TimeOfDay); var scanDescriptionNode = scanNode.SelectSingleNode("Status/StatusType/Description/text()"); if (scanDescriptionNode != null) activity.ShortDescription = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(scanDescriptionNode.Value.ToLower()); string city = null, state = null, countryCode = null; var node = scanNode.SelectSingleNode("ActivityLocation/Address/City/text()"); if (node != null) { city = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(node.Value.ToLower()); } node = scanNode.SelectSingleNode("ActivityLocation/Address/StateProvinceCode/text()"); if (node != null) state = node.Value; node = scanNode.SelectSingleNode("ActivityLocation/Address/CountryCode/text()"); if (node != null) countryCode = node.Value; activity.LocationDescription = Location.GetLocationString(city, state, countryCode); return activity; }
/// <summary> /// Gets the tracking data for the specified tracking number. /// </summary> /// <param name="trackingNumber"> /// The tracking number to get tracking data for. /// </param> /// <returns> /// </returns> public TrackingData GetTrackingData(string trackingNumber) { //Only track it if it's a valid FedEx express or ground number if (!IsFedExExpress(trackingNumber) && !IsFedExGround(trackingNumber) && !IsFedExSmartPost(trackingNumber)) return null; var trackRequest = CreateTrackRequest(_key, _password, _accountNumber, _meterNumber, trackingNumber); //Note: If you get an exception creating the web service, open Reference.cs, and replace all [][]'s with [] //Reference: http://brianseekford.com/index.php/2010/05/06/fedex-integration-address-service-unable-to-generate-a-temporary-class-parsedelement/ //Reference: http://support.microsoft.com/kb/2486643 var resp = _trackService.track(trackRequest); var td = new TrackingData { TrackerName = "FedEx", }; //No activity, no data if(resp == null || resp.TrackDetails == null || resp.TrackDetails.Length == 0) return td; td.EstimatedDelivery = resp.TrackDetails[0].EstimatedDeliveryTimestamp; foreach (var evt in resp.TrackDetails[0].Events) { var a = new Activity(); a.LocationDescription = evt.Address.GetFriendlyAddressString(); a.ShortDescription = evt.EventDescription; a.Timestamp = evt.Timestamp; td.Activity.Add(a); } td.UsageRequirements = UsageRequirements; return td; }
/// <summary> /// Parses an individual activity node value into an <see cref="Activity"/> /// </summary> /// <param name="stepDetails"> /// The text from a TrackSummary or TrackDetail XML node. /// </param> /// <returns> /// An <see cref="Activity"/> that represents the data from the step. /// </returns> public static Activity ParseActivityString(string stepDetails) { const string DETAIL_REGEX = @"(?<description>Electronic Shipping Info Received), (?<date>.*)|(?<description>Processed), (?<date>.*, \d{4}), (?<time>.*?), (?<location>.*)|(?<description>Your item was delivered) at (?<time>.*) on (?<date>.*?) in (?<location>[^.]*)\.* *(?<extraInfo>.*)"; var activity = new Activity(); Match match = Regex.Match(stepDetails, DETAIL_REGEX); Group group = match.Groups["description"]; if (!group.Success) { activity.ShortDescription = stepDetails; return activity; } activity.ShortDescription = group.Value; group = match.Groups["date"]; if (group.Success) { string dateString = group.Value; group = match.Groups["time"]; if (group.Success) dateString += " " + group.Value; activity.Timestamp = DateTime.Parse(dateString); } group = match.Groups["location"]; if (group.Success) activity.LocationDescription = group.Value; return activity; }