예제 #1
0
        public string GetCurrentThreadInfo()
        {
            EventLogger.DebugEntry("wcf ask for threads start", EventLogEntryType.Information);

            using (LockHolder <Dictionary <Guid, ThreadHolder> > lockObj =
                       new LockHolder <Dictionary <Guid, ThreadHolder> >(runningThreads, 1000)) {
                if (lockObj.LockSuccessful)
                {
                    int    counter    = 0;
                    string threadInfo = "";

                    foreach (KeyValuePair <Guid, ThreadHolder> currentThread in runningThreads)
                    {
                        DateTime tmpTime = currentThread.Value.scanThread.GetStartTime();

                        if (counter == 0)
                        {
                            threadInfo = String.Format("{0:dd.MM.yyyy HH:mm:ss}", tmpTime) + "§" + "ScanThread";
                        }
                        else
                        {
                            threadInfo = threadInfo + "#" + String.Format("{0:dd.MM.yyyy HH:mm:ss}", tmpTime) + "§" + "ScanThread";
                        }

                        counter++;
                    }

                    EventLogger.DebugEntry("wcf ask for threads: " + threadInfo, EventLogEntryType.Information);

                    return(threadInfo);
                }
            }

            return("");
        }
예제 #2
0
파일: Worker.cs 프로젝트: YouGina/MSS
        private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            runningWorkers -= 1;
            List <String> res = (List <String>)e.Result;

            if (!(e.Error == null))
            {
                EventLogger.Entry("Service Error: !" + e.Error.Message + "\r\n\r\n" + e.Error.StackTrace, EventLogEntryType.Error);
            }
            else
            {
                EventLogger.DebugEntry("Service Information: Done!", EventLogEntryType.Information);
                // send mail
                SendMail m = new SendMail();
                m.generateReport(res);
                res.Clear();
            }
            while (runningWorkers < 8 && workerCounter < maxWorker)
            {
                BackgroundWorker newWorker = startWorker();
                newWorker.RunWorkerAsync(++lastWorkerStarted);
            }
            BackgroundWorker bw = (BackgroundWorker)sender;

            bw.Dispose();
        }
예제 #3
0
        private void CheckForRun()
        {
            if (isProcessing == false && nextRun <= DateTime.Now)
            {
                EventLogger.DebugEntry("Creating complex thread", EventLogEntryType.Information);

                ThreadHolder exportThread = new ThreadHolder();
                Guid         guid         = Guid.NewGuid();

                exportThread.scanThread = new ScanThread(this, guid);
                // Here you can add the resuming, on certain conditions
                // In my case I insert data to myThread which contains all the necessary objects to continue processing from the last halt
                // exportThread.myThread = new MyThreadComplex(this, guid, threadType, 3);

                if (CreateWorkerThread(exportThread, guid))
                {
                    isProcessing = true;
                    EventLogger.DebugEntry("Creating complex thread - successful", EventLogEntryType.Information);
                }
                else
                {
                    EventLogger.Entry("Creating complex thread - failed", EventLogEntryType.Error);
                }
            }
        }
예제 #4
0
 protected override void OnStop()
 {
     try {
         ServiceExecution.GetInstance().StopServiceExecution();
         thread.Join();
         EventLogger.DebugEntry("Service stopped", EventLogEntryType.Information);
     } catch (Exception e) {
         EventLogger.Entry("Service Error: Stopping - " + e, EventLogEntryType.Error);
     }
 }
예제 #5
0
        public void StartServiceExecution()
        {
            try {
                currentState = State.Running;

                while (currentState == State.Running)
                {
                    if (!connectionActive)
                    {
                        connectionActive = true;
                        EventLogger.DebugEntry("Main-Loop", EventLogEntryType.Information);
                        IPAddress ipAd = IPAddress.Parse(Properties.Settings.Default.IPAddress);
                        myList = new TcpListener(ipAd, 19358);

                        myList.Start();

                        s = myList.AcceptSocket();

                        byte[] b = new byte[100];
                        int    k = s.Receive(b);

                        if (compareBytes(b, GetBytes("startScan", 100)))
                        {
                            CheckForRun();
                        }
                    }
                    EventLogger.DebugEntry("Main-Loop - Sleep", EventLogEntryType.Information);
                }


                while (currentState == State.Shutting_Down)
                {
                    using (LockHolder <Dictionary <Guid, ThreadHolder> > lockObj =
                               new LockHolder <Dictionary <Guid, ThreadHolder> >(runningThreads, 1000)) {
                        if (lockObj.LockSuccessful)
                        {
                            foreach (ThreadHolder currentThread in runningThreads.Values)
                            {
                                // Now break the processing of the complex thread
                                currentThread.scanThread.BreakOperation();
                            }

                            // If no more threads are left, set the state to stopped
                            if (runningThreads.Count == 0)
                            {
                                currentState = State.Stopped;
                            }
                        }
                    }
                }
            } catch (Exception e) {
                EventLogger.Entry("Service Error: " + e, EventLogEntryType.Error);
            }
        }
