Пример #1
0
        /// <summary>
        /// Deserializes the model from a file.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        public void Open(string fileName, ICancelProgressHandler progress)
        {
            var    dic    = Path.GetDirectoryName(fileName);
            var    loaded = true;
            string pname  = GetProviderName(fileName);

            SetCurrentProjectDirectory(dic);

            foreach (var provider in OpenProjectFileProviders)
            {
                if (String.Equals(provider.ProviderName, pname, StringComparison.OrdinalIgnoreCase))
                {
                    var op = provider as IOpenProjectFileProvider;
                    CurrentProject = op.Open(fileName);
                    CurrentProject.AbsolutePathToProjectFile = Path.GetDirectoryName(fileName);
                    string prj_dic = Path.GetDirectoryName(fileName);

                    //repaire path
                    if (prj_dic.ToLower() != CurrentProject.AbsolutePathToProjectFile.ToLower())
                    {
                        CurrentProject.AbsolutePathToProjectFile = prj_dic;
                    }

                    CurrentProject.FullProjectFileName = fileName;

                    string controlfile = Path.Combine(CurrentProject.FullModelWorkDirectory, CurrentProject.RelativeControlFileName);
                    string ext         = Path.GetExtension(controlfile);

                    if (!File.Exists(controlfile))
                    {
                        RaiseOpenFailed("Control file dosen't exsit!");
                        return;
                    }
                    CurrentProject.Initialize();
                    foreach (var mod in this.SurpportedModelLoaders)
                    {
                        if (mod.Extension.ToLower() == ext.ToLower())
                        {
                            loaded = mod.Load(CurrentProject, progress);
                            break;
                        }
                    }
                    break;
                }
            }
            if (loaded)
            {
                AddFileToRecentFiles(fileName);
            }
            RaiseProjectOpened(loaded);
        }