Example #1
0
 private string CreateCode()
 {
     var code = new Random().Next(1, 999999).ToString();
     code = code.PadLeft(6, '0');
     return code;
 }
Example #2
0
        /// <summary>
        /// Creates a copy of the given file, inserting a number between the
        /// filename and extension
        /// </summary>
        /// <param name="file">The file to create a copy of</param>
        /// <returns>The full name of the copy</returns>
        private static string CreateBackup(FileInfo file)
        {
            string theDirName = file.DirectoryName;
            string theFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(file.Name);
            string theExt = file.Extension;
            string theRandom = new Random().Next().ToString();
            theRandom = theRandom.PadLeft(5, '0');
            theRandom = theRandom.Substring(theRandom.Length - 5);

            string theBackupName = theDirName + System.IO.Path.DirectorySeparatorChar
                + theFileNameNoExt + "." + theRandom + theExt;

            File.Copy(file.FullName, theBackupName, true);

            return theBackupName;
        }
Example #3
0
        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            if (string.IsNullOrEmpty(this.logginName))
            {
                this.logginName = "DefaultZhu";
            }

            string ret = string.Empty;
            ret = this.logginName;
            if (ret.Length <= 10)
            {
                ret = ret.PadLeft(10, '6');
            }
            else
            {
                ret = ret.Substring(ret.Length - 10, 10);
            }

            string timeStr = DateTime.Now.ToString("yyMMddHHmmssfff");

            string randomCodeStr = new Random().Next(0, 99999).ToString();

            if (randomCodeStr.Length < 5)
            {
                randomCodeStr = randomCodeStr.PadLeft(5, '0');
            }

            this.trackId = ret + timeStr + randomCodeStr;
        }