Table of Contents

Namespace Dynamicweb.Updates

Classes

ContentUpdateProvider
FileUpdate

Represents an update that writes the contents from a provided stream to a specified file.

using System.Reflection;

namespace Dynamicweb.Updates.Examples
{
    /// <summary>
    /// Example UpdateProvider demonstrating usage of SqlUpdate, SettingUpdate, MethodUpdate, and FileUpdate.
    /// </summary>
    public class SqlUpdateSampleProvider : UpdateProvider
    {
        public override IEnumerable<Update> GetUpdates()
        {
            // SQL Update: Add a column to a table if it does not exist
            yield return SqlUpdate.AddColumn(
                id: "d50467a2-0e9b-4c70-a490-7ab4af88851b",
                provider: this,
                tableName: "MyCustomTable",
                columnName: "MyCustomColumn",
                columnDefinition: "NVARCHAR(50) NULL"
            );

            // SettingUpdate: Set a configuration value, only if it does not already exist
            yield return new SettingUpdate(
                id: "99fd48e3-f364-4108-bb19-6355e8b31896",
                provider: this,
                name: "/Globalsettings/System/Url/HighVolumeProductUrls/Enable",
                value: "True"
            );

            // SettingUpdate: Overwrite a configuration value even if it exists
            yield return new SettingUpdate(
                id: "89c68710-c2c1-4e02-8ea5-f712adeea24f",
                provider: this,
                name: "/Globalsettings/System/Url/HighVolumeProductUrls/Enable",
                value: "True",
                overwrite: true
            );

            // MethodUpdate: Execute custom logic during update
            yield return new MethodUpdate(
                id: "30c561dd-5509-4636-b81a-146be8a51e40",
                provider: this,
                method: context =>
                {
                    // Custom logic here
                    Console.WriteLine("Custom method executed as part of update.");
                }
            );

            // FileUpdate: Write a file to disk, only if it does not already exist
            yield return new FileUpdate(
                id: "efe5952c-bf3c-400d-a654-6fe2eb79ca44",
                provider: this,
                filePath: "/Files/Templates/Feeds/CustomFeedTemplate.cshtml",
                fileStreamProvider: () => GetFileStreamFromEmbeddedResource("CustomFeedTemplate.cshtml"),
                overwrite: false
            );

            // FileUpdate: Overwrite an existing file
            yield return new FileUpdate(
                id: "27c24328-285b-4cae-b62b-23130b6fcde5",
                provider: this,
                filePath: "/Files/Templates/Feeds/CustomFeedTemplate.cshtml",
                fileStreamProvider: () => GetFileStreamFromEmbeddedResource("CustomFeedTemplate.cshtml"),
                overwrite: true
            );
        }

        private Stream GetFileStreamFromEmbeddedResource(string resourceName)
        {
            string resourceFullName = $"CustomAssembly.{resourceName}";
            var assembly = Assembly.GetAssembly(this.GetType());
            var stream = assembly?.GetManifestResourceStream(resourceName);

            if (stream is null)
                throw new FileNotFoundException($"Embedded resource '{resourceFullName}' not found.");

            return stream;
        }
    }
}
InitializeDatabaseUpdate
MethodUpdate

Represents an update that executes a specified method (action) when applied.

using System.Reflection;

