public static AbstractServer GetServer(ServerType serverType, string port) { AbstractServer server = null; AbstractHandlerFactory handlerFactory = null; AbstractCommandHandler handler = null; switch (serverType) { case ServerType.TCPServer: server = new TCPServer(port); handlerFactory = new TCPHandlerFactory(); break; case ServerType.FileServer: port = GetFilserverPort(port); server = new FileServer(300, port); handlerFactory = new FileHandlerFactory(); break; case ServerType.SyncFileServer: port = GetFilserverPort(port); server = new SyncFileServer(300, port); handlerFactory = new FileHandlerFactory(); break; } server.commandHandler = handlerFactory.GetKeyBoardRequestHandler(); handler = server.commandHandler.SetNextHandler(handlerFactory.GetMouseRequestHandler()); handler = handler.SetNextHandler(handlerFactory.GetKeyLoggerRequestHandler()); handler = handler.SetNextHandler(handlerFactory.GetScreenRequestHandler()); handler.SetNextHandler(handlerFactory.GetDefaultRequestHandler()); return(server); }
static void Main(string[] args) { AbstractHandlerFactory factory = FactoryProducer.GetFactory("Entity"); factory.GetEntityHandlerFactory("A").DoOperation("Read", "Dest"); factory.GetEntityHandlerFactory("B").DoOperation("Copy", "Dest"); factory.GetEntityHandlerFactory("C").DoOperation("Delete", "Src"); Console.ReadLine(); }
/// <summary> /// Retrieves instance of the page from Spring web application context. /// </summary> /// <param name="context">current HttpContext</param> /// <param name="requestType">type of HTTP request (GET, POST, etc.)</param> /// <param name="url">requested page URL</param> /// <param name="path">translated server path for the page</param> /// <returns>instance of the configured page object</returns> IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string path) { new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand(); IConfigurableApplicationContext appContext = WebApplicationContext.GetContext(url) as IConfigurableApplicationContext; if (appContext == null) { throw new InvalidOperationException( "Implementations of IApplicationContext must also implement IConfigurableApplicationContext"); } string appRelativeVirtualPath = WebUtils.GetAppRelativePath(url); AbstractHandlerFactory.NamedObjectDefinition nod = AbstractHandlerFactory.FindWebObjectDefinition(appRelativeVirtualPath, appContext.ObjectFactory); Type serviceType = null; if (nod != null) { #if !MONO if (appContext.IsTypeMatch(nod.Name, typeof(WebServiceExporter))) { WebServiceExporter wse = (WebServiceExporter)appContext.GetObject(nod.Name); serviceType = wse.GetExportedType(); } else { serviceType = appContext.GetType(nod.Name); // check if the type defines a Web Service object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true); if (wsAttribute.Length == 0) { serviceType = null; } } #else serviceType = appContext.GetType(nod.Name); // check if the type defines a Web Service object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true); if (wsAttribute.Length == 0) { serviceType = null; } #endif } if (serviceType == null) { serviceType = WebServiceParser.GetCompiledType(url, context); } #if !MONO_2_0 return((IHttpHandler)CoreGetHandler.Invoke(this, new object[] { serviceType, context, context.Request, context.Response })); #else // find if the BuildManager already contains a cached value of the service type var buildCacheField = typeof(BuildManager).GetField("buildCache", BindingFlags.Static | BindingFlags.NonPublic); var buildCache = (IDictionary)buildCacheField.GetValue(null); if (!buildCache.Contains(appRelativeVirtualPath)) { // create new fake BuildManagerCacheItem wich represent the target type var buildManagerCacheItemType = Type.GetType("System.Web.Compilation.BuildManagerCacheItem, System.Web"); var cacheItemCtor = buildManagerCacheItemType.GetConstructor(new Type[] { typeof(Assembly), typeof(BuildProvider), typeof(CompilerResults) }); var buildProvider = new FakeBuildProvider(serviceType); var cacheItem = cacheItemCtor.Invoke(new object[] { serviceType.Assembly, buildProvider, null }); // store it in the BuildManager buildCache [appRelativeVirtualPath] = cacheItem; } // now that the target type is in the cache, let the default process continue return(base.GetHandler(context, requestType, url, path)); #endif }