/// <summary>
        /// Check if duplicate document exists
        /// </summary>
        /// <param name="clientContext">SP client context</param>
        /// <param name="documentLibraryName">Name of the document library</param>
        /// <param name="folderName">Name of the folder</param>
        /// <param name="isMailUpload">Mail upload check</param>
        /// <param name="folderPath">The folder path.</param>
        /// <param name="contentCheck">Content check object</param>
        /// <param name="uploadFileName">Name of the file.</param>
        /// <returns>message as per duplicate exists or not</returns>
        internal static bool CheckDuplicateDocument(ClientContext clientContext, string documentLibraryName, bool isMailUpload, string folderPath, ContentCheckDetails contentCheck, string uploadFileName, bool allowContentCheck, ref string message)
        {
            DuplicateDocument duplicateDocument = ServiceUtility.DocumentExists(clientContext, contentCheck, documentLibraryName, folderPath, isMailUpload);

            if (duplicateDocument.DocumentExists)
            {
                string documentPath     = string.Concat(ServiceConstantStrings.SiteURL, folderPath, ConstantStrings.ForwardSlash, uploadFileName);
                string duplicateMessage = (allowContentCheck && duplicateDocument.HasPotentialDuplicate) ? ConstantStrings.FilePotentialDuplicateMessage : ConstantStrings.FileAlreadyExistMessage;
                message = string.Format(CultureInfo.InvariantCulture, "{0}{1}{1}{1}{2}", string.Format(CultureInfo.InvariantCulture, duplicateMessage, uploadFileName, documentPath), ConstantStrings.SymbolAt, duplicateDocument.HasPotentialDuplicate.ToString());
            }
            return(duplicateDocument.DocumentExists);
        }
