Esempio n. 1
0
        private async Task <DataPortalResult> InvokeMethod(string factoryTypeName, DataPortalOperations operation, string methodName, Type objectType, object e, DataPortalContext context, bool isSync)
        {
            object factory   = FactoryLoader.GetFactory(factoryTypeName);
            var    eventArgs = new DataPortalEventArgs(context, objectType, e, operation);

            Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "Invoke", eventArgs);
            object result;

            try
            {
                Utilities.ThrowIfAsyncMethodOnSyncClient(ApplicationContext, isSync, factory, methodName, e);

                result = await Csla.Reflection.MethodCaller.CallMethodTryAsync(factory, methodName, e).ConfigureAwait(false);

                if (result is Exception error)
                {
                    throw error;
                }

                if (result is Csla.Core.ITrackStatus busy && busy.IsBusy)
                {
                    throw new InvalidOperationException(string.Format("{0}.IsBusy == true", objectType.Name));
                }

                Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "InvokeComplete", eventArgs);
            }
            catch (Exception ex)
            {
                Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "InvokeError", new DataPortalEventArgs(context, objectType, e, operation, ex));
                throw;
            }
            return(new DataPortalResult(ApplicationContext, result));
        }
        public static void TestFactory()
        {
            Console.WriteLine("-- TEST FACTORY --");

            //Factory that creates all shapes but with different factory implementations
            Console.WriteLine("\nShapeFactory");
            IFactory factory  = new FactoryShape();
            IShape   square   = factory.CreateInstance("shapesquare", 5);
            IShape   triangle = factory.CreateInstance("shapetriangle", 5);

            Console.WriteLine(square.GetInfo());
            Console.WriteLine(triangle.GetInfo());

            Console.WriteLine("\nShapeDoubleSideFactory");
            IFactory doubleFactory  = new FactoryShapeDoubleSide();
            IShape   doubleSquare   = doubleFactory.CreateInstance("shapesquare", 5);
            IShape   doubleTriangle = doubleFactory.CreateInstance("shapetriangle", 5);

            Console.WriteLine(doubleSquare.GetInfo());
            Console.WriteLine(doubleTriangle.GetInfo());

            //Load a Factory to create a specific type of ICar
            ICarFactory bmwFactory  = FactoryLoader.GetCarFactory("FactoryBMW");
            ICarFactory miniFactory = FactoryLoader.GetCarFactory("FactoryMiniCooper");
            ICar        bmw         = bmwFactory.CreateInstance();
            ICar        mini        = miniFactory.CreateInstance();

            Console.WriteLine(bmw.TurnOn());
            Console.WriteLine(bmw.TurnOff());
            Console.WriteLine(mini.TurnOn());
            Console.WriteLine(mini.TurnOff());
        }
        private void LoadFactory(int id)
        {
            FactoryLoader loader = new FactoryLoader(id, this);

            loader.FactoryDownload += new FactoryDownloadHandler(OnFactoryDownloadEvent);
            new Thread(loader.load).Start();
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            plugins = PluginLoader <BaseDll.Shape> .LoadPlugins("D:\\Visual Studio Projects\\OOP_Lab_1_test\\OOP\\OOP_Lab_1\\Plugins\\LineFactory\\LineFactory\\bin\\Debug");

            FactoryPlugins = FactoryLoader <FactoryDll.MainFactory> .LoadPlugins("D:\\Visual Studio Projects\\OOP_Lab_1_test\\OOP\\OOP_Lab_1\\Plugins\\LineFactory\\LineFactory\\bin\\Debug");

            if (plugins != null)
            {
                foreach (var p in plugins)
                {
                    LBoxClass.Items.Add(p.Name.ToString());
                    //  Shape pl = (Shape)Activator.CreateInstance(p, Color.Black, 5, 25, 600, 600, 600);
                    //  FList.AddToList(pl);
                    //  ReDraw();
                }
            }
        }
Esempio n. 5
0
 public static bool AutoUpdate(BackgroundWorker bw)
 {
     return(FactoryLoader.AutoUpdate(bw));
 }