// TODO Duplicates code from Orange.GUI.OrangeInterface.cs. Both should be presented at one file public void UpdateCacheModeCheckboxes(AssetCacheMode state) { CacheLocalAndRemote.Checked = state == (AssetCacheMode.Local | AssetCacheMode.Remote); CacheRemote.Checked = state == AssetCacheMode.Remote; CacheLocal.Checked = state == AssetCacheMode.Local; CacheNone.Checked = state == AssetCacheMode.None; The.Workspace.AssetCacheMode = state; }
/// <summary> /// Drop connection with remote server /// </summary> public void DisconnectFromRemote() { if (!IsRemoteEnabled) { return; } if (ftpClient.IsConnected) { ftpClient.Disconnect(); } Mode = IsLocalEnabled ? AssetCacheMode.Local : AssetCacheMode.None; Console.WriteLine($"[Cache] Disconnected from {serverUsername}@{serverAddress}"); }
public void LoadCacheSettings() { var config = WorkspaceConfig.Load(); if (ProjectFile != string.Empty) { AssetCacheMode = config.AssetCacheMode; LocalAssetCachePath = config.LocalAssetCachePath; if (ProjectDirectory != null && !Path.IsPathRooted(LocalAssetCachePath)) { LocalAssetCachePath = Path.Combine(ProjectDirectory, LocalAssetCachePath); } } }
/// <summary> /// Load current cache settings using workspace config and .citproj /// </summary> private void GetSettings() { dynamic data = The.Workspace.ProjectJson.AsDynamic.AssetCache; if (data == null) { Mode = AssetCacheMode.None; Console.WriteLine($"[Cache] Warning: 'AssetCache' field not found in {The.Workspace.ProjectFile}. Cache disabled"); return; } Mode = The.Workspace.AssetCacheMode; if (Mode == AssetCacheMode.None) { Console.WriteLine("[Cache] Cache disabled via WorkspaceConfig"); return; } tempFilePath = Path.Combine(The.Workspace.LocalAssetCachePath, TempFileName); if (Mode == AssetCacheMode.Local) { Console.WriteLine("[Cache] Using LOCAL cache"); return; } serverAddress = (string)data.ServerAddress; if (serverAddress == null) { HandleSetupFailure($"'ServerAddress' field not found in AssetCache settings in {The.Workspace.ProjectFile}"); return; } serverUsername = (string)data.ServerUsername; if (serverUsername == null) { HandleSetupFailure($"'ServerUsername' field not found in AssetCache settings in {The.Workspace.ProjectFile}"); return; } serverPath = (string)data.ServerPath; if (serverPath == null) { HandleSetupFailure($"'ServerPath' field not found in AssetCache settings in {The.Workspace.ProjectFile}"); return; } if (Mode == AssetCacheMode.Remote) { Console.WriteLine("[Cache] Using REMOTE cache"); } if (Mode == (AssetCacheMode.Local | AssetCacheMode.Remote)) { Console.WriteLine("[Cache] Using LOCAL and REMOTE cache"); } }
public void LoadCacheSettings() { var config = WorkspaceConfig.Load(); var projectConfig = config.GetProjectConfig(ProjectFilePath); if (projectConfig != null) { AssetCacheMode = projectConfig.AssetCacheMode; LocalAssetCachePath = projectConfig.LocalAssetCachePath; if (ProjectDirectory != null && !Path.IsPathRooted(LocalAssetCachePath)) { LocalAssetCachePath = Path.Combine(ProjectDirectory, LocalAssetCachePath); } } }
/// <summary> /// Switch cache mode to viable on current conditions and write corresponding message to console. /// Used to handle setup errors. /// </summary> private void HandleSetupFailure(string errorMessage) { string ending; if (IsLocalEnabled) { Mode = AssetCacheMode.Local; ending = "Switched to LOCAL cache"; } else { Mode = AssetCacheMode.None; ending = "Cache disabled"; } Console.WriteLine($"[Cache] WARNING: {errorMessage}. {ending}"); }
/// <summary> ///Switch cache mode to viable on current conditions and write corresponding message to console. /// Used to handle errors related to communication with remote serer /// </summary> /// <param name="hashString">SHA256 of file's binary data</param> private void HandleRemoteCacheFailure(string hashString, string errorMessage) { string ending; if (IsLocalEnabled) { Mode = AssetCacheMode.Local; ending = "Switched to LOCAL cache"; } else { Mode = AssetCacheMode.None; ending = "Cache disabled"; } Console.WriteLine($"[Cache] WARNING {serverUsername}@{serverAddress}: {errorMessage} ({hashString}). {ending}"); if (File.Exists(tempFilePath)) { File.Delete(tempFilePath); } }