Exemple #1
0
 private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
 {
     using (ThreadDataManager.Initialize())
     {
         Execute();
     }
 }
Exemple #2
0
 private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
 {
     using (ThreadDataManager.Initialize())
         using (ServiceLocator.EnsureThreadDataServiceScope())
         {
             Execute();
         }
 }
Exemple #3
0
        /// <exclude />
        public static void Application_End(object sender, EventArgs e)
        {
            if (RuntimeInformation.IsDebugBuild)
            {
                Log.LogInformation(_verboseLogEntryTitle, "AppDomain {0} ended at {1} in process {2}", AppDomain.CurrentDomain.Id, DateTime.Now.ToString("HH:mm:ss:ff"), Process.GetCurrentProcess().Id);
            }

            if (!SystemSetupFacade.IsSystemFirstTimeInitialized)
            {
                return;
            }


            using (ThreadDataManager.Initialize())
            {
                try
                {
                    CodeGenerationManager.ValidateCompositeGenerate(_startTime);
                    CodeGenerationManager.GenerateCompositeGeneratedAssembly();
                }
                catch (Exception ex)
                {
                    Log.LogCritical("Global.asax", "Error updating Composite.Generated.dll");
                    Log.LogCritical("Global.asax", ex);
                }

                try
                {
                    GlobalEventSystemFacade.PrepareForShutDown();
                    if (RuntimeInformation.IsDebugBuild)
                    {
                        LogShutDownReason();
                    }
                    GlobalEventSystemFacade.ShutDownTheSystem();

                    TempDirectoryFacade.OnApplicationEnd();
                }
                catch (Exception ex)
                {
                    Log.LogCritical("Global.asax", ex);

                    throw;
                }

                Log.LogVerbose("Global.asax", string.Format("--- Web Application End, {0} Id = {1}---",
                                                            DateTime.Now.ToLongTimeString(),
                                                            AppDomain.CurrentDomain.Id));
            }
        }
        public string Authenticate(string loginAndPassword)
        {
            if (SystemSetupFacade.IsSystemFirstTimeInitialized == false)
            {
                return("");
            }

            bool userIsValid;

            string login;
            string password;

            int separatorOffset = loginAndPassword.IndexOf("|");

            if (separatorOffset > 0 && separatorOffset < loginAndPassword.Length - 1)
            {
                login    = loginAndPassword.Substring(0, separatorOffset);
                password = loginAndPassword.Substring(separatorOffset + 1);
            }
            else
            {
                // Backward compatibility with old LogViewer
                login    = "******";
                password = loginAndPassword;
            }

            bool userIsAdmin = false;

            using (ThreadDataManager.Initialize())
            {
                userIsValid = LoginProviderPluginFacade.FormValidateUser(login, password) == LoginResult.Success;

                if (userIsValid)
                {
                    string userName = login.ToLowerInvariant();
                    var    userPermissionDefinitions      = PermissionTypeFacade.GetUserPermissionDefinitions(userName).ToList();
                    var    userGroupPermissionDefinitions = PermissionTypeFacade.GetUserGroupPermissionDefinitions(userName).ToList();

                    EntityToken rootEntityToken = AttachingPoint.PerspectivesRoot.EntityToken;
                    var         permissions     = PermissionTypeFacade.GetCurrentPermissionTypes(new UserToken(userName), rootEntityToken, userPermissionDefinitions, userGroupPermissionDefinitions);

                    userIsAdmin = permissions.Contains(PermissionType.Administrate);
                }
            }

            return((userIsValid && userIsAdmin) ? LoggerPassword : string.Empty);
        }
        private void scavengeCodeActivity_Scavenge_ExecuteCode(object sender, EventArgs e)
        {
            if (HostingEnvironment.ApplicationHost.ShutdownInitiated())
            {
                return;
            }

            try
            {
                using (ThreadDataManager.Initialize())
                {
                    ConsoleFacade.Scavenge();
                }
            }
            catch
            {
                // Ignore exceptions
            }
        }
