Beispiel #1
0
        public Dictionary <string, double> Run()
        {
            IMyAppDomain appDomain = SingletonAppDomain.GetInstance();
            var          result    = new Dictionary <string, double>();

            while (Queue.Count != 0)
            {
                var currentAction = Queue.Dequeue();
                foreach (var actionPlugin in ActionPlugins)
                {
                    if (actionPlugin.Operation == currentAction.Operation)
                    {
                        var plugin    = appDomain.GetObjectPlugin(actionPlugin.Assembly, actionPlugin.Class);
                        var attribute = (PluginAttribute)plugin.GetType().GetCustomAttribute(typeof(PluginAttribute));

                        if (attribute.AsynsOperation == true)
                        {
                            ThreadPool.QueueUserWorkItem(new WaitCallback((s) =>
                            {
                                var resultOperation = plugin.Operation(currentAction.Data);
                                result.Add(plugin.Name, resultOperation);
                            }));
                        }
                        else
                        {
                            var resultOperation = plugin.Operation(currentAction.Data);
                            result.Add(plugin.Name, resultOperation);
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var path = @"file";

            var streamFile = new StreamFileActionPlugins($"{path}.txt");

            //var streamFile = new BinaryFileActionPlugins(path);

            //SetActionPluginsInFile(new StreamFileActionPlugins($"{path}.txt"), SetActionPluginsInFile());

            var actionAlgotihm = new AAlgorithm(GetQueueAction(), GetActionPluginsFromFile(streamFile));

            foreach (var d in actionAlgotihm.Run())
            {
                Console.WriteLine($"Name: {d.Key}, value: {d.Value}");
            }

            foreach (var assem in SingletonAppDomain.GetInstance().GetAssemblies())
            {
                Console.WriteLine(assem.ToString());
            }

            SingletonAppDomain.GetInstance().UnloadAppDomain();
        }