예제 #1
0
        public void CreateNewPrj(string _prjFullPath)
        {
            m_PrjInfo = new CPrjInfo {
                PrjPath            = _prjFullPath,
                WorkspacePath      = Path.GetDirectoryName(_prjFullPath),
                WorkspaceName      = Path.GetFileNameWithoutExtension(_prjFullPath),
                DataSourceFilePath = Path.GetDirectoryName(_prjFullPath),
                DataSourceName     = Path.GetFileNameWithoutExtension(_prjFullPath)
            };
            m_connectionInfo.Version = WorkspaceVersion.UGC60;
            m_connectionInfo.Type    = WorkspaceType.SMWU;
            m_connectionInfo.Server  = $"{m_PrjInfo.WorkspacePath}\\{m_PrjInfo.WorkspaceName}.smwu";
            m_connectionInfo.Name    = m_PrjInfo.WorkspaceName;
            m_workspace.Create(m_connectionInfo);

            DatasourceConnectionInfo datasourceConInfo = new DatasourceConnectionInfo();

            datasourceConInfo.Server = $"{m_PrjInfo.DataSourceFilePath}\\{m_PrjInfo.DataSourceName}.udd";
            datasourceConInfo.Alias  = m_PrjInfo.DataSourceName;
            m_workspace.Datasources.CloseAll();
            if (System.IO.File.Exists(m_PrjInfo.DataSourceName))
            {
                m_datasource = m_workspace.Datasources.Open(datasourceConInfo);
            }
            else
            {
                m_datasource = m_workspace.Datasources.Create(datasourceConInfo);
            }
            UCEarthGlobal.m_MainSceneControl.Scene.Workspace = m_workspace;
            SaveAsPrj(_prjFullPath);
        }
예제 #2
0
        public void LoadPrj(string _prjFilePath)
        {
            m_PrjInfo = new CPrjInfo();
            m_workspace.Save();
            //主动读取配置文件
            System.Environment.CurrentDirectory = System.Windows.Forms.Application.StartupPath;
            string cfgPath = _prjFilePath;

            //反序列化
            try
            {
                //用于序列化和反序列化的对象
                IFormatter serializer = new BinaryFormatter();
                FileStream loadFile   = new FileStream(cfgPath, FileMode.OpenOrCreate, FileAccess.Read);
                CPrjInfo   prjInfo    = serializer.Deserialize(loadFile) as CPrjInfo;
                //值拷贝
                foreach (PropertyInfo proInfo in prjInfo.GetType().GetProperties())
                {
                    proInfo.SetValue(m_PrjInfo, proInfo.GetValue(prjInfo));
                }
            }
            catch (Exception e)
            {
            }
            m_connectionInfo.Version = WorkspaceVersion.UGC60;
            m_connectionInfo.Type    = WorkspaceType.SMWU;
            m_connectionInfo.Server  = $"{m_PrjInfo.WorkspacePath}\\{m_PrjInfo.WorkspaceName}.smwu";
            m_connectionInfo.Name    = m_PrjInfo.WorkspaceName;
            m_workspace.Create(m_connectionInfo);
            DatasourceConnectionInfo datasourceConInfo = new DatasourceConnectionInfo();

            datasourceConInfo.Server = $"{m_PrjInfo.DataSourceFilePath}\\{m_PrjInfo.DataSourceName}.udd";
            datasourceConInfo.Alias  = m_PrjInfo.DataSourceName;
            m_workspace.Datasources.CloseAll();
            if (System.IO.File.Exists(m_PrjInfo.DataSourceName))
            {
                m_datasource = m_workspace.Datasources.Open(datasourceConInfo);
            }
            else
            {
                m_datasource = m_workspace.Datasources.Create(datasourceConInfo);
            }
            UCEarthGlobal.m_MainSceneControl.Scene.Workspace = m_workspace;
        }