Ejemplo n.º 1
0
        /// <summary>
        /// Import contact to database
        /// </summary>
        /// <param name="contactDatabaseId">contact database id</param>
        /// <param name="contactGroupId">contact group id</param>
        /// <param name="mailData">mail data</param>
        private String importContact(String contactDatabaseId, String contactGroupId, MailData mailData)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug("importContact:contactDatabaseId=" + contactDatabaseId);
            }

             String result = OK_RESULT;
             ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy);
            Hashtable contactFieldTable = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);

            cn.tripolis.dialogue.import.ImportContactsRequest request = new cn.tripolis.dialogue.import.ImportContactsRequest();
            try
            {
                //Prepare contact CSV
                StringBuilder sb = new StringBuilder();
                //String[] contactFieldNames = null;
                int index = 0;
                foreach (String contactList in mailData.ContactJsonList)
                {
                    String[] contactFields = contactList.Split(',');
                    //init the CSV header
                    if (index == 0)
                    {

                        // contactFieldNames = new String[contactFields.Length];
                        foreach (String field in contactFields)
                        {
                            String fielName = field.Split(new[] { "#" }, StringSplitOptions.None)[0];
                            //add contact filed to table
                            if (contactFieldTable != null && !contactFieldTable.ContainsKey(fielName.ToLower()))
                            {
                                contactDatabaseFieldAction.addContactField(contactDatabaseId, fielName, "");

                            }
                            sb.Append("\"").Append(fielName).Append("\"").Append(";");
                        }
                        sb.Remove(sb.Length - 1, 1);
                        sb.Append("\n");
                    }
                    foreach (String field in contactFields)
                    {

                        sb.Append("\"").Append(field.Split(new[] { "#" }, StringSplitOptions.None)[1]).Append("\"").Append(";");

                    }

                    sb.Remove(sb.Length - 1, 1);

                    sb.Append("\n");
                    index++;
                }

                request.reportReceiverAddress = mailData.replyAddress;
                request.importMode = cn.tripolis.dialogue.import.importMode.SYNCHRONIZE_GROUP;
                request.contactGroupIds = new[] { contactGroupId };
                request.extension = cn.tripolis.dialogue.import.fileExtension.CSV;
                request.fileName = "Contacts.csv";
                request.importFile = System.Text.Encoding.UTF8.GetBytes(sb.ToString());//System.IO.File.ReadAllBytes("../../Contacts_new.csv");
                cn.tripolis.dialogue.import.ImportIDResponse response = importService.importContacts(request);
                result = response.importId;

            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("error happens in get contact database fields, error is" + ex.Detail.InnerXml);
                }
                throw new Exception(ex.Detail.InnerXml);
            }
            return result;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Import contact to database
        /// </summary>
        /// <param name="contactDatabaseId">contact database id</param>
        /// <param name="contactGroupId">contact group id</param>
        /// <param name="mailData">mail data</param>
        public String importContact(String contactDatabaseId, String contactGroupId, String reportReceiverAddress, ContactFileInfo importFiles)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug("importContact:contactDatabaseId=" + contactDatabaseId);
            }

            String result = "";
            ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy);
            Hashtable contactFieldTable = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);

            cn.tripolis.dialogue.import.ImportContactsRequest request = new cn.tripolis.dialogue.import.ImportContactsRequest();
            try
            {

                importService.Timeout = System.Threading.Timeout.Infinite;
                request.reportReceiverAddress = reportReceiverAddress;
                request.importMode = cn.tripolis.dialogue.import.importMode.SYNCHRONIZE_GROUP;
                request.contactGroupIds = new[] { contactGroupId };
                request.extension = importFiles.fileType;// cn.tripolis.dialogue.import.fileExtension.CSV;
                if (importFiles.fileType.Equals(fileExtension.CSV) && !importFiles.csvDilimiter.Equals(ContactFileInfo.DEFAULT_CSV_DELIMIT))
                {
                    string fileContent = Encoding.UTF8.GetString(importFiles.fileContent);
                    string revisedContent = fileContent.Replace(importFiles.csvDilimiter, ContactFileInfo.DEFAULT_CSV_DELIMIT);
                    importFiles.fileContent = Encoding.UTF8.GetBytes(revisedContent);
                }
                request.fileName = importFiles.filename;
                request.importFile = importFiles.fileContent;//System.IO.File.ReadAllBytes("../../Contacts_new.csv");
                //importService..importContactsAsync()
                cn.tripolis.dialogue.import.ImportIDResponse response = importService.importContacts(request);

                result = response.importId;

            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("error happens in get contact database fields, error is" + ex.Detail.InnerXml);
                }
                throw new Exception(ex.Detail.InnerXml);
            }
            return result;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Import contact to database
        /// </summary>
        /// <param name="contactDatabaseId">contact database id</param>
        /// <param name="contactGroupId">contact group id</param>
        /// <param name="mailData">mail data</param>
        public String importContact(String contactDatabaseId, String contactGroupId, String reportReceiverAddress,String fileName,byte[] contacts)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug("importContact:contactDatabaseId=" + contactDatabaseId);
            }

            String result = "" ;
            ContactDatabaseFieldAction contactDatabaseFieldAction = new ContactDatabaseFieldAction(client, userName, password, oWebProxy);
            Hashtable contactFieldTable = contactDatabaseFieldAction.getContactDatabaseFields(contactDatabaseId);

            cn.tripolis.dialogue.import.ImportContactsRequest request = new cn.tripolis.dialogue.import.ImportContactsRequest();
            try
            {

                importService.Timeout = System.Threading.Timeout.Infinite;
                request.reportReceiverAddress = reportReceiverAddress;
                request.importMode = cn.tripolis.dialogue.import.importMode.SYNCHRONIZE_GROUP;
                request.contactGroupIds = new[] { contactGroupId };
                request.extension = cn.tripolis.dialogue.import.fileExtension.CSV;
                request.fileName = fileName;
                request.importFile = contacts;//System.IO.File.ReadAllBytes("../../Contacts_new.csv");
                //importService..importContactsAsync()
                cn.tripolis.dialogue.import.ImportIDResponse response = importService.importContacts(request);
                
                result = response.importId;

            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("error happens in get contact database fields, error is" + ex.Detail.InnerXml);
                }
                throw new Exception(ex.Detail.InnerXml);
            }
            return result;
        }