/// <summary>
        /// Génération du fichier de config à partir des fichiers de l'utilisateur
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="project">The project.</param>
        /// <param name="projectFolder">The project folder.</param>
        /// <param name="forceGeneration">if set to <c>true</c> [force generation].</param>
        /// <returns></returns>
        private string GenerateConfigurationFile(Layer layer, Project project, string projectFolder,
                                                 bool forceGeneration)
        {
            if (project == null)
            {
                return(null);
            }

            IShellHelper shell = ServiceLocator.Instance.GetService <IShellHelper>();

            // Vérification si le répertoire de config existe
            string configFolderPath = Path.Combine(projectFolder, ConfigFolderName);

            // On s'assure de son intègration dans la solution
            Directory.CreateDirectory(configFolderPath);
            ProjectItem folder = shell.AddFolderToProject(project.ProjectItems, ConfigFolderName);

            // Création des fichiers à personnaliser

            // D'abord le fichier correspondant au mode courant.
            ConfigurationMode mode            = new ConfigurationMode(project);
            string            currentFileName = CreateCustomConfigurationFile(mode.CurrentMode, configFolderPath, folder);
            // Puis le fichier commun
            string commonFileName = CreateCustomConfigurationFile("Common", configFolderPath, folder);

            if (forceGeneration || File.GetLastWriteTime(commonFileName) > _lastGenerationTime ||
                File.GetLastWriteTime(currentFileName) > _lastGenerationTime)
            {
                // Fichier généré
                string generatedFileName = CalculateApplicationConfigurationFileName(layer);
                if (generatedFileName == null)
                {
                    return(configFolderPath);
                }

                if (project != null && shell != null)
                {
                    // Création d'un fichier xml correspondant à la fusion du fichier commun et
                    // du fichier correspondant au contexte courant (debug, release...)

                    // Merge
                    XmlMerger   merger         = new XmlMerger();
                    XmlDocument customDocument = merger.MergeXml(currentFileName, commonFileName);

                    // Puis merge avec les config du modèle
                    XmlDocument resultDocument = MergeDeclaredConfigurations(customDocument, layer.Component);

                    // Sauvegarde
                    string generatedFilePath = Path.Combine(projectFolder, generatedFileName);
                    Directory.CreateDirectory(Path.GetDirectoryName(generatedFilePath));
                    shell.EnsureCheckout(generatedFilePath);
                    resultDocument.Save(generatedFilePath);
                    shell.AddFileToProject(project, generatedFilePath);
                }
            }
            return(configFolderPath);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SafeStreamWriter"/> class.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="append">if set to <c>true</c> [append].</param>
        /// <param name="encoding">The encoding.</param>
        public SafeStreamWriter(string path, bool append, Encoding encoding)
        {
            IShellHelper shell = ServiceLocator.Instance.GetService <IShellHelper>();

            if (shell != null)
            {
                shell.EnsureCheckout(path);
            }
            _writer = new StreamWriter(path, append, encoding);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SafeStreamWriter"/> class.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        public SafeStreamWriter(string fileName)
        {
            IShellHelper shell = ServiceLocator.Instance.GetService <IShellHelper>();

            if (shell != null)
            {
                shell.EnsureCheckout(fileName);
            }
            _writer = new StreamWriter(fileName);
        }