Exemplo n.º 2
0
        private static void ProcessValidation(PXGraph graph, Contact record, ValidationFilter Filter)
        {
            Type    itemType = record.GetType();
            PXCache cache    = PXGraph.CreateInstance <PXGraph>().Caches[itemType];
            Type    graphType;
            object  copy = cache.CreateCopy(record);

            PXPrimaryGraphAttribute.FindPrimaryGraph(cache, ref copy, out graphType);

            if (graphType == null)
            {
                throw new PXException(Messages.UnableToFindGraph);
            }

            graph = PXGraph.CreateInstance(graphType);


            graph.Views[graph.PrimaryView].Cache.Current = copy;

            CRDuplicateEntities <PXGraph, Contact> .RunActionWithAppliedAutomation(
                graph,
                copy,
                nameof(CRDuplicateEntities <PXGraph, Contact> .CheckForDuplicates));

            DuplicateDocument document = graph.Caches[typeof(DuplicateDocument)].Current as DuplicateDocument;

            record.DuplicateStatus = document?.DuplicateStatus;
            record.DuplicateFound  = document?.DuplicateFound;

            var maxScore = graph
                           .Caches[typeof(CRDuplicateRecord)]
                           .Cached
                           .Cast <CRDuplicateRecord>()
                           .Max(_ => _?.Score) ?? 0;

            if (record.DuplicateStatus == DuplicateStatusAttribute.PossibleDuplicated &&
                record.ContactType == ContactTypesAttribute.Lead
                //&& record.Status == LeadStatusesAttribute.New
                && Filter.CloseNoActivityLeads == true &&
                maxScore > Filter.CloseThreshold)
            {
                CRActivity activity = PXSelect <CRActivity,
                                                Where <CRActivity.refNoteID, Equal <Required <Contact.noteID> > > > .SelectWindowed(graph, 0, 1, record.NoteID);

                if (activity == null)
                {
                    CRDuplicateEntities <PXGraph, Contact> .RunActionWithAppliedAutomation(
                        graph,
                        copy,
                        nameof(CRDuplicateEntities <PXGraph, Contact> .CloseAsDuplicate));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// checks for duplicate document to upload
        /// </summary>
        /// <param name="folderName">Path of the folder</param>
        /// <param name="documentLibraryName">Name of the document library</param>
        /// <param name="listResponse">List of responses</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="contentCheck">Content check object</param>
        /// <param name="clientContext">SP client context</param>
        /// <param name="folder">Name of the folder</param>
        /// <returns>true if duplicate document found</returns>
        private static bool CheckDuplicateDocument(ClientContext clientContext, string folderName, string documentLibraryName, IList <string> listResponse, string fileName, ContentCheckDetails contentCheck, bool allowContentCheck)
        {
            bool continueUpload = true;
            DuplicateDocument duplicateDocument = ServiceUtility.DocumentExists(clientContext, contentCheck, documentLibraryName, folderName, false);

            if (duplicateDocument.DocumentExists)
            {
                continueUpload = false;
                string documentPath     = string.Concat(UIConstantStrings.SiteURL, folderName, ConstantStrings.ForwardSlash, fileName);
                string duplicateMessage = (allowContentCheck && duplicateDocument.HasPotentialDuplicate) ? ConstantStrings.FilePotentialDuplicateMessage : ConstantStrings.FileAlreadyExistMessage;
                listResponse.Add(string.Format(CultureInfo.InvariantCulture, "{0}{1}{1}{1}{2}", string.Format(CultureInfo.InvariantCulture, duplicateMessage, fileName, documentPath), ConstantStrings.SymbolAt, Convert.ToString(duplicateDocument.HasPotentialDuplicate, CultureInfo.InvariantCulture)));
            }
            return(continueUpload);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks if document exists.
        /// </summary>
        /// <param name="clientContext">SP client context</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="documentLibraryName">Name of the document library.</param>
        /// <param name="folderPath">Path of the folder.</param>
        /// <returns>Returns true in case of Document presence</returns>
        public static DuplicateDocument DocumentExists(ClientContext clientContext, ContentCheckDetails contentCheck, string documentLibraryName, string folderPath, bool isMail)
        {
            DuplicateDocument duplicateDocument = new DuplicateDocument(false, false);

            if (null != clientContext && null != contentCheck && !string.IsNullOrEmpty(documentLibraryName) && !string.IsNullOrEmpty(folderPath))
            {
                string             serverRelativePath = folderPath + ConstantStrings.ForwardSlash + contentCheck.FileName;
                ListItemCollection listItemCollection = null;
                string             camlQuery          = string.Format(CultureInfo.InvariantCulture, ConstantStrings.GetAllFilesInFolderQuery, serverRelativePath);
                listItemCollection = Lists.GetData(clientContext, documentLibraryName, camlQuery);
                duplicateDocument.DocumentExists = (null != listItemCollection && 0 < listItemCollection.Count) ? true : false;

                // Check file size, from, sent date as well.
                if (duplicateDocument.DocumentExists)
                {
                    // check for other conditions as well.
                    ListItem listItem = listItemCollection.FirstOrDefault();
                    DateTime sentDate, storedFileSentDate;
                    long     fileSize = Convert.ToInt64(listItem.FieldValues[ConstantStrings.SearchEmailFileSize], CultureInfo.InvariantCulture);
                    if (isMail)
                    {
                        // check for subject, from and sent date
                        string subject = Convert.ToString(listItem.FieldValues[ConstantStrings.SearchEmailSubject], CultureInfo.InvariantCulture);
                        string from    = Convert.ToString(listItem.FieldValues[ConstantStrings.SearchEmailFrom], CultureInfo.InvariantCulture);
                        bool   isValidDateFormat;
                        isValidDateFormat  = DateTime.TryParse(Convert.ToString(listItem.FieldValues[ConstantStrings.SearchEmailSentDate], CultureInfo.InvariantCulture), out storedFileSentDate);
                        isValidDateFormat &= DateTime.TryParse(contentCheck.SentDate, out sentDate);
                        if (isValidDateFormat)
                        {
                            TimeSpan diffrence     = sentDate - storedFileSentDate;
                            uint     tolleranceMin = Convert.ToUInt16(ConstantStrings.SentDateTolerance, CultureInfo.InvariantCulture); // up to how much minutes difference between uploaded files is tolerable
                            duplicateDocument.HasPotentialDuplicate = ((fileSize == contentCheck.FileSize) && (subject.Trim() == contentCheck.Subject.Trim()) && (from.Trim() == contentCheck.FromField.Trim()) && (diffrence.Minutes < tolleranceMin));
                        }
                    }
                    else
                    {
                        duplicateDocument.HasPotentialDuplicate = (fileSize == contentCheck.FileSize);
                    }
                }
            }
            return(duplicateDocument);
        }
Exemplo n.º 5
0
        public GenericResponseVM CheckDuplicateDocument(string clientUrl, string folderName, string documentLibraryName,
                                                        string fileName, ContentCheckDetails contentCheck, bool allowContentCheck)
        {
            GenericResponseVM genericResponse   = null;
            DuplicateDocument duplicateDocument = uploadHelperFunctions.DocumentExists(clientUrl, contentCheck, documentLibraryName, folderName, false);

            if (duplicateDocument != null && duplicateDocument.DocumentExists)
            {
                string documentPath     = string.Concat(generalSettings.SiteURL, folderName, ServiceConstants.FORWARD_SLASH, fileName);
                string duplicateMessage = (allowContentCheck && duplicateDocument.HasPotentialDuplicate) ? errorSettings.FilePotentialDuplicateMessage : errorSettings.FileAlreadyExistMessage;
                duplicateMessage = $"{duplicateMessage}|{duplicateDocument.HasPotentialDuplicate}";
                genericResponse  = new GenericResponseVM()
                {
                    IsError = true,
                    Code    = UploadEnums.DuplicateDocument.ToString(),
                    Value   = string.Format(CultureInfo.InvariantCulture, duplicateMessage, fileName, documentPath)
                };
            }
            return(genericResponse);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Check if duplicate document exists
        /// </summary>
        /// <param name="clientContext">SP client context</param>
        /// <param name="documentLibraryName">Name of the document library</param>
        /// <param name="isMailUpload">Mail upload check</param>
        /// <param name="folderPath">The folder path.</param>
        /// <param name="contentCheck">Content check object</param>
        /// <param name="uploadFileName">Name of the file.</param>
        /// <returns>message as per duplicate exists or not</returns>
        public GenericResponseVM CheckDuplicateDocument(ClientContext clientContext, string documentLibraryName, bool isMailUpload, string folderPath, ContentCheckDetails contentCheck, string uploadFileName, bool allowContentCheck, ref string message)
        {
            GenericResponseVM genericResponse   = null;
            DuplicateDocument duplicateDocument = documentRepository.DocumentExists(clientContext, contentCheck, documentLibraryName, folderPath, isMailUpload);

            if (duplicateDocument.DocumentExists)
            {
                string documentPath     = string.Concat(generalSettings.SiteURL, folderPath, ServiceConstants.FORWARD_SLASH, uploadFileName);
                string duplicateMessage = (allowContentCheck && duplicateDocument.HasPotentialDuplicate) ? errorSettings.FilePotentialDuplicateMessage : errorSettings.FileAlreadyExistMessage;
                duplicateMessage = $"{duplicateMessage}|{duplicateDocument.HasPotentialDuplicate}";
                genericResponse  = new GenericResponseVM()
                {
                    IsError = true,
                    Code    = UploadEnums.DuplicateDocument.ToString(),
                    Value   = string.Format(CultureInfo.InvariantCulture, duplicateMessage, uploadFileName, documentPath)
                };
                return(genericResponse);
            }
            return(genericResponse);
        }