示例#1
0
        public string DmsServiceUpdateJobe(Entity anntotation, string documentDMSId, JsonMetadataMapping jsonMapping, Entity fetchResult)
        {
            string xmlRequestForUpload = XmlRequestForUploadOrUpdateDocuments("UpdateDocument", anntotation, documentDMSId, jsonMapping, fetchResult);

            //throw new InvalidPluginExecutionException(xmlRequestForUpload);
            return(DMSServicePostRequest(xmlRequestForUpload, "UpdateDocument"));
        }
示例#2
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);
        }
示例#3
0
        public bool CheckRequiredParametersForRetrieve(Entity target, out JsonMetadataMapping jsonMapping, out Entity fetchResult)
        {
            jsonMapping = new JsonMetadataMapping();
            fetchResult = null;

            if (authorization)
            {
                string fetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                               "<entity name='dot_documents'>" +
                               "<attribute name='dot_documentsid' />" +
                               "<attribute name='dot_name' />" +
                               "<attribute name='createdon' />" +
                               "<attribute name='dot_validated' />" +
                               "<order attribute='dot_name' descending='false' />" +
                               "<link-entity name='annotation' from='objectid' to='dot_documentsid' alias='ag'>" +
                               "<filter type='and'>" +
                               "<condition attribute='annotationid' operator='eq' uitype='annotation' value='" + target.Id + "' />" +
                               "</filter>" +
                               "</link-entity>" +
                               "</entity>" +
                               "</fetch> ";

                EntityCollection result = _service.RetrieveMultiple(new FetchExpression(fetch));

                if (result != null)
                {
                    if (result.Entities[0].Contains("dot_validated") && result.Entities[0].GetAttributeValue <bool>("dot_validated") == true)
                    {
                        var isMetadataExist = CheckIsDocumentHaveMetadata(result.Entities[0].Id, out jsonMapping, out fetchResult);
                        return(isMetadataExist);
                    }
                }
            }
            return(false);
        }
示例#4
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);
        }
示例#5
0
 public void DmsServiceUploadAnntotations(JsonMetadataMapping jsonMapping, Entity fetchResult)
 {
     foreach (var annotation in annotations)
     {
         var documentId = DMSServicePostRequest(XmlRequestForUploadOrUpdateDocuments("UploadDocument", annotation, string.Empty, jsonMapping, fetchResult), "UploadDocument");
         if (documentId != string.Empty)
         {
             var        uploadDocumentIdBytes = Encoding.UTF8.GetBytes(documentId);
             Annotation annotationForApdate   = new Annotation()
             {
                 Id           = annotation.Id,
                 DocumentBody = Convert.ToBase64String(uploadDocumentIdBytes),
             };
             _annotationRepository.Update(annotationForApdate);
         }
     }
 }
示例#6
0
        public string DmsServiceUploadJobe(Entity anntotation, JsonMetadataMapping jsonMapping, Entity fetchResult)
        {
            string xmlRequestForUpload = XmlRequestForUploadOrUpdateDocuments("UploadDocument", anntotation, string.Empty, jsonMapping, fetchResult);

            return(DMSServicePostRequest(xmlRequestForUpload, "UploadDocument"));
        }
示例#7
0
        private string XmlRequestForUploadOrUpdateDocuments(string method, Entity annotation, string documentDMSId, JsonMetadataMapping jsonMapping, Entity fetchResult)
        {
            XmlDocument xmlForUpload = new XmlDocument();
            //XmlDeclaration xmldecl;
            //xmldecl = xmlForUpload.CreateXmlDeclaration("1.0", null, null);
            //xmldecl.Encoding = "windows-1252";

            XmlElement el = (XmlElement)xmlForUpload.AppendChild(xmlForUpload.CreateElement(method));

            el.AppendChild(xmlForUpload.CreateElement("documentBinary")).InnerText = annotation.GetAttributeValue <string>("documentbody");
            if (method == "UploadDocument")
            {
                el.AppendChild(xmlForUpload.CreateElement("fileName")).InnerText = annotation.GetAttributeValue <string>("filename");
            }
            if (method == "UpdateDocument")
            {
                el.AppendChild(xmlForUpload.CreateElement("DocumentId")).InnerText = documentDMSId;
            }
            el.AppendChild(xmlForUpload.CreateElement("UserName")).InnerText      = userName;
            el.AppendChild(xmlForUpload.CreateElement("Password")).InnerText      = password;
            el.AppendChild(xmlForUpload.CreateElement("ApplicationId")).InnerText = applicationId;
            XmlElement el2 = xmlForUpload.CreateElement("metadata");

            el.AppendChild(el2);
            XmlElement el3 = xmlForUpload.CreateElement("DocumentMetadata");

            el2.AppendChild(el3);
            el3.AppendChild(xmlForUpload.CreateElement("Id")).InnerText    = "Document Type";
            el3.AppendChild(xmlForUpload.CreateElement("Value")).InnerText = jsonMapping.DocumentTypeId;

            if (method != "UpdateDocument")
            {
                foreach (var obj in jsonMapping.JsonParameters.parametersData)
                {
                    if (fetchResult.Contains(obj.parameterName))
                    {
                        var xmlElem = xmlForUpload.CreateElement("DocumentMetadata");
                        el2.AppendChild(xmlElem);
                        xmlElem.AppendChild(xmlForUpload.CreateElement("Id")).InnerText = obj.integration_name;
                        var value = string.Empty;
                        switch (obj.type)
                        {
                        case ("date"):
                            value = DateTime.Parse(fetchResult.GetAttributeValue <AliasedValue>(obj.parameterName).Value.ToString()).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
                            break;

                        case ("optionsetlabel"):
                            value = GetOptionSetStringValue(fetchResult.GetAttributeValue <AliasedValue>(obj.parameterName));
                            break;

                        default:
                            value = fetchResult.GetAttributeValue <AliasedValue>(obj.parameterName).Value.ToString();
                            break;
                        }
                        ;
                        xmlElem.AppendChild(xmlForUpload.CreateElement("Value")).InnerText = value;
                    }
                }
            }

            //xmlForUpload.InsertBefore(xmldecl, el);

            return(xmlForUpload.OuterXml);
        }