/// <summary>
        /// 记录
        /// </summary>
        /// <param name="path"></param>
        /// <param name="logDatasDto"></param>
        public void Write(string path, LogDatasDto logDatasDto)
        {
            FileStream   fs = new FileStream(path + @"\" + txtName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);

            sw.WriteLine(logDatasDto.Path + "&" + logDatasDto.ProjectName);//开始写入值
            //sw.Flush();
            sw.Close();
            sw.Dispose();
            fs.Close();
            fs.Dispose();
        }
 /// <summary>
 /// 创建记录
 /// </summary>
 /// <param name="logDatasDto"></param>
 /// <returns></returns>
 public bool CreateFile(LogDatasDto logDatasDto)
 {
     if (!string.IsNullOrEmpty(logDatasDto.Path) && !string.IsNullOrEmpty(logDatasDto.ProjectName))
     {
         //创建隐藏文件夹
         new CreateFolder().SetHiddenFolder(url);
         //创建txt文件并且写入数据
         Write(url, logDatasDto);
         flag = true;
     }
     return(flag);
 }
        /// <summary>
        /// 读取
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static LogDatasDto Read(string path)
        {
            LogDatasDto  dto = new LogDatasDto();
            StreamReader sr  = new StreamReader(path, Encoding.Default);
            String       line;

            if ((line = sr.ReadLine()) != null)
            {
                string[] array = Regex.Split(line, "&", RegexOptions.IgnoreCase);
                dto.Path        = array[0];
                dto.ProjectName = array[1];
            }
            return(dto);
        }
        /// <summary>
        /// 创建历史纪录
        /// </summary>
        /// <param name="path"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public LogDatasDto Checked(string path, string name)
        {
            LogDatasDto dto = new LogDatasDto();

            dto.Path        = path;
            dto.ProjectName = name;

            if (File.Exists(url + @"\" + txtName))
            {
                dto = Read(url + @"\" + txtName);
            }
            else
            {
                CreateFile(dto);
            }
            return(dto);
        }
예제 #5
0
        /// <summary>
        /// 排除文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FileChoose_Click(object sender, EventArgs e)
        {
            #region 记录文件路径

            LogDatasDto remeberUrl = new LogDatasDto();
            try {
                // 登录时 如果没有Data.bin文件就创建、有就打开
                FileStream      fs = new FileStream("dataUrl.bin", FileMode.OpenOrCreate);
                BinaryFormatter bf = new BinaryFormatter();
                //保存密码选中状态
                remeberUrl.ProjectName = cbbProjectName.Text.Trim();
                if (cbRemeber.Checked)
                {
                    remeberUrl.Path = textBoxEntityUrl.Text.Trim();
                }
                else
                {
                    remeberUrl.Path = "";
                }
                if (remeberUrls.ContainsKey(remeberUrl.ProjectName))
                {
                    //如果有清掉
                    remeberUrls.Remove(remeberUrl.ProjectName);
                }
                //添加用户信息到集合
                remeberUrls.Add(remeberUrl.ProjectName, remeberUrl);
                //写入文件
                bf.Serialize(fs, remeberUrls);
                //关闭
                fs.Close();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.ToString());
            }

            #endregion

            ProjectStr = cbbProjectName.Text;
            EntityStr  = textBoxEntityUrl.Text;
            if (remeberUrl.Path != EntityStr)
            {
                EntityStr = textBoxEntityUrl.Text;
            }
            var fileChoose = new ChooseFlieList(EntityStr, ProjectStr, this);
            fileChoose.ShowDialog(this);
        }