namespace Dynamicweb.Updates.Examples
{
    /// <summary>
    /// Example UpdateProvider demonstrating usage of SqlUpdate, SettingUpdate, MethodUpdate, and FileUpdate.
    /// </summary>
    public class SqlUpdateSampleProvider : UpdateProvider
    {
        public override IEnumerable<Update> GetUpdates()
        {
            // SQL Update: Add a column to a table if it does not exist
            yield return SqlUpdate.AddColumn(
                id: "d50467a2-0e9b-4c70-a490-7ab4af88851b",
                provider: this,
                tableName: "MyCustomTable",
                columnName: "MyCustomColumn",
                columnDefinition: "NVARCHAR(50) NULL"
            );

            // SettingUpdate: Set a configuration value, only if it does not already exist
            yield return new SettingUpdate(
                id: "99fd48e3-f364-4108-bb19-6355e8b31896",
                provider: this,
                name: "/Globalsettings/System/Url/HighVolumeProductUrls/Enable",
                value: "True"
            );

            // SettingUpdate: Overwrite a configuration value even if it exists
            yield return new SettingUpdate(
                id: "89c68710-c2c1-4e02-8ea5-f712adeea24f",
                provider: this,
                name: "/Globalsettings/System/Url/HighVolumeProductUrls/Enable",
                value: "True",
                overwrite: true
            );

            // MethodUpdate: Execute custom logic during update
            yield return new MethodUpdate(
                id: "30c561dd-5509-4636-b81a-146be8a51e40",
                provider: this,
                method: context =>
                {
                    // Custom logic here
                    Console.WriteLine("Custom method executed as part of update.");
                }
            );

            // FileUpdate: Write a file to disk, only if it does not already exist
            yield return new FileUpdate(
                id: "efe5952c-bf3c-400d-a654-6fe2eb79ca44",
                provider: this,
                filePath: "/Files/Templates/Feeds/CustomFeedTemplate.cshtml",
                fileStreamProvider: () => GetFileStreamFromEmbeddedResource("CustomFeedTemplate.cshtml"),
                overwrite: false
            );

            // FileUpdate: Overwrite an existing file
            yield return new FileUpdate(
                id: "27c24328-285b-4cae-b62b-23130b6fcde5",
                provider: this,
                filePath: "/Files/Templates/Feeds/CustomFeedTemplate.cshtml",
                fileStreamProvider: () => GetFileStreamFromEmbeddedResource("CustomFeedTemplate.cshtml"),
                overwrite: true
            );
        }

        private Stream GetFileStreamFromEmbeddedResource(string resourceName)
        {
            string resourceFullName = $"CustomAssembly.{resourceName}";
            var assembly = Assembly.GetAssembly(this.GetType());
            var stream = assembly?.GetManifestResourceStream(resourceName);

            if (stream is null)
                throw new FileNotFoundException($"Embedded resource '{resourceFullName}' not found.");

            return stream;
        }
    }
}
SettingUpdate

Represents an update that sets the value of a system configuration setting.

using System.Reflection;

namespace Dynamicweb.Updates.Examples
{
    /// <summary>
    /// Example UpdateProvider demonstrating usage of SqlUpdate, SettingUpdate, MethodUpdate, and FileUpdate.
    /// </summary>
    public class SqlUpdateSampleProvider : UpdateProvider
    {
        public override IEnumerable<Update> GetUpdates()
        {
            // SQL Update: Add a column to a table if it does not exist
            yield return SqlUpdate.AddColumn(
                id: "d50467a2-0e9b-4c70-a490-7ab4af88851b",
                provider: this,
                tableName: "MyCustomTable",
                columnName: "MyCustomColumn",
                columnDefinition: "NVARCHAR(50) NULL"
            );

            // SettingUpdate: Set a configuration value, only if it does not already exist
            yield return new SettingUpdate(
                id: "99fd48e3-f364-4108-bb19-6355e8b31896",
                provider: this,
                name: "/Globalsettings/System/Url/HighVolumeProductUrls/Enable",
                value: "True"
            );

            // SettingUpdate: Overwrite a configuration value even if it exists
            yield return new SettingUpdate(
                id: "89c68710-c2c1-4e02-8ea5-f712adeea24f",
                provider: this,
                name: "/Globalsettings/System/Url/HighVolumeProductUrls/Enable",
                value: "True",
                overwrite: true
            );

            // MethodUpdate: Execute custom logic during update
            yield return new MethodUpdate(
                id: "30c561dd-5509-4636-b81a-146be8a51e40",
                provider: this,
                method: context =>
                {
                    // Custom logic here
                    Console.WriteLine("Custom method executed as part of update.");
                }
            );

            // FileUpdate: Write a file to disk, only if it does not already exist
            yield return new FileUpdate(
                id: "efe5952c-bf3c-400d-a654-6fe2eb79ca44",
                provider: this,
                filePath: "/Files/Templates/Feeds/CustomFeedTemplate.cshtml",
                fileStreamProvider: () => GetFileStreamFromEmbeddedResource("CustomFeedTemplate.cshtml"),
                overwrite: false
            );

            // FileUpdate: Overwrite an existing file
            yield return new FileUpdate(
                id: "27c24328-285b-4cae-b62b-23130b6fcde5",
                provider: this,
                filePath: "/Files/Templates/Feeds/CustomFeedTemplate.cshtml",
                fileStreamProvider: () => GetFileStreamFromEmbeddedResource("CustomFeedTemplate.cshtml"),
                overwrite: true
            );
        }

