Ejemplo n.º 1
0
        /// <summary>
        /// Archive this email item to CRM.
        /// </summary>
        /// <param name="olItem">The email item to archive.</param>
        /// <param name="reason">The reason it is being archived.</param>
        /// <returns>A result object indicating success or failure.</returns>
        public static ArchiveResult Archive(this Outlook.MailItem olItem, EmailArchiveReason reason, string excludedEmails = "")
        {
            ArchiveResult result;

            Outlook.UserProperty olProperty = olItem.UserProperties[CrmIdPropertyName];

            if (olProperty == null)
            {
                result = olItem.AsArchiveable(reason).Save(excludedEmails);

                if (result.IsSuccess)
                {
                    olItem.Categories = string.IsNullOrEmpty(olItem.Categories) ?
                                        SuiteCRMCategoryName :
                                        $"{olItem.Categories},{SuiteCRMCategoryName}";
                    olItem.EnsureProperty(CrmIdPropertyName, result.EmailId);
                }
            }
            else
            {
                result = ArchiveResult.Success(olProperty.Value, new[] { new AlreadyArchivedException(olItem) });
            }

            return(result);
        }
        /// <summary>
        /// Archive this email item to CRM.
        /// </summary>
        /// <param name="olItem">The email item to archive.</param>
        /// <param name="reason">The reason it is being archived.</param>
        /// <param name="moduleKeys">Keys (standardised names) of modules to search.</param>
        /// <param name="excludedEmails">email address(es) which should not be linked.</param>
        /// <returns>A result object indicating success or failure.</returns>
        public static ArchiveResult Archive(this Outlook.MailItem olItem, EmailArchiveReason reason, IEnumerable <CrmEntity> moduleKeys, string excludedEmails = "")
        {
            ArchiveResult result = olItem.AsArchiveable(reason).Save(moduleKeys, excludedEmails);

            if (result.IsSuccess)
            {
                try
                {
                    if (string.IsNullOrEmpty(olItem.Categories))
                    {
                        olItem.Categories = SuiteCRMCategoryName;
                    }
                    else if (olItem.Categories.IndexOf(SuiteCRMCategoryName) == -1)
                    {
                        olItem.Categories = $"{olItem.Categories},{SuiteCRMCategoryName}";
                    }

                    olItem.EnsureProperty(CrmIdPropertyName, result.EmailId);
                }
                catch (COMException cex)
                {
                    ErrorHandler.Handle("Could not set property while archiving email", cex);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Save this email item, of this type, to CRM.
        /// </summary>
        /// <param name="mailItem">The email item to send.</param>
        /// <param name="type">?unknown</param>
        /// <returns>An archive result comprising the CRM id of the email, if stored,
        /// and a list of exceptions encountered in the process.</returns>
        public ArchiveResult SaveEmailToCrm(Outlook.MailItem mailItem, string type)
        {
            ArchiveResult result;

            try
            {
                SaveMailItemIfNecessary(mailItem, type);

                result = ConstructAndDespatchCrmItem(mailItem, type);

                if (!String.IsNullOrEmpty(result.EmailId))
                {
                    /* we successfully saved the email item itself */
                    mailItem.Categories = "SuiteCRM";
                    mailItem.Save();

                    if (mailItem.Attachments.Count > 0)
                    {
                        result = ConstructAndDespatchAttachments(mailItem, result);
                    }
                }
            }
            catch (System.Exception failure)
            {
                Log.Warn("Could not upload email to CRM", failure);
                result = ArchiveResult.Failure(failure);
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Construct and despatch a CRM representation of this mail item, without its attachments, to CRM
        /// </summary>
        /// <param name="mailItem">The mail item to despatch.</param>
        /// <param name="type">?unknown.</param>
        /// <returns>An archive result comprising the CRM id of the email, if stored,
        /// and a list of exceptions encountered in the process.</returns>
        private ArchiveResult ConstructAndDespatchCrmItem(Outlook.MailItem mailItem, string type)
        {
            ArchiveResult result;

            eNameValue[] crmItem = ConstructCrmItem(mailItem, type);

            try
            {
                result = ArchiveResult.Success(clsSuiteCRMHelper.SetEntry(crmItem, "Emails"), null);
            }
            catch (System.Exception firstFailure)
            {
                Log.Warn("EmailArchiving.SaveEmailToCrm: first attempt to upload email failed", firstFailure);

                try
                {
                    /* try again without the HTML body. I have no idea why this might make a difference. */
                    crmItem[5] = clsSuiteCRMHelper.SetNameValuePair("description_html", string.Empty);

                    result = ArchiveResult.Success(clsSuiteCRMHelper.SetEntry(crmItem, "Emails"), new[] { firstFailure });
                }
                catch (System.Exception secondFailure)
                {
                    Log.Warn("EmailArchiving.SaveEmailToCrm: second attempt to upload email (without HTML body) failed", firstFailure);
                    result = ArchiveResult.Failure(new[] { firstFailure, secondFailure });
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        protected override void _Execute(params object[] args)
        {
            bool   needClearBusyState = false;
            string projectName        = null;

            try
            {
                Debug.Assert(args.Length > 0);

                string projectPath = args[0] as string;
                Debug.Assert(projectPath != null);

                // get project name
                projectName = Path.GetFileNameWithoutExtension(projectPath);

                // get project configuration
                ProjectConfiguration config = _FindConfigByName(projectName);
                if (config != null)
                {
                    // check if we need to auto-archive project
                    if (_NeedToAutoArchive(config))
                    {
                        // set status
                        string statusMessage = string.Format((string)_Application.FindResource("ArchiveMessageProcessStatusFormat"), projectName);
                        WorkingStatusHelper.SetBusy(statusMessage);
                        needClearBusyState = true;

                        ProjectArchivingSettings arSet = config.ProjectArchivingSettings;
                        DateTime date = DateTime.Now.Date.AddMonths(-arSet.TimeDomain);

                        ArchiveResult result = ProjectFactory.ArchiveProject(config, date);
                        _ShowResult(projectName, result);

                        if (result.IsArchiveCreated)
                        {   // Update project page
                            ProjectsPage projectsPage = (ProjectsPage)_Application.MainWindow.GetPage(PagePaths.ProjectsPagePath);
                            projectsPage.UpdateView();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                Collection <MessageDetail> details = new Collection <MessageDetail>();
                details.Add(new MessageDetail(MessageType.Error, ex.Message));

                string message = string.Format((string)_Application.FindResource("ArchiveMessageProcessFailedFromat"), projectName);
                _Application.Messenger.AddMessage(MessageType.Warning, message, details);
            }

            if (needClearBusyState)
            {
                WorkingStatusHelper.SetReleased();
            }
        }
        public ArchiveResult ArchiveEmailWithEntityRelationships(Outlook.MailItem mailItem, IEnumerable <CrmEntity> selectedCrmEntities, string type)
        {
            var result = this.SaveEmailToCrm(mailItem, type);

            if (result.IsFailure)
            {
                return(result);
            }
            var warnings = CreateEmailRelationshipsWithEntities(result.EmailId, selectedCrmEntities);

            return(ArchiveResult.Success(
                       result.EmailId,
                       result.Problems.Concat(warnings)));
        }
Ejemplo n.º 7
0
 private void _ShowResult(string projectName, ArchiveResult result)
 {
     if (result.IsArchiveCreated)
     {
         string message = string.Format((string)_Application.FindResource("ArchiveMessageProcessDoneFromat"),
                                        projectName, Path.GetFileNameWithoutExtension(result.ArchivePath));
         _Application.Messenger.AddInfo(message);
     }
     else
     {   // project database does not contain data to archive
         string message = string.Format((string)_Application.FindResource("ArchiveMessageNothingArchiveFormat"), projectName);
         _Application.Messenger.AddWarning(message);
     }
 }
Ejemplo n.º 8
0
        private async void Compress_Click(object sender, RoutedEventArgs e)
        {
            lblCaptureCount.Content = "Compressing...";
            ArchiveResult result = await _appController.CompressAndStartNewSession();

            if (result.Success)
            {
                lblCaptureCount.Content = "Compressed successfully";
            }
            else
            {
                lblCaptureCount.Content = string.Format("Archive failed: {0}", result.Exception.Message);
            }
        }
Ejemplo n.º 9
0
        public async Task <ArchiveResult> CreateArchiveAsync(ArchiveParams parameters)
        {
            var url1 = Api.ApiUrlV.ResourceType("image").Action("generate_archive");

            if (!string.IsNullOrEmpty(parameters.ResourceType()))
            {
                url1.ResourceType(parameters.ResourceType());
            }
            var url2 = url1.BuildUrl();

            parameters.Mode(ArchiveCallMode.Create);
            using (var response = await Api.CallAsync(HttpMethod.Post, url2, parameters.ToParamsDictionary(), null, null))
            {
                return(await ArchiveResult.Parse(response));
            }
        }
        public ArchiveResult ArchiveEmailWithEntityRelationships(Outlook.MailItem olItem, IEnumerable <CrmEntity> selectedCrmEntities, EmailArchiveReason reason)
        {
            var result = olItem.Archive(reason);

            if (result.IsSuccess)
            {
                var warnings = CreateEmailRelationshipsWithEntities(result.EmailId, selectedCrmEntities);
                result = ArchiveResult.Success(
                    result.EmailId,
                    result.Problems == null ?
                    warnings :
                    result.Problems.Concat(warnings));
            }

            return(result);
        }
Ejemplo n.º 11
0
        public async Task ArchiveAndStartUpload(DS4Session session, string apiBase, string apiKey, string apiSecret)
        {
            // Archive

            if (!File.Exists(session.CompressedScanFile))
            {
                Archiver archiver = new Archiver();
                session.Compressing = true;
                ArchiveResult result = await archiver.PerformArchive(session.SessionPath, session.CompressedScanFile);

                if (!result.Success)
                {
                    return;
                }
            }

            session.Compressing = false;

            _upload(session, apiBase, apiKey, apiSecret);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Construct and despatch CRM representations of the attachments of this email item to CRM.
        /// </summary>
        /// <param name="mailItem">The mail item whose attachments should be sent.</param>
        /// <param name="result">The result of transmitting the item itself to CRM.</param>
        /// <returns>A (possibly modified) archive result.</returns>
        private ArchiveResult ConstructAndDespatchAttachments(Outlook.MailItem mailItem, ArchiveResult result)
        {
            var warnings = new List <System.Exception>();

            if (settings.ArchiveAttachments)
            {
                foreach (Outlook.Attachment attachment in mailItem.Attachments)
                {
                    warnings.Add(ConstructAndDespatchCrmAttachment(mailItem, result.EmailId, attachment));
                }
            }

            if (warnings.Where(w => w != null).Count() > 0)
            {
                if (result.Problems != null)
                {
                    warnings.AddRange(result.Problems);
                }
                result = ArchiveResult.Success(result.EmailId, warnings.Where(w => w != null));
            }

            return(result);
        }
 public WcxException(ArchiveResult archiveResult, string message, Exception inner)
     : base(message, inner)
 {
     ArchiveResult = archiveResult;
 }
 public WcxException(ArchiveResult archiveResult, string message)
     : base(message)
 {
     ArchiveResult = archiveResult;
 }
 public WcxException(ArchiveResult archiveResult)
 {
     ArchiveResult = archiveResult;
 }
        public ArchiveResult SaveEmailToCrm(Outlook.MailItem mailItem, string type)
        {
            try
            {
                SaveMailItemIfNecessary(mailItem, type);

                eNameValue[] data = new eNameValue[12];
                data[0]  = clsSuiteCRMHelper.SetNameValuePair("name", mailItem.Subject ?? "");
                data[1]  = clsSuiteCRMHelper.SetNameValuePair("date_sent", DateTimeOfMailItem(mailItem, type).ToString("yyyy-MM-dd HH:mm:ss"));
                data[2]  = clsSuiteCRMHelper.SetNameValuePair("message_id", mailItem.EntryID);
                data[3]  = clsSuiteCRMHelper.SetNameValuePair("status", "archived");
                data[4]  = clsSuiteCRMHelper.SetNameValuePair("description", mailItem.Body ?? "");
                data[5]  = clsSuiteCRMHelper.SetNameValuePair("description_html", mailItem.HTMLBody);
                data[6]  = clsSuiteCRMHelper.SetNameValuePair("from_addr", clsGlobals.GetSenderAddress(mailItem, type));
                data[7]  = clsSuiteCRMHelper.SetNameValuePair("to_addrs", mailItem.To);
                data[8]  = clsSuiteCRMHelper.SetNameValuePair("cc_addrs", mailItem.CC);
                data[9]  = clsSuiteCRMHelper.SetNameValuePair("bcc_addrs", mailItem.BCC);
                data[10] = clsSuiteCRMHelper.SetNameValuePair("reply_to_addr", mailItem.ReplyRecipientNames);
                data[11] = clsSuiteCRMHelper.SetNameValuePair("assigned_user_id", clsSuiteCRMHelper.GetUserId());

                string crmEmailId;
                try
                {
                    crmEmailId = clsSuiteCRMHelper.SetEntry(data, "Emails");
                }
                catch (System.Exception firstFailure)
                {
                    Log.Warn("1st attempt to upload email failed", firstFailure);
                    data[5] = clsSuiteCRMHelper.SetNameValuePair("description_html", "");
                    try
                    {
                        crmEmailId = clsSuiteCRMHelper.SetEntry(data, "Emails");
                    }
                    catch (System.Exception secondFailure)
                    {
                        Log.Warn("2nd attempt to upload email failed", secondFailure);
                        return(ArchiveResult.Failure(new[] { firstFailure, secondFailure }));
                    }
                }

                mailItem.Categories = "SuiteCRM";
                mailItem.Save();
                var warnings = new List <System.Exception>();
                if (settings.ArchiveAttachments)
                {
                    foreach (Outlook.Attachment attachment in mailItem.Attachments)
                    {
                        try
                        {
                            clsSuiteCRMHelper.UploadAttachment(
                                new clsEmailAttachments
                            {
                                DisplayName = attachment.DisplayName,
                                FileContentInBase64String = GetAttachmentBytes(attachment, mailItem)
                            },
                                crmEmailId);
                        }
                        catch (System.Exception problem)
                        {
                            Log.Warn("Failed to upload email attachment", problem);
                            warnings.Add(problem);
                        }
                    }
                }
                return(ArchiveResult.Success(crmEmailId, warnings));
            }
            catch (System.Exception failure)
            {
                Log.Warn("Could not upload email to CRM", failure);
                return(ArchiveResult.Failure(failure));
            }
        }
Ejemplo n.º 17
0
        public ArchiveResult CreateArchiveItems(ArchiveItemDTO message, DR_Requester requester)
        {
            ArchiveResult result = new ArchiveResult();

            try
            {
                // افزوده شدن نامه ها به آرشیو بعدا بررسی شود

                if (message.ID != 0)
                {
                    throw new Exception();
                }
                BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity();
                if (!bizTableDrivedEntity.DataIsAccessable(requester, message.DatItem.TargetEntityID, new List <SecurityAction>()
                {
                    SecurityAction.ArchiveEdit
                }))
                {
                    throw new Exception("عدم دسترسی ثبت آرشیو");
                }
                using (var context = new MyIdeaDataDBEntities())
                {
                    var dbArchiveItem = new ArchiveItem();
                    if (message.DatItem.DataItemID == 0)
                    {
                        dbArchiveItem.MyDataItemID = bizDataItem.GetOrCreateDataItem(message.DatItem);
                        message.DatItem.DataItemID = dbArchiveItem.MyDataItemID;
                    }
                    else
                    {
                        dbArchiveItem.MyDataItemID = message.DatItem.DataItemID;
                    }
                    //var dataItem = bizDataItem.GetOrCreateDataItem(message.DatItem);
                    //var archiveItemDataItem = new MyDataItem_ArchiveItem();

                    dbArchiveItem.FolderID     = message.FolderID;
                    dbArchiveItem.CreationDate = DateTime.Now;
                    dbArchiveItem.UserID       = requester.Identity;
                    dbArchiveItem.Name         = message.Name;
                    var type = GetArchiveItemType(message);
                    message.FileType       = type.Item2;
                    message.MainType       = type.Item1;
                    dbArchiveItem.FileType = (short)message.FileType;
                    dbArchiveItem.MainType = (short)message.MainType;
                    if (message.AttechedFile != null && message.AttechedFile.Content != null)
                    {
                        dbArchiveItem.FileSize        = message.AttechedFile.Content.Count();
                        dbArchiveItem.FileRepository1 = bizFileRepository.ToFileRepository(context, message.AttechedFile);
                    }
                    SetPossibleThumbnail(context, dbArchiveItem, message.MainType, message.FileType, message.AttechedFile.Content, message.AttechedFile.FileName);
                    //if (!hasThumbnail)
                    //{
                    //    dbArchiveItem.ThumbnailFileRepositoryID = null;
                    //    //    dbArchiveItem.FileRepository1 = null;
                    //}
                    foreach (var tagid in message.TagIDs)
                    {
                        dbArchiveItem.ArchiveItem_Tag.Add(new ArchiveItem_Tag()
                        {
                            TagID = tagid
                        });
                    }
                    context.ArchiveItem.Add(dbArchiveItem);
                    context.SaveChanges();
                    message.ID = dbArchiveItem.ID;

                    result.Result = true;


                    //انتیتی فرمورک قاطی داره رابطه فایل را برای تامبنیل هم میزاره

                    //context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                result.Result  = false;
                result.Message = ex.Message;
            }
            finally
            {
                var logResult = bizLogManager.AddLog(GetCreateItemDataLog(message, result.Message), requester);
                if (!string.IsNullOrEmpty(logResult))
                {
                    result.Message += (!string.IsNullOrEmpty(result.Message) ? Environment.NewLine : "") + "خطا در ثبت لاگ" + " , " + logResult;
                }
            }
            return(result);
        }
Ejemplo n.º 18
0
 public WcxException(ArchiveResult archiveResult)
 {
     ArchiveResult = archiveResult;
 }
Ejemplo n.º 19
0
 public WcxException(ArchiveResult archiveResult, string message)
     : base(message)
 {
     ArchiveResult = archiveResult;
 }
Ejemplo n.º 20
0
 public WcxException(ArchiveResult archiveResult, string message, Exception inner)
     : base(message, inner)
 {
     ArchiveResult = archiveResult;
 }
Ejemplo n.º 21
0
        protected override void _Execute(params object[] args)
        {
            Debug.Assert(null != _projectsPage);

            string filePath           = null;
            bool   needClearBusyState = false;
            string projectName        = null;
            bool   isAutoArchive      = false;

            try
            {
                // select project to archiving
                isAutoArchive = ((1 == args.Length) && (null != args[0]));
                projectName   = (isAutoArchive) ? args[0] as string : _projectsPage.SelectedProjectName;
                // prescribed for command or selected project

                Debug.Assert(null != projectName);

                // find checked project configuration
                ProjectConfiguration config = _FindConfigByName(projectName);
                Debug.Assert(null != config);

                // set status
                string statusMessage = string.Format((string)_Application.FindResource("ArchiveMessageProcessStatusFormat"), projectName);
                WorkingStatusHelper.SetBusy(statusMessage);
                needClearBusyState = true;

                bool routingOperationsInProgress = false;
                if (projectName.Equals(_projectsPage.CurrentProjectName, StringComparison.InvariantCultureIgnoreCase))
                {   // check some routing operation is on progress
                    if (_Application.Solver.HasPendingOperations)
                    {
                        _Application.Messenger.AddWarning((string)_Application.FindResource("ArchiveMessageRoutingOperationsInProgress"));
                        routingOperationsInProgress = true;
                    }
                    else
                    {
                        // since archiving requires project to be closed, the command must close the project at first
                        _Application.CloseCurProject();
                        filePath = config.FilePath;
                    }
                }

                if (!routingOperationsInProgress)
                {   // archive it
                    ProjectArchivingSettings archivingSettings = config.ProjectArchivingSettings;
                    Debug.Assert(!archivingSettings.IsArchive);

                    DateTime      date   = DateTime.Now.Date.AddMonths(-archivingSettings.TimeDomain);
                    ArchiveResult result = ProjectFactory.ArchiveProject(config, date);
                    if (result.IsArchiveCreated)
                    {   // project was successfully archived
                        string message = string.Format((string)_Application.FindResource("ArchiveMessageProcessDoneFromat"),
                                                       projectName, Path.GetFileNameWithoutExtension(result.ArchivePath));
                        _Application.Messenger.AddInfo(message);
                        _projectsPage.UpdateView();
                    }
                    else
                    {   // command run for a project and there is nothing to archive actually
                        string message = string.Format((string)_Application.FindResource("ArchiveMessageNothingArchiveFormat"), projectName);
                        _Application.Messenger.AddWarning(message);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Critical(ex);

                Collection <MessageDetail> details = new Collection <MessageDetail>();
                details.Add(new MessageDetail(MessageType.Error, ex.Message));
                string      message = string.Format((string)_Application.FindResource("ArchiveMessageProcessFailedFromat"), projectName);
                MessageType type    = (isAutoArchive)? MessageType.Warning : MessageType.Error;
                _Application.Messenger.AddMessage(type, message, details);
            }
            if (needClearBusyState)
            {
                WorkingStatusHelper.SetReleased();
            }

            // open it again
            if (!string.IsNullOrEmpty(filePath))
            {
                _Application.OpenProject(filePath, false);
            }
        }
 private void _ShowResult(string projectName, ArchiveResult result)
 {
     if (result.IsArchiveCreated)
     {
         string message = string.Format((string)_Application.FindResource("ArchiveMessageProcessDoneFromat"),
                                         projectName, Path.GetFileNameWithoutExtension(result.ArchivePath));
         _Application.Messenger.AddInfo(message);
     }
     else
     {   // project database does not contain data to archive
         string message = string.Format((string)_Application.FindResource("ArchiveMessageNothingArchiveFormat"), projectName);
         _Application.Messenger.AddWarning(message);
     }
 }