Beispiel #1
0
        public virtual void SaveLog(LogEntry logEntry)
        {
            ConsoleColor originalColor = Console.ForegroundColor;

            try
            {
                switch (logEntry.Severity)
                {
                case "Information":
                    Console.ForegroundColor = ConsoleColor.White;
                    break;

                case "Warning":
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    break;

                default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    break;
                }

                Console.WriteLine(_formatter.Serialize(logEntry) + Environment.NewLine);
            }
            finally
            {
                Console.ForegroundColor = originalColor;
            }
        }
 public virtual void SaveLog(LogEntry logEntry)
 {
     if (Debugger.IsAttached)
     {
         Debug.WriteLine(_formatter.Serialize(logEntry) + Environment.NewLine);
     }
 }
Beispiel #3
0
        public virtual DefaultPageModel GetDefaultPageModel()
        {
            AppEnvironment activeAppEnvironment = _appEnvironmentProvider.GetActiveAppEnvironment();

            DefaultPageModel defaultPageModel = new DefaultPageModel
            {
                AppVersion = activeAppEnvironment.AppInfo.Version,
                DebugMode  = activeAppEnvironment.DebugMode,
                AppName    = activeAppEnvironment.AppInfo.Name
            };

            UserSetting userSetting = _usersSettingsProvider?.GetCurrentUserSetting();

            string theme = userSetting?.Theme ?? activeAppEnvironment.AppInfo.DefaultTheme;

            string culture = userSetting?.Culture ?? activeAppEnvironment.AppInfo.DefaultCulture;

            string desiredTimeZone = userSetting?.DesiredTimeZone ??
                                     activeAppEnvironment.AppInfo.DefaultTimeZone;

            string desiredTimeZoneValue = null;

            if (culture == null || string.Equals(culture, "Auto", StringComparison.OrdinalIgnoreCase))
            {
                culture = "EnUs";
            }

            if (desiredTimeZone != null &&
                !string.Equals(desiredTimeZone, "Auto", StringComparison.CurrentCulture))
            {
                desiredTimeZoneValue = desiredTimeZone;
            }

            string appTitle = activeAppEnvironment.Cultures.Any() ? activeAppEnvironment.Cultures
                              .ExtendedSingle($"Finding culture {culture} in environment {activeAppEnvironment.Name}", c => c.Name == culture).Values.ExtendedSingle($"Finding AppTitle in culture {culture}", v =>
                                                                                                                                                                     string.Equals(v.Name, "AppTitle", StringComparison.OrdinalIgnoreCase)).Title : string.Empty;

            defaultPageModel.AppTitle             = appTitle;
            defaultPageModel.Culture              = culture;
            defaultPageModel.DesiredTimeZoneValue = desiredTimeZoneValue;
            defaultPageModel.Theme = theme;

            defaultPageModel.EnvironmentConfigsJSON = _contentFormatter.Serialize(activeAppEnvironment
                                                                                  .Configs.Where(c => c.AccessibleInClientSide == true)
                                                                                  .Select(c => new { value = c.Value, key = c.Key }));

            defaultPageModel.BaseHref = activeAppEnvironment.GetHostVirtualPath();

            return(defaultPageModel);
        }
