Esempio n. 1
0
        public void TestDeployWebresources()
        {
            CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["integration_testing"].ConnectionString);
            var userId = crmSvc.GetMyCrmUserId();
            var trace  = new TraceLogger();
            var task   = new DeployWebResourcesTask(crmSvc, trace);
            var path   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                      @"..\..\..\Webresources");

            task.Execute(path);
        }
Esempio n. 2
0
        public void DeployHtmlJSWebresources()
        {
            using (ShimsContext.Create())
            {
                #region Arrange
                Fakes.ShimQueries.GetPluginStepsOrganizationServiceContextString = (OrganizationServiceContext context, string name) =>
                {
                    // Return no existing steps
                    return(new List <SdkMessageProcessingStep>());
                };

                var                  trace        = new TraceLogger();
                List <Entity>        created      = new List <Entity>();
                int                  publishCount = 0;
                IOrganizationService service      = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService()
                {
                    CreateEntity = delegate(Entity entity)
                    {
                        created.Add(entity);
                        return(Guid.NewGuid());
                    },

                    ExecuteOrganizationRequest = delegate(OrganizationRequest request)
                    {
                        if (request.GetType() == typeof(RetrieveMultipleRequest))
                        {
                            var query           = request as RetrieveMultipleRequest;
                            var queryExpression = query.Query as QueryExpression;
                            var results         = new List <Entity>();

                            switch (queryExpression.EntityName)
                            {
                            case WebResource.EntityLogicalName:

                                break;
                            }

                            return(new Microsoft.Xrm.Sdk.Messages.Fakes.ShimRetrieveMultipleResponse()
                            {
                                EntityCollectionGet = delegate() { return new EntityCollection(results); }
                            });
                        }
                        else if (request.GetType() == typeof(PublishXmlRequest))
                        {
                            publishCount++;
                            return(new PublishXmlResponse());
                        }
                        else
                        {
                            throw new Exception("Unexpected Call");
                        }
                    }
                };
                #endregion

                #region Act

                var  config     = new ConfigFile();
                Guid id         = Guid.NewGuid();
                var  tempFolder = Path.Combine(Path.GetTempPath(), id.ToString());
                Directory.CreateDirectory(tempFolder);

                config.filePath = tempFolder;

                Directory.CreateDirectory(Path.Combine(tempFolder, @"new_"));
                // Create an html webresorce
                File.WriteAllText(Path.Combine(tempFolder, @"new_\page.htm"), @"<html><body>test</body></html>");

                /// Create a js webresource
                File.WriteAllText(Path.Combine(tempFolder, @"new_\script.js"), @"<html><body>test</body></html>");

                config.webresources = new List <WebresourceDeployConfig>();
                config.webresources.Add(new WebresourceDeployConfig
                {
                    files = new List <WebResourceFile>()
                });
                config.webresources[0].files.Add(new WebResourceFile()
                {
                    file        = @"new_\page.htm",
                    displayname = @"new_/page.htm"
                });
                config.webresources[0].files.Add(new WebResourceFile()
                {
                    file        = @"new_\script.js",
                    displayname = @"new_/script.js"
                });
                using (var ctx = new OrganizationServiceContext(service))
                {
                    var webresourceDeploy = new DeployWebResourcesTask(service, trace);
                    var guids             = webresourceDeploy.DeployWebresources(ctx, config, config.webresources[0]);
                    webresourceDeploy.PublishWebresources(guids);
                }
                #endregion

                #region Assert
                Assert.AreEqual(2, created.Where(a => a.GetType() == typeof(WebResource)).Count(), "2 Webresources created");
                Assert.AreEqual((int)WebResourceWebResourceType.Webpage_HTML, created[0].ToEntity <WebResource>().WebResourceType.Value, "html file");
                Assert.AreEqual(@"new_/page.htm", created[0].ToEntity <WebResource>().DisplayName, "html display name");
                Assert.AreEqual(@"new_/page.htm", created[0].ToEntity <WebResource>().Name, "html name");
                Assert.AreEqual((int)WebResourceWebResourceType.Script_JScript, created[1].ToEntity <WebResource>().WebResourceType.Value, "javascript file");
                Assert.AreEqual(@"new_/script.js", created[1].ToEntity <WebResource>().DisplayName, "javascript display name");
                Assert.AreEqual(@"new_/script.js", created[1].ToEntity <WebResource>().Name, "javascript name");
                Assert.AreEqual(1, publishCount, "files published");

                #endregion
            }
        }