예제 #6
0
 protected override void OnStart(string[] args)
 {
     try {
         thread = new Thread(ServiceExecution.GetInstance().StartServiceExecution)
         {
             Name = "Service Executer"
         };
         thread.Start();
         EventLogger.DebugEntry("Service started", EventLogEntryType.Information);
     } catch (Exception e) {
         EventLogger.Entry("Service Error: Starting - " + e, EventLogEntryType.Error);
     }
 }
예제 #7
0
        public void ThreadFinished(Guid threadId)
        {
            EventLogger.DebugEntry("Thread closing start", EventLogEntryType.Information);

            using (LockHolder <Dictionary <Guid, ThreadHolder> > lockObj = new LockHolder <Dictionary <Guid, ThreadHolder> >(runningThreads, 1000)) {
                if (lockObj.LockSuccessful)
                {
                    isProcessing = false;

                    runningThreads.Remove(threadId);
                }
            }

            EventLogger.DebugEntry("Thread closing end", EventLogEntryType.Information);
        }
예제 #8
0
파일: Worker.cs 프로젝트: YouGina/MSS
 public Worker(StringCollection servers)
 {
     try {
         EventLogger.DebugEntry("Service Start: Service started", EventLogEntryType.SuccessAudit);
         List <String> list = new List <String>();
         list      = servers.Cast <String>().ToList();
         maxWorker = list.Count;
         for (int i = 0; i < maxWorkersRunning && i < list.Count; i++)
         {
             BackgroundWorker bw = startWorker();
             bw.RunWorkerAsync(list[++lastWorkerStarted]);
         }
     } catch (Exception ex) {
         EventLogger.Entry("!Service Error: Worker error, could not start first itteration!;  " + ex.StackTrace + " \r\n\r\nServers count: " + servers.Count, EventLogEntryType.Error);
     }
 }
예제 #9
0
        public void ThreadFinished(Guid threadId)
        {
            EventLogger.DebugEntry("Thread closing start", EventLogEntryType.Information);

            using (LockHolder <Dictionary <Guid, ThreadHolder> > lockObj = new LockHolder <Dictionary <Guid, ThreadHolder> >(runningThreads, 1000)) {
                if (lockObj.LockSuccessful)
                {
                    nextRun      = DateTime.Now.AddSeconds(Properties.Settings.Default.trigger_thread);
                    isProcessing = false;

                    runningThreads.Remove(threadId);
                }
            }

            EventLogger.DebugEntry("Thread closing end", EventLogEntryType.Information);
        }
예제 #10
0
        public void StartServiceExecution()
        {
            try {
                currentState = State.Running;

                while (currentState == State.Running)
                {
                    EventLogger.DebugEntry("Main-Loop", EventLogEntryType.Information);
                    Thread.Sleep(10000);
                    CheckForRun();

                    EventLogger.DebugEntry("Main-Loop - Sleep", EventLogEntryType.Information);
                    Thread.Sleep(Properties.Settings.Default.interval * 1000 * 60);
                }


                while (currentState == State.Shutting_Down)
                {
                    using (LockHolder <Dictionary <Guid, ThreadHolder> > lockObj =
                               new LockHolder <Dictionary <Guid, ThreadHolder> >(runningThreads, 1000)) {
                        if (lockObj.LockSuccessful)
                        {
                            foreach (ThreadHolder currentThread in runningThreads.Values)
                            {
                                // Now break the processing of the complex thread
                                currentThread.scanThread.BreakOperation();
                            }

                            // If no more threads are left, set the state to stopped
                            if (runningThreads.Count == 0)
                            {
                                currentState = State.Stopped;
                            }
                        }
                    }
                }
            } catch (Exception e) {
                EventLogger.Entry("Service Error: " + e + "\r\n\r\n" + e.StackTrace, EventLogEntryType.Error);
            }
        }
예제 #11
0
        private void CheckForRun()
        {
            if (isProcessing == false)
            {
                EventLogger.DebugEntry("Creating complex thread", EventLogEntryType.Information);

                ThreadHolder exportThread = new ThreadHolder();
                Guid         guid         = Guid.NewGuid();

                exportThread.scanThread = new ScanThread(this, guid);

                if (CreateWorkerThread(exportThread, guid))
                {
                    isProcessing = true;
                    EventLogger.DebugEntry("Creating complex thread - successful", EventLogEntryType.Information);
                }
                else
                {
                    EventLogger.Entry("Creating complex thread - failed", EventLogEntryType.Error);
                }
            }
        }