示例#1
0
 // 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;
 }
示例#2
0
 /// <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}");
 }
示例#3
0
        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);
                }
            }
        }
示例#4
0
        /// <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");
            }
        }
示例#5
0
        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);
                }
            }
        }
示例#6
0
        /// <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}");
        }
示例#7
0
        /// <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);
            }
        }