コード例 #1
0
        public bool CheckRequiredParametersForIntegration(Entity target, out JsonMetadataMapping jsonMapping, out Entity fetchResult)
        {
            dot_documents document = new dot_documents();

            jsonMapping = new JsonMetadataMapping();
            fetchResult = null;
            bool isExistMetadada = false;

            if (target.LogicalName == "annotation")
            {
                document        = _documentRepository.GetCrmEntityById(target.GetAttributeValue <EntityReference>("objectid").Id);
                isExistMetadada = CheckIsDocumentHaveMetadata(document.Id, out jsonMapping, out fetchResult);
            }
            else if (target.LogicalName == "dot_documents")
            {
                annotations     = _annotationRepository.GetEntitiesByField("objectid", target.Id, new ColumnSet(true)).ToList();
                isExistMetadada = CheckIsDocumentHaveMetadata(target.Id, out jsonMapping, out fetchResult);
            }
            if (authorization && isExistMetadada && ((document != null && document.dot_Validated != null && document.dot_Validated.Value == true) || (annotations != null && annotations.Count > 0)))
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        public bool CheckIsDocumentHaveMetadata(Guid documentId, out JsonMetadataMapping jsonMapping, out Entity fetchResult)
        {
            jsonMapping = new JsonMetadataMapping();
            fetchResult = null;
            var document = _documentRepository.GetCrmEntityById(documentId);

            if (document != null && document.dot_DocumentTypeid != null)
            {
                var documentType = _documentTypeRepository.GetCrmEntityById(document.dot_DocumentTypeid.Id);
                if (documentType != null && documentType.dot_dmsintegrationquery != null && documentType.dot_dmsintegrationquery != string.Empty &&
                    documentType.dot_dmsintegrationmapping != null && documentType.dot_dmsintegrationmapping != string.Empty &&
                    documentType.dot_dmsdocumenttype != null && documentType.dot_dmsdocumenttype != string.Empty)
                {
                    var jsonMappingString = documentType.dot_dmsintegrationmapping;
                    try
                    {
                        using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonMappingString)))
                        {
                            DataContractJsonSerializer serialiser = new DataContractJsonSerializer(typeof(RootObject));
                            jsonMapping.JsonParameters = (RootObject)serialiser.ReadObject(ms);
                            jsonMapping.DocumentTypeId = documentType.dot_dmsdocumenttype;
                        }
                    }
                    catch (Exception ex)
                    {
                        error = "Can't read dms integration mapping";
                        throw new InvalidPluginExecutionException("Can't read dms integration mapping");
                    }
                    if (jsonMapping != null)
                    {
                        try
                        {
                            var fetch = string.Format(documentType.dot_dmsintegrationquery, documentId);
                            fetchResult = _service.RetrieveMultiple(new FetchExpression(fetch)).Entities.FirstOrDefault();
                            if (fetchResult == null)
                            {
                                error = "Fetch for metadata don't given results";
                                return(false);
                            }
                            else
                            {
                                return(true);
                            }
                        }
                        catch (Exception ex)
                        {
                            error = "Fetch for metadata broken";
                            return(false);
                        }
                    }
                }
                else
                {
                    error = "One of required field in Document type is empty";
                    return(false);
                }
            }
            return(false);
        }