示例#1
0
        private static void Commond_ConfigPathSet()
        {
            PathRecorder tempPath = s_pathController.SetPath(true);

            if (tempPath != null)
            {
                s_path = tempPath;
            }
        }
示例#2
0
        private static void Commond_TargetPathSet()
        {
            PathRecorder tempPath = s_pathController.SetPath(false);

            if (tempPath != null)
            {
                s_path = tempPath;
            }
        }
示例#3
0
 static void Main(string[] args)
 {
     Console.Title = "ExcelChanger";
     //获得配置表和Json路径
     s_pathController = new PathController();
     s_path           = s_pathController.GetXMLPath();
     Console.WriteLine("input commond , use {0} to get more", _HELP);
     while (true)
     {
         string userInput = Console.ReadLine().ToLower();
         CommondMethod(userInput);
         if (s_isFinished)
         {
             break;
         }
         if (s_willExit)
         {
             return;
         }
     }
     Console.WriteLine("press any key to exit");
     Console.ReadKey();
 }
示例#4
0
        public PathRecorder SetPath(bool isConfigPath)
        {
            PathRecorder pathRecorder;
            string       tempPath;

            while (true)
            {
                tempPath = Console.ReadLine();
                if (new DirectoryInfo(tempPath).Exists)
                {
                    Console.WriteLine("Set {0} path: {1}",
                                      isConfigPath ? "config" : "target"
                                      , tempPath);
                    break;
                }
                else
                {
                    Console.WriteLine("wrong path,input again");
                    return(null);
                }
            }
            DirectoryInfo di = new DirectoryInfo(curPath);

            FileInfo[] files    = di.GetFiles(PATH_FILE_NAME);
            string     fullPath = string.Format("{0}/{1}", curPath, PATH_FILE_NAME);

            //存在XML文件时
            if (files != null && files.Length > 0)
            {
                FileStream    xmlFS;
                XmlSerializer xmlserializer = new XmlSerializer(typeof(PathRecorder));
                xmlFS          = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
                xmlFS.Position = 0;
                pathRecorder   = xmlserializer.Deserialize(xmlFS) as PathRecorder;
                if (isConfigPath)
                {
                    pathRecorder.ConfigPath = tempPath;
                }
                else
                {
                    pathRecorder.TargetPath = tempPath;
                }
                xmlFS.Close();
                xmlFS.Dispose();
                xmlFS = new FileStream(fullPath, FileMode.Create, FileAccess.Write);
                xmlserializer.Serialize(xmlFS, pathRecorder);
                xmlFS.Close();
                xmlFS.Dispose();
            }
            //不存在时
            else
            {
                FileStream    fs           = new FileStream(curPath + "/" + PATH_FILE_NAME, FileMode.Create, FileAccess.Write);
                XmlSerializer xmlSerialize = new XmlSerializer(typeof(PathRecorder));
                pathRecorder = new PathRecorder();
                if (isConfigPath)
                {
                    pathRecorder.ConfigPath = tempPath;
                }
                else
                {
                    pathRecorder.TargetPath = tempPath;
                }
                xmlSerialize.Serialize(fs, pathRecorder);
                fs.Close();
                fs.Dispose();
            }
            return(pathRecorder);
        }