Esempio n. 1
0
 public override void Initialise(List <MailFolder> folderList)
 {
     Status          = MessageProcessorStatus.Initialising;
     _mainFolderList = folderList;
     service         = ExchangeHelper.ExchangeConnect(_hostname, _username, _password);
     //service.TraceEnabled = true;
     //service.TraceFlags = TraceFlags.All;
     folders = new List <ExchangeFolder>();
     ExchangeHelper.GetAllSubFolders(service, new ExchangeFolder {
         Folder = Folder.Bind(service, WellKnownFolderName.MsgFolderRoot)
     }, folders, false);
     if (_createAllFolders)
     {
         // we need to create all folders which don't exist
         foreach (var mailFolder in _mainFolderList)
         {
             GetCreateFolder(mailFolder.DestinationFolder);
         }
     }
     _lastState = new ImportState();
     _queue     = new PCQueue <RawMessageDescriptor, ImportState>(Name + "-exchangeTarget")
     {
         ProduceMethod      = ProcessMessage,
         InitialiseProducer = () => _lastState,
         ShutdownProducer   = ShutdownQueue
     };
     _queue.Start();
     Status = MessageProcessorStatus.Initialised;
 }
Esempio n. 2
0
        public void EnqueueDequeueTest()
        {
            PCQueue queue = new PCQueue();

            for (int i = 0; i < 10; i++)
            {
                queue.Enqueue(i);
            }

            for (int i = 0; i < 10; i++)
            {
                int dqed = -1;

                if (queue.Dequeue(ref dqed))
                {
                    Console.WriteLine(dqed + ":" + i);
                    if (dqed != i)
                    {
                        Assert.Fail();
                    }
                }
            }

            Assert.Pass();
        }
