Beispiel #1
0
 /// <summary>
 /// 加载工程
 /// </summary>
 /// <param name="fileName"></param>
 public static void LoadProject(string fileName)
 {
     if (!Path.IsPathRooted(fileName))
     {
         throw new ArgumentException("Path must be rooted!");
     }
     BeforeLoadProject();
     OnProjectLoading(fileName);
     try
     {
         currentProject = CommonProject.Load(fileName);
         if (currentProject == null)
         {
             return;
         }
     }
     catch (IOException ex)
     {
         return;
     }
     catch (UnauthorizedAccessException ex)
     {
         return;
     }
     OnProjectLoaded(new ProjectEventArgs(currentProject));
 }
Beispiel #2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            var btn = sender as System.Windows.Controls.Button;

            if (btn.Content.ToString() == "浏览")
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog();
                dialog.RootFolder = Environment.SpecialFolder.DesktopDirectory;
                dialog.ShowDialog();
                projPath.Text = dialog.SelectedPath;
            }
            else if (btn.Content.ToString() == "确定")
            {
                if (string.IsNullOrEmpty(projName.Text))
                {
                    System.Windows.MessageBox.Show("请输入工程的名字!");
                    return;
                }
                else
                {
                    //验证工程的名字是否合适
                    //MessageBox.Show("请输入工程的名字!");
                    //return;
                }
                if (string.IsNullOrEmpty(projPath.Text))
                {
                    System.Windows.MessageBox.Show("请输入工程保存的路径!");
                    return;
                }
                else
                {
                    if (!Directory.Exists(projPath.Text))
                    {
                        System.Windows.MessageBox.Show("输入的路径不正确,请重新输入!");
                        return;
                    }
                }
                //建立新工程,进入主界面
                IProject project = CommonProject.NewProject(projPath.Text + "\\" + projName.Text);

                ProjectService.CurrentProject = project;
                this.Close();
            }
            else
            {
                this.Close();
            }
        }
Beispiel #3
0
        /// <summary>
        /// 转换文件到Project对象
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static IProject ParseToProject(string fileName)
        {
            IProject project;

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(fileName);
            }
            XElement rootElement           = XElement.Load(fileName);
            IEnumerable <XElement> element = from el in rootElement.Elements() select el;
            string guid = element.Where(el => el.Name == "GuidID").First <XElement>().Value;

            project = new CommonProject(fileName, guid);
            ParseToProjectItem(rootElement, project);
            return(project);
        }