Sync javascript Files

Ethan Nguyen asked on January 28, 2021 04:52

Hi All,

How to sync javascript files across CMSApp and MVC website ? Can use UpdateFileWebFarmTask class to do it as the https://docs.xperience.io/k11/custom-development/miscellaneous-custom-development-tasks/web-farm-internals-and-api/creating-custom-web-farm-synchronization-tasks I am using the Kentico version 11 Thanks,

Recent Answers


Brenden Kehren answered on January 28, 2021 05:10

Why would you use your MVC scripts in your CMS app? Just to use the Kentico JS editor? Better off to just deploy your MVC app with the JS files in it.

2 votesVote for this answer Mark as a Correct answer

Ethan Nguyen answered on January 28, 2021 11:22 (last edited on January 28, 2021 11:27)

Hi Brenden Kehren, Thank you for your quick support. that is a requirement of my client, my client knows technical knowledge Kentico. They want if upload any javascript file in CMS admin after it should sync to MVC via Web Farm. I tried creating custom web farm synchronization tasks as the article https://docs.xperience.io/k11/custom-development/miscellaneous-custom-development-tasks/web-farm-internals-and-api/creating-custom-web-farm-synchronization-tasks after that implement code to Changing content file paths to a shared storage

// Registers a custom web farm synchronization task in the system
        public void RegisterCustomTask()
        {
            // Creates a custom web farm task which logs information to the event log
            WebFarmTask task = new WebFarmTask
            {
                Type = "CustomTask",

                // Logs a record into the system's event log, with 'Execute' as the event code
                Execute = (target, textData, binaryData) =>
                {
                    string message = String.Format("Slave {0} is going to process task from master {1}", SystemContext.ServerName, textData);
                    EventLogProvider.LogInformation(target, "Execute", message);

                    // TODO: Slave operation

                    // Creates a new StorageProvider instance for the Windows file system
                    var mediaProvider = StorageProvider.CreateFileSystemStorageProvider();

                    // Specifies the target root directory. The provider creates the relative path of the mapped folders within the given directory.
                    mediaProvider.CustomRootPath = @"D:\Projects\Kentiko\Sources\makino\BE\admin-local\CMS\makino-cn";

                    // Maps a directory to the provider
                    StorageHelper.MapStoragePath("~/CMSScripts/Custom", mediaProvider);
                }
            };

            // Registers the given web farm task
            WebFarmHelper.RegisterTask(task);
        }

However, it does not work. Please advice Note: If I only Writing a custom file system provider as the article https://docs.xperience.io/k12sp/custom-development/working-with-physical-files-using-the-api/writing-a-custom-file-system-provider then it work well Thanks,

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on January 28, 2021 12:15

I assume they upload the JS file using the Javascript files application - which in fact places the file onto the file system into given folder. So, why don't you just use services like Dropbox, Google Drive OneDrive, etc. to keep physical folders in sync? Why adding Kentico into the equation?

1 votesVote for this answer Mark as a Correct answer

Ethan Nguyen answered on January 29, 2021 03:19

Hi Juraj Ondrus, Thank you for your information. will check and get back to my client.

0 votesVote for this answer Mark as a Correct answer

Ethan Nguyen answered on January 29, 2021 04:02

Hi @Brenden Kehren and @Juraj Ondrus No need to create a custom web farm task. There is built-in web farm task for File such as UpdateFileWebFarmTask, DeleteFileWebFarmTask ,DeleteFolderWebFarmTask. just need to delegate the above web farm track into CreateIOTask from your custom file system provider CoreServices.WebFarm.CreateIOTask(new DeleteFolderWebFarmTask { Path = path, TaskFilePath = path }); How do you think if do this way. Please advice

Thanks,

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.