Beispiel #4
0
        public virtual Task SaveLogAsync(LogEntry logEntry)
        {
            if (logEntry == null)
            {
                throw new ArgumentNullException(nameof(logEntry));
            }

            EventLog appLog = new EventLog("Application")
            {
                Source = _activeAppEnvironment.AppInfo.Name
            };

            EventLogEntryType eventLogsSeverity;

            if (logEntry.Severity == "Warning")
            {
                eventLogsSeverity = EventLogEntryType.Warning;
            }
            else if (logEntry.Severity == "Information")
            {
                eventLogsSeverity = EventLogEntryType.Information;
            }
            else
            {
                eventLogsSeverity = EventLogEntryType.Error;
            }

            string logContents = _contentFormatter.Serialize(logEntry);

            if (logContents.Length >= 30000)
            {
                logContents = logContents.Substring(0, 29999);
            }

            if (_activeAppEnvironment.TryGetConfig("EventLogId", out long eventLogId))
            {
                appLog.WriteEntry(logContents, eventLogsSeverity, Convert.ToInt32(eventLogId));
            }
            else
            {
                appLog.WriteEntry(logContents, eventLogsSeverity);
            }

            return(Task.FromResult <object>(null));
        }
        internal void EmitCode(ILightNodeOptions options, IDictionary<string, object> environment)
        {
            environment[OwinConstants.ResponseStatusCode] = (int)StatusCode;
            if (ReasonPhrase != null)
            {
                environment[OwinConstants.ResponseReasonPhrase] = ReasonPhrase;
            }
            if (content != null)
            {
                contentFormatter = contentFormatter ?? options.DefaultFormatter;
                var encoding = contentFormatter.Encoding;
                var responseHeader = environment.AsResponseHeaders();
                responseHeader["Content-Type"] = new[] { contentFormatter.MediaType + ((encoding == null) ? "" : "; charset=" + encoding.WebName) };

                if (environmentEmitter != null)
                {
                    environmentEmitter(environment);
                }

                var responseStream = environment.AsResponseBody();
                if (options.StreamWriteOption == StreamWriteOption.DirectWrite)
                {
                    contentFormatter.Serialize(new UnclosableStream(responseStream), content);
                }
                else
                {
                    using (var buffer = new MemoryStream())
                    {
                        contentFormatter.Serialize(new UnclosableStream(buffer), content);
                        responseHeader["Content-Length"] = new[] { buffer.Position.ToString() };
                        buffer.Position = 0;
                        if (options.StreamWriteOption == StreamWriteOption.BufferAndWrite)
                        {
                            buffer.CopyTo(responseStream); // not CopyToAsync
                        }
                        else
                        {
                            // EmitCode is void:)
                            buffer.CopyTo(responseStream);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        internal void EmitCode(ILightNodeOptions options, IDictionary <string, object> environment)
        {
            environment[OwinConstants.ResponseStatusCode] = (int)StatusCode;
            if (ReasonPhrase != null)
            {
                environment[OwinConstants.ResponseReasonPhrase] = ReasonPhrase;
            }
            if (content != null)
            {
                contentFormatter = contentFormatter ?? options.DefaultFormatter;
                var encoding       = contentFormatter.Encoding;
                var responseHeader = environment.AsResponseHeaders();
                responseHeader["Content-Type"] = new[] { contentFormatter.MediaType + ((encoding == null) ? "" : "; charset=" + encoding.WebName) };

                if (environmentEmitter != null)
                {
                    environmentEmitter(environment);
                }

                var responseStream = environment.AsResponseBody();
                if (options.StreamWriteOption == StreamWriteOption.DirectWrite)
                {
                    contentFormatter.Serialize(new UnclosableStream(responseStream), content);
                }
                else
                {
                    using (var buffer = new MemoryStream())
                    {
                        contentFormatter.Serialize(new UnclosableStream(buffer), content);
                        responseHeader["Content-Length"] = new[] { buffer.Position.ToString() };
                        buffer.Position = 0;
                        if (options.StreamWriteOption == StreamWriteOption.BufferAndWrite)
                        {
                            buffer.CopyTo(responseStream); // not CopyToAsync
                        }
                        else
                        {
                            // EmitCode is void:)
                            buffer.CopyTo(responseStream);
                        }
                    }
                }
            }
        }
 public virtual SSOPageModel GetSSOPageModel()
 {
     return(new SSOPageModel
     {
         AppTitle = _activeAppEnvironment
                    .Cultures
                    .Single(c => c.Name == _activeAppEnvironment.AppInfo.DefaultCulture)
                    .Values
                    .Single(v => v.Name == "AppTitle").Title,
         AppName = _activeAppEnvironment.AppInfo.Name,
         AppVersion = _activeAppEnvironment.AppInfo.Version,
         Culture = _activeAppEnvironment.AppInfo.DefaultCulture,
         DebugMode = _activeAppEnvironment.DebugMode,
         DesiredTimeZoneValue = _activeAppEnvironment.AppInfo.DefaultTimeZone,
         Theme = _activeAppEnvironment.AppInfo.DefaultTheme,
         EnvironmentConfigsJSON = _contentFormatter.Serialize(_activeAppEnvironment
                                                              .Configs.Where(c => c.AccessibleInClientSide == true)
                                                              .Select(c => new { value = c.Value, key = c.Key })),
         BaseHref = _activeAppEnvironment.GetConfig("ClientHostVirtualPath", "/")
     });
 }
Beispiel #8
0
        public override async Task Invoke(IOwinContext context)
        {
            IContentFormatter contentFormatter =
                context.GetDependencyResolver().Resolve <IContentFormatter>();

            IAppMetadataProvider appMetadataProvider =
                context.GetDependencyResolver().Resolve <IAppMetadataProvider>();

            context.Response.ContentType = "application/json; charset=utf-8";

            await context.Response.WriteAsync(contentFormatter.Serialize(await appMetadataProvider.GetAppMetadata()), context.Request.CallCancelled);
        }
        internal void EmitCode(IIMOwinOptions options, IDictionary<string, object> environment)
        {
            environment[OwinConstants.ResponseStatusCode] = (int)StatusCode;
            if (ReasonPhrase != null)
            {
                environment[OwinConstants.ResponseReasonPhrase] = ReasonPhrase;
            }
            if (Content != null)
            {
                _contentFormatter = _contentFormatter ?? options.ContentFormatter;
                var encoding = _contentFormatter.Encoding;
                var responseHeader = environment.AsResponseHeaders();
                responseHeader["Content-Type"] = new[] { _contentFormatter.MediaType + ((encoding == null) ? "" : "; charset=" + encoding.WebName) };

                var responseStream = environment.AsResponseBody();
                if (options.StreamWriteOption == StreamWriteOption.DirectWrite)
                {
                    _contentFormatter.Serialize(new UnclosableStream(responseStream), Content);
                }
                else
                {
                    using (var buffer = new MemoryStream())
                    {
                        _contentFormatter.Serialize(new UnclosableStream(buffer), Content);
                        responseHeader["Content-Length"] = new[] { buffer.Position.ToString(CultureInfo.InvariantCulture) };
                        buffer.Position = 0;
                        if (options.StreamWriteOption == StreamWriteOption.BufferAndWrite)
                        {
                            buffer.CopyTo(responseStream); // not CopyToAsync
                        }
                        else
                        {
                            // can't await in catch clouse..
                            // return buffer.CopyToAsync(responseStream);
                            buffer.CopyTo(responseStream);
                        }
                    }
                }
            }
        }
        internal void EmitCode(ILightNodeOptions options, HttpContext httpContext)
        {
            httpContext.Response.StatusCode = (int)StatusCode;
   
            if (content != null)
            {
                contentFormatter = contentFormatter ?? options.DefaultFormatter;
                var encoding = contentFormatter.Encoding;
                var responseHeader = httpContext.Response.Headers;
                responseHeader["Content-Type"] = new[] { contentFormatter.MediaType + ((encoding == null) ? "" : "; charset=" + encoding.WebName) };

                contextEmitter?.Invoke(httpContext);

                var responseStream = httpContext.Response.Body;
                if (options.StreamWriteOption == StreamWriteOption.DirectWrite)
                {
                    contentFormatter.Serialize(new UnclosableStream(responseStream), content);
                }
                else
                {
                    using (var buffer = new MemoryStream())
                    {
                        contentFormatter.Serialize(new UnclosableStream(buffer), content);
                        responseHeader["Content-Length"] = new[] { buffer.Position.ToString() };
                        buffer.Position = 0;
                        if (options.StreamWriteOption == StreamWriteOption.BufferAndWrite)
                        {
                            buffer.CopyTo(responseStream); // not CopyToAsync
                        }
                        else
                        {
                            // EmitCode is void:)
                            buffer.CopyTo(responseStream);
                        }
                    }
                }
            }
        }
Beispiel #11
0
        internal void EmitCode(ILightNodeOptions options, HttpContext httpContext)
        {
            httpContext.Response.StatusCode = (int)StatusCode;

            if (content != null)
            {
                contentFormatter = contentFormatter ?? options.DefaultFormatter;
                var encoding       = contentFormatter.Encoding;
                var responseHeader = httpContext.Response.Headers;
                responseHeader["Content-Type"] = new[] { contentFormatter.MediaType + ((encoding == null) ? "" : "; charset=" + encoding.WebName) };

                contextEmitter?.Invoke(httpContext);

                var responseStream = httpContext.Response.Body;
                if (options.StreamWriteOption == StreamWriteOption.DirectWrite)
                {
                    contentFormatter.Serialize(new UnclosableStream(responseStream), content);
                }
                else
                {
                    using (var buffer = new MemoryStream())
                    {
                        contentFormatter.Serialize(new UnclosableStream(buffer), content);
                        responseHeader["Content-Length"] = new[] { buffer.Position.ToString() };
                        buffer.Position = 0;
                        if (options.StreamWriteOption == StreamWriteOption.BufferAndWrite)
                        {
                            buffer.CopyTo(responseStream); // not CopyToAsync
                        }
                        else
                        {
                            // EmitCode is void:)
                            buffer.CopyTo(responseStream);
                        }
                    }
                }
            }
        }
Beispiel #12
0
        public override async Task Invoke(IOwinContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            IContentFormatter contentFormatter =
                context.GetDependencyResolver().Resolve <IContentFormatter>();

            IAppMetadataProvider appMetadataProvider =
                context.GetDependencyResolver().Resolve <IAppMetadataProvider>();

            context.Response.ContentType = "application/json; charset=utf-8";

            await context.Response.WriteAsync(contentFormatter.Serialize(await appMetadataProvider.GetAppMetadata().ConfigureAwait(false)), context.Request.CallCancelled).ConfigureAwait(false);
        }
Beispiel #13
0
        public async Task Invoke(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            IContentFormatter contentFormatter =
                context.RequestServices.GetService <IContentFormatter>();

            IAppMetadataProvider appMetadataProvider =
                context.RequestServices.GetService <IAppMetadataProvider>();

            context.Response.ContentType = "application/json; charset=utf-8";

            await context.Response.WriteAsync(contentFormatter.Serialize(await appMetadataProvider.GetAppMetadata().ConfigureAwait(false)), context.RequestAborted).ConfigureAwait(false);
        }