Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private AppLocalConfig ReadSeedConfig()
        {
            AppLocalConfig r = new AppLocalConfig()
            {
                IsRemote = true,
                LocalConfigDirectoryPath = "~/Config",
                Version = 0
            };

            try
            {
                string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;                                                              //获取根目录路径
                r = Newtonsoft.Json.JsonConvert.DeserializeObject <AppLocalConfig>(File.ReadAllText(baseDirectory + "/appconfig.config")); //读取根目录下的配置文件
                if (r.IsVirtualPath)                                                                                                       //web系统相对部署根目录获取绝对路径
                {
                    r.LocalConfigDirectoryPath = baseDirectory + r.LocalConfigDirectoryPath.Replace("~/", "");
                }
            }
            catch (Exception ex)
            {
                r = new AppLocalConfig()
                {
                };
            }

            return(r);
        }
Exemplo n.º 2
0
        private void ReReadRemote(AppLocalConfig seedConfig)
        {
            AppConfig localconfig = null;

            //远程拉取配置文件
            Console.WriteLine("远程拉取配置文件:" + seedConfig.SeedServerUrl);
            var remoteConfig = GetRemote(seedConfig.SeedServerUrl, seedConfig.AppConfigSolutionID, seedConfig.SecurityToken, seedConfig.Version.HasValue ? seedConfig.Version.Value : 0, seedConfig.AppID);

            //判断配置文件的新鲜程度
            if (remoteConfig != null)        //无法获取远程配置时不更新本地
            {
                if (seedConfig.Version == 0) //永远最新
                {
                    File.Delete(seedConfig.LocalConfigDirectoryPath + "/" + seedConfig.AppConfigFileName);
                    //固化指定目录下制定的文件
                    File.AppendAllText(seedConfig.LocalConfigDirectoryPath + "/" + seedConfig.AppConfigFileName, Newtonsoft.Json.JsonConvert.SerializeObject(remoteConfig));
                }
                Console.WriteLine("准备写入");
                if ((seedConfig.Version > 0) && (localconfig == null))//本地没有配置文件并且不是永远更新
                {
                    Console.WriteLine("写入:" + seedConfig.LocalConfigDirectoryPath);
                    File.AppendAllText(seedConfig.LocalConfigDirectoryPath + "/" + seedConfig.AppConfigFileName, Newtonsoft.Json.JsonConvert.SerializeObject(remoteConfig));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 远程获取程序配置
        /// </summary>
        /// <param name="seedConfig"></param>
        private void ReadRemote(AppLocalConfig seedConfig)
        {
            AppConfig localconfig = null;

            //判断配置文件是否已经存在
            if (File.Exists(seedConfig.LocalConfigDirectoryPath + "/app.json"))
            {
                localconfig = ReadLocal(seedConfig);
            }

            //远程拉取配置文件
            var remoteConfig = GetRemote(seedConfig.SeedServerUrl, seedConfig.AppConfigID, seedConfig.SecurityToken);

            //判断配置文件的新鲜程度
            if (remoteConfig != null)        //无法获取远程配置时不更新本地
            {
                if (seedConfig.Version == 0) //永远最新
                {
                    File.Delete(seedConfig.LocalConfigDirectoryPath + "/" + seedConfig.AppConfigFileName);
                    //固化指定目录下制定的文件
                    File.AppendAllText(seedConfig.LocalConfigDirectoryPath + "/" + seedConfig.AppConfigFileName, Newtonsoft.Json.JsonConvert.SerializeObject(remoteConfig));
                }
                if ((seedConfig.Version > 0) && (localconfig == null))//本地没有配置文件并且不是永远更新
                {
                    File.AppendAllText(seedConfig.LocalConfigDirectoryPath + "/" + seedConfig.AppConfigFileName, Newtonsoft.Json.JsonConvert.SerializeObject(remoteConfig));
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private AppLocalConfig ReadSeedConfig()
        {
            AppLocalConfig r = new AppLocalConfig()
            {
                Remote = true,
                LocalConfigDirectoryPath = "~/Config",
                Version = 0
            };

            try
            {
                string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;                                                    //获取根目录路径
                r = JsonHelper.Deserialize <AppLocalConfig>(File.ReadAllText(baseDirectory + "/appconfig.json", Encoding.UTF8)); //读取根目录下的配置文件
                if (r.VirtualPath)                                                                                               //web系统相对部署根目录获取绝对路径
                {
                    r.LocalConfigDirectoryPath = baseDirectory + r.LocalConfigDirectoryPath.Replace("~/", "");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("无法读取根目录配置:" + ex.Message);
            }

            return(r);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 开始导出
        /// </summary>
        /// <param name="localConfig"></param>
        /// <param name="progressCallback"></param>
        /// <param name="cancellationToken"></param>
        private void StartExport(AppLocalConfig localConfig, Action <int> progressCallback, CancellationToken cancellationToken)
        {
            using (var log = new RuntimeLog())
            {
                var config = new ExportConfig();
                config.InputFilePath = localConfig.InputFilePath;
                config.TargetPath    = localConfig.LastTargetPath;
                config.Features      = localConfig.Features.ToDictionary(x => x, x => true);
                config.Trace         = log.Log;
                config.FontPath      = new List <string>
                {
                    App.GetFontFolderPath()
                };

                #region Add Plugin - CreatePropDb
                {
                    var cliPath = Path.Combine(
                        App.GetHomePath(),
                        @"Tools",
                        @"CreatePropDb",
                        @"CreatePropDbCLI.exe");
                    if (File.Exists(cliPath))
                    {
                        config.Addins.Add(new ExportPlugin(
                                              FeatureType.GenerateModelsDb,
                                              cliPath,
                                              new[] { @"-i", config.TargetPath }
                                              ));
                    }
                }
                #endregion

                Exporter.ExportToSvf(config, x => progressCallback?.Invoke((int)x), cancellationToken);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 开始导出
        /// </summary>
        /// <param name="uidoc"></param>
        /// <param name="view"></param>
        /// <param name="localConfig"></param>
        /// <param name="exportType"></param>
        /// <param name="outputStream"></param>
        /// <param name="features"></param>
        /// <param name="useShareTexture"></param>
        /// <param name="progressCallback"></param>
        /// <param name="cancellationToken"></param>
        private void StartExport(UIDocument uidoc, View3D view, AppLocalConfig localConfig, ExportType exportType, Stream outputStream, Dictionary <FeatureType, bool> features, bool useShareTexture, Action <int> progressCallback, CancellationToken cancellationToken)
        {
            using (var log = new RuntimeLog())
            {
                var config = new ExportConfig();
                config.TargetPath      = localConfig.LastTargetPath;
                config.ExportType      = exportType;
                config.UseShareTexture = useShareTexture;
                config.OutputStream    = outputStream;
                config.Features        = features ?? new Dictionary <FeatureType, bool>();
                config.Trace           = log.Log;
                config.ElementIds      = (features?.FirstOrDefault(x => x.Key == FeatureType.OnlySelected).Value ?? false)
                    ? _ElementIds
                    : null;
                config.LevelOfDetail = localConfig.LevelOfDetail;

                #region Add Plugin - CreatePropDb
                {
                    var cliPath = Path.Combine(
                        App.GetHomePath(),
                        @"Tools",
                        @"CreatePropDb",
                        @"CreatePropDbCLI.exe");

                    if (File.Exists(cliPath))
                    {
                        config.Addins.Add(new ExportPlugin(
                                              FeatureType.GenerateModelsDb,
                                              cliPath,
                                              new[] { @"-i", config.TargetPath }
                                              ));
                    }
                }
                #endregion

                #region Add Plugin - CreateThumbnail
                {
                    var cliPath = Path.Combine(
                        App.GetHomePath(),
                        @"Tools",
                        @"CreateThumbnail",
                        @"CreateThumbnailCLI.exe");

                    if (File.Exists(cliPath))
                    {
                        config.Addins.Add(new ExportPlugin(
                                              FeatureType.GenerateThumbnail,
                                              cliPath,
                                              new[] { @"-i", config.TargetPath }
                                              ));
                    }
                }
                #endregion

                Exporter.ExportToSvf(uidoc, view, config, x => progressCallback?.Invoke((int)x), cancellationToken);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取AppId
        /// </summary>
        /// <returns></returns>
        public static FunctionOpenResult <AppLocalConfig> GetAppLocalConfig()
        {
            var            r      = new FunctionOpenResult <AppLocalConfig>();
            AppLocalConfig config = ProgramDistributedConfig.Instance.GetSeedConfig();

            if (config != null)
            {
                r.Data = config;
            }
            return(r);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取AppId
        /// </summary>
        /// <returns></returns>
        internal static AppLocalConfig GetAppLocalConfig()
        {
            var            r      = new AppLocalConfig();
            AppLocalConfig config = ProgramDistributedConfig.Instance.GetSeedConfig();

            if (config != null)
            {
                r = config;
            }
            return(r);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 开始导出
        /// </summary>
        /// <param name="localConfig"></param>
        /// <param name="exportType"></param>
        /// <param name="outputStream"></param>
        /// <param name="features"></param>
        /// <param name="useShareTexture"></param>
        /// <param name="progressCallback"></param>
        /// <param name="cancellationToken"></param>
        private void StartExport(AppLocalConfig localConfig, ExportType exportType, Stream outputStream, Dictionary <FeatureType, bool> features, bool useShareTexture, Action <int> progressCallback, CancellationToken cancellationToken)
        {
            using (var log = new RuntimeLog())
            {
                var config = new ExportConfig();
                config.TargetPath   = localConfig.LastTargetPath;
                config.ExportType   = exportType;
                config.OutputStream = outputStream;
                config.Features     = features?.Keys.ToList() ?? new List <FeatureType>();
                config.Trace        = log.Log;

                #region Add Plugin - CreatePropDb
                {
                    var cliPath = Path.Combine(
                        App.GetHomePath(),
                        @"Tools",
                        @"CreatePropDb",
                        @"CreatePropDbCLI.exe");
                    if (File.Exists(cliPath))
                    {
                        config.Addins.Add(new ExportPlugin(
                                              FeatureType.GenerateModelsDb,
                                              cliPath,
                                              new[] { @"-i", config.TargetPath }
                                              ));
                    }
                }
                #endregion

                #region Add Plugin - CreateThumbnail
                {
                    var cliPath = Path.Combine(
                        App.GetHomePath(),
                        @"Tools",
                        @"CreateThumbnail",
                        @"CreateThumbnailCLI.exe");
                    if (File.Exists(cliPath))
                    {
                        config.Addins.Add(new ExportPlugin(
                                              FeatureType.GenerateThumbnail,
                                              cliPath,
                                              new[] { @"-i", config.TargetPath }
                                              ));
                    }
                }
                #endregion

                Exporter.ExportToSvf(config, x => progressCallback?.Invoke((int)x), cancellationToken);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// 读取程序的配置
 /// </summary>
 /// <param name="seedConfig"></param>
 /// <returns></returns>
 private AppConfig ReadLocal(AppLocalConfig seedConfig)
 {
     if (string.IsNullOrEmpty(seedConfig.LocalConfigDirectoryPath)) //如果没有默认路径和默认文件配置不读取
     {
         return(null);                                              //构造函数里默认数值
     }
     try
     {
         var temp = Newtonsoft.Json.JsonConvert.DeserializeObject <AppConfig>(File.ReadAllText(seedConfig.LocalConfigDirectoryPath + "/" + seedConfig.AppConfigFileName));
         return(temp);
     }
     catch (Exception ex)//预期异常:格式错误,错误内容
     {
     }
     return(null);
 }
Exemplo n.º 11
0
 /// <summary>
 /// 读取程序的配置
 /// </summary>
 /// <param name="seedConfig"></param>
 /// <returns></returns>
 private AppConfig ReadLocal(AppLocalConfig seedConfig)
 {
     if (string.IsNullOrEmpty(seedConfig.LocalConfigDirectoryPath)) //如果没有默认路径和默认文件配置不读取
     {
         return(null);                                              //构造函数里默认数值
     }
     try
     {
         var temp = JsonHelper.Deserialize <AppConfig>(File.ReadAllText(seedConfig.LocalConfigDirectoryPath + "/" + seedConfig.AppConfigFileName));
         return(temp);
     }
     catch (Exception ex)//预期异常:格式错误,错误内容
     {
         throw new Exception("ReadLocal反序列化异常:" + ex.Message);
     }
 }
Exemplo n.º 12
0
 private ProgramDistributedConfig()
 {
     _appConfig = new AppConfig()
     {
         Components    = new List <ComponentConfig>(),
         ConfigContent = "",
         SolutionID    = Guid.Empty,
         SolutionName  = "本地配置",
         Version       = 0,
     };//构造函数默认对象内属性数值,默认为本地模式参数
     try
     {
         _seedConfig = ReadSeedConfig();//防止基础配置不存在或者错误导致程序无法启动
     }
     catch (Exception ex)
     {
         throw new Exception("无法读取App的Seed配置:" + ex.Message);//错误配置下扔出
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// 本地配置模式下只有一个方案序列化文件
 /// </summary>
 /// <param name="seedConfig"></param>
 private void ReadLocal(AppLocalConfig seedConfig, InitResult result)
 {
     if (string.IsNullOrEmpty(seedConfig.LocalConfigDirectoryPath))//如果没有默认路径不读取
     {
         result.Result  = false;
         result.Message = "本地配置文件路径为空";
         return;//构造函数里默认数值
     }
     try
     {
         var temp = Newtonsoft.Json.JsonConvert.DeserializeObject <AppConfig>(File.ReadAllText(seedConfig.LocalConfigDirectoryPath + "/" + seedConfig.AppConfigFileName));
         if (temp != null)//使用构造函数里的数值,避免多位置同效代码赋值
         {
             _appConfig = temp;
         }
     }
     catch (Exception ex)//预期异常:格式错误,错误内容
     {
         throw new Exception("ReadLocal反序列化异常:" + ex.Message);
     }
 }
Exemplo n.º 14
0
 private ProgramDistributedConfig()
 {
     _appConfig = new AppConfig()
     {
         Components    = new List <ComponentConfig>(),
         ConfigContent = "",
         SolutionID    = Guid.Empty,
         SolutionName  = "本地配置",
         Version       = 0,
     };//构造函数默认对象内属性数值,默认为本地模式参数
     try
     {
         _seedConfig = ReadSeedConfig();//防止基础配置不存在或者错误导致程序无法启动
     }
     catch (Exception ex)
     {
         _seedConfig = new AppLocalConfig()
         {
             Version = 0, AppConfigID = Guid.Empty, IsRemote = false
         };                                                                                             //错误配置下给予最小化配置
     }
 }