public new ActionResult HandleAction(Controller controller) { XForm xForm = this.GetXForm(controller); if (xForm == null) { return null; } var xFormPostedData = this.GetXFormPostedData(controller, this.ActionName); // This part reads in specific elements and adds in basic custom validation var formName = xFormPostedData.XFormFragments.FirstOrDefault(f => f.Reference == "formName"); var elementInForm = xFormPostedData.XFormFragments.FirstOrDefault(f => f.Reference == "elementInForm"); if (formName == null || elementInForm == null || string.IsNullOrEmpty(elementInForm.Value)) { controller.ModelState.AddModelError("elementInForm", "Value must be entered"); } if (controller.ModelState.IsValid && ProcessXFormAction(controller, xFormPostedData)) { return InvokeSuccessAction(xForm, xFormPostedData, controller); } return InvokeFailedAction(xForm, xFormPostedData, controller); }
protected static void SetupControllerContext(Controller controller,string[] userRoles = null, NameValueCollection form = null) { var routes = new RouteCollection(); MvcApplication.RegisterRoutes(routes); var request = new Mock<HttpRequestBase>(MockBehavior.Strict); request.SetupGet(x => x.ApplicationPath).Returns("/"); request.SetupGet(x => x.Url).Returns(new Uri("http://localhost/a", UriKind.Absolute)); request.SetupGet(x => x.ServerVariables).Returns(new System.Collections.Specialized.NameValueCollection()); request.SetupGet(x => x.Form).Returns(new NameValueCollection()); request.SetupGet(x => x.IsAuthenticated).Returns(true); var response = new Mock<HttpResponseBase>(MockBehavior.Strict); response.Setup(x => x.ApplyAppPathModifier("/post1")).Returns("http://localhost/post1"); var context = new Mock<HttpContextBase>(MockBehavior.Strict); context.SetupGet(x => x.Request).Returns(request.Object); context.SetupGet(x => x.Response).Returns(response.Object); context.SetupGet(x => x.Items).Returns(new Dictionary<string, string>()); context.SetupGet(x => x.User.Identity.Name).Returns("someUser"); context.SetupGet(x => x.Request.IsAuthenticated).Returns(true); context.Setup(x => x.User.IsInRole("User")).Returns(() => true); context.Setup(x => x.Request).Returns(request.Object); if (form != null) context.Setup(x => x.Request.Form).Returns(form); //Add user roles to contexts User if (userRoles != null) { foreach (var role in userRoles) { context.Setup(x => x.User.IsInRole(role)).Returns(true); } } controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller); controller.Url = new UrlHelper(new RequestContext(context.Object, new RouteData()), routes); }
static void Main(string[] args) { //declare settings and data structures const Boolean MUX_ENABLE = false; const int iterations = 10000; ArrayList myTags = new ArrayList(); Controller c = new Controller(); Console.Out.WriteLine("Setup"); //create device if (c.CreateUSBDevice()) { Console.Out.WriteLine("\tSkyetek USB Device Created"); } else { c.CreateSerialDevice(); Console.Out.WriteLine("\tSkyetek Serial Device Created"); } //create reader (automatically opens the device too) c.CreateReader(); Console.Out.WriteLine("\tSkyetek Reader Created"); Console.Out.WriteLine(String.Format("\tProduct Code: {0}", c.GetProduct())); Console.Out.WriteLine(String.Format("\tReader Name: {0}", c.GetName())); //set tag type /************************************************************************************ * If no type is specified, tag type defaults to auto detect all types. * It is recommended the type be specified for quickest responses and best performance * ISO-18000-6C (gen2) is a common UHF tag protocol (for M7/M9 modules) * ISO-15693 is a common HF tag protocol (for M2/M4 modules) *************************************************************************************/ if (c.GetProduct() == "0007" || c.GetProduct() == "0009") { c.SetTagType(TagType.ISO_18000_6C_AUTO_DETECT); } else if (c.GetProduct() == "0002" || c.GetProduct() == "0004") { c.SetTagType(TagType.ISO_15693_AUTO_DETECT); } Console.Out.WriteLine("\tTag Type Set To " + c.GetTagType() + "\n"); //perform an inventory select for the set number of iterations //if a mux is connected, then cycle through all available ports if (!MUX_ENABLE) { for (int i = 1; i <= iterations; i++) { myTags = c.GetTags(); Console.Out.WriteLine("Iteration #" + i.ToString()); foreach (string k in myTags) { Console.Out.WriteLine("\tTag Found: " + k.ToString()); } } } else //mux enabled { byte[] muxPorts; if (c.GetMuxPorts() == 4) { muxPorts = new byte[] { 0, 2, 5, 7 }; } else if (c.GetMuxPorts() == 8) { muxPorts = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; } else { Console.Out.WriteLine("ERROR: NO MUX DETECTED"); muxPorts = new byte[] { 0 }; } for (int i = 1; i <= iterations; i++) { Console.Out.WriteLine("Iteration #" + i.ToString()); foreach (byte j in muxPorts) { Console.Out.WriteLine("\tPort=" + j); c.SetMuxPort(j); myTags = c.GetTags(); foreach (string k in myTags) { Console.Out.WriteLine("\t\tTag Found: " + k.ToString()); } } } } //close the device c.Stop(); Console.Out.WriteLine("\nSkyetek Device Closed"); }