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;
        }
        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;
        }
Exemple #3
0
        static Config()
        {
            var config = new AppConfigReader();

            var thumbprint = config.Get <string>("Security.Thumbprint");

            SecureConfig.Initialize(thumbprint);

            ConfluenceUsername = config.Get <string>("Confluence.Username");
            ConfluencePassword = SecureConfig.Decrypt(config.Get <string>("Confluence.Password"));

            CCNetUrl = config.Get <string>("CCNet.Url");
            NuGetUrl = config.Get <string>("NuGet.Url");
            TfsUrl   = config.Get <string>("Tfs.Url");
        }
        private string GetValue(IOrganizationService service, string key, string defaultValue)
        {
            try
            {
                string value = SecureConfig.GetConfigValue(service, key);
                if (!string.IsNullOrEmpty(value))
                {
                    return(value);
                }

                return(defaultValue);
            }
            catch
            {
                return(defaultValue);
            }
        }
        private decimal GetValue(IOrganizationService service, string key, decimal defaultValue)
        {
            try
            {
                string value = SecureConfig.GetConfigValue(service, key);
                if (!string.IsNullOrEmpty(value))
                {
                    return(defaultValue);
                }

                bool res = decimal.TryParse(value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out decimal numberValue);
                if (!res)
                {
                    bool res2 = decimal.TryParse(value.Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out numberValue);
                }
                return(numberValue);
            }
            catch
            {
                return(defaultValue);
            }
        }
 private string GetBingMap(IOrganizationService service)
 {
     return(SecureConfig.GetConfigValue(service, "BingMapsKey"));
 }