Beispiel #1
0
 internal static void ExecuteWithBasicExceptionHandling(Action handler, bool setErrorInRequestState, bool set500StatusCode)
 {
     try {
         handler();
     }
     catch (Exception e) {
         // Suppress all exceptions since there is no way to report them and in some cases they could wreck the control flow for the request.
         try {
             EwlStatics.CallEveryMethod(
                 delegate {
                 const string prefix = "An exception occurred that could not be handled by the main exception handler:";
                 if (setErrorInRequestState)
                 {
                     Instance.RequestState.SetError(prefix, e);
                 }
                 else
                 {
                     TelemetryStatics.ReportError(prefix, e);
                 }
             },
                 delegate {
                 if (set500StatusCode)
                 {
                     Instance.set500StatusCode("Exception");
                 }
             });
         }
         catch {}
     }
 }
        internal void CleanUpConnectionsAndExecuteNonTransactionalModificationMethods(bool cacheEnabled, bool skipNonTransactionalModificationMethods = false)
        {
            var methods = new List <Action>();

            if (primaryDatabaseConnectionInitialized)
            {
                methods.Add(() => cleanUpConnection(dataAccessState.PrimaryDatabaseConnection));
            }
            foreach (var databaseName in secondaryDatabasesWithInitializedConnections)
            {
                var databaseNameCopy = databaseName;
                methods.Add(() => cleanUpConnection(dataAccessState.GetSecondaryDatabaseConnection(databaseNameCopy)));
            }
            methods.Add(
                () => {
                try {
                    if (!skipNonTransactionalModificationMethods && !transactionsMarkedForRollback)
                    {
                        if (cacheEnabled)
                        {
                            dataAccessState.DisableCache();
                            try {
                                foreach (var i in nonTransactionalModificationMethods)
                                {
                                    i();
                                }
                            }
                            finally {
                                dataAccessState.ResetCache();
                            }
                        }
                        else
                        {
                            foreach (var i in nonTransactionalModificationMethods)
                            {
                                i();
                            }
                        }
                    }
                }
                finally {
                    nonTransactionalModificationMethods.Clear();
                }
            });
            EwlStatics.CallEveryMethod(methods.ToArray());
            transactionsMarkedForRollback = false;
        }