Exemplo n.º 1
0
        /// <summary>
        /// Add an element in the queue.
        /// </summary>
        /// <param name="Object">SpooledObject to put in the queue</param>
        public static void AddElement(SpooledObject Object)
        {
            // check if the element is not already in the queue
            if (FindInQueue(Object.Name) == false)
            {
                _mutexQueueFIFO.WaitOne();
                try
                {
                    // add the element in the queue
                    _queueFIFO.Add(Object);
                    Global.Log.WriteEvent(LogType.debug, string.Format("[QUEUE STD] Name         : {0}", Object.Name));
                    Global.Log.WriteEvent(LogType.debug, string.Format("[QUEUE STD] Object       : {0}", Object.Object));
                    Global.Log.WriteEvent(LogType.debug, string.Format("[QUEUE STD] Type         : {0}", Object.Type));
                    Global.Log.WriteEvent(LogType.debug, string.Format("[QUEUE STD] State        : {0}", Object.State));
                    Global.Log.WriteEvent(LogType.debug, string.Format("[QUEUE STD] Sending date : {0}", Object.SendingDate));
                    Global.Log.WriteEvent(LogType.debug, string.Format("[QUEUE STD] Added date   : {0}", Object.AddedDate));
                }

                catch (Exception ex)
                {
                    Global.Log.WriteError("[QUEUE STD] " + ex.Message);
                    Global.Log.WriteError("[QUEUE STD] " + ex.StackTrace);
                }

                _mutexQueueFIFO.ReleaseMutex();
            }
        }
Exemplo n.º 2
0
		/// <summary>
		/// Add an element in the queue.
		/// </summary>
		/// <param name="Object">SpooledObject to put in the queue</param>

		public static void AddElement(SpooledObject Object)
		{
			// check if the element is not already in the queue
			if (FindInQueue(Object.Name) == false)
			{
				_mutexQueueScheduled.WaitOne();
				try
				{
					// add the element in the queue
					_queueScheduled.Add(Object);
					Global.Log.WriteEvent(LogType.debug,string.Format("[QUEUE SCHEDULED] Name         : {0}",Object.Name));
					Global.Log.WriteEvent(LogType.debug,string.Format("[QUEUE SCHEDULED] Object       : {0}",Object.Object));
					Global.Log.WriteEvent(LogType.debug,string.Format("[QUEUE SCHEDULED] Type         : {0}",Object.Type));
					Global.Log.WriteEvent(LogType.debug,string.Format("[QUEUE SCHEDULED] State        : {0}",Object.State));
					Global.Log.WriteEvent(LogType.debug,string.Format("[QUEUE SCHEDULED] Sending date : {0}",Object.SendingDate));
					Global.Log.WriteEvent(LogType.debug,string.Format("[QUEUE SCHEDULED] Added date   : {0}",Object.AddedDate));

					_queueScheduled.Sort();
				}

				catch (Exception ex)
				{
					Global.Log.WriteError("[QUEUE SCHEDULED] " + ex.Message);
					Global.Log.WriteError("[QUEUE SCHEDULED] " + ex.StackTrace);
				}

				_mutexQueueScheduled.ReleaseMutex();
			}
		}