Exemple #6
0
            public void WrapperAction(TSource source)
            {
                var originalHttpContext = HttpContext.Current;

                bool dataScopePushed     = false;
                bool languageScopePushed = false;

                var currentThread = System.Threading.Thread.CurrentThread;

                CultureInfo originalCulture   = currentThread.CurrentCulture;
                CultureInfo originalUiCulture = currentThread.CurrentUICulture;

                using (ThreadDataManager.Initialize(_parentData))
                {
                    try
                    {
                        DataScopeManager.EnterThreadLocal();

                        if (DataScopeManager.CurrentDataScope != _parentThreadDataScope)
                        {
                            DataScopeManager.PushDataScope(_parentThreadDataScope);
                            dataScopePushed = true;
                        }

                        LocalizationScopeManager.EnterThreadLocal();

                        if (LocalizationScopeManager.CurrentLocalizationScope != _parentThreadLocale)
                        {
                            LocalizationScopeManager.PushLocalizationScope(_parentThreadLocale);
                            languageScopePushed = true;
                        }

                        HttpContext.Current = _parentThreadHttpContext;

                        currentThread.CurrentCulture   = _parentThreadCulture;
                        currentThread.CurrentUICulture = _parentThreadUiCulture;

                        try
                        {
                            _body(source);
                        }
                        catch (ThreadAbortException threadAbort)
                        {
                            object state = threadAbort.ExceptionState;

                            if (state != null)
                            {
                                Thread.ResetAbort();

                                // Throwing another exception because Thread.ResetAbort clears ThreadAbortException.ExceptionState
                                throw new RethrowableThreadAbortException(state);
                            }
                        }
                    }
                    finally
                    {
                        currentThread.CurrentCulture   = originalCulture;
                        currentThread.CurrentUICulture = originalUiCulture;

                        HttpContext.Current = originalHttpContext;

                        if (dataScopePushed)
                        {
                            DataScopeManager.PopDataScope();
                        }
                        if (languageScopePushed)
                        {
                            LocalizationScopeManager.PopLocalizationScope();
                        }

                        DataScopeManager.ExitThreadLocal();
                        LocalizationScopeManager.ExitThreadLocal();
                    }
                }
            }
