Example #1
0
        /// <summary>
        /// Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The method invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            if (!this.loggers.ContainsKey(invocation.TargetType))
            {
                lock (Mutex)
                {
                    if (!this.loggers.ContainsKey(invocation.TargetType))
                    {
                        this.loggers.Add(invocation.TargetType, factory.Create(invocation.TargetType.ToString()));
                    }
                }
            }
            ILoggerImplementation logger = this.loggers[invocation.TargetType];
            var info = new MethodTraceInfo()
            {
                MachineName         = Environment.MachineName,
                AppDomainName       = AppDomain.CurrentDomain.FriendlyName,
                ThreadIdentityName  = Thread.CurrentPrincipal.Identity.Name,
                WindowsIdentityName = WindowsIdentity.GetCurrent().Name,
                ClassName           = invocation.TargetType.Name,
                MethodName          = invocation.Method.Name,
                Dump = CreateInvocationLogInfo(invocation).ToString()
            };

            logger.TraceMethodCall(info);
            invocation.Proceed();
            logger.TraceEndMethodCall(info);
        }
 public static string FlattenSafe(
     this ILoggerImplementation self, string levelName, Type sender, string message, params object[] args)
 {
     try {
         if (args.Length <= 0)
         {
             return(string.Format("{0} {1} ", sender.FullName, levelName) + message);
         }
         return(string.Format("{0} {1} ", sender.FullName, levelName) + string.Format(message, args));
     } catch (Exception ex) {
         return("[LOGGING ERROR] Failed to format message: " + message + " because of " + ex);
     }
 }
 public LoggerUsingLoggerImplementation(ILoggerImplementation loggerImplementation)
 {
     LoggerImplementation = loggerImplementation;
 }
Example #4
0
 public static void ConfigureImplementation(ILoggerImplementation impl)
 {
     _impl = impl;
 }
Example #5
0
        public static void InitializeToolkit(
            ILoggerImplementation customLogger = null,
            Func <DatagridContent, Task <FileModel> > spreadsheetBuilder = null,
            bool?clickingOutsideOfDialogDismissesIt = null)
        {
            ExecOnUiThread.SetImplementation(
                async x => {
                x();
                await Task.Run(() => {});     //NOP
            },
                async x => {
                await x();
            });

            if (customLogger != null)
            {
                Logger.ConfigureImplementation(customLogger);
            }
            else if (DocumentUtil.HasQueryParameter("debug") && DocumentUtil.GetQueryParameter("debug") == "lite")
            {
                var toIgnoreByType = new [] {
                    typeof(Philadelphia.Web.GeneralAttrChangedObserver),
                    typeof(Philadelphia.Web.GeneralChildListChangedObserver),
                    typeof(Philadelphia.Web.SpecificChildListChangedObserver),
                    typeof(Philadelphia.Web.TooltipManager),
                    typeof(Philadelphia.Web.MouseObserver),
                    typeof(Philadelphia.Web.FormCanvasExtensions),
                    typeof(Philadelphia.Web.SpecificResizeObserver)
                };

                var toIgnoreByBaseName = new [] {
                    typeof(Philadelphia.Web.DataGridColumn <string, Unit>).FullNameWithoutGenerics()
                };

                Logger.ConfigureImplementation(new ForwardMatchingToConsoleLogLoggerImplementation(
                                                   x => !toIgnoreByType.Contains(x) && !toIgnoreByBaseName.Contains(x.FullNameWithoutGenerics())));
            }
            else if (DocumentUtil.HasQueryParameter("debug"))
            {
                Logger.ConfigureImplementation(new ForwardEverythingToConsoleLogLoggerImplementation());
            }
            else
            {
                Logger.ConfigureImplementation(new ForwardErrorsToConsoleLogLoggerImplementation());
            }

            DocumentUtil.Initialize(); //initialize tooltips, esc handler etc

            var env = EnvironmentTypeUtil.GetInstanceFromWindow(Window.Instance);

            Document.Body.SetAttribute(Magics.AttrDataEnvironment, env.AsDataEnvironmentAttributeValue());

            Func <DatagridContent, Task <FileModel> > noExportImpl =
                _ => {
                throw new Exception("spreadsheet builder not provided via DataGridSettings.Init()");
            };

            DataGridSettings.Init(spreadsheetBuilder ?? noExportImpl);

            Document.OnDragEnter += ev => {
                Document.Body.SetAttribute(Magics.AttrDataDraggingFile, "x");
                ev.PreventDefault();
            };
            //detect real end of dragging (leaving outside of browser)
            //https://stackoverflow.com/questions/3144881/how-do-i-detect-a-html5-drag-event-entering-and-leaving-the-window-like-gmail-d#14248483
            Document.OnDragLeave += ev => {
                var clientX = (int)ev.GetFieldValue("clientX");
                var clientY = (int)ev.GetFieldValue("clientY");

                if (clientX <= 0 || clientY <= 0)
                {
                    Document.Body.RemoveAttribute(Magics.AttrDataDraggingFile);
                }

                Logger.Debug(typeof(Toolkit), "Document dragleave {0}", ev.Target);
            };

            switch (env)
            {
            case EnvironmentType.Desktop:
                BaseFormCanvasTitleStrategy           = x => new RegularDomElementTitleFormCanvasStrategy(x);
                BaseFormCanvasExitButtonBuilderOrNull = DefaultExitButtonBuilder;
                ClickingOutsideOfDialogDismissesIt    = clickingOutsideOfDialogDismissesIt ?? false;
                break;

            case EnvironmentType.IndustrialAndroidWebApp:
                BaseFormCanvasTitleStrategy           = x => new BodyBasedPropagatesToAppBatTitleFormCanvasStrategy(x);
                BaseFormCanvasExitButtonBuilderOrNull = null;
                ClickingOutsideOfDialogDismissesIt    = clickingOutsideOfDialogDismissesIt ?? true;

                IawAppApi.SetOnBackPressed(() => {
                    Logger.Debug(typeof(Toolkit), "backbutton pressed");
                    var consumed = DocumentUtil.TryCloseTopMostForm();
                    Logger.Debug(typeof(Toolkit), "backbutton consumed?={0}", consumed);
                    return(consumed);
                });
                break;

            default: throw new Exception("unsupported environment");
            }
        }