public override void MapDataFields(System.Data.DataRow currentRow)
        {
            base.MapDataFields(currentRow);

            System.Xml.XmlDocument configurationXml = new System.Xml.XmlDocument();


            assemblyPath = (String)currentRow["AssemblyPath"];

            assemblyName = (String)currentRow["AssemblyName"];

            assemblyClassName = (String)currentRow["AssemblyClassName"];


            FaxServerConfiguration = new Public.Faxing.FaxServerConfiguration();

            try {
                if (!(currentRow["FaxServerConfiguration"] is DBNull))
                {
                    if (!String.IsNullOrEmpty((String)currentRow["FaxServerConfiguration"]))
                    {
                        configurationXml.LoadXml((String)currentRow["FaxServerConfiguration"]);

                        FaxServerConfiguration.XmlImport(configurationXml.ChildNodes[0]);
                    }
                }
            }

            catch { /* DO NOTHING */ }


            WebServiceHostConfiguration = new Public.WebService.WebServiceHostConfiguration();

            try {
                if (!(currentRow["WebServiceHostConfiguration"] is DBNull))
                {
                    if (!String.IsNullOrEmpty((String)currentRow["WebServiceHostConfiguration"]))
                    {
                        configurationXml.LoadXml((String)currentRow["WebServiceHostConfiguration"]);

                        WebServiceHostConfiguration.XmlImport(configurationXml.ChildNodes[0]);
                    }
                }
            }

            catch { /* DO NOTHING */ }

            return;
        }
        public override List <ImportExport.Result> XmlImport(System.Xml.XmlNode objectNode)
        {
            List <ImportExport.Result> response = base.XmlImport(objectNode);

            System.Xml.XmlDocument configurationXml = new System.Xml.XmlDocument();


            try {
                foreach (System.Xml.XmlNode currentNode in objectNode.ChildNodes)
                {
                    switch (currentNode.Name)
                    {
                    case "Properties":

                        foreach (System.Xml.XmlNode currentPropertyNode in currentNode.ChildNodes)
                        {
                            switch (currentPropertyNode.Attributes["Name"].InnerText)
                            {
                            case "AssemblyPath": AssemblyPath = currentPropertyNode.InnerText; break;

                            case "AssemblyName": AssemblyName = currentPropertyNode.InnerText; break;

                            case "AssemblyClassName": AssemblyClassName = currentPropertyNode.InnerText; break;

                            case "FaxServerConfiguration":

                                configurationXml = new System.Xml.XmlDocument();


                                FaxServerConfiguration = new Public.Faxing.FaxServerConfiguration();

                                try {
                                    if (!String.IsNullOrEmpty(currentPropertyNode.InnerText))
                                    {
                                        configurationXml.LoadXml(currentPropertyNode.InnerText);

                                        FaxServerConfiguration.XmlImport(configurationXml.ChildNodes[0]);
                                    }
                                }

                                catch { /* DO NOTHING */ }

                                break;

                            case "WebServiceHostConfiguration":

                                configurationXml = new System.Xml.XmlDocument();


                                WebServiceHostConfiguration = new Public.WebService.WebServiceHostConfiguration();

                                try {
                                    if (!String.IsNullOrEmpty(currentPropertyNode.InnerText))
                                    {
                                        configurationXml.LoadXml(currentPropertyNode.InnerText);

                                        WebServiceHostConfiguration.XmlImport(configurationXml.ChildNodes[0]);
                                    }
                                }

                                catch { /* DO NOTHING */ }

                                break;

                            default: break;
                            }
                        }

                        break;
                    } // switch (currentNode.Attributes["Name"].InnerText) {
                }     // foreach (System.Xml.XmlNode currentNode in objectNode.ChildNodes) {


                // SAVE IMPORTED CLASS

                if (!Save())
                {
                    throw new ApplicationException("Unable to save " + base.ObjectType + ": " + Name + ".");
                }
            }

            catch (Exception importException) {
                response.Add(new ImportExport.Result(ObjectType, Name, importException));
            }

            return(response);
        }
        public void Fax(Public.Faxing.FaxServerConfiguration forFaxServerConfiguration, FaxSender forSender, FaxRecipient forRecipient, FaxDocument forDocument, Dictionary <String, String> extendedProperties)
        {
            faxServerConfiguration = forFaxServerConfiguration;

            sender = forSender;

            recipient = forRecipient;

            document = forDocument;


            String controlFileName = document.UniqueId + ".xml";

            String attachmentFileName = document.UniqueId + "." + document.Attachment.Extension;

            String statusFileName = controlFileName + ".status";


            System.Diagnostics.Debug.WriteLine("Source ID:" + document.UniqueId);


            // CREATE FAX CONTROL FILE


            System.Xml.XmlDocument controlDocument = new System.Xml.XmlDocument();

            System.Xml.XmlDeclaration xmlDeclaration = controlDocument.CreateXmlDeclaration("1.0", "utf-8", String.Empty);

            System.Xml.XmlElement controlElementNode = controlDocument.CreateElement("faxmakerdata");

            System.Xml.XmlElement fieldsElementNode = controlDocument.CreateElement("fields");

            System.Xml.XmlElement senderElementNode = controlDocument.CreateElement("sender");

            System.Xml.XmlElement recipientsElementNode = controlDocument.CreateElement("recipients");

            System.Xml.XmlElement recipientsFaxElementNode = controlDocument.CreateElement("fax");

            System.Xml.XmlElement recipientElementNode = controlDocument.CreateElement("recipient");


            #region Initialize Document Structure

            controlDocument.InsertBefore(xmlDeclaration, controlDocument.DocumentElement);

            controlDocument.AppendChild(controlElementNode);

            controlElementNode.AppendChild(fieldsElementNode);

            controlElementNode.AppendChild(senderElementNode);

            controlElementNode.AppendChild(recipientsElementNode);

            recipientsElementNode.AppendChild(recipientsFaxElementNode);

            recipientsFaxElementNode.AppendChild(recipientElementNode);


            // FAXMAKERDATA

            // +-- FIELDS

            // +-- SENDER

            // +-- RECIPIENTS

            // +-- +-- FAX

            // +-- +-- +-- RECIPIENT

            #endregion


            #region Sender Node

            if (!String.IsNullOrWhiteSpace(sender.Name))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, senderElementNode, "lastname", sender.Name);
            }

            if (!String.IsNullOrWhiteSpace(sender.Company))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, senderElementNode, "company", sender.Company);
            }

            if (!String.IsNullOrWhiteSpace(sender.Department))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, senderElementNode, "department", sender.Department);
            }

            if (!String.IsNullOrWhiteSpace(sender.FaxNumber))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, senderElementNode, "faxnumber", sender.FaxNumber);
            }

            if (!String.IsNullOrWhiteSpace(sender.VoiceNumber))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, senderElementNode, "voicenumber", sender.VoiceNumber);
            }

            // if (!String.IsNullOrWhiteSpace (sender.Email)) { Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode (controlDocument, senderElementNode, "emailaddress", sender.Email); }

            Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, senderElementNode, "emailaddress", sender.Email);

            #endregion


            #region Recipient Node

            String faxNumber = recipient.FaxNumber;

            faxNumber = (faxNumber.Length == 7) ? faxNumber.Substring(0, 3) + "-" + faxNumber.Substring(3, 4) : faxNumber;

            faxNumber = (faxNumber.Length == 10) ? "1-" + faxNumber.Substring(0, 3) + "-" + faxNumber.Substring(3, 3) + "-" + faxNumber.Substring(6, 4) : faxNumber;



            if (!String.IsNullOrWhiteSpace(recipient.RecipientName))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, recipientElementNode, "lastname", recipient.RecipientName);
            }

            if (!String.IsNullOrWhiteSpace(recipient.CompanyName))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, recipientElementNode, "company", recipient.CompanyName);
            }

            if (!String.IsNullOrWhiteSpace(recipient.DepartmentName))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, recipientElementNode, "department", recipient.DepartmentName);
            }

            Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, recipientElementNode, "faxnumber", faxNumber);

            if (!String.IsNullOrWhiteSpace(recipient.RecipientEmail))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, recipientElementNode, "emaladdress", recipient.RecipientEmail);
            }

            #endregion


            #region Fields Node

            if (!String.IsNullOrWhiteSpace(document.Subject))
            {
                Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, fieldsElementNode, "subject", document.Subject);
            }

            Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, fieldsElementNode, "resolution", "high");

            Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, fieldsElementNode, "attachment", attachmentFileName);

            Mercury.Server.Public.CommonFunctions.XmlDocumentAppendNode(controlDocument, fieldsElementNode, "uid", document.UniqueId);

            #endregion


            attachmentFileName = faxServerConfiguration.FaxUrl + @"\" + attachmentFileName;

            attachmentFileName = attachmentFileName.Replace(@"\\" + attachmentFileName, @"\" + attachmentFileName);


            System.IO.FileStream attachmentFile = new System.IO.FileStream(attachmentFileName, System.IO.FileMode.Create);

            document.Attachment.Image.Seek(0, System.IO.SeekOrigin.Begin);

            document.Attachment.Image.WriteTo(attachmentFile);

            attachmentFile.Flush();

            attachmentFile.Close();


            controlFileName = faxServerConfiguration.FaxUrl + @"\" + controlFileName;

            controlFileName = controlFileName.Replace(@"\\" + controlFileName, @"\" + controlFileName);

            controlDocument.Save(controlFileName);


            statusWatchStartTime = DateTime.Now;

            statusWatcher = new System.IO.FileSystemWatcher();

            statusWatcher.Filter = "*.status";

            statusWatcher.Created += new System.IO.FileSystemEventHandler(StatusWatcher_OnFileCreated);

            statusWatcher.Path = faxServerConfiguration.FaxUrl;

            statusWatcher.EnableRaisingEvents = true;


            return;
        }