Exemple #7
0
        private void editPreviewActivity_ExecuteCode(object sender, EventArgs e)
        {
            Stopwatch functionCallingStopwatch = null;
            long      millisecondsToken        = 0;

            CultureInfo oldCurrentCulture   = Thread.CurrentThread.CurrentCulture;
            CultureInfo oldCurrentUICulture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                IXsltFunction xslt = this.GetBinding <IXsltFunction>("CurrentXslt");

                string xslTemplate = this.GetBinding <string>("XslTemplate");

                IFile persistemTemplateFile = IFileServices.TryGetFile <IXsltFile>(xslt.XslFilePath);
                if (persistemTemplateFile != null)
                {
                    string persistemTemplate = persistemTemplateFile.ReadAllText();

                    if (this.GetBinding <int>("XslTemplateLastSaveHash") != persistemTemplate.GetHashCode())
                    {
                        xslTemplate = persistemTemplate;
                        ConsoleMessageQueueFacade.Enqueue(new LogEntryMessageQueueItem {
                            Level = LogLevel.Fine, Message = "XSLT file on file system was used. It has been changed by another process.", Sender = this.GetType()
                        }, this.GetCurrentConsoleId());
                    }
                }

                List <NamedFunctionCall> namedFunctions = this.GetBinding <IEnumerable <NamedFunctionCall> >("FunctionCalls").ToList();

                // If preview is done multiple times in a row, with no postbacks an object reference to BaseFunctionRuntimeTreeNode may be held
                // If the function in the BaseFunctionRuntimeTreeNode have ben unloaded / reloaded, this preview will still run on the old instance
                // We force refresh by serializing / deserializing
                foreach (NamedFunctionCall namedFunction in namedFunctions)
                {
                    namedFunction.FunctionCall = (BaseFunctionRuntimeTreeNode)FunctionFacade.BuildTree(namedFunction.FunctionCall.Serialize());
                }


                List <ManagedParameterDefinition> parameterDefinitions = this.GetBinding <IEnumerable <ManagedParameterDefinition> >("Parameters").ToList();

                Guid        pageId        = this.GetBinding <Guid>("PageId");
                string      dataScopeName = this.GetBinding <string>("PageDataScopeName");
                string      cultureName   = this.GetBinding <string>("ActiveCultureName");
                CultureInfo cultureInfo   = null;
                if (cultureName != null)
                {
                    cultureInfo = CultureInfo.CreateSpecificCulture(cultureName);
                }

                IPage page;

                TransformationInputs transformationInput;
                using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), cultureInfo))
                {
                    Thread.CurrentThread.CurrentCulture   = cultureInfo;
                    Thread.CurrentThread.CurrentUICulture = cultureInfo;

                    page = DataFacade.GetData <IPage>(f => f.Id == pageId).FirstOrDefault();
                    if (page != null)
                    {
                        PageRenderer.CurrentPage = page;
                    }

                    functionCallingStopwatch = Stopwatch.StartNew();
                    transformationInput      = RenderHelper.BuildInputDocument(namedFunctions, parameterDefinitions, true);
                    functionCallingStopwatch.Stop();

                    Thread.CurrentThread.CurrentCulture   = oldCurrentCulture;
                    Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture;
                }


                string output = "";
                string error  = "";
                try
                {
                    Thread.CurrentThread.CurrentCulture   = cultureInfo;
                    Thread.CurrentThread.CurrentUICulture = cultureInfo;

                    var styleSheet = XElement.Parse(xslTemplate);

                    XsltBasedFunctionProvider.ResolveImportIncludePaths(styleSheet);

                    LocalizationParser.Parse(styleSheet);

                    XDocument transformationResult = new XDocument();
                    using (XmlWriter writer = new LimitedDepthXmlWriter(transformationResult.CreateWriter()))
                    {
                        XslCompiledTransform xslTransformer = new XslCompiledTransform();
                        xslTransformer.Load(styleSheet.CreateReader(), XsltSettings.TrustedXslt, new XmlUrlResolver());

                        XsltArgumentList transformArgs = new XsltArgumentList();
                        XslExtensionsManager.Register(transformArgs);

                        if (transformationInput.ExtensionDefinitions != null)
                        {
                            foreach (IXsltExtensionDefinition extensionDef in transformationInput.ExtensionDefinitions)
                            {
                                transformArgs.AddExtensionObject(extensionDef.ExtensionNamespace.ToString(),
                                                                 extensionDef.EntensionObjectAsObject);
                            }
                        }

                        Exception   exception   = null;
                        HttpContext httpContext = HttpContext.Current;

                        Thread thread = new Thread(delegate()
                        {
                            Thread.CurrentThread.CurrentCulture   = cultureInfo;
                            Thread.CurrentThread.CurrentUICulture = cultureInfo;

                            Stopwatch transformationStopwatch = Stopwatch.StartNew();

                            try
                            {
                                using (ThreadDataManager.Initialize())
                                    using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), cultureInfo))
                                    {
                                        HttpContext.Current = httpContext;

                                        var reader = transformationInput.InputDocument.CreateReader();
                                        xslTransformer.Transform(reader, transformArgs, writer);
                                    }
                            }
                            catch (ThreadAbortException ex)
                            {
                                exception = ex;
                                Thread.ResetAbort();
                            }
                            catch (Exception ex)
                            {
                                exception = ex;
                            }

                            transformationStopwatch.Stop();

                            millisecondsToken = transformationStopwatch.ElapsedMilliseconds;
                        });

                        thread.Start();
                        bool res = thread.Join(1000);  // sadly, this needs to be low enough to prevent StackOverflowException from fireing.

                        if (res == false)
                        {
                            if (thread.ThreadState == System.Threading.ThreadState.Running)
                            {
                                thread.Abort();
                            }
                            throw new XslLoadException("Transformation took more than 1000 milliseconds to complete. This could be due to a never ending recursive call. Execution aborted to prevent fatal StackOverflowException.");
                        }

                        if (exception != null)
                        {
                            throw exception;
                        }
                    }

                    if (xslt.OutputXmlSubType == "XHTML")
                    {
                        XhtmlDocument xhtmlDocument = new XhtmlDocument(transformationResult);

                        output = xhtmlDocument.Root.ToString();
                    }
                    else
                    {
                        output = transformationResult.Root.ToString();
                    }
                }
                catch (Exception ex)
                {
                    output = "<error/>";
                    error  = string.Format("{0}\n{1}", ex.GetType().Name, ex.Message);

                    Exception inner = ex.InnerException;

                    string indent = "";

                    while (inner != null)
                    {
                        indent = indent + " - ";
                        error  = error + "\n" + indent + inner.Message;
                        inner  = inner.InnerException;
                    }
                }
                finally
                {
                    Thread.CurrentThread.CurrentCulture   = oldCurrentCulture;
                    Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture;
                }

                Page currentPage = HttpContext.Current.Handler as Page;
                if (currentPage == null)
                {
                    throw new InvalidOperationException("The Current HttpContext Handler must be a System.Web.Ui.Page");
                }

                UserControl inOutControl = (UserControl)currentPage.LoadControl(UrlUtils.ResolveAdminUrl("controls/Misc/MarkupInOutView.ascx"));
                inOutControl.Attributes.Add("in", transformationInput.InputDocument.ToString());
                inOutControl.Attributes.Add("out", output);
                inOutControl.Attributes.Add("error", error);
                inOutControl.Attributes.Add("statusmessage", string.Format("Execution times: Total {0} ms. Functions: {1} ms. XSLT: {2} ms.",
                                                                           millisecondsToken + functionCallingStopwatch.ElapsedMilliseconds,
                                                                           functionCallingStopwatch.ElapsedMilliseconds,
                                                                           millisecondsToken));

                FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
                var webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>();
                webRenderService.SetNewPageOutput(inOutControl);
            }
            catch (Exception ex)
            {
                FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
                Control errOutput        = new LiteralControl("<pre>" + ex.ToString() + "</pre>");
                var     webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>();
                webRenderService.SetNewPageOutput(errOutput);
            }
        }