Esempio n. 1
0
        public async Task <bool> Initialize()
        {
            if (IsInitialized)
            {
                return(true);
            }

            return(await StandardLibrary.InitializeStandardLib() && await Task.Run(() =>
            {
                if (IsInitialized)
                {
                    return true;
                }
                bool success;
                lock (initializationLock)
                {
                    if (IsInitialized)
                    {
                        return true;
                    }

                    success = InternalInitialize();
                    IsInitialized = success;
                    HadInitializationError = !success;
                }

                InitializationStatusChange?.Invoke(true);
                return success;
            }));
        }
        /// <summary>
        /// Run a git command asynchronously.
        /// Throw GitOperationException on unrecoverable errors.
        /// Throw CancelledByUserException and RepeatOperationException.
        /// </summary>
        async private Task runAsync(Command command)
        {
            try
            {
                await command();
            }
            catch (Exception ex)
            {
                Debug.Assert(!(ex is InvalidOperationException));

                // Exception handling does not mean that we can return valid GitClient
                bool cancelledByUser = isCancelledByUser(ex);

                string result = cancelledByUser ? "cancelled by user" : "failed";
                InitializationStatusChange?.Invoke(String.Format("Git repository update {0}", result));

                if (cancelledByUser)
                {
                    throw new CancelledByUserException();
                }

                if (isSSLCertificateProblem(ex as GitOperationException))
                {
                    InitializationStatusChange?.Invoke("Cannot clone due to SSL verification error");
                    if (handleSSLCertificateProblem())
                    {
                        throw new RepeatOperationException();
                    }
                    throw new CancelledByUserException();
                }

                throw;
            }
        }
        /// <summary>
        /// Update passed GitClient object.
        /// Throw GitOperationException on unrecoverable errors.
        /// Throw CancelledByUserException and RepeatOperationException.
        /// </summary>
        async internal Task UpdateAsync(GitClient client, IInstantProjectChecker instantChecker,
                                        Action <string> onProgressChange)
        {
            if (client.DoesRequireClone() && !isCloneAllowed(client.Path))
            {
                InitializationStatusChange?.Invoke("Clone rejected");
                throw new CancelledByUserException();
            }

            InitializationStatusChange?.Invoke("Updating git repository...");

            await runAsync(async() => await client.Updater.ManualUpdateAsync(instantChecker, onProgressChange));

            InitializationStatusChange?.Invoke("Git repository updated");
        }
        ///<summary>
        /// Handle exceptions caused by SSL certificate problem
        ///</summary>
        private bool handleSSLCertificateProblem()
        {
            if (!isGlobalSSLFixAllowed())
            {
                return(false);
            }

            try
            {
                GitUtils.SetGlobalSSLVerify(false);
            }
            catch (Exception ex)
            {
                ExceptionHandlers.Handle(ex, "Cannot change global http.verifySSL setting");
                throw;
            }

            InitializationStatusChange?.Invoke("SSL certificate verification disabled. Please repeat git operation.");
            return(true);
        }
Esempio n. 5
0
 void IPackageUser.handleUpdate(List <PackageUpdate> updates)
 {
     if (_symbols is null)
     {
         return;
     }
     //TODO: invalidate this when changes are made to script objects in this file
     foreach (PackageUpdate update in updates.Where(u => u.Change.Has(PackageChange.Export)))
     {
         if (ScriptUIndexes.Contains(update.Index) ||
             update.Change.Has(PackageChange.Add) && Pcc.GetEntry(update.Index) is ExportEntry exp && (IsScriptExport(exp) || exp.ClassName == "Function"))
         {
             lock (initializationLock)
             {
                 IsInitialized          = false;
                 HadInitializationError = false;
                 _symbols = null;
             }
             InitializationStatusChange?.Invoke(false);
             return;
         }
     }
 }