        private Stream GetFileStreamFromEmbeddedResource(string resourceName)
        {
            string resourceFullName = $"CustomAssembly.{resourceName}";
            var assembly = Assembly.GetAssembly(this.GetType());
            var stream = assembly?.GetManifestResourceStream(resourceName);

            if (stream is null)
                throw new FileNotFoundException($"Embedded resource '{resourceFullName}' not found.");

            return stream;
        }
    }
}
SqlUpdate

Represents an update which executes a given sql statement.

using System.Reflection;

namespace Dynamicweb.Updates.Examples
{
    /// <summary>
    /// Example UpdateProvider demonstrating usage of SqlUpdate, SettingUpdate, MethodUpdate, and FileUpdate.
    /// </summary>
    public class SqlUpdateSampleProvider : UpdateProvider
    {
        public override IEnumerable<Update> GetUpdates()
        {
            // SQL Update: Add a column to a table if it does not exist
            yield return SqlUpdate.AddColumn(
                id: "d50467a2-0e9b-4c70-a490-7ab4af88851b",
                provider: this,
                tableName: "MyCustomTable",
                columnName: "MyCustomColumn",
                columnDefinition: "NVARCHAR(50) NULL"
            );

            // SettingUpdate: Set a configuration value, only if it does not already exist
            yield return new SettingUpdate(
                id: "99fd48e3-f364-4108-bb19-6355e8b31896",
                provider: this,
                name: "/Globalsettings/System/Url/HighVolumeProductUrls/Enable",
                value: "True"
            );

            // SettingUpdate: Overwrite a configuration value even if it exists
            yield return new SettingUpdate(
                id: "89c68710-c2c1-4e02-8ea5-f712adeea24f",
                provider: this,
                name: "/Globalsettings/System/Url/HighVolumeProductUrls/Enable",
                value: "True",
                overwrite: true
            );

            // MethodUpdate: Execute custom logic during update
            yield return new MethodUpdate(
                id: "30c561dd-5509-4636-b81a-146be8a51e40",
                provider: this,
                method: context =>
                {
                    // Custom logic here
                    Console.WriteLine("Custom method executed as part of update.");
                }
            );

            // FileUpdate: Write a file to disk, only if it does not already exist
            yield return new FileUpdate(
                id: "efe5952c-bf3c-400d-a654-6fe2eb79ca44",
                provider: this,
                filePath: "/Files/Templates/Feeds/CustomFeedTemplate.cshtml",
                fileStreamProvider: () => GetFileStreamFromEmbeddedResource("CustomFeedTemplate.cshtml"),
                overwrite: false
            );

            // FileUpdate: Overwrite an existing file
            yield return new FileUpdate(
                id: "27c24328-285b-4cae-b62b-23130b6fcde5",
                provider: this,
                filePath: "/Files/Templates/Feeds/CustomFeedTemplate.cshtml",
                fileStreamProvider: () => GetFileStreamFromEmbeddedResource("CustomFeedTemplate.cshtml"),
                overwrite: true
            );
        }

        private Stream GetFileStreamFromEmbeddedResource(string resourceName)
        {
            string resourceFullName = $"CustomAssembly.{resourceName}";
            var assembly = Assembly.GetAssembly(this.GetType());
            var stream = assembly?.GetManifestResourceStream(resourceName);

            if (stream is null)
                throw new FileNotFoundException($"Embedded resource '{resourceFullName}' not found.");

            return stream;
        }
    }
}
Update

Base class for updates

UpdateContext

Provides context information for updates.

UpdateManager

Handles updates by calling instances of UpdateProvider.

UpdateProvider

Represents a provider of update packages.

Structs

UpdateKey
To top