Ejemplo n.º 1
0
        public void Execute(IServiceProvider serviceProvider)
        {
            IOrganizationServiceFactory factory  = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IPluginExecutionContext     context  = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationService        _service = factory.CreateOrganizationService(context.UserId);

            if (context.MessageName == "Update" && context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                Entity document = (Entity)context.InputParameters["Target"];
                if (document.Contains("dot_validated") && document.GetAttributeValue <bool>("dot_validated") == true)
                {
                    var dmsService = new DmsWebService(_service);
                    JsonMetadataMapping jsonMapping = new JsonMetadataMapping();
                    Entity fetchResult = null;
                    if (dmsService.CheckRequiredParametersForIntegration(document, out jsonMapping, out fetchResult))
                    {
                        dmsService.DmsServiceUploadAnntotations(jsonMapping, fetchResult);
                    }
                    if (dmsService.error != string.Empty)
                    {
                        document["dot_integrationerror"]  = dmsService.error;
                        document["dot_integrationstatus"] = new OptionSetValue(180000002);
                    }
                    else
                    {
                        document["dot_integrationstatus"] = new OptionSetValue(180000001);
                        document["dot_integrationerror"]  = string.Empty;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var connection = new CrmConnection("Crm");
            var _service   = new OrganizationService(connection);

            var dmsService = new DmsWebService(_service);
            JsonMetadataMapping jsonMapping = null;
            Entity fetchResult = null;

            var document = _service.Retrieve(dot_documents.EntityLogicalName, new Guid("308DF494-0545-E711-80C9-005056B90C62"), new ColumnSet(true));

            if (dmsService.CheckRequiredParametersForIntegration(document, out jsonMapping, out fetchResult))
            {
                dmsService.DmsServiceUploadAnntotations(jsonMapping, fetchResult);
            }


            //3D4E35CA-E692-E711-80CD-005056B90C62
            var anntotation2 = _service.Retrieve(Annotation.EntityLogicalName, new Guid("9577BE91-8F93-E711-80CD-005056B90C62"), new ColumnSet(true));
            var anntotation1 = _service.Retrieve(Annotation.EntityLogicalName, new Guid("A9EBAA09-8E93-E711-80CD-005056B90C62"), new ColumnSet(true));

            //JsonMetadataMapping jsonMapping = new JsonMetadataMapping();
            //Entity fetchResult = null;
            //dmsService.CheckRequiredParametersForRetrieve(anntotation1, out jsonMapping, out fetchResult);

            //var discription = anntotation1.GetAttributeValue<string>("notetext");
            //if (discription != null && discription.Split('^').Length == 2)
            //{
            //    var documentDMSIdBase64EncodedBytes = Convert.FromBase64String(discription.Split('^')[1]);
            //    var documentDMSId = Encoding.UTF8.GetString(documentDMSIdBase64EncodedBytes);
            //    dmsService.DmsServiceUpdateJobe(anntotation2, documentDMSId, jsonMapping, fetchResult);
            //}


            // string documentBody = dmsService.DmsServiceDownloadJobe(anntotation);
        }
Ejemplo n.º 3
0
        public void Execute(IServiceProvider serviceProvider)
        {
            IOrganizationServiceFactory factory  = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IPluginExecutionContext     context  = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationService        _service = factory.CreateOrganizationService(context.UserId);

            var dmsService = new DmsWebService(_service);

            if (context.MessageName == "Create" && context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                Entity document = (Entity)context.InputParameters["Target"];

                if (document.Contains("objectid") && document.GetAttributeValue <EntityReference>("objectid") != null && document.GetAttributeValue <EntityReference>("objectid").LogicalName == "dot_documents")
                {
                    JsonMetadataMapping jsonMapping = new JsonMetadataMapping();
                    Entity fetchResult = null;
                    if (dmsService.CheckRequiredParametersForIntegration(document, out jsonMapping, out fetchResult))
                    {
                        string uploadDocumentId = dmsService.DmsServiceUploadJobe(document, jsonMapping, fetchResult);
                        if (uploadDocumentId != string.Empty)
                        {
                            var uploadDocumentIdBytes = Encoding.UTF8.GetBytes(uploadDocumentId);
                            document["documentbody"] = Convert.ToBase64String(uploadDocumentIdBytes);
                        }
                    }
                    dmsService.UpdateDocumentIntegrationStatus(document.GetAttributeValue <EntityReference>("objectid").Id);
                }
            }
            else if (context.MessageName == "Update" && context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.PreEntityImages.Contains("PreImage") && context.PreEntityImages["PreImage"] is Entity)
            {
                Entity document        = (Entity)context.InputParameters["Target"];
                var    preMessageImage = (Entity)context.PreEntityImages["PreImage"];

                JsonMetadataMapping jsonMapping = new JsonMetadataMapping();
                Entity fetchResult = null;

                if (preMessageImage.Contains("objectid") && preMessageImage.GetAttributeValue <EntityReference>("objectid") != null && preMessageImage.GetAttributeValue <EntityReference>("objectid").LogicalName == "dot_documents" &&
                    document.Contains("documentbody") && document.GetAttributeValue <string>("documentbody") != null && dmsService.CheckRequiredParametersForRetrieve(preMessageImage, out jsonMapping, out fetchResult))
                {
                    if (preMessageImage.Contains("documentbody") && preMessageImage.GetAttributeValue <string>("documentbody") != null && preMessageImage.GetAttributeValue <string>("documentbody") != string.Empty)
                    {
                        if (document.GetAttributeValue <string>("documentbody") != string.Empty)
                        {
                            var  base64EncodedBytes = Convert.FromBase64String(document.GetAttributeValue <string>("documentbody"));
                            var  docId       = Encoding.UTF8.GetString(base64EncodedBytes);
                            bool checkIsGuid = false;
                            try
                            {
                                new Guid(docId);
                            }
                            catch (Exception ex)
                            {
                                checkIsGuid = true;
                            }

                            if (checkIsGuid)
                            {
                                var documentDMSIdBase64EncodedBytes = Convert.FromBase64String(preMessageImage.GetAttributeValue <string>("documentbody"));
                                var documentDMSId = Encoding.UTF8.GetString(documentDMSIdBase64EncodedBytes);
                                dmsService.DmsServiceUpdateJobe(document, documentDMSId, jsonMapping, fetchResult);
                                document["documentbody"] = preMessageImage.GetAttributeValue <string>("documentbody");
                            }
                            dmsService.UpdateDocumentIntegrationStatus(preMessageImage.GetAttributeValue <EntityReference>("objectid").Id);
                        }
                        else
                        {
                            var discription = preMessageImage.GetAttributeValue <string>("notetext");
                            document["notetext"] = string.Format("{0}^{1}", discription, preMessageImage.GetAttributeValue <string>("documentbody"));
                        }
                    }
                    else
                    {
                        var discription = preMessageImage.GetAttributeValue <string>("notetext");
                        if (discription != null && discription.Split('^').Length == 2)
                        {
                            var documentDMSIdBase64EncodedBytes = Convert.FromBase64String(discription.Split('^')[1]);
                            var documentDMSId = Encoding.UTF8.GetString(documentDMSIdBase64EncodedBytes);
                            dmsService.DmsServiceUpdateJobe(document, documentDMSId, jsonMapping, fetchResult);
                            document["documentbody"] = discription.Split('^')[1];
                            document["notetext"]     = discription.Split('^')[0];
                        }
                        dmsService.UpdateDocumentIntegrationStatus(preMessageImage.GetAttributeValue <EntityReference>("objectid").Id);
                    }
                }
            }

            else if (context.MessageName == "Retrieve" && context.OutputParameters.Contains("BusinessEntity") && context.OutputParameters["BusinessEntity"] is Entity)
            {
                var document = (Entity)context.OutputParameters["BusinessEntity"];
                JsonMetadataMapping jsonMapping = new JsonMetadataMapping();
                Entity fetchResult = null;
                if (document.GetAttributeValue <string>("documentbody") != null && dmsService.CheckRequiredParametersForRetrieve(document, out jsonMapping, out fetchResult))
                {
                    string documentBody = dmsService.DmsServiceDownloadJobe(document);

                    if (documentBody != string.Empty)
                    {
                        document["documentbody"] = documentBody;
                    }
                }
                //dmsService.UpdateDocumentIntegrationStatus(document.GetAttributeValue<EntityReference>("objectid").Id);
            }
        }