Esempio n. 3
0
        public void DeployHtmlJSWebresources()
        {
            #region Arrange
            ServiceLocator.Init();
            var                  trace        = new TraceLogger();
            List <Entity>        created      = new List <Entity>();
            int                  publishCount = 0;
            IOrganizationService service      = A.Fake <IOrganizationService>(a => a.Strict());
            A.CallTo(() => service.Create(A <Entity> .Ignored))
            .ReturnsLazily((Entity entity) =>
            {
                created.Add(entity);
                return(Guid.NewGuid());
            });
            A.CallTo(() => service.Execute(A <OrganizationRequest> .Ignored))
            .ReturnsLazily((OrganizationRequest request) =>
            {
                if (request.GetType() == typeof(RetrieveMultipleRequest))
                {
                    var query           = request as RetrieveMultipleRequest;
                    var queryExpression = query.Query as QueryExpression;
                    var results         = new List <Entity>();

                    switch (queryExpression.EntityName)
                    {
                    case WebResource.EntityLogicalName:

                        break;
                    }

                    var response = new RetrieveMultipleResponse();
                    response.Results["EntityCollection"] = new EntityCollection(results);

                    return(response);
                }
                else if (request.GetType() == typeof(PublishXmlRequest))
                {
                    publishCount++;
                    return(new PublishXmlResponse());
                }
                else
                {
                    throw new Exception("Unexpected Call");
                }
            });

            #endregion

            #region Act

            var  config     = new ConfigFile();
            Guid id         = Guid.NewGuid();
            var  tempFolder = Path.Combine(Path.GetTempPath(), id.ToString());
            Directory.CreateDirectory(tempFolder);

            config.filePath = tempFolder;

            Directory.CreateDirectory(Path.Combine(tempFolder, @"new_"));
            // Create an html webresorce
            File.WriteAllText(Path.Combine(tempFolder, @"new_\page.htm"), @"<html><body>test</body></html>");

            /// Create a js webresource
            File.WriteAllText(Path.Combine(tempFolder, @"new_\script.js"), @"<html><body>test</body></html>");

            config.webresources = new List <WebresourceDeployConfig>();
            config.webresources.Add(new WebresourceDeployConfig
            {
                files = new List <WebResourceFile>()
            });
            config.webresources[0].files.Add(new WebResourceFile()
            {
                file        = @"new_\page.htm",
                displayname = @"new_/page.htm"
            });
            config.webresources[0].files.Add(new WebResourceFile()
            {
                file        = @"new_\script.js",
                displayname = @"new_/script.js"
            });
            using (var ctx = new OrganizationServiceContext(service))
            {
                var webresourceDeploy = new DeployWebResourcesTask(service, trace);
                var guids             = webresourceDeploy.DeployWebresources(ctx, config, config.webresources[0]);
                webresourceDeploy.PublishWebresources(guids);
            }
            #endregion

            #region Assert
            Assert.AreEqual(2, created.Where(a => a.GetType() == typeof(WebResource)).Count(), "2 Webresources created");
            Assert.AreEqual(webresource_webresourcetype.Webpage_HTML, created[0].ToEntity <WebResource>().WebResourceType.Value, "html file");
            Assert.AreEqual(@"new_/page.htm", created[0].ToEntity <WebResource>().DisplayName, "html display name");
            Assert.AreEqual(@"new_/page.htm", created[0].ToEntity <WebResource>().Name, "html name");
            Assert.AreEqual(webresource_webresourcetype.Script_JScript, created[1].ToEntity <WebResource>().WebResourceType.Value, "javascript file");
            Assert.AreEqual(@"new_/script.js", created[1].ToEntity <WebResource>().DisplayName, "javascript display name");
            Assert.AreEqual(@"new_/script.js", created[1].ToEntity <WebResource>().Name, "javascript name");
            Assert.AreEqual(1, publishCount, "files published");

            #endregion
        }
