Example #1
0
       /// <summary>
       /// import contact
       /// </summary>
        /// <param name="contactDatabaseId">contactDatabaseId</param>
        /// <param name="groupId">groupId</param>
        /// <param name="fileName">fileName</param>
        /// <param name="reportReceiverAddress">reportReceiverAddress</param>
        /// <param name="importFile">importFile</param>
       /// <returns></returns>
        public String importContacts(String contactDatabaseId, String groupId, String fileName, String reportReceiverAddress, byte[] importFile)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug("importContactFromFTP:contactDatabaseId=" + contactDatabaseId);
            }
            String result;
            cn.tripolis.dialogue.import.ImportContactsRequest request = new cn.tripolis.dialogue.import.ImportContactsRequest();
            try
            {

                request.contactDatabaseId = contactDatabaseId;
                string[] contactGroupIds = new string[1];
                contactGroupIds[0] = groupId;
                request.contactGroupIds = contactGroupIds;
                request.extension = cn.tripolis.dialogue.import.fileExtension.CSV;
                request.fileName = fileName;
                request.importFile = importFile;
               
                request.importMode = cn.tripolis.dialogue.import.importMode.ADD_TO_GROUP;
                request.reportReceiverAddress = reportReceiverAddress;
                

                cn.tripolis.dialogue.import.ImportIDResponse response = importService.importContacts(request);

                result = response.importId;


            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                if (!Util.isCodeExist(ex.Detail) || Util.getExistId(ex.Detail).Equals(""))
                {
                    result = ex.Detail.InnerXml;
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("error happens in import contact, error is" + result);
                    }
                    throw new Exception(ex.Detail.InnerXml);
                }
                result = Util.getExistId(ex.Detail);

            }
            return result;
        }
Example #2
0
 /// <remarks/>
 public void importContactsAsync(ImportContactsRequest importContactsRequest, object userState) {
     if ((this.importContactsOperationCompleted == null)) {
         this.importContactsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnimportContactsOperationCompleted);
     }
     this.InvokeAsync("importContacts", new object[] {
                 importContactsRequest}, this.importContactsOperationCompleted, userState);
 }
Example #3
0
 /// <remarks/>
 public void importContactsAsync(ImportContactsRequest importContactsRequest) {
     this.importContactsAsync(importContactsRequest, null);
 }
Example #4
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);
            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(";");
                        }

                        if (contactFieldTable != null && !contactFieldTable.ContainsKey(FROMMAIL.ToLower()))
                        {
                            contactDatabaseFieldAction.addContactField(contactDatabaseId, FROMMAIL, "");

                        }
                        sb.Append("\"").Append(FROMMAIL).Append("\"").Append(";");

                        if (contactFieldTable != null && !contactFieldTable.ContainsKey(SUBJECT.ToLower()))
                        {
                            contactDatabaseFieldAction.addContactField(contactDatabaseId, SUBJECT, "");

                        }
                        sb.Append("\"").Append(SUBJECT).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.Append("\"").Append(mailData.FromAddress).Append("\"").Append(";");
                    sb.Append("\"").Append(mailData.Subject).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;
        }