public Task SaveProject(OneDasProjectSettings projectSettings) { string fileName; string directoryPath; string currentFilePath; string newFilePath; Contract.Requires(projectSettings != null); return(Task.Run(() => { projectSettings.Validate(); directoryPath = Path.Combine(_webServerOptions.BaseDirectoryPath, "project"); fileName = $"{ projectSettings.Description.PrimaryGroupName }_{ projectSettings.Description.SecondaryGroupName }_{ projectSettings.Description.CampaignName }_{ projectSettings.Description.Guid.ToString() }.json"; currentFilePath = Path.Combine(directoryPath, fileName); try { if (File.Exists(currentFilePath)) { newFilePath = Path.Combine(_webServerOptions.BaseDirectoryPath, "backup", $"{ DateTime.UtcNow.ToString("yyyy-MM-ddTHH-mm-ss") }_{ fileName }"); File.Copy(currentFilePath, newFilePath, true); } } finally { _projectSerializer.Save(projectSettings, currentFilePath); _webServerLogger.LogInformation("project file saved"); } })); }
public AppModel(OneDasProjectSettings activeProjectSettings, IEnumerable <OneDasPackageMetaData> installedPackageSet, IEnumerable <string> clientSet, IEnumerable <ExtensionIdentificationAttribute> dataGatewayExtensionIdentificationSet, IEnumerable <ExtensionIdentificationAttribute> dataWriterExtensionIdentificationSet, string productVersion, string lastError, OneDasState oneDasState, WebServerOptionsLight webServerOptionsLight) { this.ProductVersion = productVersion; this.InstalledPackageSet = installedPackageSet; this.ActiveProjectSettings = activeProjectSettings; this.ClientSet = clientSet; this.DataGatewayExtensionIdentificationSet = dataGatewayExtensionIdentificationSet; this.DataWriterExtensionIdentificationSet = dataWriterExtensionIdentificationSet; this.LastError = lastError; this.OneDasState = oneDasState; this.WebServerOptionsLight = webServerOptionsLight; }
/* improvements: * - settings.ChannelHubSet.Add(new ChannelHub()); // improve ChannelHub constructor * - reduce OneDasEngine dependencies (e.g. JSON.NET) */ static void Main(string[] args) { var services = new ServiceCollection(); ConfigureServices(services); var provider = services.BuildServiceProvider(); var engine = provider.GetRequiredService <OneDasEngine>(); var settings = new OneDasProjectSettings("OneDAS", "Engine", "Example"); engine.ActivateProject(settings); engine.Start(); Console.ReadKey(); }
public void Save(OneDasProjectSettings projectSettings, string filePath) { string directoryPath; directoryPath = Path.GetDirectoryName(filePath); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } using (StreamWriter streamWriter = new StreamWriter(filePath)) { string rawJson; JsonTextWriter jsonTextWriter; rawJson = _oneDasSerializer.Serialize(projectSettings); jsonTextWriter = new JsonTextWriter(streamWriter); jsonTextWriter.WriteRaw(rawJson); } }