Ejemplo n.º 1
0
        public static void WaitForAll()
        {
            var Factory = SingletonFactory.GetInstance <ThreadFactory>();

            while (Factory.Tasks.Any(kp => kp.Value.Running))
            {
            }
        }
Ejemplo n.º 2
0
 public static bool RegisterConfiguration(Type ConfigurationType)
 {
     if (typeof(IConfiguration).IsAssignableFrom(ConfigurationType))
     {
         var Factory = SingletonFactory.GetInstance <ConfigurationFactory>();
         return(false);
     }
     throw new Exception($"Class {ConfigurationType} don't implements IConfiguration");
 }
Ejemplo n.º 3
0
        static void Clear(int ID)
        {
            var Factory = SingletonFactory.GetInstance <StackFactory>();

            if (Factory.Stacks.ContainsKey(ID))
            {
                lock (Factory.Stacks[ID])
                    Factory.Stacks[ID].Clear();
            }
        }
Ejemplo n.º 4
0
        static object Pop(int ID)
        {
            var Factory = SingletonFactory.GetInstance <StackFactory>();

            if (Factory.Stacks.ContainsKey(ID))
            {
                lock (Factory.Stacks[ID])
                    return(Factory.Stacks[ID].Pop());
            }
            return(null);
        }
Ejemplo n.º 5
0
        static object Dequeue(int ID)
        {
            var Factory = SingletonFactory.GetInstance <QueueFactory>();

            if (Factory.Queues.ContainsKey(ID) && Factory.Queues[ID].Count > 0)
            {
                lock (Factory.Queues[ID])
                    return(Factory.Queues[ID].Dequeue());
            }
            return(null);
        }
Ejemplo n.º 6
0
        public static void Start(IThread Thread)
        {
            var Factory = SingletonFactory.GetInstance <ThreadFactory>();
            var ID      = Thread.GetHashCode();

            if (!Factory.Tasks.ContainsKey(ID))
            {
                lock (Factory.syncLock)
                    Factory.Tasks.Add(ID, new ThreadTask(Thread));
            }

            Start(ID);
        }
Ejemplo n.º 7
0
        public static ILogger GetLogger([CallerFilePathAttribute] string Name = "")
        {
            Name = Path.GetFileNameWithoutExtension(Name);

            var Factory = SingletonFactory.GetInstance <LoggerFactory>();

            if (!Factory.Loggers.ContainsKey(Name))
            {
                var Logger = (ILogger)Activator.CreateInstance(LoggerType, Name);
                Factory.Loggers.Add(Name, Logger);
            }
            return(Factory.Loggers[Name]);
        }
Ejemplo n.º 8
0
        static void Push(int ID, object Value)
        {
            var Factory = SingletonFactory.GetInstance <StackFactory>();

            if (!Factory.Stacks.ContainsKey(ID))
            {
                lock (Factory.syncLock)
                    Factory.Stacks.Add(ID, new Stack <object>());
            }

            lock (Factory.Stacks[ID])
                Factory.Stacks[ID].Push(Value);
        }
Ejemplo n.º 9
0
        public static void Start(IUpdater Updater)
        {
            var Factory = SingletonFactory.GetInstance <UpdaterFactory>();
            var ID      = Updater.GetHashCode();

            if (!Factory.Tasks.ContainsKey(ID))
            {
                lock (Factory.syncLock)
                    Factory.Tasks.Add(ID, new UpdaterTask(Updater));
            }

            Start(ID);
        }
Ejemplo n.º 10
0
        static void Enqueue(int ID, object Value)
        {
            var Factory = SingletonFactory.GetInstance <QueueFactory>();

            if (!Factory.Queues.ContainsKey(ID))
            {
                lock (Factory.syncLock)
                    Factory.Queues.Add(ID, new Queue <object>());
            }

            lock (Factory.Queues[ID])
                Factory.Queues[ID].Enqueue(Value);
        }
Ejemplo n.º 11
0
        static void Start(int ID)
        {
            var Factory = SingletonFactory.GetInstance <ThreadFactory>();
            var Task    = Factory.Tasks[ID];

            if (!Task.Running)
            {
                Task.Start();
            }
            else
            {
                throw new Exception("Thread as already started!");
            }
        }
Ejemplo n.º 12
0
        public static void Start(Type ThreadType)
        {
            if (typeof(IThread).IsAssignableFrom(ThreadType))
            {
                var Factory = SingletonFactory.GetInstance <ThreadFactory>();
                var ID      = ThreadType.GetHashCode();

                Start(ID);
            }
            else
            {
                throw new Exception($"Class {ThreadType} don't implements IThread");
            }
        }
Ejemplo n.º 13
0
        public static void Start(Type UpdaterType)
        {
            if (typeof(IUpdater).IsAssignableFrom(UpdaterType))
            {
                var Factory = SingletonFactory.GetInstance <UpdaterFactory>();
                var ID      = UpdaterType.GetHashCode();



                Start(ID);
            }
            else
            {
                throw new Exception($"Class {UpdaterType} don't implements IUpdater");
            }
        }
Ejemplo n.º 14
0
        static void Stop(int ID)
        {
            var Factory = SingletonFactory.GetInstance <ThreadFactory>();

            if (Factory.Tasks.ContainsKey(ID))
            {
                var Task = Factory.Tasks[ID];

                if (Task.Running)
                {
                    Task.Stop();
                }
                else
                {
                    throw new Exception("Thread as not been started!");
                }
            }
            else
            {
                throw new Exception("Thread as not been created!");
            }
        }
Ejemplo n.º 15
0
        static bool IsRunning(int ID)
        {
            var Factory = SingletonFactory.GetInstance <ThreadFactory>();

            return(Factory.Tasks.ContainsKey(ID) && Factory.Tasks[ID].Running);
        }