internal static void GoIntoScope(LoggingScope loggingScope)
        {
            NeedUpdateCurrentValue = true;
            var scopedRootEventId = LogEventIdFactory.Create(name: loggingScope.ToString());

            scopedRootEventId.LoggingScopeTraceId = loggingScope.TranceId;
        }
Exemple #2
0
 public LinqToSparqlExpTranslator(StringBuilder stringBuilder)
 {
     using (var ls = new LoggingScope("LinqToSparqlExpTranslator ctor"))
     {
         this.stringBuilder = stringBuilder;
     }
 }
 /// <inheritdoc />
 public IDisposable BeginScope <TState>(TState state)
 {
     if (state == null)
     {
         throw new ArgumentNullException(nameof(state));
     }
     return(LoggingScope.Push(StateNamespace, state));
 }
            public static LoggingScope Push(object state)
            {
                var current = currentScope.Value;
                var next    = new LoggingScope(state, current);

                currentScope.Value = next;
                return(next);
            }
        public MainWindow()
        {
            this.InitializeComponent();
#if DEBUG
            this.AttachDevTools();
#endif
            using var initScope = new TimedScope(LoggingScope.Global($"{nameof(MainWindow)}.InitializeServices"));

            Session = new Session();

            var menuProvider = new MenuProvider();
            Services.AddService <IMenuProvider>(menuProvider);

            Session.EditorViewModel = new EditorViewModel(menuProvider);
            Session.Services        = Services;

            Services.AddService <Window>(this);
            Services.AddService <Session>(Session);
            Services.AddService <IRootViewModelContainer>(Session);
            Services.AddService <ViewRegistry>(new ViewRegistry());
            Services.AddService <IDialogService>(new DialogService(Services));

            var viewDataTemplate = new ViewDataTemplate(Services);
            Services.AddService <IViewUpdater>(viewDataTemplate);
            DataTemplates.Add(viewDataTemplate);

            Services.AddService <IUndoService>(new UndoService());
            Services.AddService <IMemberViewProvider <IViewBuilder> >(new MemberViewProvider(Services));

            var commandDispatcher = new CommandDispatcher(Services);
            Services.AddService <ICommandDispatcher>(commandDispatcher);
            // after all synchronous code caused by user input has been executed
            // we begin the commands processing.
            InputManager.Instance.PostProcess.Subscribe(async(e) => await commandDispatcher.ProcessDispatchedCommands());

            var tabManager = new SimpleTabManager(Services);
            Services.AddService <ITabManager>(tabManager);
            Services.AddService <SimpleTabManager>(tabManager);

            var assetManager = new AssetManager(Services);
            Services.AddService <IAssetManager>(assetManager);
            Services.AddService <IAssetEditorRegistry>(assetManager);

            var pluginRegistry = new PluginRegistry(Services);
            pluginRegistry.RefreshAvailablePlugins();

            Services.AddService <PluginRegistry>(pluginRegistry);

            foreach (var initialPlugin in pluginRegistry.AvailablePlugins)
            {
                pluginRegistry.Register(initialPlugin);
            }

            // It will be rendered by the DataTemplate
            DataContext = Session.EditorViewModel;
        }
        /// <summary>
        /// Invokes the specified environment.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public override async Task Invoke(IOwinContext context)
        {
            var method    = context.Request.Method;
            var path      = context.Request.Path;
            var scopeName = $"{path} [{method}]";

            using (var scope = new LoggingScope(scopeName))
            {
                await Next.Invoke(context);

                scope.Log("Status Code: {0}", context.Response.StatusCode);
            }
        }
