public FactoryRequest BuildShipInDock(int dockId, int oil, int steel, int ammo, int alum) { z.instance.BeforeBuildShip(dockId, oil, steel, ammo, alum); FactoryRequest component = new FactoryRequest(); component.BuildShip(dockId, oil, steel, ammo, alum); return component; }
public FactoryRequest BuildShipInDock(int dockId, int oil, int steel, int ammo, int alum) { FactoryRequest component = new FactoryRequest(); component.BuildShip(dockId, oil, steel, ammo, alum); return(component); }
public FactoryRequest ToggleShipBuildLogFav(BuildLogVO log) { FactoryRequest component = new FactoryRequest(); component.SetFavLog(log); return(component); }
public FactoryRequest GetShipFromDock(int dockId) { FactoryRequest component = new FactoryRequest(); component.GetShip(dockId); return(component); }
public FactoryRequest FastBuildShipAtDock(int dockId) { FactoryRequest component = new FactoryRequest(); component.FastBuild(dockId); return(component); }
public FactoryRequest GetShipBuildLog() { FactoryRequest component = new FactoryRequest(); component.GetBuildLog(); return(component); }
/// <summary> /// Creates a factory instance that can create instaces of the given /// <paramref name="serviceType"/> using the <paramref name="implementingType"/> /// as the implementation. /// </summary> /// <param name="serviceType">The service being implemented.</param> /// <param name="implementingType">The actual type that will implement the service.</param> /// <param name="lifecycle">The <see cref="LifecycleType"/> that determines the lifetime of each instance being created.</param> /// <returns>A valid <see cref="IFactory"/> instance.</returns> public IFactory CreateFactory(Type serviceType, Type implementingType, LifecycleType lifecycle) { // Determine the factory type Type factoryTypeDefinition = _factoryTypes[lifecycle]; Type actualType = GetActualType(serviceType, implementingType); if (!serviceType.ContainsGenericParameters && !actualType.ContainsGenericParameters) { Type factoryType = factoryTypeDefinition.MakeGenericType(serviceType); return(CreateFactory(serviceType, actualType, factoryType)); } Func <IFactoryRequest, object> factoryMethod = request => { string serviceName = request.ServiceName; Type type = request.ServiceType; IServiceContainer currentContainer = request.Container; object[] arguments = request.Arguments; // Determine the implementing type Type concreteType = GetActualType(type, implementingType); // The concrete type cannot be null if (concreteType == null) { return(null); } // Generate the concrete factory instance // at runtime Type factoryType = factoryTypeDefinition.MakeGenericType(type); IFactory factory = CreateFactory(type, concreteType, factoryType); var factoryRequest = new FactoryRequest { ServiceType = serviceType, ServiceName = serviceName, Arguments = arguments, Container = currentContainer }; return(factory.CreateInstance(factoryRequest)); }; return(new FunctorFactory(factoryMethod)); }
/// <summary> /// Creates a factory instance that can create instaces of the given /// <paramref name="serviceType"/> using the <paramref name="implementingType"/> /// as the implementation. /// </summary> /// <param name="serviceType">The service being implemented.</param> /// <param name="implementingType">The actual type that will implement the service.</param> /// <param name="lifecycle">The <see cref="LifecycleType"/> that determines the lifetime of each instance being created.</param> /// <returns>A valid <see cref="IFactory"/> instance.</returns> private static IFactory CreateFactory(Type serviceType, Type implementingType, LifecycleType lifecycle) { // HACK: Use a lazy factory since the actualy IFactoryBuilder instance won't // be available until runtime Func <IFactoryRequest, object> factoryMethod = request => { var currentContainer = request.Container; var arguments = request.Arguments; var builder = currentContainer.GetService <IFactoryBuilder>(); // HACK: If the service type is a type definition and // the implementing type is a type definition, // assume that the service type has the same number of // generic arguments as the implementing type var actualServiceType = serviceType; var actualImplementingType = implementingType; if (serviceType.IsGenericTypeDefinition && implementingType.IsGenericTypeDefinition && serviceType.GetGenericArguments().Count() == implementingType.GetGenericArguments().Count()) { var typeArguments = request.ServiceType.GetGenericArguments(); actualServiceType = serviceType.MakeGenericType(typeArguments); actualImplementingType = implementingType.MakeGenericType(typeArguments); } var actualFactory = builder.CreateFactory(actualServiceType, actualImplementingType, lifecycle); var factoryRequest = new FactoryRequest { ServiceType = serviceType, ServiceName = request.ServiceName, Arguments = arguments, Container = currentContainer }; return(actualFactory.CreateInstance(factoryRequest)); }; return(new FunctorFactory(factoryMethod)); }
public void SingletonFactoryShouldCreateTheSameInstanceOnce() { var factory = new SingletonFactory <ISerializable>(createInstance); var container = new ServiceContainer(); var request = new FactoryRequest { ServiceName = null, Arguments = new object[0], Container = container, ServiceType = typeof(ISerializable) }; ISerializable first = factory.CreateInstance(request); ISerializable second = factory.CreateInstance(request); // Both instances must be the same Assert.AreSame(first, second); Assert.IsNotNull(first); Assert.IsNotNull(second); }
public void GenericFactoryAdapterShouldCallUntypedFactoryInstance() { var container = new ServiceContainer(); var mockFactory = new Mock <IFactory <ISerializable> >(); var mockService = new Mock <ISerializable>(); var adapter = new FactoryAdapter <ISerializable>(mockFactory.Object); // The adapter itself should call the container on creation mockFactory.Expect(f => f.CreateInstance(It.Is <IFactoryRequest>(request => request.Container == container))) .Returns(mockService.Object); Assert.IsInstanceOfType(typeof(IFactory), adapter); var factoryRequest = new FactoryRequest { ServiceName = null, ServiceType = typeof(ISerializable), Container = container }; adapter.CreateInstance(factoryRequest); mockFactory.VerifyAll(); }
/// <summary> /// Creates a factory instance that can create instaces of the given /// <paramref name="serviceType"/> using the <paramref name="implementingType"/> /// as the implementation. /// </summary> /// <param name="serviceType">The service being implemented.</param> /// <param name="implementingType">The actual type that will implement the service.</param> /// <param name="lifecycle">The <see cref="LifecycleType"/> that determines the lifetime of each instance being created.</param> /// <returns>A valid <see cref="IFactory"/> instance.</returns> private static IFactory CreateFactory(Type serviceType, Type implementingType, LifecycleType lifecycle) { // HACK: Use a lazy factory since the actualy IFactoryBuilder instance won't // be available until runtime Func<IFactoryRequest, object> factoryMethod = request => { IServiceContainer currentContainer = request.Container; object[] arguments = request.Arguments; var builder = currentContainer.GetService<IFactoryBuilder>(); // HACK: If the service type is a type definition and // the implementing type is a type definition, // assume that the service type has the same number of // generic arguments as the implementing type Type actualServiceType = serviceType; Type actualImplementingType = implementingType; if (serviceType.IsGenericTypeDefinition && implementingType.IsGenericTypeDefinition && serviceType.GetGenericArguments().Count() == implementingType.GetGenericArguments().Count()) { Type[] typeArguments = request.ServiceType.GetGenericArguments(); actualServiceType = serviceType.MakeGenericType(typeArguments); actualImplementingType = implementingType.MakeGenericType(typeArguments); } IFactory actualFactory = builder.CreateFactory(actualServiceType, actualImplementingType, lifecycle); var factoryRequest = new FactoryRequest { ServiceType = serviceType, ServiceName = request.ServiceName, Arguments = arguments, Container = currentContainer }; return actualFactory.CreateInstance(factoryRequest); }; return new FunctorFactory(factoryMethod); }
public FactoryRequest ToggleShipBuildLogFav(BuildLogVO log) { FactoryRequest component = new FactoryRequest(); component.SetFavLog(log); return component; }
public FactoryRequest GetShipFromDock(int dockId) { FactoryRequest component = new FactoryRequest(); component.GetShip(dockId); return component; }
private void StartExpand(int isUseGold) { if (!this.isRequestingServer) { this.isRequestingServer = true; this.expandDock = ServerRequestManager.instance.ExpandDock(isUseGold); this.expandDock.ExpandSuccess += new EventHandler<EventArgs>(this.OnExpandSuccess); this.expandDock.ExpandFail += new EventHandler<EventArgs>(this.OnExpandFail); } }
public void GetShipFromDock(int dockId) { if (!this.isRequestingServer && GlobalLock.instance.CanGo) { GlobalLock.instance.GoNow(); } else { return; } if (this.gamedata.IsUserShipsFull) { UIManager.instance.ShowNeedAddFunctionNum(ShopItemFunction.ShipTopNum).Confirm += delegate (object sender, EventArgs e) { UnityEngine.Object.Destroy(base.gameObject); }; } else { TutorialManager.instance.CheckStepFinishAction("FactoryFinishBuildClick"); this.isRequestingServer = true; this.getShipFromDock = ServerRequestManager.instance.GetShipFromDock(dockId); this.getShipFromDock.GetShipSuccess += new EventHandler<EventArgs>(this.OnGetShipSuccess); this.getShipFromDock.GetShipFail += new EventHandler<EventArgs>(this.OnGetShipFail); } }
private void StartBuildShip(object o, SelectMaterialpArgs e) { this.showActionGO.SetActive(true); this.showActionGO.GetComponent<AnimatePosition>().StartMove(); if ((e != null) && !this.isRequestingServer) { this.isRequestingServer = true; TutorialManager.instance.CheckStepFinishAction("FactoryConfirmBuildClick"); this.buildingArgs = e; this.buildShipInDock = ServerRequestManager.instance.BuildShipInDock(this.selectedDockIndex, e.oil, e.steel, e.ammo, e.aluminium); this.buildShipInDock.BuildShipSuccess += new EventHandler<EventArgs>(this.OnStartBuildShipSuccess); this.buildShipInDock.BuildShipFail += new EventHandler<EventArgs>(this.OnStartBuildShipFail); } }
public FactoryRequest FastBuildShipAtDock(int dockId) { FactoryRequest component = new FactoryRequest(); component.FastBuild(dockId); return component; }
private void StartFastBuildShip() { if (!this.isRequestingServer) { this.isRequestingServer = true; this.fastBuildShipInDock = ServerRequestManager.instance.FastBuildShipAtDock(this.fastBuildDockId); this.fastBuildShipInDock.FastBuildShipSuccess += new EventHandler<EventArgs>(this.OnStartFastBuildShipSuccess); this.fastBuildShipInDock.FastBuildShipFail += new EventHandler<EventArgs>(this.OnStartFastBuildShipFail); } }
public FactoryRequest GetShipBuildLog() { FactoryRequest component = new FactoryRequest(); component.GetBuildLog(); return component; }