Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthTokenController" /> class.
 /// </summary>
 /// <param name="repositoryService">IRepositoryService</param>
 /// <param name="userService">IUserService</param>
 /// <param name="repositoryAdapterFactory">IRepositoryAdapterFactory</param>
 public AuthTokenController(IRepositoryService repositoryService, IUserService userService)
 {
     this.repositoryService = repositoryService;
     this.userService       = userService;
     this.diagnostics       = new DiagnosticsProvider(this.GetType());
     this.user = IdentityHelper.GetCurrentUser(this.userService, this.User as ClaimsPrincipal);
 }
        /// <summary>
        /// Initializes the specified event source.
        /// </summary>
        /// <param name="eventSource">The event source.</param>
        public override void Initialize(IEventSource eventSource)
        {
            // get log file path from incoming parameters
            var logFile = GetLogFilePath(this.Parameters);


#if DEBUG
            this.diagnostics = DiagnosticsProvider.GetLogger();
            this.diagnostics.WriteMessage($"Parameters: {this.Parameters}");
            this.diagnostics.WriteMessage($"Verbosity level: {this.Verbosity}");
#endif

            try
            {
                // open the file
                this.streamWriter = new StreamWriter(logFile);

                // start JSON logging
                this.BeginJsonArray();

                // initialize JSON.NET writer
                this.jsonWriter            = new JsonTextWriter(this.streamWriter);
                this.jsonWriter.Formatting = Formatting.Indented;

                // initialize serializer
                this.serializer = new JsonSerializer();
            }
            catch (Exception ex)
            {
#if DEBUG
                // let's look at it
                this.diagnostics.WriteException(ex);
#endif

                if
                (
                    ex is UnauthorizedAccessException ||
                    ex is ArgumentNullException ||
                    ex is PathTooLongException ||
                    ex is DirectoryNotFoundException ||
                    ex is NotSupportedException ||
                    ex is ArgumentException ||
                    ex is SecurityException ||
                    ex is IOException
                )
                {
                    throw new LoggerException("Failed to create log file: " + ex.Message);
                }
                else
                {
                    // Unexpected failure
                    throw;
                }
            }

            // Occurs when a build raises any other type of build event.
            // Not sensitive to chosen MsBuild Verbosity level
            // Default logger behavior
            eventSource.AnyEventRaised += this.HandleEventSourceEvent;
        }
