private static async Task RunRepeatAsync(string schedule) { try { var factory = new StdSchedulerFactory(new NameValueCollection { { "quartz.serializer.type", "binary" } }); var sched = await factory.GetScheduler(); await sched.Start(); var job = JobBuilder.Create <SchedJob>() .WithIdentity("job1", "group1") .Build(); var trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .StartNow() .WithCronSchedule(schedule) .WithPriority(1) .Build(); await sched.ScheduleJob(job, trigger); await Task.Delay(-1); await sched.Shutdown(); } catch (Exception ex) { await CliUtils.PrintErrorAsync(ex.Message); } }
public static async Task RunExecuteAsync(string commandName, string[] commandArgs, IJobExecutionContext jobContext) { try { Func <IJobContext, Task> job; if (Jobs.TryGetValue(commandName, out job)) { if (job != null) { var context = new JobContextImpl(commandName, commandArgs, jobContext); await job(context); } } } catch (Exception ex) { await CliUtils.PrintErrorAsync(ex.Message); var errorLogFilePath = CliUtils.CreateErrorLogFile("siteserver"); await CliUtils.AppendErrorLogsAsync(errorLogFilePath, new List <TextLogInfo> { new TextLogInfo { DateTime = DateTime.Now, Detail = "Console Error", Exception = ex } }); } }
private async Task RunHelpAsync(bool _isHelp, string commandName) { if (_isHelp || string.IsNullOrEmpty(commandName)) { var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); await Console.Out.WriteLineAsync($"Cli 命令行版本: {version.Substring(0, version.Length - 2)}"); await Console.Out.WriteLineAsync($"当前文件夹: {Settings.ContentRootPath}"); await Console.Out.WriteLineAsync($"Cli 命令行文件夹: {Assembly.GetExecutingAssembly().Location}"); await Console.Out.WriteLineAsync(); await CliUtils.PrintRowLine(); await CliUtils.PrintRow("Usage"); await CliUtils.PrintRowLine(); BackupJob.PrintUsage(); RestoreJob.PrintUsage(); await CliUtils.PrintRowLine(); await CliUtils.PrintRow("https://www.datory.io/docs/"); await CliUtils.PrintRowLine(); Console.ReadLine(); } else { Console.WriteLine($"'{commandName}' is not a siteserver command. See 'sitserver --help'"); } }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } if (!await _configRepository.IsNeedInstallAsync()) { await WriteUtils.PrintErrorAsync($"SS CMS has been installed in {_settingsManager.ContentRootPath}"); return; } var userName = string.IsNullOrEmpty(_userName) ? ReadUtils.GetString("Super administrator username:"******"Super administrator password:"******"index.html"), Constants.Html5Empty); await WriteUtils.PrintSuccessAsync("Congratulations, SS CMS was installed successfully!"); }
public void ExtractArgs_NullOrEmptyString_ReturnsEmptyList() { var resultNullString = CliUtils.ExtractAndParseDoubleParams(null); var resultEmptyString = CliUtils.ExtractAndParseDoubleParams(""); Assert.That(resultNullString, Is.EqualTo(new List <object>())); Assert.That(resultEmptyString, Is.EqualTo(new List <object>())); }
public void ParseRange_GettingInRangeFactorForRgb_ReturnExpectedFactor(string rangeString, double expFactor) { Color color = Color.FromRgb(1, 0.1, 0); // a bit yellowish max saturated red var range = CliUtils.ParseRange(rangeString); double factor = range.InRangeFactor(color); Assert.That(factor, Is.EqualTo(expFactor)); }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var directory = _directory; if (string.IsNullOrEmpty(directory)) { directory = string.Empty; } var configPath = CliUtils.GetConfigPath(_settingsManager); if (!FileUtils.IsFileExists(configPath)) { await WriteUtils.PrintErrorAsync($"The sscms.json file does not exist: {configPath}"); return; } await Console.Out.WriteLineAsync($"Database type: {_settingsManager.DatabaseType.GetDisplayName()}"); await Console.Out.WriteLineAsync($"Database connection string: {_settingsManager.DatabaseConnectionString}"); var(isConnectionWorks, errorMessage) = await _settingsManager.Database.IsConnectionWorksAsync(); if (!isConnectionWorks) { await WriteUtils.PrintErrorAsync($"Unable to connect to database, error message: {errorMessage}"); return; } var site = await _databaseManager.SiteRepository.GetSiteByDirectoryAsync(directory); if (site == null) { await WriteUtils.PrintErrorAsync($"Unable to find the site, directory: {directory}"); return; } await Console.Out.WriteLineAsync($"site: {site.SiteName}"); //await _createManager.CreateByAllAsync(site.Id); await _createManager.ExecuteAsync(site.Id, CreateType.All, 0, 0, 0, 0); await WriteUtils.PrintSuccessAsync("create pages successfully!"); }
/// <inheritdoc cref=""/> public Assembly LoadAssembly(string assemblyPath) { if (!CliUtils.IsCliAssembly(assemblyPath)) { return(null); } var directory = Path.GetDirectoryName(assemblyPath); var fileName = Path.GetFileName(assemblyPath); Assembly loadedAssembly = SpeciallyLoadedByAssemblyFileName(fileName); if (loadedAssembly == null) { if (!loadContexts.TryGetValue(directory, out var loadContext)) { loadContext = new PluginAssemblyLoadContext(directory, this.SpeciallyLoadedByAssemblyName); if (!loadContexts.TryAdd(directory, loadContext)) { if (!loadContexts.TryGetValue(directory, out loadContext)) { Console.Error.WriteLine($"Unable to load assembly {assemblyPath}."); } } } if (loadContext != null) { try { loadedAssembly = loadContext.LoadFromAssemblyPath(assemblyPath); } catch (BadImageFormatException) { // // this means it is native code or otherwise // not readable by the CLR. // loadedAssembly = null; } catch (FileLoadException e) { Console.Error.WriteLine( "[warn]: managed assembly `{0}` cannot be loaded - {1}.", assemblyPath, e.FusionLog); loadedAssembly = null; } catch (FileNotFoundException) { loadedAssembly = null; } } } return(loadedAssembly); }
/// <summary> /// Saves a feed. /// </summary> /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the feed file could not be read or written.</exception> /// <exception cref="UnauthorizedAccessException">Read or write access to a feed file is not permitted.</exception> /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception> private void SaveFeed(FeedEditing feedEditing) { if (_unsign) { // Remove any existing signatures feedEditing.SignedFeed.SecretKey = null; } else { var openPgp = OpenPgpFactory.CreateDefault(); if (_xmlSign) { // Signing explicitly requested if (feedEditing.SignedFeed.SecretKey == null) { // No previous signature // Use user-specified key or default key feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key); } else { // Existing siganture if (!string.IsNullOrEmpty(_key)) // Use new user-specified key { feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key); } //else resign implied } } //else resign implied } // If no signing or unsigning was explicitly requested and the content did not change // there is no need to overwrite (and potentiall resign) the file if (!_xmlSign && !_unsign && !feedEditing.Changed) { return; } while (true) { try { Debug.Assert(feedEditing.Path != null); feedEditing.SignedFeed.Save(feedEditing.Path, _openPgpPassphrase); break; // Exit loop if passphrase is correct } catch (WrongPassphraseException ex) { // Continue loop if passhrase is incorrect if (!string.IsNullOrEmpty(_openPgpPassphrase)) { Log.Error(ex); } } // Ask for passphrase to unlock secret key if we were unable to save without it _openPgpPassphrase = CliUtils.ReadPassword(string.Format(Resources.AskForPassphrase, feedEditing.SignedFeed.SecretKey)); } }
public void TryParseRangeForRangeParam_CallMethod_ReturnMinAndMaxAndSucceeded(string rangeStr, string rangeParam, bool expSuccess, double expMin, double expMax) { ParameterRange range = CliUtils.TryParseRangeForRangeParam(rangeStr, rangeParam); Assert.That(range != null == expSuccess); Assert.That(range?.MinStart ?? 0, Is.EqualTo(expMin)); Assert.That(range?.MaxEnd ?? 0, Is.EqualTo(expMax)); }
public async Task SaveStatusAsync(ConfigStatus status) { var configPath = CliUtils.GetOsUserConfigFilePath(); var config = new Config { Status = status }; await FileUtils.WriteTextAsync(configPath, TranslateUtils.JsonSerialize(config)); }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var pluginsPath = CliUtils.IsSsCmsExists(_settingsManager.ContentRootPath) ? _pathManager.PluginsPath : _settingsManager.ContentRootPath; var(status, _) = await _apiService.GetStatusAsync(); var publisher = status == null ? ReadUtils.GetString("What's the publisher of your plugin?") : status.UserName; if (status == null && !StringUtils.IsStrictName(publisher)) { await WriteUtils.PrintErrorAsync( $@"Invalid plugin publisher: ""{publisher}"", string does not match the pattern of ""{StringUtils.StrictNameRegex}"""); return; } var name = ReadUtils.GetString("What's the name of your plugin?"); if (!StringUtils.IsStrictName(name)) { await WriteUtils.PrintErrorAsync( $@"Invalid plugin name: ""{publisher}"", string does not match the pattern of ""{StringUtils.StrictNameRegex}"""); return; } var pluginId = PluginUtils.GetPluginId(publisher, name); var pluginPath = PathUtils.Combine(pluginsPath, pluginId); var dict = new Dictionary <string, object> { ["name"] = name, ["publisher"] = publisher }; var json = TranslateUtils.JsonSerialize(dict); await FileUtils.WriteTextAsync(PathUtils.Combine(pluginPath, Constants.PackageFileName), json); await WriteUtils.PrintSuccessAsync($@"The plugin ""{pluginId}"" was created successfully."); }
private static async Task RunHelpAsync(bool isHelp, string commandName, Dictionary <string, Func <IJobContext, Task> > pluginJobs) { if (isHelp || string.IsNullOrEmpty(commandName)) { var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); await Console.Out.WriteLineAsync($"Cli 命令行版本: {version.Substring(0, version.Length - 2)}"); await Console.Out.WriteLineAsync($"当前文件夹: {CliUtils.PhysicalApplicationPath}"); await Console.Out.WriteLineAsync($"Cli 命令行文件夹: {Assembly.GetExecutingAssembly().Location}"); await Console.Out.WriteLineAsync(); await CliUtils.PrintRowLine(); await CliUtils.PrintRow("Usage"); await CliUtils.PrintRowLine(); var backupJob = new BackupJob(); var installJob = new InstallJob(); var restoreJob = new RestoreJob(); var syncJob = new SyncJob(); var updateJob = new UpdateJob(); var versionJob = new VersionJob(); backupJob.PrintUsage(); installJob.PrintUsage(); restoreJob.PrintUsage(); syncJob.PrintUsage(); updateJob.PrintUsage(); versionJob.PrintUsage(); if (pluginJobs != null && pluginJobs.Count > 0) { Console.WriteLine($"插件命令: {TranslateUtils.ObjectCollectionToString(pluginJobs.Keys)}"); Console.WriteLine(); } await CliUtils.PrintRowLine(); await CliUtils.PrintRow(CloudUtils.Root.DocsCliUrl); await CliUtils.PrintRowLine(); Console.ReadLine(); } else { Console.WriteLine($"'{commandName}' is not a siteserver command. See 'sitserver --help'"); } }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } Process proc; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var psi = new ProcessStartInfo("./SSCMS.Web") { RedirectStandardOutput = true }; proc = Process.Start(psi); } else { proc = Process.Start("./SSCMS.Web"); } if (proc == null) { await WriteUtils.PrintErrorAsync("Can not run SSCMS."); } else { Console.WriteLine("Starting SS CMS..."); Thread.Sleep(5000); OpenUrl("http://localhost:5000/ss-admin/"); using var sr = proc.StandardOutput; while (!sr.EndOfStream) { Console.WriteLine(sr.ReadLine()); } if (!proc.HasExited) { proc.Kill(); } } }
protected KeyValuePair <string, TableInfo> GetNewTableInfo(string oldTableName, TableInfo oldTableInfo, string newTableName, List <TableColumn> newColumns, Dictionary <string, string> convertKeyDict, Dictionary <string, string> convertValueDict) { if (string.IsNullOrEmpty(newTableName)) { newTableName = oldTableName; } if (newColumns == null || newColumns.Count == 0) { newColumns = oldTableInfo.Columns; } var newTableInfo = new TableInfo { Columns = newColumns, TotalCount = oldTableInfo.TotalCount, RowFiles = oldTableInfo.RowFiles }; CliUtils.PrintRow(oldTableName, newTableName, oldTableInfo.TotalCount.ToString("#,0")); var i = 0; using (var progress = new ProgressBar()) { foreach (var fileName in oldTableInfo.RowFiles) { progress.Report((double)i++ / oldTableInfo.RowFiles.Count); var oldFilePath = OldTreeInfo.GetTableContentFilePath(oldTableName, fileName); var newFilePath = NewTreeInfo.GetTableContentFilePath(newTableName, fileName); if (convertKeyDict != null) { var oldRows = TranslateUtils.JsonDeserialize <List <JObject> >(FileUtils.ReadText(oldFilePath, Encoding.UTF8)); var newRows = UpdateUtils.UpdateRows(oldRows, convertKeyDict, convertValueDict); FileUtils.WriteText(newFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newRows)); } else { FileUtils.CopyFile(oldFilePath, newFilePath); } } } return(new KeyValuePair <string, TableInfo>(newTableName, newTableInfo)); }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } if (string.IsNullOrEmpty(_name)) { if (context.Extras != null && context.Extras.Length > 0) { _name = context.Extras[0]; } } if (string.IsNullOrEmpty(_name)) { await WriteUtils.PrintErrorAsync("missing required name"); return; } var(status, failureMessage) = await _apiService.GetStatusAsync(); if (status == null) { await WriteUtils.PrintErrorAsync(failureMessage); return; } bool success; (success, failureMessage) = await _apiService.ThemeUnPublishAsync(_name); if (success) { await WriteUtils.PrintSuccessAsync($"Theme {_name} unpublished ."); } else { await WriteUtils.PrintErrorAsync(failureMessage); } }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var(status, failureMessage) = await _apiService.GetStatusAsync(); if (status == null) { await WriteUtils.PrintErrorAsync(failureMessage); return; } var(success, name, filePath) = await ThemePackageJob.PackageAsync(_pathManager, _cacheManager, _databaseManager, _directory, false); if (!success) { return; } var fileSize = FileUtils.GetFileSizeByFilePath(filePath); await Console.Out.WriteLineAsync($"Theme Packaged: {filePath}"); await Console.Out.WriteLineAsync($"Publishing theme {name} ({fileSize})..."); (success, failureMessage) = await _apiService.ThemePublishAsync(filePath); if (success) { await WriteUtils.PrintSuccessAsync($"Theme published, your theme will live at {CloudUtils.Www.GetThemeUrl(status.UserName, name)}."); } else { await WriteUtils.PrintErrorAsync(failureMessage); } }
public static async Task Execute(IJobContext context) { if (!CliUtils.ParseArgs(Options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); await Console.Out.WriteLineAsync($"SiteServer CLI Version: {version.Substring(0, version.Length - 2)}"); await Console.Out.WriteLineAsync($"Work Directory: {CliUtils.PhysicalApplicationPath}"); await Console.Out.WriteLineAsync(); if (string.IsNullOrEmpty(_webConfigFileName)) { _webConfigFileName = "web.config"; } if (FileUtils.IsFileExists(PathUtils.Combine(CliUtils.PhysicalApplicationPath, _webConfigFileName))) { WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, _webConfigFileName); try { var cmsVersion = FileVersionInfo.GetVersionInfo(PathUtils.Combine(CliUtils.PhysicalApplicationPath, "Bin", "SiteServer.CMS.dll")).ProductVersion; await Console.Out.WriteLineAsync($"SitServer CMS Version: {cmsVersion}"); } catch { // ignored } await Console.Out.WriteLineAsync($"Database Type: {WebConfigUtils.DatabaseType.Value}"); await Console.Out.WriteLineAsync($"Connection String Decode: {WebConfigUtils.ConnectionString}"); await Console.Out.WriteLineAsync($"Connection String Encode: {TranslateUtils.EncryptStringBySecretKey(WebConfigUtils.ConnectionString, WebConfigUtils.SecretKey)}"); } }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } if (string.IsNullOrEmpty(_userName)) { await WriteUtils.PrintErrorAsync("missing required options '--username'"); return; } if (!StringUtils.IsStrictName(_userName)) { await WriteUtils.PrintErrorAsync( $@"Invalid username: ""{_userName}"", string does not match the pattern of ""{StringUtils.StrictNameRegex}"""); return; } if (string.IsNullOrEmpty(_password)) { await WriteUtils.PrintErrorAsync("missing required options '--password'"); return; } var(success, failureMessage) = await _apiService.RegisterAsync(_userName, _mobile, _email, _password); if (success) { await WriteUtils.PrintSuccessAsync("you have registered successfully, run sscms login to log in."); } else { await WriteUtils.PrintErrorAsync(failureMessage); } }
public void ExtractParams_StringWithExtraComma_ReturnsListWithEmptyStrings() { const string inputString = ",2.1, 1.0, 0.1,1, "; var result = CliUtils.ExtractAndParseDoubleParams(inputString); double[] expected = { 0, 2.1, 1.0, 0.1, 1, 0 }; if (result.Length == expected.Length) { for (int i = 0; i < expected.Length; i++) { Assert.That(result[i], Is.EqualTo(expected[i])); } } else { Assert.Fail(); } }
public void ExtractParams_CorrectlyFormattedString_ReturnsExpectedList() { const string inputString = "2.1, 1.0, 0.1,1 "; var result = CliUtils.ExtractAndParseDoubleParams(inputString); double[] expected = { 2.1, 1.0, 0.1, 1.0 }; if (result.Length == expected.Length) { for (int i = 0; i < expected.Length; i++) { Assert.That(result[i], Is.EqualTo(expected[i])); } } else { Assert.Fail(); } }
public async Task Execute(IJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); await Console.Out.WriteLineAsync($"SiteServer CLI 版本号: {version.Substring(0, version.Length - 2)}"); await Console.Out.WriteLineAsync($"当前文件夹: {CliUtils.PhysicalApplicationPath}"); await Console.Out.WriteLineAsync(); var webConfigPath = CliUtils.GetWebConfigPath(_configFile); if (FileUtils.IsFileExists(webConfigPath)) { WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, webConfigPath); try { var cmsVersion = FileVersionInfo.GetVersionInfo(PathUtils.Combine(CliUtils.PhysicalApplicationPath, "Bin", "SiteServer.CMS.dll")).ProductVersion; await Console.Out.WriteLineAsync($"SitServer CMS Version: {cmsVersion}"); } catch { // ignored } await Console.Out.WriteLineAsync($"数据库类型: {WebConfigUtils.DatabaseType.Value}"); await Console.Out.WriteLineAsync($"连接字符串: {WebConfigUtils.ConnectionString}"); await Console.Out.WriteLineAsync($"连接字符串(加密): {TranslateUtils.EncryptStringBySecretKey(WebConfigUtils.ConnectionString, WebConfigUtils.SecretKey)}"); } }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } if (context.Extras == null || context.Extras.Length == 0) { await WriteUtils.PrintErrorAsync("missing required pluginId"); return; } var(status, failureMessage) = await _apiService.GetStatusAsync(); if (status == null) { await WriteUtils.PrintErrorAsync(failureMessage); return; } bool success; (success, failureMessage) = await _apiService.PluginUnPublishAsync(context.Extras[0]); if (success) { await WriteUtils.PrintSuccessAsync($"Plugin {context.Extras[0]} unpublished."); } else { await WriteUtils.PrintErrorAsync(failureMessage); } }
public async Task Execute(IJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { return; } var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); await Console.Out.WriteLineAsync($"SiteServer CLI Version: {version.Substring(0, version.Length - 2)}"); await Console.Out.WriteLineAsync($"Work Directory: {CliUtils.PhysicalApplicationPath}"); await Console.Out.WriteLineAsync($"siteserver.exe Path: {Assembly.GetExecutingAssembly().Location}"); await Console.Out.WriteLineAsync(); }
/// <inheritdoc/> protected override bool Ask(string question, MsgSeverity severity) { Log.Debug($"Question: {question}"); Console.Error.WriteLine(question); // Loop until the user has made a valid choice while (true) { switch (CliUtils.ReadString(@"[Y/N]").ToLower()) { case "y": case "yes": Log.Debug("Answer: Yes"); return(true); case "n": case "no": Log.Debug("Answer: No"); return(false); } } }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var(success, _, filePath) = await PackageAsync(_pathManager, _cacheManager, _databaseManager, _directory, true); if (success) { var fileSize = FileUtils.GetFileSizeByFilePath(filePath); await WriteUtils.PrintSuccessAsync($"Theme packaged: {filePath} ({fileSize})"); } }
public async Task RunAsync(IJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); await Console.Out.WriteLineAsync($"SiteServer CLI 版本号: {version.Substring(0, version.Length - 2)}"); await Console.Out.WriteLineAsync($"当前文件夹: {_settings.ContentRootPath}"); await Console.Out.WriteLineAsync(); var(isConnectionWorks, errorMessage) = await CliUtils.CheckSettingsAsync(_settings); if (!isConnectionWorks) { try { var cmsVersion = FileVersionInfo.GetVersionInfo(Path.Combine(_settings.ContentRootPath, "Bin", "SiteServer.CMS.dll")).ProductVersion; await Console.Out.WriteLineAsync($"SitServer CMS Version: {cmsVersion}"); } catch { // ignored } await Console.Out.WriteLineAsync($"数据库类型: {_settings.Database.DatabaseType.GetValue()}"); await Console.Out.WriteLineAsync($"连接字符串: {_settings.Database.ConnectionString}"); } }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var pluginId = string.Empty; if (context.Extras != null && context.Extras.Length > 0) { pluginId = context.Extras[0]; } var pluginPath = string.IsNullOrEmpty(pluginId) ? _settingsManager.ContentRootPath : PathUtils.Combine(_pathManager.GetPluginPath(pluginId)); var(plugin, errorMessage) = await PluginUtils.ValidateManifestAsync(pluginPath); if (plugin == null) { await WriteUtils.PrintErrorAsync(errorMessage); return; } var zipPath = Package(_pathManager, plugin); var fileSize = FileUtils.GetFileSizeByFilePath(zipPath); await WriteUtils.PrintSuccessAsync($"Packaged: {zipPath} ({fileSize})"); }
public static void Execute(string[] args) { if (!CliUtils.ParseArgs(Options, args)) { return; } if (_isHelp) { return; } var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); Console.WriteLine($"SiteServer CLI Version: {version.Substring(0, version.Length - 2)}"); Console.WriteLine($"Work Directory: {CliUtils.PhysicalApplicationPath}"); Console.WriteLine(); var content = FileUtils.ReadText(PathUtils.Combine(CliUtils.PhysicalApplicationPath, "_metadata.json"), Encoding.UTF8); var table = TranslateUtils.JsonDeserialize <TableInfo>(content); Console.WriteLine($"_metadata: {TranslateUtils.JsonSerialize(table.Columns)}"); }
/// <summary> /// Loads the specified path as an assembly into the default load context. /// </summary> /// <param name="assemblyPath"> /// Path to an assembly. /// </param> public Assembly LoadAssembly(string assemblyPath) { if (!CliUtils.IsCliAssembly(assemblyPath)) { return(null); } Assembly loadedAssembly; try { loadedAssembly = Assembly.LoadFrom(assemblyPath); } catch (BadImageFormatException) { // // this means it is native code or otherwise // not readable by the CLR. // loadedAssembly = null; } catch (FileLoadException e) { Console.Error.WriteLine( "[warn]: managed assembly `{0}` cannot be loaded - {1}.", assemblyPath, e.FusionLog); loadedAssembly = null; } catch (FileNotFoundException) { loadedAssembly = null; } return(loadedAssembly); }