Ejemplo n.º 1
0
 public void WriteToFile(IProcessInstance proc, FinalFile file)
 {
     if (proc.CurrentScope.Exists(proc.DefaultWriter))
     {
         string             writer = proc.CurrentScope.GetVariable(proc.DefaultWriter).ValueString;
         o2Mate.LocaleGroup lg     = new LocaleGroup();
         string             groupName;
         string             title;
         if (lg.ExtractGroupAndName(this.localeName, out groupName, out title))
         {
             ILocaleSet set      = lg.Get(groupName) as ILocaleSet;
             string     language = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
             try
             {
                 // lève une exception si l'élement n'existe pas
                 FinalFile.WriteToFile(ref writer, set.Get(title, language), this.enc);
             }
             catch
             {
                 FinalFile.WriteToFile(ref writer, this.localeName, this.enc);
             }
         }
         proc.CurrentScope.GetVariable(proc.DefaultWriter).Value = writer;
     }
 }
        /// <summary>
        /// This function reads a file and rewrites it with reported values
        /// </summary>
        /// <param name="fileName">file to rewrite</param>
        /// <param name="extension">new file extension (ex: .cs)</param>
        /// <param name="progName">Dll or Exe name</param>
        /// <param name="language">CultureInfo name</param>
        public void UpdateFile(string fileName, string extension, string progName, string language)
        {
            if (!this.versions.Exists(progName))
            {
                this.versions.Create(progName);
            }
            ILocaleSet set = this.versions.Get(progName);

            using (FileStream fsR = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (StreamReader sr = new StreamReader(fsR))
                {
                    using (FileStream fsW = new FileStream(fileName + extension, FileMode.Create, FileAccess.Write, FileShare.Write))
                    {
                        using (StreamWriter sw = new StreamWriter(fsW))
                        {
                            Regex  r           = new Regex(@"(\$<([^>]+)>)", RegexOptions.Multiline);
                            string dataToWrite = r.Replace(sr.ReadToEnd(), new MatchEvaluator(a => {
                                string name = a.Groups[2].Value;
                                if (set.ExistsOne(name, language))
                                {
                                    return(set.Get(name, language).Replace(Environment.NewLine, "\\r\\n"));
                                }
                                else
                                {
                                    return(String.Empty);
                                }
                            }));
                            sw.Write(dataToWrite);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// This function updates version values associated with the program name
        /// </summary>
        public void Commit()
        {
            if (!this.versions.Exists(this.ProgramName))
            {
                this.versions.Create(this.ProgramName);
            }
            ILocaleSet set = this.versions.Get(this.ProgramName);

            this.ComputeProductVersion();
            this.ComputeFileVersion();
            this.ComputeAssemblyVersion();

            foreach (string key in this.nv.Keys)
            {
                if (set.Exists(key))
                {
                    Console.WriteLine("update " + this.programName + " :" + key + "," + this.nv[key]);
                    set.Modify(key, this.Language, this.nv[key]);
                }
                else
                {
                    Console.WriteLine("add " + this.programName + " :" + key + "," + this.nv[key]);
                    set.Add(key, this.Language, this.nv[key]);
                }
            }
        }
        /// <summary>
        /// Calcule la version du produit
        /// (voir le fichier numérotation.txt pour les détails)
        ///
        /// </summary>
        /// <returns>le numéro de version</returns>
        private IVersion GetProductVersion()
        {
            // la version de la production du
            // logiciel est stockée dans
            // le répertoire où je stocke les
            // versions actuelles des fichiers .DLL et .EXE
            ILocaleSet set = this.versions.Get("Versioning");

            if (set.ExistsOne("ProductVersion", ""))
            {
                uint  majorVersion = 0, minorVersion = 0;
                Regex r = new Regex(@"^([0-9]+)\.([0-9]+)");
                Match m = r.Match(set.Get("ProductVersion", ""));
                if (m.Success)
                {
                    majorVersion = Convert.ToUInt32(m.Groups[1].Value);
                    minorVersion = Convert.ToUInt32(m.Groups[2].Value);
                }
                return(new Version(majorVersion, minorVersion, 0, 0));
            }
            else
            {
                // version par défaut
                return(new Version(global::o2Mate.Properties.Settings.Default.DefaultMajorVersion, global::o2Mate.Properties.Settings.Default.DefaultMinorVersion, 0, 0));
            }
        }
        /// <summary>
        /// Gets the software version
        /// </summary>
        /// <returns>an IVersion interface</returns>
        public IVersion GetSoftwareVersion()
        {
            if (!this.versions.Exists(CodeCommander.Documents.ProgramName))
            {
                this.versions.Create(CodeCommander.Documents.ProgramName);
            }
            ILocaleSet set = this.versions.Get(CodeCommander.Documents.ProgramName);

            return(new Version(set.Get("ProductVersion", System.Globalization.CultureInfo.InvariantCulture.Name)));
        }
        /// <summary>
        /// Computes the assembly version
        /// The file version are the number of modified files and a number of compilation execution
        /// and the next numbers are the number of files and the number of lines in all files
        /// </summary>
        public void ComputeAssemblyVersion()
        {
            IVersion files = this.CountSource();

            if (!this.versions.Exists(this.ProgramName))
            {
                this.versions.Create(this.ProgramName);
            }
            ILocaleSet set     = this.versions.Get(this.ProgramName);
            IVersion   current = null;

            if (set.ExistsOne("FileVersion", this.Language))
            {
                current = new Version(set.Get("FileVersion", this.Language));
            }
            else
            {
                current = new Version(1, 0, 0, 0);
            }
            IVersion product = this.TestModifiedFiles(current);
            IVersion result  = new Version(product.Major, product.Minor, files.Major, files.Minor);

            this.nv.Add("AssemblyVersion", result.ToString());
        }