Beispiel #3
0
        private static void DumpDiagnostics(HostOptions options, Microsoft.Extensions.Logging.ILogger logger)
        {
            var providerText = new List <string>();

            providerText.AddRange(
                new[] { options.DistributedTraceProvider, options.LoggingProvider, options.MetricsProvider }
                .Where(p => p is object)
                .Cast <string>());

            foreach (var text in providerText)
            {
                if (DiagnosticsProvider.TryParse(text, out var provider))
                {
                    if (DiagnosticsProvider.WellKnownProviders.TryGetValue(provider.Key, out var wellKnown))
                    {
                        logger.LogInformation(wellKnown.LogFormat, provider.Value);
                    }
                    else
                    {
                        logger.LogWarning("Unknown diagnostics provider {Key}:{Value}", provider.Key, provider.Value);
                    }
                }
                else
                {
                    logger.LogError("Could not parse provider argument: {Arg}", text);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Executes when Unhandled Exception is thrown.
        /// </summary>
        /// <param name="context">ActionExecuted Context</param>
        public override void OnException(HttpActionExecutedContext context)
        {
            DiagnosticsProvider diagnostics = new DiagnosticsProvider(this.GetType());
            Exception           exception   = context.Exception;

            diagnostics.WriteErrorTrace(TraceEventId.Exception, exception);
            context.Response = context.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message);
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QCController" /> class.
 /// </summary>
 /// <param name="qcService">IQC Service object.</param>
 /// <param name="fileServiceFactory">File service factory</param>
 /// <param name="userService">User service</param>
 public QCController(IQCService qcService, IFileServiceFactory fileServiceFactory, IUserService userService)
 {
     this.qcService          = qcService;
     this.fileServiceFactory = fileServiceFactory;
     this.userService        = userService;
     this.user        = IdentityHelper.GetCurrentUser(this.userService, this.User as ClaimsPrincipal);
     this.diagnostics = new DiagnosticsProvider(this.GetType());
 }
Beispiel #6
0
            public void TestDiagnosticNoErrors()
            {
                var errors = new List <FakeElementObject>();
                IDiagnosticsProvider diagnosticsService = new DiagnosticsProvider(new FileRepository(new PhysicalFile()));

                var diagnostics = diagnosticsService.ConvertToLSPDiagnostics(errors);

                Assert.AreEqual(0, diagnostics.Count);
            }
        /// <summary>
        /// Invokes the DiagnosticProvider to assemble diagnsotics
        /// </summary>
        /// <returns>Diagnostics ready to publish</returns>
        private PublishDiagnosticsParams GetDiagnostics(Uri uri, IFileRepository fileRepository)
        {
            _log.LogInformation(Resources.LoggingMessages.request_update_diagnostics);
            _mss.SendCurrentDocumentInProcess(fileRepository.PhysicalFile.Filepath);
            IFileRepository      repo     = _workspaceManager.GetFileRepository(uri);
            IDiagnosticsProvider provider = new DiagnosticsProvider(repo);
            var diags = provider.GetPublishableDiagnostics();

            return(diags);
        }
Beispiel #8
0
 /// <summary>
 /// Instantiates the PublishController
 /// </summary>
 public PublishController(IPublishQueueService publishQueueService, IUserService userService, IRepositoryService repositoryService, IFileServiceFactory fileServiceFactory)
     : base()
 {
     diagnostics = new DiagnosticsProvider(this.GetType());
     this.publishQueueService = publishQueueService;
     this.userService         = userService;
     this.repositoryService   = repositoryService;
     this.fileServiceFactory  = fileServiceFactory;
     this.user = IdentityHelper.GetCurrentUser(this.userService, this.User as ClaimsPrincipal);
 }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilesController" /> class.
 /// </summary>
 /// <param name="fileServiceFactory">IFileServiceFactory</param>
 /// <param name="repositoryService">IRepositoryService</param>
 /// <param name="qcService">IQCService</param>
 /// <param name="userService">IUserService</param>
 /// <param name="repositoryAdapterFactory">IRepositoryAdapterFactory</param>
 public FilesController(IFileServiceFactory fileServiceFactory, IRepositoryService repositoryService, IQCService qcService, IUserService userService, IRepositoryAdapterFactory repositoryAdapterFactory)
 {
     this.repositoryService        = repositoryService;
     this.qcService                = qcService;
     this.fileServiceFactory       = fileServiceFactory;
     this.userService              = userService;
     this.fileService              = fileServiceFactory.GetFileService(BaseRepositoryEnum.Default.ToString());
     this.diagnostics              = new DiagnosticsProvider(this.GetType());
     this.repositoryAdapterFactory = repositoryAdapterFactory;
     this.user = IdentityHelper.GetCurrentUser(this.userService, this.User as ClaimsPrincipal);
 }
Beispiel #10
0
        private static void HandleTaskStarted(
            TaskStartedEvent e)
        {
            var diagnosticsLog = new DiagnosticsLog(
                DiagnosticsProvider.GetGlobalDiagnostic(),
                DiagnosticsProvider.GetFirstDiagnostic());

            var log = new TaskExecutionLog(diagnosticsLog);

            log.TaskDuration.SetStart(e.Timestamp);

            e.Task.SetExecutionLog(log);
        }
Beispiel #11
0
        public override void Registered(EntityManager entityManager)
        {
            DiagnosticsProvider.EnableGroup <ChunkRegionLoadingDiagnosticGroup>();

            InputManager.Instance.RegisterInputAction(() => Log.Debug(string.Format(FormatHelper.DEFAULT_LOGGING, nameof(ChunkRegionSystem),
                                                                                    $"Average update time: {DiagnosticsProvider.GetGroup<ChunkRegionLoadingDiagnosticGroup>().Average():0.00}ms")), Key.ShiftLeft, Key.X);
            InputManager.Instance.RegisterInputAction(() =>
            {
                foreach (Chunk chunk in _VoxelWorld.Entities.Select(entity => entity.Component <Chunk>() !))
                {
                    chunk !.State = GenerationState.AwaitingMesh;
                }
            }, Key.ShiftLeft, Key.R);
        }
Beispiel #12
0
            public void TestDiagnosticOneError()
            {
                var errors = new List <FakeElementObject>();
                var info   = new FakeElementObject(token, "Msg");

                errors.Add(info);

                IDiagnosticsProvider diagnosticsService = new DiagnosticsProvider(new FileRepository(createFakeFile(token.filename, randomFakeSource)));

                var diagnostics = diagnosticsService.ConvertToLSPDiagnostics(errors);

                Assert.AreEqual(1, diagnostics.Count);
                Assert.AreEqual(token.filename, diagnostics[0].Source);
            }
Beispiel #13
0
        public BlobController(IFileServiceFactory fileServiceFactory, IUserService userService, IFileHandlerFactory fileHandlerFactory)
        {
            Check.IsNotNull(fileServiceFactory, "fileServiceFactory");
            Check.IsNotNull(userService, "userService");
            Check.IsNotNull(fileHandlerFactory, "fileHandlerFactory");
            diagnostics = new DiagnosticsProvider(this.GetType());

            this.userService = userService;
            this.fileService = fileServiceFactory.GetFileService(Constants.Default);

            // get the current/signed in user
            this.user = IdentityHelper.GetCurrentUser(this.userService, this.User as ClaimsPrincipal);
            this.fileHandlerFactory = fileHandlerFactory;
        }
Beispiel #14
0
        private static void TryAddDiagnostic(
            DateTime timestamp,
            TaskExecutionLog log,
            bool isLastDiagnostic = false)
        {
            var diagnosticsLog   = log.DiagnosticsLog;
            var latestDiagnostic = diagnosticsLog.GetLatestDiagnostic();

            if (isLastDiagnostic && diagnosticsLog.HasFirstDiagnosticOnly() ||
                timestamp - latestDiagnostic.Timestamp >= DiagnosticMinInterval)
            {
                var diagnostic = DiagnosticsProvider.GetDiagnostic(latestDiagnostic);
                diagnosticsLog.AddDiagnostic(diagnostic);
            }
        }
Beispiel #15
0
            public void TestDiagnosticSubError()
            {
                var errors      = new List <FakeElementObject>();
                var errorObject = new FakeElementObject(token, "Msg");

                errorObject.AddAuxInfo(token, "SubMsg");
                errorObject.AddAuxInfo(token, "SubMsg2");
                errors.Add(errorObject);

                IDiagnosticsProvider diagnosticsService = new DiagnosticsProvider(new FileRepository(createFakeFile(token.filename, randomFakeSource)));

                var diagnostics = diagnosticsService.ConvertToLSPDiagnostics(errors);

                Assert.AreEqual(3, diagnostics.Count);
                Assert.IsNull(diagnostics.FirstOrDefault()?.RelatedInformation, "Related Diagnostic should be separate");
            }
Beispiel #16
0
        protected void Application_Error(object sender, EventArgs e)
        {
            // Get the error details
            Exception ex = Server.GetLastError();

            // Check exception type and default Http 500 (internal server error)
            Response.StatusCode = (ex is HttpException) ? (ex as HttpException).GetHttpCode() : (int)HttpStatusCode.InternalServerError;

            // Log exception
            DiagnosticsProvider diagnostics = new DiagnosticsProvider(this.GetType());
            string error = string.Join("\n", "Unhandled Exception: ", ex.ToString());

            diagnostics.WriteErrorTrace(TraceEventId.Exception, error);

            // Clear buffers
            Server.ClearError();
            Response.End();
        }
Beispiel #17
0
        private static AggregateApplicationProcessor CreateApplicationProcessor(ReplicaRegistry replicaRegistry, HostOptions options, Microsoft.Extensions.Logging.ILogger logger)
        {
            var diagnosticsCollector = new DiagnosticsCollector(logger)
            {
                // Local run always uses metrics for the dashboard
                MetricSink = new MetricSink(logger),
            };

            if (options.LoggingProvider != null &&
                DiagnosticsProvider.TryParse(options.LoggingProvider, out var logging))
            {
                diagnosticsCollector.LoggingSink = new LoggingSink(logger, logging);
            }

            if (options.DistributedTraceProvider != null &&
                DiagnosticsProvider.TryParse(options.DistributedTraceProvider, out var tracing))
            {
                diagnosticsCollector.TracingSink = new TracingSink(logger, tracing);
            }

            // Print out what providers were selected and their values
            DumpDiagnostics(options, logger);

            var processors = new List <IApplicationProcessor>
            {
                new EventPipeDiagnosticsRunner(logger, diagnosticsCollector),
                new PortAssigner(logger),
                new ProxyService(logger),
                new HttpProxyService(logger),
                new DockerImagePuller(logger),
                new FuncFinder(logger),
                new ReplicaMonitor(logger),
                new DockerRunner(logger, replicaRegistry),
                new ProcessRunner(logger, replicaRegistry, ProcessRunnerOptions.FromHostOptions(options))
            };

            // If the docker command is specified then transform the ProjectRunInfo into DockerRunInfo
            if (options.Docker)
            {
                processors.Insert(0, new TransformProjectsIntoContainers(logger));
            }

            return(new AggregateApplicationProcessor(processors));
        }
        public void Execute(Raven.Database.DocumentDatabase database)
        {
            // First step setup diagnostics:
            DiagnosticsProvider.Initialize();

            // And then storage:
            StorageProvider.Initialize();

            var storageDirectory = StorageProvider.GetDirectoryForDatabase(database.Name);

            log.Info("Setting storage directory for default database to: {0}", storageDirectory.FullName);
            database.Configuration.DataDirectory = storageDirectory.FullName;

            // Setup replication:
            var selfInstance = InstanceEnumerator.EnumerateInstances().First(i => i.IsSelf);

            if (selfInstance.InstanceType == InstanceType.ReadWrite)
            {
                ReplicationUtilities.UpdateReplication(selfInstance, InstanceEnumerator, database);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowsLiveAuthorizationController" /> class.
        /// </summary>
        public WindowsLiveAuthorizationController()
        {
            this.diagnostics = new DiagnosticsProvider(this.GetType());

            // Read the config settings;
            string baseRepositoryName = BaseRepositoryEnum.SkyDrive.ToString();

            this.oAuthURL = ConfigReader <string> .GetRepositoryConfigValues(baseRepositoryName, SkyDriveConstants.OAuthUrl);

            this.oAuthAuthZUrl = ConfigReader <string> .GetRepositoryConfigValues(baseRepositoryName, SkyDriveConstants.OAuthAuthZUrl);

            this.clientId = ConfigReader <string> .GetRepositoryConfigValues(baseRepositoryName, SkyDriveConstants.ClientId);

            this.redirectionURL = ConfigReader <string> .GetRepositoryConfigValues(baseRepositoryName, SkyDriveConstants.RedicrectionUrl);

            this.clientSecret = ConfigReader <string> .GetRepositoryConfigValues(baseRepositoryName, SkyDriveConstants.ClientSecret);

            this.skyDriveUpdateScope = ConfigReader <string> .GetRepositoryConfigValues(baseRepositoryName, SkyDriveConstants.SkyDriveUpdateScope);

            this.offlineAccessScope = ConfigReader <string> .GetRepositoryConfigValues(baseRepositoryName, SkyDriveConstants.WindowsLiveOfflinseAccessScope);
        }
 /// <summary>
 /// Instantiates the AuthenticationController
 /// </summary>
 public AuthenticationController()
     : base()
 {
     diagnostics = new DiagnosticsProvider(this.GetType());
 }
Beispiel #21
0
 public CorsHandler()
 {
     diagnostics = new DiagnosticsProvider(this.GetType());
 }
Beispiel #22
0
 public LoggingSink(Microsoft.Extensions.Logging.ILogger logger, DiagnosticsProvider provider)
 {
     _logger   = logger;
     _provider = provider;
 }
 public ApiJWTSecurityTokenHandler()
     : base()
 {
     diagnostics = new DiagnosticsProvider(this.GetType());
 }
Beispiel #24
0
 public TracingSink(ILogger logger, DiagnosticsProvider provider)
 {
     _logger   = logger;
     _provider = provider;
 }
Beispiel #25
0
 public JWTTokenValidationHandler()
     : base()
 {
     diagnostics = new DiagnosticsProvider(this.GetType());
 }
Beispiel #26
0
 public UsersController(IUserService userService)
 {
     this.userService = userService;
     diagnostics      = new DiagnosticsProvider(this.GetType());
 }