public override void OnExecute(IPluginProvider provider)
        {
            // Get configuration values
            var resource = SecureConfig.GetValue <string>("resource");
            var username = SecureConfig.GetValue <string>("username");
            var password = SecureConfig.GetValue <string>("password");

            // Get access token
            var token = provider.TokenService.GetToken(resource, username, password);

            // Get current versions
            var current  = GetCurrentVersions(token);
            var previous = GetPreviousVersions(provider.OrganizationAdminService);

            var isUpdated = current.Application > previous.Application || current.Database > previous.Database;

            if (isUpdated)
            {
                var entity = new Entity("bg_versionlog")
                {
                    ["bg_application"] = current.Application.ToString(),
                    ["bg_database"]    = current.Database.ToString()
                };
                provider.OrganizationAdminService.Create(entity);
            }

            var output = provider.ExecutionContext.OutputParameters;

            output["Application"] = current.Application.ToString();
            output["Database"]    = current.Database.ToString();
            output["IsUpdated"]   = isUpdated;
        }
Beispiel #2
0
        public override void OnExecute(IPluginProvider provider)
        {
            // Get configuration values
            var resource = SecureConfig.GetValue <string>("resource");
            var username = SecureConfig.GetValue <string>("username");
            var password = SecureConfig.GetValue <string>("password");

            var renderer = new Renderer(resource, username, password);

            var service = provider.OrganizationService;
            var context = provider.ExecutionContext;
            var target  = provider.Target;

            // Render the report
            var output = string.Empty;

            switch (target.LogicalName)
            {
            case "report":
                var reportColumns = new ColumnSet("reportnameonsrs", "languagecode", "defaultfilter");
                var report        = service.Retrieve(target.LogicalName, target.Id, reportColumns);
                var format        = context.InputParameterOrDefault <string>("Format");
                var parameters    = context.InputParameterOrDefault <string>("Parameters");
                var rendered      = renderer.RenderReport(report, format, parameters);
                output = Convert.ToBase64String(rendered);
                break;

            case "documenttemplate":
                var templateColumns = new ColumnSet("documenttype", "associatedentitytypecode");
                var template        = service.Retrieve(target.LogicalName, target.Id, templateColumns);

                switch (template.GetAttributeValue <OptionSetValue>("documenttype")?.Value)
                {
                case 1:
                    var savedView = Guid.Parse(context.InputParameterOrDefault <string>("ViewId"));
                    output = renderer.RenderExcelTemplate(template.Id, savedView);
                    break;

                case 2:
                    var typeCode = template.GetAttributeValue <string>("associatedentitytypecode");
                    var metadata = service.GetEntityMetadata(typeCode);
                    var recordId = Guid.Parse(context.InputParameterOrDefault <string>("RecordId"));
                    output = renderer.RenderWordTemplate(template.Id, recordId, metadata.ObjectTypeCode ?? 0);
                    break;

                default:
                    throw new Exception("Invalid document template type.");
                }
                break;

            default:
                throw new Exception("Invalid input target.");
            }
            // Return as Base-64
            provider.ExecutionContext.OutputParameters["Output"] = output;
        }