Exemple #7
0
        public IEnumerator <T> ExecuteQuery()
        {
            using (var loggingScope = new LoggingScope("SparqlCommand<T>.ExecuteQuery()"))
            {
                #region Tracing
#line hidden
                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug("{0}.", CommandText);
                }
#line default
                #endregion
                MethodCallExpression e       = null;
                IList <T>            results = new List <T>();
                switch (Connection.Store.QueryMethod)
                {
                case LinqQueryMethod.CustomSparql:
                case LinqQueryMethod.GenericSparql:
                case LinqQueryMethod.InMemorySparql:
                case LinqQueryMethod.NativeSparql:
                case LinqQueryMethod.RemoteSparql:
                    //Set up the Connection and the Results Sink
                    LinqToSparqlConnection <T> connection = (LinqToSparqlConnection <T>)Connection;
                    if (connection.SparqlQuery.Expressions.ContainsKey("Select"))
                    {
                        e = connection.SparqlQuery.Expressions["Select"];
                    }
                    ObjectDeserialiserQuerySink sink = new ObjectDeserialiserQuerySink(connection.SparqlQuery.OriginalType, typeof(T), InstanceName, ElideDuplicates, e, (RdfDataContext)connection.SparqlQuery.DataContext);

                    //Compile and Parse the Query
                    DateTime    beforeQueryCompilation = DateTime.Now;
                    SparqlQuery query = this._parser.ParseFromString(CommandText);
                    DateTime    afterQueryCompilation = DateTime.Now;
                    DateTime    beforeQueryRun        = DateTime.Now;

                    //Run the Query
                    connection.Store.QueryProcessor.Run(query, sink);

                    //Extract and Register Results
                    DateTime afterQueryRun = DateTime.Now;
                    ExtractResultsIntoList(results, sink);
                    RegisterResults(connection.SparqlQuery, results);

                    break;

                default:
                    break;
                }
                return(results.GetEnumerator());
            }
        }
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }
            if (logLevel < minLogLevel)
            {
                return;
            }
            var message = formatter(state, exception);

            if (string.IsNullOrEmpty(message))
            {
                return;
            }
            var sb = new StringBuilder();

            sb.Append(logLevel);
            sb.Append(": ");
            var leftMargin = sb.Length;

            sb.Append(Name);
            if (LoggingScope.Current != null)
            {
                sb.AppendLine();
                sb.Append(' ', leftMargin);
                foreach (var scope in LoggingScope.Trace())
                {
                    sb.Append(" -> ");
                    sb.Append(scope.State);
                }
            }
            sb.AppendLine();
            sb.Append(' ', leftMargin);
            sb.Append(message);
            if (exception != null)
            {
                sb.AppendLine();
                sb.Append(' ', leftMargin);
                sb.Append(exception);
            }
            Output.WriteLine(sb.ToString());
        }
Exemple #9
0
        public async Task <PackageSessionResult> LoadProject(string path)
        {
            var viewUpdater = Services.GetService <IViewUpdater>();

            PackageSessionResult sessionResult = await SetupResultProgress(viewUpdater, LoadProjectScope);

            using (var scope = new TimedScope(LoadProjectScope, TimedScope.Status.Failure))
            {
                // Force PackageSession.Load to be executed on the thread pool
                // otherwise it would block execution and we want this process to be async
                await Task.Run(() =>
                {
                    PackageSession.Load(path, sessionResult);
                }).ConfigureAwait(false);

                PackageSession = sessionResult.Session;

                foreach (var pkg in PackageSession.LocalPackages)
                {
                    pkg.UpdateAssemblyReferences(LoggingScope.Global($"{nameof(Session)}.{nameof(pkg.UpdateAssemblyReferences)}"));
                }

                if (!sessionResult.HasErrors)
                {
                    scope.Result = TimedScope.Status.Success;
                }
            }

            // Create asset browser for package and add it to the viewmodel
            var browser = new AssetBrowserViewModel(PackageSession);
            await Services.GetService <ITabManager>().CreateToolTab(browser);

            EditorViewModel.LoadingStatus = null;
            await viewUpdater.UpdateView();

            ProjectLoaded?.Invoke(sessionResult);

            return(sessionResult);
        }
 private LoggingScope(object state, LoggingScope parent)
 {
     State  = state;
     Parent = parent;
 }
 public IDisposable BeginScope <TState>(TState state)
 {
     return(LoggingScope.Push(state));
 }
Exemple #12
0
        private async Task <PackageSessionResult> SetupResultProgress(IViewUpdater viewUpdater, LoggingScope scope)
        {
            EditorViewModel.LoadingStatus = new LoadingStatus(LoadingStatus.LoadingMode.Indeterminate);
            await viewUpdater.UpdateView();

            // in this result will be any errors from loading the project
            var sessionResult = new PackageSessionResult();

            sessionResult.MessageLogged   += (_, e) => scope.Log(e.Message);
            sessionResult.ProgressChanged += async(_, e) =>
            {
                if (e.HasKnownSteps && e.CurrentStep > 0)
                {
                    var percentage    = EditorViewModel.LoadingStatus.PercentCompleted;
                    var newPercentage = 100 * e.CurrentStep / e.StepCount;
                    EditorViewModel.LoadingStatus.Mode             = LoadingStatus.LoadingMode.Percentage;
                    EditorViewModel.LoadingStatus.PercentCompleted = newPercentage;
                }
                else
                {
                    EditorViewModel.LoadingStatus.Mode = LoadingStatus.LoadingMode.Indeterminate;
                }
                EditorViewModel.LoadingStatus.Message = e.Message;

                await viewUpdater.UpdateView();
            };
            return(sessionResult);
        }
 public void WriteLine(string line) => _next.WriteLine(LoggingScope.GetIndentation() + line);