public void EqualsActionIsNullTest() { IARoute route = new IARoute(null, "/example"); IARoute other = new IARoute("GET", "/example2"); Assert.IsFalse(route.Equals(other)); Assert.AreNotEqual(route.GetHashCode(), other.GetHashCode()); }
public IARequest(IARoute route) : base() { this.Route = route; this.Metadata = new Dictionary<string,string>(); this.Parameters = new Dictionary<string,string>(); }
public void EqualsDifferentResourceTest() { IARoute route = new IARoute("GET", "/example"); IARoute other = new IARoute("GET", "/example2"); Assert.IsFalse(route.Equals(other)); Assert.AreNotEqual(route.GetHashCode(), other.GetHashCode()); }
private void OnServiceFound(SDService service, bool ownService) { if (ownService) { IADevice device = new IADevice(service.Name, service.Hostname, service.Port, this.SupportedRoutes); this.OwnDevice = device.AsOption(); OnDeviceFound(device, true); } else { IADevice device = new IADevice(service.Name, service.Hostname, service.Port, null); IARequest request = new IARequest(IARoute.Get("/routes")); SendRequest(request, device, delegate(IAResponse response, Exception error) { if (error == null) { if (response.StatusCode == 200) { List <IARoute> supportedRoutes = response.BodyAs <IARoute>(); IADevice deviceWithRoutes = new IADevice(service.Name, service.Hostname, service.Port, new HashSet <IARoute>(supportedRoutes)); this.devices.Add(deviceWithRoutes); OnDeviceFound(deviceWithRoutes, false); } else { Console.WriteLine(String.Format("An error ocurred trying to request routes from {0}", device)); } } else { Console.WriteLine(String.Format("An error ocurred: {0}", error)); } }); } }
public IARequest(IARoute route) : base() { this.Route = route; this.Metadata = new Dictionary <string, string>(); this.Parameters = new Dictionary <string, string>(); this.Origin = new None <IADevice>(); }
public IARequest(IARoute route, Dictionary<String, String> metadata, Dictionary<String, String> parameters, IADevice origin, byte[] body, string contentType) : base(body, contentType) { this.Route = route; this.Metadata = metadata; this.Parameters = parameters; this.Origin = origin; }
public IARequest(IARoute route, Dictionary <String, String> metadata, Dictionary <String, String> parameters, IADevice origin, byte[] body, string contentType) : base(body, contentType) { this.Route = route; this.Metadata = metadata; this.Parameters = parameters; this.Origin = origin.AsOption(); }
public override bool Equals(Object obj) { if (this == obj) { return(true); } if (obj == null || (obj as IARoute) == null) { return(false); } IARoute route = (IARoute)obj; return((this.Action != null && this.Action.Equals(route.Action)) && (this.Resource != null && this.Resource.Equals(route.Resource))); }
public NancyRouteModule(NancyServerAdapter adapter) { foreach (KeyValuePair <IARoute, Action <IARequest, IAResponse> > kvp in adapter.Routes) { IARoute route = kvp.Key; Action <IARequest, IAResponse> action = kvp.Value; RouteBuilder rb = new RouteBuilder(route.Action, this); rb[route.Resource] = nancyDynamicDictionary => { Dictionary <string, string> parameters = new Dictionary <string, string>(); // get parameters out of path foreach (string key in nancyDynamicDictionary) { DynamicDictionaryValue value = nancyDynamicDictionary[key]; string urldecoded = HttpUtility.UrlDecode(value.ToString()); parameters.Add(key, urldecoded); } // get parameters out of query string foreach (string key in Request.Query) { DynamicDictionaryValue value = Request.Query[key]; parameters.Add(key, "" + value.Value); } string contentType = Request.Headers.ContentType; IADevice origin = null; if (Request.Headers.Keys.Contains("X-IA-Origin")) { IAIntAirAct intAirAct = TinyIoC.TinyIoCContainer.Current.Resolve <IAIntAirAct>(); if (intAirAct != null) { origin = intAirAct.DeviceWithName(Request.Headers["X-IA-Origin"].First()); } } Dictionary <string, string> metadata = new Dictionary <string, string>(); foreach (KeyValuePair <string, IEnumerable <string> > header in Request.Headers) { var value = header.Value.First(); metadata[header.Key] = value; } IARequest iaRequest = new IARequest(route, metadata, parameters, origin, Request.BodyAsByte(), contentType); IAResponse iaResponse = new IAResponse(); action(iaRequest, iaResponse); Response response = new Response(); response.StatusCode = (HttpStatusCode)iaResponse.StatusCode; response.Contents = stream => { var writer = new BinaryWriter(stream); writer.Write(iaResponse.Body); writer.Flush(); }; response.Headers = iaResponse.Metadata; response.ContentType = iaResponse.ContentType; return(response); }; } }
public void IARouteConstructorTest() { string action = "GET"; string resource = "/tests"; string actualAction; string actualResource; IARoute target = new IARoute(action, resource); actualAction = target.Action; actualResource = target.Resource; Assert.AreEqual(action, actualAction); Assert.AreEqual(resource, actualResource); }
public void Route(IARoute route, Action <IARequest, IAResponse> action) { SupportedRoutes.Add(route); server.Route(route, action); }
public IEnumerable <IADevice> DevicesSupportingRoute(IARoute route) { return(this.Devices.FindAll(device => device.SupportedRoutes.Contains(route))); }
public void Route(IARoute route, Action<IARequest, IAResponse> action) { Routes.Add(route, action); resolveCache().RebuildCache(); }
public void Route(IARoute route, Action<IARequest, IAResponse> action) { SupportedRoutes.Add(route); server.Route(route, action); }
public IEnumerable<IADevice> DevicesSupportingRoute(IARoute route) { return this.Devices.FindAll(device => device.SupportedRoutes.Contains(route)); }
public void ToStringTest() { IARoute route = new IARoute("", ""); Assert.IsNotNull(route.ToString()); }
public void EqualsSelfTest() { IARoute route = new IARoute("GET", "/example"); IARoute other = route; Assert.IsTrue(route.Equals(other)); Assert.AreEqual(route.GetHashCode(), other.GetHashCode()); }
public void EqualsNullTest() { IARoute route = new IARoute("GET", "/example"); IARoute other = null; Assert.IsFalse(route.Equals(other)); }
private void CallIntAirActRoute(IARoute route, Dictionary<string, string> parameters, Delegate successGeneric, MSEErrorHandler failure) { //Setup Routes with Device in View IARequest request = new IARequest(route); //Add Parameters foreach (KeyValuePair<string, string> pair in parameters) request.Parameters[pair.Key] = pair.Value; //Get all devices that support this route IEnumerable devicesSupportingRoute = this.intAirAct.DevicesSupportingRoute(route); bool sentToServer = false; //Request Devices in View foreach (IADevice device in devicesSupportingRoute) { sentToServer = true; this.intAirAct.SendRequest(request, device, delegate(IAResponse response, Exception exception) { if (exception != null) { failure(exception); } // QUESTION - Is this the same as saying if(successGeneric is MSEDeviceCollectionHandler) if (successGeneric.GetType() == typeof(MSEDeviceCollectionHandler)) { // Handle the response as if response was a collection MSEDeviceCollectionHandler success = (MSEDeviceCollectionHandler)successGeneric; List<MSEDevice> deviceList = Util.DeserializeIntoList(response.BodyAsString()); Util.CompleteDeviceListInformation(deviceList, this.intAirAct); success(deviceList); return; } else if(successGeneric.GetType() == typeof(MSESingleDeviceHandler)) { // Handle the response as if response was a single device MSESingleDeviceHandler success = (MSESingleDeviceHandler)successGeneric; MSEDevice result = Util.DeserializeSingleDevice(response.BodyAsString()); Util.CompleteDeviceInformation(result, this.intAirAct); success(result); return; } }); } // If sentToServer is false, that means there was no devices capable of handling the route. This could mean that no devices can handle the route, or it just hasn't been found yet // I would normally use IEnumerable.Count, but that doesn't exist if (sentToServer == false) { failure(new Exception("MSE Error - There are no Devices discovered on the Network that can handle the " + route.Action + " " + route.Resource + " request. Is your Locator Server running and visible on the network?")); return; } }
public void Route(IARoute route, Action <IARequest, IAResponse> action) { Routes.Add(route, action); resolveCache().RebuildCache(); }