Esempio n. 4
0
        private static void RunTask(CommandLineArgs arguments, IOrganizationService service, ITrace trace)
        {
            if (arguments.Path == null)
            {
                arguments.Path = Directory.GetCurrentDirectory();
            }
            else
            {
                // Strip trailing \
                arguments.Path = arguments.Path.TrimEnd('\\');
                arguments.Path = Path.Combine(Directory.GetCurrentDirectory(), arguments.Path);
            }

            BaseTask task    = null;
            string   command = arguments.Task.ToLower();

            switch (command)
            {
            case "plugins":
                trace.WriteLine("Deploying Plugins");
                task = new DeployPluginsTask(service, trace);
                break;

            case "workflow":
                trace.WriteLine("Deploying Custom Workflow Activities");
                task = new DeployWorkflowActivitiesTask(service, trace);
                break;

            case "webresources":
                trace.WriteLine("Deploying WebResources");
                task = new DeployWebResourcesTask(service, trace);
                break;

            case "instrument":
                trace.WriteLine("Downloading Plugin/Workflow Activity Metadata");
                task = new DownloadPluginMetadataTask(service, trace);
                break;

            case "download-webresources":
                trace.WriteLine("Downloading Webresources");
                task = new DownloadWebresourceFileTask(service, trace)
                {
                    Overwrite = arguments.Overwrite
                };
                break;

            case "get-webresources":
                trace.WriteLine("Downloading Webresources");
                task        = new DownloadWebresourceConfigTask(service, trace);
                task.Prefix = arguments.Prefix;
                break;

            case "earlybound":
                trace.WriteLine("Generating early bound types");
                var earlyBound = new EarlyBoundClassGeneratorTask(service, trace);
                task = earlyBound;
                earlyBound.ConectionString = arguments.Connection;
                break;

            case "unpack":
                trace.WriteLine("Unpacking solution");
                var packager = new SolutionPackagerTask(service, trace);
                packager.command = command;
                task             = packager;
                break;

            case "unpacksolution":
                trace.WriteLine("Unpacking solution Zip");
                var unpackfromsolution = new SolutionPackagerTask(service, trace);
                unpackfromsolution.command = command;
                task = unpackfromsolution;
                break;

            case "pack":
                trace.WriteLine("Packing Solution");
                var pack = new SolutionPackagerTask(service, trace);
                pack.command = command;
                task         = pack;
                break;

            case "import":
                trace.WriteLine("Packing & Import Solution");
                var import = new SolutionPackagerTask(service, trace);
                import.command = command;
                task           = import;
                break;

            case "compare":
                trace.WriteLine("Comparing Solution");
                var compare = new SolutionPackagerTask(service, trace);
                compare.command = command;
                task            = compare;
                break;
            }


            if (task != null)
            {
                if (arguments.Profile != null)
                {
                    task.Profile = arguments.Profile;
                }
                task.Execute(arguments.Path);
            }
            else
            {
                throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.NO_TASK_SUPPLIED, String.Format("Task '{0}' not recognised. Please consult help!", arguments.Task.ToLower()));
            }
        }
Esempio n. 5
0
        private static void RunTask(CommandLineArgs arguments, IOrganizationService service, ITrace trace)
        {
            if (arguments.Path == null)
            {
                arguments.Path = Directory.GetCurrentDirectory();
            }
            else
            {
                // Strip trailing \
                arguments.Path = arguments.Path.TrimEnd('\\');
                arguments.Path = Path.Combine(Directory.GetCurrentDirectory(), arguments.Path);
            }

            BaseTask task = null;

            switch (arguments.Task.ToLower())
            {
            case "plugins":
                trace.WriteLine("Deploying Plugins");
                task = new DeployPluginsTask(service, trace);
                break;

            case "workflow":
                trace.WriteLine("Deploying Custom Workflow Activities");
                task = new DeployWorkflowActivitiesTask(service, trace);
                break;

            case "webresources":
                trace.WriteLine("Deploying WebResources");
                task = new DeployWebResourcesTask(service, trace);
                break;

            case "instrument":
                trace.WriteLine("Downloading Plugin/Workflow Activity Metadata");
                task = new DownloadPluginMetadataTask(service, trace);
                break;

            case "get-webresources":
                trace.WriteLine("Downloading Webresources");
                task        = new DownloadWebresourceConfigTask(service, trace);
                task.Prefix = arguments.Prefix;
                break;

            case "earlybound":
                trace.WriteLine("Generating early bound types");
                var earlyBound = new EarlyBoundClassGeneratorTask(service, trace);
                task = earlyBound;
                earlyBound.ConectionString = arguments.Connection;
                break;
            }


            if (task != null)
            {
                if (arguments.Profile != null)
                {
                    task.Profile = arguments.Profile;
                }
                task.Execute(arguments.Path);
            }
            else
            {
                throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.NO_TASK_SUPPLIED, String.Format("Task '{0}' not recognised. Please consult help!", arguments.Task.ToLower()));
            }
        }