Esempio n. 3
0
        public override void Initialise(List <MailFolder> folderList)
        {
            Status   = MessageProcessorStatus.Initialising;
            _outlook = new Application();
            var pstPath = Regex.Replace(_saveFolder + @"\" + _pstName + ".pst", @"\\+", @"\");

            Logger.Info("Writing to PST " + pstPath);
            _pstHandle  = PstHandle(_outlook.GetNamespace("MAPI"), pstPath, _pstName);
            _rootFolder = _pstHandle.GetRootFolder() as Folder;
            //_importFolder = GetCreateFolder(_rootFolder.FolderPath + @"\_zinkuba_import", _outlook);
            if (_createAllFolders)
            {
                foreach (var mailFolder in folderList)
                {
                    GetCreateFolder(_rootFolder.FolderPath + @"\" + mailFolder.DestinationFolder, _outlook, true);
                }
            }
            _lastState = new ImportState();
            _queue     = new PCQueue <MsgDescriptor, ImportState>(Name + "-pstTarget")
            {
                ProduceMethod      = ProcessMessage,
                InitialiseProducer = () => _lastState,
                ShutdownProducer   = ShutdownQueue
            };
            _queue.Start();
            Status = MessageProcessorStatus.Initialised;
            Logger.Info("PstTarget Initialised");
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            int outvalue = 0;

            Console.WriteLine("QueueTests");

            queue = new PCQueue();

            for (int i = 0; i < 20; i++)
            {
                queue.Enqueue(i);
            }

            queue.printList();

            for (int i = 0; i < 20; i++)
            {
                queue.Dequeue(ref outvalue);
            }

            Thread t1 = new Thread(() => Dtest());
            Thread t2 = new Thread(() => Etest());

            t1.Start();
            t2.Start();

            Console.WriteLine("SorterTests");
            ThreadPoolSleepSorter sorter = new ThreadPoolSleepSorter(Console.Out, 10);

            byte[] values = { 1, 7, 8, 2, 3, 4, 5, 6, 9, 10 };
            sorter.Sort(values);
            sorter.Dispose();

            Console.WriteLine("done");
        }
Esempio n. 5
0
        public void multiThreadTest()
        {
            PCQueue pCQueue = new PCQueue();

            Thread producer;
            Thread consumer;

            pCQueue.Enqueue(1);

            producer = new Thread(new ThreadStart(() => {
                pCQueue.Enqueue(2);
            }
                                                  ));
            consumer = new Thread(new ThreadStart(() => {
                //int out_value = 0;
                //bool success = pCQueue.Dequeue (ref out_value);
                //Console.WriteLine ("success = " + success + "\nout_value = " + out_value);

                //out_value = 0;
                //success = pCQueue.Dequeue (ref out_value);
                //Console.WriteLine ("success = " + success + "\nout_value = " + out_value);
            }));

            consumer.Start();
            producer.Start();
        }
Esempio n. 6
0
        public void DequeueNullTest()
        {
            PCQueue queue = new PCQueue();

            int t = 0;

            Assert.IsFalse(queue.Dequeue(ref t));
        }
Esempio n. 7
0
        protected readonly PCQueue q;                       // имплементация Producer-Cansumer



        //  конструктор с параметрами
        protected MainModul(long blockSize = MinBlockSize, int maxQueueSize = QueueMaxSize)
        {
            BlockSize               = blockSize;
            ThreadsCount            = Environment.ProcessorCount;// количество ядер процессора
            MaxQueueSize            = maxQueueSize;
            initialThread           = new Thread(ReadInputStream);
            writeOutputStreamThread = new Thread(WriteOutputStream);
            q = new PCQueue(ThreadsCount);

            buffer_Queue = new RedyQueue <byte[]>(); // очередь для хранения
            Semafor      = new Semaphor(maxQueueSize);
            Exceptionss  = new List <Exception>();
        }
Esempio n. 8
0
 public override void Initialise(List <MailFolder> folderList)
 {
     Status = MessageProcessorStatus.Initialising;
     NextReader.Initialise(folderList);
     _lastState = new MessageProcessState();
     _queue     = new PCQueue <RawMessageDescriptor, MessageProcessState>(Name)
     {
         ProduceMethod      = ProcessMessage,
         InitialiseProducer = () => _lastState,
         ShutdownProducer   = ShutdownQueue
     };
     _queue.Start();
     Status = MessageProcessorStatus.Initialised;
     Logger.Info("RawToMessageProcessor Initialised");
 }
        static void Show()
        {
            PCQueue q = new PCQueue(2);

            Console.WriteLine("Enqueuing 10 items...");

            for (int i = 0; i < 10; i++)
            {
                int itemNumber = i;                      // To avoid the captured variable trap
                q.EnqueueItem(() =>
                {
                    Thread.Sleep(1000);                              // Simulate time-consuming work
                    Console.Write(" Task" + itemNumber);
                });
            }

            q.Shutdown(true);
            Console.WriteLine();
            Console.WriteLine("Workers complete!");
        }
Esempio n. 10
0
        public void MonitorProducerConsumer()
        {
            const int workersCount = 10;
            const int workCount    = 1000;
            int       workDone     = 0;
            PCQueue   q            = new PCQueue(workersCount);

            for (int i = 0; i < workCount; i++)
            {
                int itemNumber = i;
                q.EnqueueItem(() =>
                {
                    Thread.Sleep(1);
                    Interlocked.Increment(ref workDone);
                });
            }

            q.Shutdown(true);
            Assert.AreEqual(workCount, workDone);
        }
Esempio n. 11
0
    static void Initialize()
    {
        if (!initialized)
        {
            if (!Application.isPlaying)
            {
                return;
            }
            initialized = true;
            var g = new GameObject("PCQueue");
            _current          = g.AddComponent <PCQueue>();
            _current._workers = new Thread[maxThreads];

            // Create and start a separate thread for each worker
            for (int i = 0; i < maxThreads; i++)
            {
                _current._workers[i] = new Thread(_current.Consume);
                _current._workers[i].IsBackground = true;
                _current._workers[i].Start();
            }
        }
    }
Esempio n. 12
0
        public static void Main(string[] args)
        {
            PCQueue pCQueue   = new PCQueue();
            int     out_value = -1;
            bool    success   = false;

            for (int i = 0; i < 10; i++)
            {
                pCQueue.Enqueue(i);
            }

            //pCQueue.printQueue ();

            for (int i = 0; i < 11; i++)
            {
                success = pCQueue.Dequeue(ref out_value);
                Console.WriteLine("success = " + success);
                Console.WriteLine("out_value = " + out_value);
                out_value = -1;
            }



            /*using (ThreadPoolSleepSorter tpss =
             *      new ThreadPoolSleepSorter (Console.Out, 30)) {
             *      tpss.Sort (new byte[]{ 4, 2, 9, 3 , 5, 8, 7, 10, 1, 6});
             *      tpss.Sort (new byte[]{ 3, 0, 2 });
             *      tpss.Sort (new byte[]{ 0, 0, 0});
             *
             *      for (int i = 14; i > 0; i--) {
             *              tpss.Sort (new byte[]{ (byte)i });
             *      }
             *
             *      //Console.WriteLine ("Press ENTER to cancel wait.");
             *      //Console.ReadLine ();
             * }*/
        }
Esempio n. 13
0
 public test()
 {
     queue1 = new PCQueue();
 }
Esempio n. 14
0
 public void TestMethod1()
 {
     PCQueue q    = new PCQueue();
     Random  rand = new Random();
 }
Esempio n. 15
0
 public void Setup()
 {
     queue = new PCQueue();
 }
Esempio n. 16
0
        static void process(
            AssetUpdate data, int workers,
            Dictionary <string, string> pathToGuid,
            Dictionary <string, HashSet <string> > parents,
            Dictionary <string, HashSet <string> > children,
            Ref <float> progress, ILog log
            )
        {
            progress.value = 0;
            Func <string, bool> predicate = p =>
                                            p.EndsWithFast(".asset") ||
                                            p.EndsWithFast(".prefab") ||
                                            p.EndsWithFast(".unity") ||
                                            p.EndsWithFast(".mat");

            var assets          = data.filter(predicate, _ => predicate(_.fromPath));
            var firstScan       = children.isEmpty() && parents.isEmpty();
            var updatedChildren =
                firstScan
        ? children
        : new Dictionary <string, HashSet <string> >();

            var    progressIdx    = 0;
            Action updateProgress = () => progress.value = (float)progressIdx / assets.totalAssets;

            var addedPool = new PCQueue(workers);

            foreach (var added in assets.newAssets)
            {
                updateProgress();
                addedPool.EnqueueItem(() => {
                    parseFile(pathToGuid, log, added, updatedChildren);
                    lock (data) {
                        progressIdx++;
                        updateProgress();
                    }
                });
            }
            // Block until parallel part is done.
            addedPool.Shutdown(waitForWorkers: true);

            foreach (var deleted in assets.deletedAssets)
            {
                updateProgress();
                if (pathToGuid.ContainsKey(deleted))
                {
                    updatedChildren.getOrUpdate(pathToGuid[deleted], () => new HashSet <string>());
                    pathToGuid.Remove(deleted);
                }
                progressIdx++;
            }
            foreach (var moved in assets.movedAssets)
            {
                updateProgress();
                foreach (var guid in pathToGuid.getAndRemove(moved.fromPath))
                {
                    pathToGuid[moved.toPath] = guid;
                }
                progressIdx++;
            }
            updateProgress();

            if (!firstScan)
            {
                foreach (var parent in updatedChildren.Keys)
                {
                    if (children.ContainsKey(parent))
                    {
                        var set = children[parent];
                        foreach (var child in set)
                        {
                            parents[child].Remove(parent);
                        }
                        children.Remove(parent);
                    }
                }
            }
            addParents(parents, updatedChildren);
            if (!firstScan)
            {
                foreach (var kv in updatedChildren)
                {
                    if (kv.Value.Count > 0)
                    {
                        children.Add(kv.Key, kv.Value);
                    }
                }
            }
        }
Esempio n. 17
0
 public void SetUp()
 {
     //Arrange
     _queue = new PCQueue();
 }