コード例 #1
0
        /// <summary>
        /// Serializes and saves the provided data commands to file ready for execution.
        /// </summary>
        /// <param name="commandsDirectoryPath">The physical path to the schema commands directory.</param>
        /// <param name="commands">The data schema command to serialize and save.</param>
        /// <param name="groupName">The name of the group/module that the commands apply to. (This is used in the file name.)</param>
        /// <param name="version">The version of data schema that the command corresponds with. (This is used in the file name.)</param>
        public void SaveCommands(string commandsDirectoryPath, DataSchemaCommandCollection commands, string groupName, Version version)
        {
            string commandFile = CreateCommandFilePath(commandsDirectoryPath, groupName, version);

            if (!Directory.Exists(Path.GetDirectoryName(commandFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(commandFile));
            }

            // Define the extra types that might be required during serialization
            Type[] extraTypes = new Type[]
            {
                typeof(RenameTypeCommand),
                typeof(RenamePropertyCommand)
            };

            XmlSerializer serializer = new XmlSerializer(commands.GetType(), extraTypes);

            using (StreamWriter writer = File.CreateText(commandFile))
            {
                serializer.Serialize(writer, commands);

                writer.Close();
            }
        }
コード例 #2
0
        /// <summary>
        /// Checks whether the legacy version matches the current application version, therefore indicating that data schema.
        /// </summary>
        /// <returns>A boolean flag indicating whether the schema is up to date with the current application.</returns>
        public bool CheckIsUpToDate()
        {
            // Load the commands
            DataSchemaCommandCollection foundCommands = GetCommands();


            // If no relevant commands were found then the data structure must be up to date
            return(foundCommands.Count == 0);
        }
コード例 #3
0
        /// <summary>
        /// Retrieves the schema commands that are applicable to legacy data (between legacy version and current application version).
        /// </summary>
        /// <returns>A collection of the commands that need to be applied the legacy data.</returns>
        public DataSchemaCommandCollection GetCommands()
        {
            DataSchemaCommandCollection collection = new DataSchemaCommandCollection();

            string  schemaCommandDirectoryPath = SchemaCommandDirectoryPath;
            Version legacyVersion  = LegacyVersion;
            Version currentVersion = ApplicationVersion;

            if (Directory.Exists(schemaCommandDirectoryPath))
            {
                foreach (string file in Directory.GetFiles(schemaCommandDirectoryPath))
                {
                    Version commandVersion = ExtractVersionFromFileName(file);

                    // If the version specified in the command file is greater than the legacy version and less than or equal to the current version (inclusive)
                    if (commandVersion > legacyVersion &&
                        commandVersion <= currentVersion)
                    {
                        // Define the extra types that might be required during serialization
                        Type[] extraTypes = new Type[]
                        {
                            typeof(RenameTypeCommand),
                            typeof(RenamePropertyCommand)
                        };

                        XmlSerializer serializer = new XmlSerializer(typeof(DataSchemaCommandCollection), extraTypes);
                        using (StreamReader reader = new StreamReader(File.OpenRead(file)))
                        {
                            DataSchemaCommandCollection c = (DataSchemaCommandCollection)serializer.Deserialize(reader);

                            collection.AddRange(c);

                            reader.Close();
                        }
                    }
                }
            }

            return(collection);
        }
コード例 #4
0
        /// <summary>
        /// Serializes and saves the provided data commands to file ready for execution.
        /// </summary>
        /// <param name="commands">The data schema command to serialize and save.</param>
        /// <param name="groupName">The name of the group/module that the commands apply to. (This is used in the file name.)</param>
        /// <param name="version">The version of data schema that the command corresponds with. (This is used in the file name.)</param>
        public void SaveCommands(DataSchemaCommandCollection commands, string groupName, Version version)
        {
            string path = Configuration.Config.Application.PhysicalApplicationPath + Path.DirectorySeparatorChar + SchemaDirectory;

            SaveCommands(path, commands, groupName, version);
        }
コード例 #5
0
 /// <summary>
 /// Executes the requires commands from those provided. Changes already applied once are not
 /// re-applied.
 /// </summary>
 /// <param name="commands">The commands to apply.</param>
 public void ApplyCommands(DataSchemaCommandCollection commands)
 {
     throw new NotImplementedException();
 }