Exemplo n.º 3
0
        /// <summary>
        /// Find a object in the queue
        /// </summary>
        /// <param name="Name">Name of object to find</param>
        /// <returns>the object found</returns>
        public static SpooledObject GiveSpooledObject(string Name)
        {
            SpooledObject spooledObject = null;

            _mutexQueueFIFO.WaitOne();
            try
            {
                if (_queueFIFO.Count > 0)
                {
                    for (int i = 0; i < _queueFIFO.Count; i++)
                    {
                        if (((SpooledObject)_queueFIFO[i]).Name == Name)
                        {
                            spooledObject = (((SpooledObject)_queueFIFO[i]));
                            break;
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                Global.Log.WriteError("[QUEUE STD] " + ex.Message);
                Global.Log.WriteError("[QUEUE STD] " + ex.StackTrace);
            }

            _mutexQueueFIFO.ReleaseMutex();

            return(spooledObject);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add a spooled object to the dispacher.
        /// </summary>
        /// <param name="Object">Object to add</param>
        public void AddToDispacher(SpooledObject Object)
        {
            _mutexSpooledObjects.WaitOne();
            try
            {
                _spooledObjects.Add(Object);
            }

            catch (Exception ex)
            {
                Global.Log.WriteError("[DISPACHER] " + ex.Message);
                Global.Log.WriteError("[DISPACHER] " + ex.StackTrace);
            }

            _mutexSpooledObjects.ReleaseMutex();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="o">An object to compare with this instance</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the comparands</returns>
        int IComparable.CompareTo(object o)
        {
            SpooledObject objToCompare = (SpooledObject)o;

            long ticksInstance = _sendingDate.Ticks;
            long ticksObject   = objToCompare.SendingDate.Ticks;

            if (ticksInstance > ticksObject)
            {
                return(1);
            }

            if (ticksInstance < ticksObject)
            {
                return(-1);
            }

            return(0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Delete a scheduled mail.
        /// </summary>
        /// <param name="Elem">The mail to delete</param>
        /// <returns>True if deleted successfully, otherwise, False</returns>
        public static bool DeleteScheduledMail(string Elem)
        {
            SpooledObject objToDel      = QueueScheduled.GiveSpooledObject(Elem);
            bool          flagIsDeleted = false;

            switch (objToDel.State)
            {
            case StateSpooledObject.queued:
            {
                QueueScheduled.Remove(Elem);
                File.Delete(Elem);
                ActiveQLibrary.Form.ManageForm.RemoveElemScheduledQueue(Elem);
                flagIsDeleted = true;
            } break;

            case StateSpooledObject.dispacher:
            {
                if (_processer.Dispacher.Delete(Elem) == true)
                {
                    QueueScheduled.Remove(Elem);
                    File.Delete(Elem);
                    ActiveQLibrary.Form.ManageForm.RemoveElemScheduledQueue(Elem);
                    flagIsDeleted = true;
                }
                else
                {
                    flagIsDeleted = false;
                }
            } break;

            case StateSpooledObject.sent:
            {
                flagIsDeleted = false;
            } break;
            }

            return(flagIsDeleted);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Delete a scheduled task.
        /// </summary>
        /// <param name="File">File name</param>
        /// <param name="Id">id</param>
        /// <returns>True if deleted successfully, otherwise, False</returns>
        public static bool DeleteScheduledTask(string File, string Id)
        {
            string        ElemToDel     = string.Format("{0}?{1}", File, Id);
            SpooledObject objToDel      = QueueScheduled.GiveSpooledObject(ElemToDel);
            bool          flagIsDeleted = false;

            switch (objToDel.State)
            {
            case StateSpooledObject.queued:
            {
                QueueScheduled.Remove(ElemToDel);
                DeleteTaskInFile(File, Id);
                flagIsDeleted = true;
            } break;

            case StateSpooledObject.dispacher:
            {
                if (_processer.Dispacher.Delete(ElemToDel) == true)
                {
                    QueueScheduled.Remove(ElemToDel);
                    DeleteTaskInFile(File, Id);
                    flagIsDeleted = true;
                }
                else
                {
                    flagIsDeleted = false;
                }
            } break;

            case StateSpooledObject.sent:
            {
                flagIsDeleted = false;
            } break;
            }

            return(flagIsDeleted);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Function used in the thread.
        /// </summary>
        private void FctThreadDispacher()
        {
            IsRunning = true;

            while (IsRunning == true)
            {
                // find a free worker
                bool oneWorkerIsFree = false;

                while (oneWorkerIsFree == false)
                {
                    foreach (Worker work in _workers)
                    {
                        if (work.TaskToDo == null)
                        {
                            oneWorkerIsFree = true;
                            break;
                        }
                    }

                    Thread.Sleep(100);
                }

                _mutexSpooledObjects.WaitOne();

                try
                {
                    if (_spooledObjects.Count > 0)
                    {
                        for (int i = 0; i < _workers.Count; i++)
                        {
                            // dispach the spooled object to a free worker
                            if (((Worker)_workers[i]).TaskToDo == null)
                            {
                                SpooledObject toWork = (SpooledObject)_spooledObjects[0];
                                _spooledObjects.RemoveAt(0);


                                // modify state of object
                                switch (toWork.Type)
                                {
                                case TypeSpooledObject.standardMail:
                                {
                                    QueueStandard.ModifyState(toWork.Name, StateSpooledObject.sent);
                                } break;

                                case TypeSpooledObject.scheduledMail:
                                case TypeSpooledObject.scheduledTask:
                                {
                                    QueueScheduled.ModifyState(toWork.Name, StateSpooledObject.sent);
                                } break;
                                }


                                Global.Log.WriteEvent(LogType.normal, string.Format("[DISPACHER] '{0}' is assigned to {1}", toWork.Name, ((Worker)_workers[i]).Name));

                                ((Worker)_workers[i]).TaskToDo = toWork;

                                break;
                            }
                        }
                    }
                }

                catch (ThreadAbortException)
                {
                }

                catch (Exception ex)
                {
                    Global.Log.WriteError("[DISPACHER] " + ex.Message);
                    Global.Log.WriteError("[DISPACHER] " + ex.StackTrace);
                }

                _mutexSpooledObjects.ReleaseMutex();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Function used in the thread reader xml.
        /// </summary>
        private void FctThreadReaderXml()
        {
            IsRunningMail = true;

            while (IsRunningMail == true)
            {
                try
                {
                    foreach (string file in Global.ConfigValue.XmlPickupFiles)
                    {
                        Global.Log.WriteEvent(LogType.normal, string.Format("[READER:XML] Scanning xml file : {0}", file));

                        if (File.Exists(file))
                        {
                            // deserialize xml task file
                            TextReader    reader    = new StreamReader(file);
                            XmlSerializer serialize = new XmlSerializer(typeof(Tasks));
                            Tasks         tasks     = (Tasks)serialize.Deserialize(reader);
                            reader.Close();

                            DateTime now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);

                            for (int i = 0; i < tasks.TasksList.Count; i++)
                            {
                                Task   t        = (Task)tasks.TasksList[i];
                                string fileName = string.Format("{0}?{1}", file, t.Id);

                                if (QueueScheduled.FindInQueue(fileName) == true)
                                {
                                    Global.Log.WriteEvent(LogType.debug, string.Format("[READER:XML] '{0} (id:{1})' already in the scheduled queue, discarding...", file, t.Id));
                                }

                                else
                                {
                                    if (now <= t.DateEnd)
                                    {
                                        DateTime triggerDate = t.GetNextTriggered();
                                        if (triggerDate != DateTime.MinValue)
                                        {
                                            SpooledObject newElement = new SpooledObject(fileName, TypeSpooledObject.scheduledTask, t, triggerDate);
                                            QueueScheduled.AddElement(newElement);
                                            ActiveQLibrary.Form.ManageForm.AddElementTaskQueue(file, string.Format("Task(id:{0})", t.Id));
                                            Global.Log.WriteEvent(LogType.normal, string.Format("[READER:XML] '{0} (id:{1})' added in the scheduled queue...", file, t.Id));
                                        }
                                        else
                                        {
                                            Global.Log.WriteEvent(LogType.debug, string.Format("[READER:XML] '{0} (id:{1})' up to date, discarding...", file, t.Id));
                                        }
                                    }
                                    else
                                    {
                                        Global.Log.WriteEvent(LogType.debug, string.Format("[READER:XML] '{0} (id:{1})' up to date, discarding...", file, t.Id));
                                    }
                                }
                            }
                        }

                        else
                        {
                            Global.Log.WriteError(string.Format("[READER:XML] File : '{0}' doesn't exist, discarding...", file));
                        }
                    }
                }

                catch (ThreadAbortException)
                {
                }

                catch (Exception ex)
                {
                    Global.Log.WriteError("[READER:XML] " + ex.Message);
                    Global.Log.WriteError("[READER:XML] " + ex.StackTrace);

                    Thread.Sleep(500);
                }

                Global.Log.WriteEvent(LogType.normal, string.Format("[READER:XML] Next scan xml in {0} seconds", Global.ConfigValue.Readers.XmlPickup));
                Thread.Sleep(Global.ConfigValue.Readers.XmlPickup * 1000);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Function used in the thread reader mail
        /// </summary>
        private void FctThreadReaderMail()
        {
            IsRunningMail = true;

            while (IsRunningMail == true)
            {
                //if (Global.ActiveMailAsm == null)
                if (Global.ActiveCommonAsm == null)
                {
                    IsRunningMail = false;
                }

                else
                {
                    try
                    {
                        foreach (string dir in Global.ConfigValue.MailPickupDirectories)
                        {
                            Global.Log.WriteEvent(LogType.normal, string.Format("[READER:MAIL] Scanning mail directory : {0}", dir));

                            DirectoryInfo dirInfo = new DirectoryInfo(dir);
                            // refrash information
                            dirInfo.Refresh();

                            if (Directory.Exists(dir))
                            {
                                FileInfo[] listingFile = dirInfo.GetFiles();

                                foreach (FileInfo file in listingFile)
                                {
                                    string ext = ".EML";

                                    string fileName = dir + @"\" + file.Name;

                                    if (File.Exists(fileName) && file.Length > 4 && file.ToString().Substring(file.ToString().Length - ext.Length).ToUpper() == ext)
                                    {
                                        FileInfo fileInfo = new FileInfo(fileName);
                                        fileInfo.Refresh();

                                        if (fileInfo.Exists)
                                        {
                                            // check the validity of the message
                                            Object message = Activator.CreateInstance(Global.ActiveCommonAsm.GetType("ActiveUp.Net.Mail.Message", true));

                                            bool isMessageValid = true;
                                            try
                                            {
                                                message = Global.ActiveCommonAsm.GetType("ActiveUp.Net.Mail.Parser").GetMethod("ParseMessageFromFile", new Type[] { Type.GetType("System.String") }).Invoke(null, new object[] { fileName });

                                                if (ValidateMailMessage(message) == false)
                                                {
                                                    isMessageValid = false;
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                Console.WriteLine(ex);
                                                isMessageValid = false;
                                            }

                                            if (isMessageValid == false)
                                            {
                                                Global.Log.WriteError(string.Format("[READER:MAIL] '{0}' is not a valid mail message or cannot be parsed, moving it to the error directory...", fileName));
                                                Global.MoveFileToError(fileName, "[READER:MAIL]");
                                            }

                                            else
                                            {
                                                /*message.GetType().GetProperty("To").PropertyType.GetMethod("Clear",new Type[] {}).Invoke(message.GetType().GetProperty("To").GetValue(message,null),null);
                                                 * message.GetType().GetProperty("To").PropertyType.GetMethod("Add",new Type[] {Type.GetType("System.String")}).Invoke(message.GetType().GetProperty("To").GetValue(message,null),new Object[] {"*****@*****.**"});
                                                 * message.GetType().GetProperty("Subject").SetValue(message,"ACTIVEMAIL",null);*/

                                                DateTime dateMessage = DateTime.Parse(((System.Collections.Specialized.NameValueCollection)message.GetType().GetProperty("HeaderFields").GetValue(message, null))["date"]);

                                                if (dateMessage <= DateTime.Now)
                                                {
                                                    // message to send immediately
                                                    if (QueueScheduled.FindInQueue(fileName) == true)
                                                    {
                                                        Global.Log.WriteEvent(LogType.debug, string.Format("[READER:MAIL] '{0}' already in the scheduled queue, discarding...", fileName));
                                                    }
                                                    else
                                                    {
                                                        if (QueueStandard.FindInQueue(fileName) == false)
                                                        {
                                                            SpooledObject newElement = new SpooledObject(fileName, TypeSpooledObject.standardMail, message);

                                                            Global.Log.WriteEvent(LogType.normal, string.Format("[READER:MAIL] '{0}' added in the standard queue...", fileName));
                                                            QueueStandard.AddElement(newElement);
                                                            ActiveQLibrary.Form.ManageForm.AddElemStandardQueue(newElement.Name);
                                                        }
                                                        else
                                                        {
                                                            Global.Log.WriteEvent(LogType.debug, string.Format("[READER:MAIL] '{0}' already in the standard queue, discarding...", fileName));
                                                        }
                                                    }
                                                }

                                                else
                                                {
                                                    // message scheduled
                                                    if (QueueScheduled.FindInQueue(fileName) == false)
                                                    {
                                                        SpooledObject newElement = new SpooledObject(fileName, TypeSpooledObject.scheduledMail, message, dateMessage);

                                                        Global.Log.WriteEvent(LogType.normal, string.Format("[READER:MAIL] '{0}' added in the scheduled queue...", fileName));
                                                        QueueScheduled.AddElement(newElement);
                                                        ActiveQLibrary.Form.ManageForm.AddElementScheduledQueue(newElement.Name);
                                                    }
                                                    else
                                                    {
                                                        Global.Log.WriteEvent(LogType.debug, string.Format("[READER:MAIL] '{0}' already in the scheduled queue, discarding...", fileName));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Global.Log.WriteError(string.Format("[READER:MAIL] File '{0}' is not valid or doesn't have .eml extention, it's moved to the error directory...", file.FullName));
                                        Global.MoveFileToError(file.FullName, "[READER:MAIL]");
                                    }
                                }
                            }
                            else
                            {
                                Global.Log.WriteError(string.Format("[READER:MAIL] Directory : '{0}' doesn't exist, discarding...", dir));
                            }
                        }
                    }

                    catch (ThreadAbortException)
                    {
                    }

                    catch (Exception ex)
                    {
                        Global.Log.WriteError("[READER:MAIL] " + ex.Message);
                        Global.Log.WriteError("[READER:MAIL] " + ex.StackTrace);
                        if (ex.InnerException != null)
                        {
                            Global.Log.WriteError("[READER:MAIL] " + ex.InnerException.Message);
                            Global.Log.WriteError("[READER:MAIL] " + ex.InnerException.StackTrace);
                        }
                        Thread.Sleep(500);
                    }

                    Global.Log.WriteEvent(LogType.normal, string.Format("[READER:MAIL] Next scan mail in {0} seconds", Global.ConfigValue.Readers.MailPickUp));
                    Thread.Sleep(Global.ConfigValue.Readers.MailPickUp * 1000);
                }
            }
        }
Exemplo n.º 11
0
		/// <summary>
		/// Add a spooled object to the dispacher.
		/// </summary>
		/// <param name="Object">Object to add</param>
		public void AddToDispacher(SpooledObject Object)
		{
			_mutexSpooledObjects.WaitOne();
			try
			{
				_spooledObjects.Add(Object);
			}

			catch(Exception ex)
			{
				Global.Log.WriteError("[DISPACHER] " + ex.Message);
				Global.Log.WriteError("[DISPACHER] " + ex.StackTrace);
			}

			_mutexSpooledObjects.ReleaseMutex();
		}
Exemplo n.º 12
0
		/// <summary>
		/// Function used in the thread reader xml.
		/// </summary>
		private void FctThreadReaderXml()
		{
			IsRunningMail = true;

			while (IsRunningMail == true)
			{
				try
				{

					foreach(string file in Global.ConfigValue.XmlPickupFiles)
					{
						Global.Log.WriteEvent(LogType.normal,string.Format("[READER:XML] Scanning xml file : {0}",file));

						if (File.Exists(file))
						{
							
							// deserialize xml task file
							TextReader reader = new StreamReader(file);
							XmlSerializer serialize = new XmlSerializer(typeof(Tasks));
							Tasks tasks = (Tasks)serialize.Deserialize(reader);
							reader.Close();

							DateTime now = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,0,0,0);
                            
							for (int i = 0 ; i < tasks.TasksList.Count ; i++)
							{
								Task t = (Task)tasks.TasksList[i];
								string fileName = string.Format("{0}?{1}",file,t.Id);

								if (QueueScheduled.FindInQueue(fileName) == true)
									Global.Log.WriteEvent(LogType.debug,string.Format("[READER:XML] '{0} (id:{1})' already in the scheduled queue, discarding...",file,t.Id));
									
								else
								{
									if (now <= t.DateEnd)
									{
									
										DateTime triggerDate = t.GetNextTriggered();
										if (triggerDate != DateTime.MinValue)
										{
											SpooledObject newElement = new SpooledObject(fileName, TypeSpooledObject.scheduledTask,t,triggerDate);
											QueueScheduled.AddElement(newElement);
											ActiveQLibrary.Form.ManageForm.AddElementTaskQueue(file,string.Format("Task(id:{0})",t.Id));
											Global.Log.WriteEvent(LogType.normal,string.Format("[READER:XML] '{0} (id:{1})' added in the scheduled queue...",file,t.Id));
										}
										else
											Global.Log.WriteEvent(LogType.debug,string.Format("[READER:XML] '{0} (id:{1})' up to date, discarding...",file,t.Id));

									}
									else
										Global.Log.WriteEvent(LogType.debug,string.Format("[READER:XML] '{0} (id:{1})' up to date, discarding...",file,t.Id));
								}
							}
							
						}

						else
							Global.Log.WriteError(string.Format("[READER:XML] File : '{0}' doesn't exist, discarding...",file));

					}
				}

				catch(ThreadAbortException)
				{
				}

				catch(Exception ex)
				{
					Global.Log.WriteError("[READER:XML] " + ex.Message);
					Global.Log.WriteError("[READER:XML] " + ex.StackTrace);

					Thread.Sleep(500);
				}

				Global.Log.WriteEvent(LogType.normal,string.Format("[READER:XML] Next scan xml in {0} seconds",Global.ConfigValue.Readers.XmlPickup));
				Thread.Sleep(Global.ConfigValue.Readers.XmlPickup * 1000);
			}
		}
Exemplo n.º 13
0
		/// <summary>
		/// Function used in the thread reader mail
		/// </summary>
		private void FctThreadReaderMail()
		{
			IsRunningMail = true;

			while (IsRunningMail == true)
			{
				//if (Global.ActiveMailAsm == null)
                if(Global.ActiveCommonAsm == null)
				{
					IsRunningMail = false;
				}

				else
				{
					try
					{
						foreach(string dir in Global.ConfigValue.MailPickupDirectories)
						{

							Global.Log.WriteEvent(LogType.normal,string.Format("[READER:MAIL] Scanning mail directory : {0}",dir));

							DirectoryInfo dirInfo = new DirectoryInfo(dir);
							// refrash information
							dirInfo.Refresh();
							
							if (Directory.Exists(dir))
							{

								FileInfo[] listingFile = dirInfo.GetFiles();
								
								foreach(FileInfo file in listingFile)
								{
									string ext = ".EML";

									string fileName = dir + @"\" + file.Name;

									if (File.Exists(fileName) && file.Length > 4 && file.ToString().Substring(file.ToString().Length - ext.Length).ToUpper() == ext)
									{
				                        
										FileInfo fileInfo = new FileInfo(fileName);
										fileInfo.Refresh();

										if (fileInfo.Exists)
										{
											// check the validity of the message
											Object message = Activator.CreateInstance(Global.ActiveCommonAsm.GetType("ActiveUp.Net.Mail.Message",true));
											
											bool isMessageValid = true;
											try
											{
                                                message = Global.ActiveCommonAsm.GetType("ActiveUp.Net.Mail.Parser").GetMethod("ParseMessageFromFile", new Type[] { Type.GetType("System.String") }).Invoke(null, new object[] { fileName });
                                                
												if (ValidateMailMessage(message) == false)
												{
													isMessageValid = false;
												}
											}
											catch (Exception ex)
											{
                                                Console.WriteLine(ex);
												isMessageValid = false;
											}

											if (isMessageValid == false)
											{
												Global.Log.WriteError(string.Format("[READER:MAIL] '{0}' is not a valid mail message or cannot be parsed, moving it to the error directory...",fileName));
												Global.MoveFileToError(fileName,"[READER:MAIL]");
											}

											else
											{
												/*message.GetType().GetProperty("To").PropertyType.GetMethod("Clear",new Type[] {}).Invoke(message.GetType().GetProperty("To").GetValue(message,null),null);
												message.GetType().GetProperty("To").PropertyType.GetMethod("Add",new Type[] {Type.GetType("System.String")}).Invoke(message.GetType().GetProperty("To").GetValue(message,null),new Object[] {"*****@*****.**"});
												message.GetType().GetProperty("Subject").SetValue(message,"ACTIVEMAIL",null);*/

                                                DateTime dateMessage = DateTime.Parse(((System.Collections.Specialized.NameValueCollection)message.GetType().GetProperty("HeaderFields").GetValue(message, null))["date"]);

												if (dateMessage <= DateTime.Now)
												{
													// message to send immediately
													if (QueueScheduled.FindInQueue(fileName) == true)
														Global.Log.WriteEvent(LogType.debug,string.Format("[READER:MAIL] '{0}' already in the scheduled queue, discarding...",fileName));
													else
													{
														if (QueueStandard.FindInQueue(fileName) == false)
														{

															SpooledObject newElement = new SpooledObject(fileName,TypeSpooledObject.standardMail,message);

															Global.Log.WriteEvent(LogType.normal,string.Format("[READER:MAIL] '{0}' added in the standard queue...",fileName));
															QueueStandard.AddElement(newElement);
															ActiveQLibrary.Form.ManageForm.AddElemStandardQueue(newElement.Name);
														}
														else
															Global.Log.WriteEvent(LogType.debug,string.Format("[READER:MAIL] '{0}' already in the standard queue, discarding...",fileName));
													}
													
												}

												else
												{
													// message scheduled
													if (QueueScheduled.FindInQueue(fileName) == false)
													{

														SpooledObject newElement = new SpooledObject(fileName,TypeSpooledObject.scheduledMail,message,dateMessage);

														Global.Log.WriteEvent(LogType.normal,string.Format("[READER:MAIL] '{0}' added in the scheduled queue...",fileName));
														QueueScheduled.AddElement(newElement);
														ActiveQLibrary.Form.ManageForm.AddElementScheduledQueue(newElement.Name);
													}
													else
														Global.Log.WriteEvent(LogType.debug,string.Format("[READER:MAIL] '{0}' already in the scheduled queue, discarding...",fileName));
												}
											}
										}
									}
									else
									{
										Global.Log.WriteError(string.Format("[READER:MAIL] File '{0}' is not valid or doesn't have .eml extention, it's moved to the error directory...",file.FullName));
										Global.MoveFileToError(file.FullName,"[READER:MAIL]");
									}
										
								}
							}
							else
							{
								Global.Log.WriteError(string.Format("[READER:MAIL] Directory : '{0}' doesn't exist, discarding...",dir));
							}
						}
					}

					catch(ThreadAbortException)
					{
					}

					catch(Exception ex)
					{
						Global.Log.WriteError("[READER:MAIL] " + ex.Message);
						Global.Log.WriteError("[READER:MAIL] " + ex.StackTrace);
						if (ex.InnerException != null)
						{
							Global.Log.WriteError("[READER:MAIL] " + ex.InnerException.Message);
							Global.Log.WriteError("[READER:MAIL] " + ex.InnerException.StackTrace);
						}
						Thread.Sleep(500);
					}

					Global.Log.WriteEvent(LogType.normal,string.Format("[READER:MAIL] Next scan mail in {0} seconds",Global.ConfigValue.Readers.MailPickUp));
					Thread.Sleep(Global.ConfigValue.Readers.MailPickUp * 1000);
				}
			}
		}