Exemple #1
0
 internal static void UpdateAndLogServiceEndpoint(ILogger logger, ServiceEndpoint endpoint)
 {
     LoadBalanceUtils.SetDataContractSerializerBehavior(endpoint.Contract);
     logger.LogVerbose("Connected endpoint {0} with binding {1} and contract {2} with session mode {3}", new object[]
     {
         endpoint.Address,
         endpoint.Binding.Name,
         endpoint.Contract.Name,
         endpoint.Contract.SessionMode
     });
     foreach (OperationDescription operationDescription in endpoint.Contract.Operations)
     {
         logger.LogVerbose("Operation:: {0}, {1}, {2}", new object[]
         {
             operationDescription.Name,
             operationDescription.ProtectionLevel,
             operationDescription.Behaviors.Find <DataContractSerializerOperationBehavior>()
         });
         foreach (MessageDescription messageDescription in operationDescription.Messages)
         {
             logger.LogVerbose("Operation[{0}]::Message({1}, {2})", new object[]
             {
                 operationDescription.Name,
                 messageDescription.Action,
                 messageDescription.MessageType
             });
         }
     }
 }
        private List <KeyValuePair <string, string> > ExecuteSearch(Server server, ObjectQuery objectQuery, String category)
        {
            var list = new List <KeyValuePair <string, string> >();

            try
            {
                _logger.LogVerbose($"ExecuteSearch Called for IP '{server.ServerIpAddress}'. Query: {objectQuery.QueryString}", category);

                using (var searcher = new ManagementObjectSearcher(GetManagementScope(server.ServerIpAddress), objectQuery))
                {
                    foreach (ManagementObject managementObject in searcher.Get())
                    {
                        foreach (var prop in managementObject.Properties)
                        {
                            list.Add(new KeyValuePair <string, string>(prop.Name, (prop.Value ?? string.Empty).ToString()));
                        }
                    }
                }

                _logger.LogVerbose(
                    $"ExecuteSearch Called for IP '{server.ServerIpAddress}'. Query: {objectQuery.QueryString} - Success", category);
            }
            catch (Exception ex)
            {
                _logger.LogError(
                    $"ExecuteSearch Called for IP '{server.ServerIpAddress}'. Query: {objectQuery.QueryString} - Failure. Server: {server.ServerName}. Details: {ex.Message}", ex, category);
                throw ex;
            }

            return(list);
        }
        public bool Execute(ProcessControl processControl)
        {
            logger.LogVerbose("GetPerformanceMetrics Called");

            try
            {
                //2	Errors
                logger.LogVerbose("Calling LoadErrorHealthDWData");
                LoadApplicationDw(ProcTypes.LoadErrorHealthDwData);
                logger.LogVerbose("Calling LoadErrorHealthDWData - Done");

                //4	Users
                logger.LogVerbose("Calling LoadUserHealthDWData");
                LoadApplicationDw(ProcTypes.LoadUserHealthDwData);
                logger.LogVerbose("Calling LoadUserHealthDWData - Done");

                logger.LogVerbose("GetPerformanceMetrics Called - Success");
            }
            catch (Exception ex)
            {
                logger.LogError($"GetPerformanceMetrics: {ex.Message}", ex);
            }

            return(true);
        }
Exemple #4
0
        private static Task<PackageInput> GetPackageInput(string file, ILogger log)
        {
            // Validate package
            log.LogVerbose($"Reading {file}");
            PackageInput packageInput = null;

            try
            {
                // Read basic info from the package and verify that it isn't broken.
                packageInput = PackageInput.Create(file);
            }
            catch
            {
                log.LogError($"Invalid package '{file}'.");
                throw;
            }

            // Display a message for non-normalized packages
            if (packageInput.Identity.Version.ToString() != packageInput.Identity.Version.ToNormalizedString())
            {
                var message = $"Package '{packageInput.PackagePath}' does not contain a normalized version. Normalized: '{packageInput.Identity.Version.ToNormalizedString()}' Nuspec version: '{packageInput.Identity.Version.ToString()}'. See https://semver.org/ for details.";
                log.LogVerbose(message);
            }

            return Task.FromResult(packageInput);
        }
Exemple #5
0
        private void DeleteEntity(Entity crmEntity, DataImportResult result = null)
        {
            _logger.LogVerbose($"Deleting {crmEntity.LogicalName} entity with Id: '{crmEntity.Id}'");

            try
            {
                _crmService.Delete(crmEntity.LogicalName, crmEntity.Id);
                if (result != null)
                {
                    result.RecordsDeleted++;
                }
            }
            catch (FaultException <OrganizationServiceFault> fex)
            {
                switch ((uint)fex.Detail.ErrorCode)
                {
                //Continue if object does not exist
                //TODO: Behavior should be configurable
                case (uint)0x80040217:
                    _logger.LogWarning($"Could not delete {crmEntity.LogicalName} entity with Id: '{crmEntity.Id}'. Object does not exist.");
                    if (result != null)
                    {
                        result.RecordsSkipped++;
                    }
                    break;

                default:
                    throw;
                }
            }
        }
        public List <EntityWrapper> ReadBatchDataFromStore()
        {
            logger.LogVerbose($"DataCrmStoreReader ReadBatchDataFromStore started, queryIndex:{currentQueryIdx}, page{currentPage}");

            var entities = new List <EntityWrapper>();

            if (currentQueryIdx < fetchXMLQueries.Count)
            {
                string fetchXMLQuery = fetchXMLQueries[currentQueryIdx];

                while (entities.Count < batchSize)
                {
                    currentPage++;

                    List <EntityWrapper> pageData = RetrieveEntitiesInPages(entities, fetchXMLQuery);

                    if (pageData.Count < pageSize || recordsCount >= topCount)
                    {
                        UpdatePageTrackingVariables();

                        if (ShouldExitLoop(entities))
                        {
                            break;
                        }

                        fetchXMLQuery = fetchXMLQueries[currentQueryIdx];
                    }
                }
            }

            logger.LogVerbose($"DataCrmStoreReader ReadBatchDataFromStore finished, queryIndex:{currentQueryIdx}, page:{currentPage}, totalCount:{totalCount}");

            return(entities);
        }
Exemple #7
0
        /// <summary>
        /// Scan for singleton types that are marked by either [Singleton] or [LazySingleton].
        /// </summary>
        public void ScanSingletonTypes()
        {
            var singletonTypes = reflection.FindTypesMarkedByAttributes(new Type[] { typeof(SingletonAttribute) });

            var singletonDefs = singletonTypes
                                .Where(type =>
            {
                return(reflection.GetAttributes <SingletonAttribute>(type).All(attr => attr.Discoverable()));
            })
                                .Select(type =>
            {
                var attrs = reflection.GetAttributes <SingletonAttribute>(type).ToArray();

                return(new SingletonDef()
                {
                    singletonType = type,
                    dependencyNames = attrs
                                      .Where(attribute => attribute.DependencyName != null)
                                      .Select(attribute => attribute.DependencyName)
                                      .ToArray(),
                    lazy = attrs.Any(atribute => atribute.Lazy),
                    Instantiate = (factory, t) => attrs.First().CreateInstance(factory, t)
                });
            })
                                .ToArray();

            logger.LogVerbose("Found singletons:");
            singletonDefs.Each(def => logger.LogVerbose("\t" + def.ToString()));

            singletonDefs
            .Each(singletonDef => singletonManager.RegisterSingleton(singletonDef));
        }
Exemple #8
0
        public void Send(string roomId, string message)
        {
            var name = Context.User.Identity.Name;

            Clients.Group(roomId).sendMessage(name, message);
            _logger.LogVerbose("Message has been sent from [" + name + "] in room [" + roomId + "]\n" + message);
        }
Exemple #9
0
 public static void Route(ILogger logger, string msg)
 {
     if (!msg.IsNullOrEmpty())
     {
         if (msg.StartsWith(StartVerbose))
             _isVerboseMode = true;
         else if (msg.StartsWith(StopVerbose))
             _isVerboseMode = false;
         else
         {
             if (msg.StartsWith(Verbose))
                 logger.LogVerbose(msg.Substring(Verbose.Length));
             else if (msg.StartsWith(Success))
                 logger.LogSuccess(msg.Substring(Success.Length));
             else if (msg.StartsWith(Warning))
                 logger.LogWarning(msg.Substring(Warning.Length));
             else if (msg.StartsWith(Error))
                 logger.LogError(msg.Substring(Error.Length));
             else if (msg.StartsWith(Header))
             {
                 _isVerboseMode = false;
                 logger.LogHeader(msg.Substring(Header.Length));
             }
             else if (_isVerboseMode)
                 logger.LogVerbose(msg);
             else
                 logger.LogInfo(msg);
         }
     }
     else
     {
         //logger.LogInfo(msg);
     }
 }
        private static bool ShouldDisplayErrorPage(DataStoreErrorLogger.DataStoreErrorLog lastError, Exception exception, ILogger logger)
        {
            logger.LogVerbose(Strings.FormatDatabaseErrorPage_AttemptingToMatchException(exception.GetType()));

            if (!lastError.IsErrorLogged)
            {
                logger.LogVerbose(Strings.DatabaseErrorPage_NoRecordedException);
                return(false);
            }

            bool match = false;

            for (var e = exception; e != null && !match; e = e.InnerException)
            {
                match = lastError.Exception == e;
            }

            if (!match)
            {
                logger.LogVerbose(Strings.DatabaseErrorPage_NoMatch);
                return(false);
            }

            logger.LogVerbose(Strings.DatabaseErrorPage_Matched);
            return(true);
        }
        public static async Task DeployServiceFabricApp(this IServiceFabricClient Client, ServiceFabricApplicationSpec app, ILogger Logger = null)
        {
            var serverAppVersions = await Client.Applications.GetApplicationInfoListAsync();

            var deployed = serverAppVersions.Data.FirstOrDefault(sa => sa.Name == "fabric:/" + app.Name);

            if (deployed != null)
            {
                if (deployed.TypeVersion == app.Version)
                {
                    Logger?.LogInfo($"{app.Name} version {app.Version} is already deployed");
                    return;
                }

                var upgradeDescription = new ApplicationUpgradeDescription("fabric:/" + app.Name, app.Version, UpgradeKind.Rolling, app.Parameters, UpgradeMode.Monitored, 15);
                Logger?.LogInfo($"Upgrading app {upgradeDescription.Name} to version {upgradeDescription.TargetApplicationTypeVersion}");
                await Client.Applications.StartApplicationUpgradeAsync(app.Name, upgradeDescription);
            }
            else
            {
                var appDescription = new ApplicationDescription("fabric:/" + app.Name, app.Manifest.ApplicationTypeName, app.Manifest.ApplicationTypeVersion, app.Parameters);

                Logger?.LogInfo($"Creating app {appDescription.Name} with type {appDescription.TypeName} version {appDescription.TypeVersion}");
                Logger?.LogVerbose($"With parameters");
                if (appDescription.Parameters != null)
                {
                    foreach (var parameter in appDescription.Parameters.Keys)
                    {
                        Logger?.LogVerbose($"{parameter} =  {appDescription.Parameters[(string)parameter]}");
                    }
                }

                await Client.Applications.CreateApplicationAsync(appDescription);
            }
        }
Exemple #12
0
        /// <summary>
        /// Inspects the provided <paramref name="file"/>. If the file is a solution (.sln) file all
        /// non-excluded projects are inspected. If the file is a project (.csproj) file that project is
        /// inspected.
        /// </summary>
        /// <param name="file">An absolute file path to either a solution (.sln) or project (.csproj) file.</param>
        /// <param name="parameters">The inspection parameters provided by the user.</param>
        /// <param name="ct">A cancellation token.</param>
        /// <exception cref="InspectionException">This exception is thrown if the inspection process encounters an error.</exception>
        public async IAsyncEnumerable <ProjectInspectionResult> InspectAsync(FileSystemInfo file, InspectionParameters parameters, [EnumeratorCancellation] CancellationToken ct)
        {
            MSBuildLocator.RegisterDefaults();

            _logger.LogInformation("Initializing");

            using (var workspace = MSBuildWorkspace.Create())
            {
                workspace.LoadMetadataForReferencedProjects = true;

                var context = new InspectionContext(file, workspace, parameters);
                var metrics = context.CreateMetricInstances(context.Parameters).ToList();

                if (file.HasExtension(".csproj"))
                {
                    _logger.LogVerbose($"Inspecting project: {file}");

                    yield return(await InspectProject(context, metrics, ct));
                }
                else if (file.HasExtension(".sln"))
                {
                    _logger.LogVerbose($"Inspecting solution: {file}");

                    await foreach (var result in InspectSolution(context, metrics, ct))
                    {
                        yield return(result);
                    }
                }
                else
                {
                    throw new InspectionException("The specified file path is not a reference to a solution or project file");
                }
            }
        }
Exemple #13
0
        protected override async Task CopyFromSource(ILogger log, CancellationToken token)
        {
            if (await _blob.ExistsAsync())
            {
                log.LogVerbose($"GET {_blob.Uri.AbsoluteUri}");

                DeleteInternal();

                using (var cache = File.OpenWrite(LocalCacheFile.FullName))
                {
                    await _blob.DownloadToStreamAsync(cache);
                }

                // If the blob is compressed it needs to be decompressed locally before it can be used
                if (_blob.Properties.ContentEncoding?.Equals("gzip", StringComparison.OrdinalIgnoreCase) == true)
                {
                    log.LogVerbose($"Decompressing {_blob.Uri.AbsoluteUri}");

                    var gzipFile = LocalCacheFile.FullName + ".gz";
                    File.Move(LocalCacheFile.FullName, gzipFile);

                    using (Stream destination = File.Create(LocalCacheFile.FullName))
                        using (Stream source = File.OpenRead(gzipFile))
                            using (Stream zipStream = new GZipStream(source, CompressionMode.Decompress))
                            {
                                await zipStream.CopyToAsync(destination);
                            }

                    File.Delete(gzipFile);
                }
            }
        }
        public void TargetRpc_SpawnItem(NetworkConnection target, SpawnItemMessage data)
        {
            if (ClientScene.prefabs.ContainsKey(data.assetID) == false)
            {
                logger.Warning($"Server told to spawn asset with ID {data.assetID}, but no local asset with this ID was found!");
                return;
            }

            var prefab = ClientScene.prefabs[data.assetID];
            var obj    = UnityEngine.Object.Instantiate <GameObject>(prefab, data.position, data.rotation);

            // Create 3D model in the world.
            obj.GetOrAddComponent <UNetTrigger>();
            obj.GetOrAddComponent <TriggerInputHandler>();

            // TODO: Sync up the item definition to the client, so the client can show data about the object.

            var rangeHandler = new GameObject("_RangeHandler");

            rangeHandler.transform.SetParent(obj.transform);
            rangeHandler.transform.localPosition = Vector3.zero;
            rangeHandler.transform.localRotation = Quaternion.identity;
            var handler = rangeHandler.AddComponent <TriggerRangeHandler>();

            handler.useRange = 10f; // TODO: Set this in a global location somewhere...

            ClientScene.SetLocalObject(data.networkInstanceID, obj);

            logger.LogVerbose($"Created object with instance ID: {data.networkInstanceID} and assetID: {data.assetID}");
        }
        public virtual int ScriptMigration(
            [CanBeNull] string from,
            [CanBeNull] string to,
            [CanBeNull] string output,
            bool idempotent,
            [CanBeNull] string context,
            [CanBeNull] string startupProject)
        {
            return(Execute(
                       startupProject,
                       () =>
            {
                var sql = _migrationTool.ScriptMigration(from, to, idempotent, context);

                if (string.IsNullOrEmpty(output))
                {
                    _logger.LogInformation(sql);
                }
                else
                {
                    _logger.LogVerbose("Writing SQL script to '{0}'.", output);
                    File.WriteAllText(output, sql);

                    _logger.LogInformation("Done.");
                }

                return 0;
            }));
        }
Exemple #16
0
        public async Task <ProcessTransactionResult> ProcessTransaction(TransactionDto transactionDto)
        {
            _logger.LogVerbose($"Transaction received: {transactionDto}.");

            if (transactionDto == null)
            {
                return(ProcessTransactionResult.CreateFailure("Input transaction is null."));
            }

            Transaction transaction = _mapper.Map <TransactionDto, Transaction>(transactionDto);

            ActionResult addTransactionResult = await _accountingEngine.AddTransaction(transaction);

            if (!addTransactionResult.IsSuccess)
            {
                return(ProcessTransactionResult.CreateFailure(addTransactionResult.FailureMessage));
            }

            UpdateAccountBalancesResult updateAccountResult = await _accountingEngine.PerformDoubleEntryUpdateAccountBalance(
                transactionDto.DebitAccountQualifiedName,
                transactionDto.CreditAccountQualifiedName,
                transactionDto.Amount);

            if (!updateAccountResult.IsSuccess)
            {
                return(ProcessTransactionResult.CreateFailure(updateAccountResult.FailureMessage));
            }

            _logger.LogInformation($"Transaction processed: {transaction}");

            return(ProcessTransactionResult.CreateSuccess(
                       null,
                       _mapper.Map <IEnumerable <Account>, IEnumerable <AccountDto> >(updateAccountResult.UpdatedAccounts)));
        }
Exemple #17
0
        public async Task InvokeCommand <TCommand>(TCommand command, Guid correlationId) where TCommand : class, ICommand
        {
            var message = _options.CommandMessageFactory.CreateMessage(command, correlationId);

            _logger.LogVerbose(new { type = typeof(TCommand).FullName, correlationId = message.CorrelationId, command }, arg => $"Invoking command of type {arg.type} with correlationId {arg.correlationId}. Command: {arg.command.ToString()}");
            await _engine.SendCommand(message).ConfigureAwait(false);
        }
Exemple #18
0
        public virtual void Migrate(string targetMigration = null)
        {
            var connection = _connection.DbConnection;

            _logger.LogVerbose(RelationalStrings.UsingConnection(connection.Database, connection.DataSource));

            if (!_historyRepository.Exists())
            {
                if (!_databaseCreator.Exists())
                {
                    _databaseCreator.Create();
                }

                var command = _commandBuilderFactory.Create()
                              .Append(_historyRepository.GetCreateScript())
                              .BuildRelationalCommand();

                Execute(new[] { command });
            }

            var commands = GetMigrationCommands(_historyRepository.GetAppliedMigrations(), targetMigration);

            foreach (var command in commands)
            {
                Execute(command());
            }
        }
Exemple #19
0
        protected override async Task CopyToSource(ILogger log, CancellationToken token)
        {
            var absoluteUri = UriUtility.GetPath(RootPath, key);

            if (!File.Exists(LocalCacheFile.FullName))
            {
                if (await FileExistsAsync(client, bucketName, key, token).ConfigureAwait(false))
                {
                    log.LogVerbose($"Removing {absoluteUri}");
                    await RemoveFileAsync(client, bucketName, key, token).ConfigureAwait(false);
                }
                else
                {
                    log.LogVerbose($"Skipping {absoluteUri}");
                }

                return;
            }

            log.LogVerbose($"Pushing {absoluteUri}");

            using (var cache = LocalCacheFile.OpenRead())
            {
                Stream writeStream = cache;
                string contentType = null, contentEncoding = null;
                if (key.EndsWith(".nupkg", StringComparison.Ordinal))
                {
                    contentType = "application/zip";
                }
                else if (key.EndsWith(".xml", StringComparison.Ordinal) ||
                         key.EndsWith(".nuspec", StringComparison.Ordinal))
                {
                    contentType = "application/xml";
                }
                else if (key.EndsWith(".json", StringComparison.Ordinal) ||
                         await JsonUtility.IsJsonAsync(LocalCacheFile.FullName))
                {
                    contentType     = "application/json";
                    contentEncoding = "gzip";

                    // Compress content before uploading
                    log.LogVerbose($"Compressing {absoluteUri}");
                    writeStream = await JsonUtility.GZipAndMinifyAsync(cache);
                }
                else if (key.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
                         key.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase))
                {
                    contentType = "application/octet-stream";
                }
                else
                {
                    log.LogWarning($"Unknown file type: {absoluteUri}");
                }

                await UploadFileAsync(client, bucketName, key, contentType, contentEncoding, writeStream, token)
                .ConfigureAwait(false);

                writeStream.Dispose();
            }
        }
Exemple #20
0
 public static void Verbose(String message, Exception ex)
 {
     if (VerboseEnabled)
     {
         logger.LogVerbose(message, ex);
     }
 }
Exemple #21
0
        public void OnNext(Frame <JObject> value)
        {
            var request = value.Data;

            if (_logger.IsEnabled(LogLevel.Verbose))
            {
                _logger.LogVerbose("Received JSON RPC request: {request}", request);
            }
            JObject response = null;

            Func <JObject, JObject> callback;

            if (_callbacks.TryGetValue(request.Value <string>("method"), out callback))
            {
                response = callback(request);
            }
            else
            {
                // If there's no method then return a failed response for this request
                response          = new JObject();
                response["id"]    = request["id"];
                response["error"] = string.Format("Unknown method '{0}'", request.Value <string>("method"));
            }

            _logger.LogVerbose("Sending JSON RPC response: {data}", response);
            value.Output.Produce(response);
        }
Exemple #22
0
        public CoveragePrepareResult PrepareModules()
        {
            string[] modules = _instrumentationHelper.GetCoverableModules(_moduleOrAppDirectory, _parameters.IncludeDirectories, _parameters.IncludeTestAssembly);

            Array.ForEach(_parameters.ExcludeFilters ?? Array.Empty <string>(), filter => _logger.LogVerbose($"Excluded module filter '{filter}'"));
            Array.ForEach(_parameters.IncludeFilters ?? Array.Empty <string>(), filter => _logger.LogVerbose($"Included module filter '{filter}'"));
            Array.ForEach(_parameters.ExcludedSourceFiles ?? Array.Empty <string>(), filter => _logger.LogVerbose($"Excluded source files filter '{FileSystem.EscapeFileName(filter)}'"));

            _parameters.ExcludeFilters = _parameters.ExcludeFilters?.Where(f => _instrumentationHelper.IsValidFilterExpression(f)).ToArray();
            _parameters.IncludeFilters = _parameters.IncludeFilters?.Where(f => _instrumentationHelper.IsValidFilterExpression(f)).ToArray();

            foreach (string module in modules)
            {
                if (_instrumentationHelper.IsModuleExcluded(module, _parameters.ExcludeFilters) ||
                    !_instrumentationHelper.IsModuleIncluded(module, _parameters.IncludeFilters))
                {
                    _logger.LogVerbose($"Excluded module: '{module}'");
                    continue;
                }

                var instrumenter = new Instrumenter(module,
                                                    Identifier,
                                                    _parameters,
                                                    _logger,
                                                    _instrumentationHelper,
                                                    _fileSystem,
                                                    _sourceRootTranslator,
                                                    _cecilSymbolHelper);

                if (instrumenter.CanInstrument())
                {
                    _instrumentationHelper.BackupOriginalModule(module, Identifier);

                    // Guard code path and restore if instrumentation fails.
                    try
                    {
                        InstrumenterResult result = instrumenter.Instrument();
                        if (!instrumenter.SkipModule)
                        {
                            _results.Add(result);
                            _logger.LogVerbose($"Instrumented module: '{module}'");
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogWarning($"Unable to instrument module: {module}\n{ex}");
                        _instrumentationHelper.RestoreOriginalModule(module, Identifier);
                    }
                }
            }

            return(new CoveragePrepareResult()
            {
                Identifier = Identifier,
                ModuleOrDirectory = _moduleOrAppDirectory,
                Parameters = _parameters,
                Results = _results.ToArray()
            });
        }
Exemple #23
0
        private static IList <CompatibilityCheckResult> VerifyCompatibility(
            PackageSpec project,
            Dictionary <RestoreTargetGraph, Dictionary <string, LibraryIncludeFlags> > includeFlagGraphs,
            IReadOnlyList <NuGetv3LocalRepository> localRepositories,
            LockFile lockFile,
            IEnumerable <RestoreTargetGraph> graphs,
            bool validateRuntimeAssets,
            ILogger logger)
        {
            // Scan every graph for compatibility, as long as there were no unresolved packages
            var checkResults = new List <CompatibilityCheckResult>();

            if (graphs.All(g => !g.Unresolved.Any()))
            {
                var checker = new CompatibilityChecker(localRepositories, lockFile, validateRuntimeAssets, logger);
                foreach (var graph in graphs)
                {
                    logger.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.Log_CheckingCompatibility, graph.Name));

                    var includeFlags = IncludeFlagUtils.FlattenDependencyTypes(includeFlagGraphs, project, graph);

                    var res = checker.Check(graph, includeFlags);
                    checkResults.Add(res);
                    if (res.Success)
                    {
                        logger.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.Log_PackagesAndProjectsAreCompatible, graph.Name));
                    }
                    else
                    {
                        // Get error counts on a project vs package basis
                        var projectCount = res.Issues.Count(issue => issue.Type == CompatibilityIssueType.ProjectIncompatible);
                        var packageCount = res.Issues.Count(issue => issue.Type != CompatibilityIssueType.ProjectIncompatible);

                        // Log a summary with compatibility error counts
                        if (projectCount > 0)
                        {
                            logger.LogError(
                                string.Format(CultureInfo.CurrentCulture,
                                              Strings.Log_ProjectsIncompatible,
                                              graph.Name));

                            logger.LogDebug($"Incompatible projects: {projectCount}");
                        }

                        if (packageCount > 0)
                        {
                            logger.LogError(
                                string.Format(CultureInfo.CurrentCulture,
                                              Strings.Log_PackagesIncompatible,
                                              graph.Name));

                            logger.LogDebug($"Incompatible packages: {packageCount}");
                        }
                    }
                }
            }

            return(checkResults);
        }
Exemple #24
0
        public override T AddOrUpdate(long index, Func <long, T> createFunc, Func <T, T> updateFunc, out T old)
        {
            _log.LogVerbose("Start add or update item at index {0}", index);
            var result = GetOrCreateNode(index).AddOrUpdate(index, createFunc, updateFunc, out old);

            _log.LogVerbose("End add or update item at index {0}: old={1}, new={2}", index, old, result);
            return(result);
        }
Exemple #25
0
        public void Run()
        {
            _logger.LogVerbose("Started seeding data");

            EnsureDatabaseCreated();

            _logger.LogVerbose("Completed seeding data");
        }
Exemple #26
0
        private async Task HandleEventMessage <TEventHandler, TEvent>(TEventHandler handler, EventMessage <TEvent> message)
            where TEventHandler : IEventHandler <TEvent>
            where TEvent : class, IEvent
        {
            _logger.LogVerbose(new { eventType = typeof(TEvent).FullName, handlerType = handler.GetType().FullName, correlationId = message.CorrelationId, @event = message.Event.ToString() }, arg => $"Handling event of type {arg.eventType} with correlationId {arg.correlationId} with handler of type {arg.handlerType}. Event: {arg.@event}");

            var context = _options.EventContextFactory.CreateContext(message, _options);
            await handler.Handle(context).ConfigureAwait(false);
        }
        /// <summary>
        /// Packages the file.
        /// </summary>
        /// <param name="artifact">Single file artifact.</param>
        /// <param name="workingDirectory">The working directory.</param>
        /// <param name="zip">if set to <c>true</c> [zip].</param>
        /// <param name="s3">Interface to S3</param>
        /// <param name="logger">Interface to logger.</param>
        /// <returns>A <see cref="ResourceUploadSettings"/></returns>
        public static async Task <ResourceUploadSettings> PackageFile(
            FileInfo artifact,
            string workingDirectory,
            bool zip,
            IPSS3Util s3,
            ILogger logger)
        {
            ResourceUploadSettings resourceToUpload;

            if (zip && string.Compare(
                    Path.GetExtension(artifact.Name),
                    ".zip",
                    StringComparison.OrdinalIgnoreCase) != 0)
            {
                // Zip if zipping is required and file is not already zipped
                var fileToUpload = Path.Combine(
                    workingDirectory,
                    $"{Path.GetFileNameWithoutExtension(artifact.Name)}.zip");

                resourceToUpload = new ResourceUploadSettings
                {
                    File      = new FileInfo(fileToUpload),
                    Hash      = artifact.MD5(),
                    HashMatch = true,
                    KeyPrefix = s3.KeyPrefix
                };

                if (await s3.ObjectChangedAsync(resourceToUpload))
                {
                    logger.LogVerbose($"Zipping '{artifact.FullName}' to {Path.GetFileName(fileToUpload)}");

                    // Compute hash before zipping as zip hashes not idempotent due to temporally changing attributes in central directory
                    Zipper.Zip(
                        new CrossPlatformZipSettings
                    {
                        Artifacts        = artifact.FullName,
                        CompressionLevel = 9,
                        LogMessage       = m => logger.LogVerbose(m),
                        LogError         = e => logger.LogError(e),
                        ZipFile          = fileToUpload,
                        TargetPlatform   = ZipPlatform.Unix
                    });

                    resourceToUpload.HashMatch = false;
                }
            }
            else
            {
                resourceToUpload = new ResourceUploadSettings {
                    File = artifact, Hash = artifact.MD5()
                };
                resourceToUpload.HashMatch = !await s3.ObjectChangedAsync(resourceToUpload);
            }

            return(resourceToUpload);
        }
Exemple #28
0
        public Task SendStatusAsync(int statusCode)
        {
            ApplyResponseHeaders(statusCode);

            if (_logger.IsEnabled(LogLevel.Verbose))
            {
                _logger.LogVerbose(string.Format("Handled. Status code: {0} File: {1}", statusCode, SubPath));
            }
            return(Constants.CompletedTask);
        }
Exemple #29
0
        protected virtual byte[] SerializeMessage <T>(T message) where T : class
        {
            var body = JsonConvert.SerializeObject(message, new JsonSerializerSettings {
                ContractResolver = new CumulativeUpdateContractResolver()
            });

            _log.LogVerbose(body);

            return(Encoding.UTF8.GetBytes(body));
        }
Exemple #30
0
        public virtual void Commit()
        {
            _logger.LogVerbose(
                RelationalLoggingEventId.CommittingTransaction,
                () => RelationalStrings.RelationalLoggerCommittingTransaction);

            _transaction.Commit();

            ClearTransaction();
        }
        // todo
        ///// <summary>
        ///// Initializes a new instance of the <see cref="DefaultTokenService" /> class.
        ///// </summary>
        ///// <param name="options">The options.</param>
        ///// <param name="claimsProvider">The claims provider.</param>
        ///// <param name="tokenHandles">The token handles.</param>
        ///// <param name="signingService">The signing service.</param>
        ///// <param name="events">The OWIN environment service.</param>
        ///// <param name="owinEnvironmentService">The events service.</param>
        //public DefaultTokenService(IdentityServerOptions options, IClaimsProvider claimsProvider, ITokenHandleStore tokenHandles, ITokenSigningService signingService, IEventService events, OwinEnvironmentService owinEnvironmentService)
        //{
        //    _options = options;
        //    _claimsProvider = claimsProvider;
        //    _tokenHandles = tokenHandles;
        //    _signingService = signingService;
        //    _events = events;
        //    _owinEnvironmentService = owinEnvironmentService;
        //}

        /// <summary>
        /// Creates an identity token.
        /// </summary>
        /// <param name="request">The token creation request.</param>
        /// <returns>
        /// An identity token
        /// </returns>
        public virtual async Task <Token> CreateIdentityTokenAsync(TokenCreationRequest request)
        {
            _logger.LogVerbose("Creating identity token");
            request.Validate();

            // host provided claims
            var claims = new List <Claim>();

            // if nonce was sent, must be mirrored in id token
            if (request.Nonce.IsPresent())
            {
                claims.Add(new Claim(Constants.ClaimTypes.Nonce, request.Nonce));
            }

            // add iat claim
            claims.Add(new Claim(Constants.ClaimTypes.IssuedAt, DateTimeOffsetHelper.UtcNow.ToEpochTime().ToString(), ClaimValueTypes.Integer));

            // add at_hash claim
            if (request.AccessTokenToHash.IsPresent())
            {
                claims.Add(new Claim(Constants.ClaimTypes.AccessTokenHash, HashAdditionalData(request.AccessTokenToHash)));
            }

            // add c_hash claim
            if (request.AuthorizationCodeToHash.IsPresent())
            {
                claims.Add(new Claim(Constants.ClaimTypes.AuthorizationCodeHash, HashAdditionalData(request.AuthorizationCodeToHash)));
            }

            // add sid if present
            if (request.ValidatedRequest.SessionId.IsPresent())
            {
                claims.Add(new Claim(Constants.ClaimTypes.SessionId, request.ValidatedRequest.SessionId));
            }

            claims.AddRange(await _claimsProvider.GetIdentityTokenClaimsAsync(
                                request.Subject,
                                request.Client,
                                request.Scopes,
                                request.IncludeAllIdentityClaims,
                                request.ValidatedRequest));

            var issuer = _context.GetIssuerUri();

            var token = new Token(Constants.TokenTypes.IdentityToken)
            {
                Audience = request.Client.ClientId,
                Issuer   = issuer,
                Lifetime = request.Client.IdentityTokenLifetime,
                Claims   = claims.Distinct(new ClaimComparer()).ToList(),
                Client   = request.Client
            };

            return(token);
        }
        public static bool Match(IReadOnlyDictionary<string, IRouteConstraint> constraints,
                                 IDictionary<string, object> routeValues,
                                 HttpContext httpContext,
                                 IRouter route,
                                 RouteDirection routeDirection,
                                 ILogger logger)
        {
            if (routeValues == null)
            {
                throw new ArgumentNullException(nameof(routeValues));
            }

            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (constraints == null)
            {
                return true;
            }

            foreach (var kvp in constraints)
            {
                var constraint = kvp.Value;
                if (!constraint.Match(httpContext, route, kvp.Key, routeValues, routeDirection))
                {
                    if (routeDirection.Equals(RouteDirection.IncomingRequest))
                    {
                        object routeValue;
                        routeValues.TryGetValue(kvp.Key, out routeValue);

                        logger.LogVerbose(
                            "Route value '{RouteValue}' with key '{RouteKey}' did not match " +
                            "the constraint '{RouteConstraint}'.",
                            routeValue,
                            kvp.Key,
                            kvp.Value);
                    }

                    return false;
                }
            }

            return true;
        }
Exemple #33
0
        public static void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            logger = loggerFactory.CreateLogger("main");
            logger.LogVerbose("Configure");

            app.UseWebSockets(new WebSocketOptions() { ReplaceFeature = true });

            app.Use(async (context, next) =>
            {
                if (context.WebSockets.IsWebSocketRequest) await InitConnection(context);
                else await next();
            });
        }
Exemple #34
0
        public static void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IConfigurationRoot config)
        {
            logger = loggerFactory.CreateLogger("BaseHub");

            logger.LogVerbose("Configure");

            if (_dal == null)
            {
                var hostName = config["Data:DbConnection:Hostname"];
                var dbName = config["Data:DbConnection:DbName"];
                _dal = new BaseDAL(hostName, dbName);
                var connectionRetult = _dal.InitConnection();
                logger.LogVerbose("connectionRetult=" + connectionRetult);
            }

            app.UseWebSockets(new WebSocketOptions() { ReplaceFeature = true });
            app.Use(async (context, next) =>
            {
                if (context.WebSockets.IsWebSocketRequest) await InitConnection(context);
                else await next();
            });
        }
        public static async Task<HttpResponseMessage> GetAsync(this HttpClient httpClient, string requestUri,
            ILogger logger)
        {
            if (logger == null)
            {
                return await httpClient.GetAsync(requestUri);
            }

            logger.LogVerbose($"Sending request {requestUri}");
            var now = DateTimeOffset.Now;
            var res = await httpClient.GetAsync(requestUri).ConfigureAwait(false);
            if (res.IsSuccessStatusCode)
            {
                logger.LogVerbose(
                    $"Got response {res.StatusCode} in {(DateTimeOffset.Now - now).TotalMilliseconds.ToString("F2")}ms");
            }
            else
            {
                logger.LogError(
                    $"Got response {res.StatusCode} in {(DateTimeOffset.Now - now).TotalMilliseconds.ToString("F2")}ms");
            }
            return res;
        }
        public static RedisMessage FromBytes(byte[] data, ILogger logger)
        {
            using (var stream = new MemoryStream(data))
            {
                var message = new RedisMessage();

                // read message id from memory stream until SPACE character
                var messageIdBuilder = new StringBuilder(20);
                do
                {
                    // it is safe to read digits as bytes because they encoded by single byte in UTF-8
                    int charCode = stream.ReadByte();
                    if (charCode == -1)
                    {
                        logger.LogVerbose("Received Message could not be parsed.");
                        throw new EndOfStreamException();
                    }
                    char c = (char)charCode;
                    if (c == ' ')
                    {
                        message.Id = ulong.Parse(messageIdBuilder.ToString(), CultureInfo.InvariantCulture);
                        messageIdBuilder = null;
                    }
                    else
                    {
                        messageIdBuilder.Append(c);
                    }
                }
                while (messageIdBuilder != null);

                var binaryReader = new BinaryReader(stream);
                int count = binaryReader.ReadInt32();
                byte[] buffer = binaryReader.ReadBytes(count);

                message.ScaleoutMessage = ScaleoutMessage.FromBytes(buffer);
                return message;
            }
        }
        private static bool ShouldDisplayErrorPage(DataStoreErrorLogger.DataStoreErrorLog lastError, Exception exception, ILogger logger)
        {
            logger.LogVerbose(Strings.FormatDatabaseErrorPage_AttemptingToMatchException(exception.GetType()));

            if (!lastError.IsErrorLogged)
            {
                logger.LogVerbose(Strings.DatabaseErrorPage_NoRecordedException);
                return false;
            }

            bool match = false;
            for (var e = exception; e != null && !match; e = e.InnerException)
            {
                match = lastError.Exception == e;
            }

            if (!match)
            {
                logger.LogVerbose(Strings.DatabaseErrorPage_NoMatch);
                return false;
            }

            logger.LogVerbose(Strings.DatabaseErrorPage_Matched);
            return true;
        }
Exemple #38
0
 public static ReportTemplate LoadTemplate(ReportType reportType, ILogger logger)
 {
     logger.LogVerbose(Message.Common_DebugCall);
     const string REPORTTEMPLATE_FILEPATH_FORMAT = "./Data/Templates/{0}.xml";
     const string REPORTTEMPLATE_SCHEMA_FILEPATH = "./Data/Schemas/ReportTemplate.xsd";
     const string REPORTTEMPLATE_SCHEMA_URL = "http://localhost/Schemas/SIB2003/ReportTemplate";
     var templatePath = new FileInfo(string.Format(REPORTTEMPLATE_FILEPATH_FORMAT, reportType));
     if (!templatePath.Exists)
     {
         logger.LogError(Message.PrintingReportTemplateNotFound, reportType);
         throw new Exception("Не найден шаблон: " + reportType);
     }
     try
     {
         var doc = new XmlDocument();
         doc.Load(templatePath.FullName);
         var xmlSettings = new XmlReaderSettings();
         xmlSettings.Schemas.Add(REPORTTEMPLATE_SCHEMA_URL, REPORTTEMPLATE_SCHEMA_FILEPATH);
         xmlSettings.ValidationEventHandler +=
             (sender, args) => logger.LogError(
                 Message.PrintingReportTemplateValidationError,
                 args.Exception,
                 reportType);
         var xmlTextReader = new XmlTextReader(doc.InnerXml, XmlNodeType.Document, null);
         var xmlReader = XmlReader.Create(xmlTextReader, xmlSettings);
         var oSerializer = new XmlSerializer(typeof(ReportTemplate), REPORTTEMPLATE_SCHEMA_URL);
         logger.LogVerbose(Message.Common_DebugReturn);
         return (ReportTemplate)oSerializer.Deserialize(xmlReader);
     }
     catch (Exception ex)
     {
         logger.LogError(Message.PrintingLoadReportTemplateFailed, ex, reportType);
         throw;
     }
 }
Exemple #39
0
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
      log("Configure");
      loggerFactory.AddConsole(Configuration.GetSection("Logging"));
      loggerFactory.AddDebug();
      _logger = loggerFactory.CreateLogger("mw5");
      _logger.LogInformation("DataFolder = " + _DataFolder);

      app.UseIISPlatformHandler();


      // Register a simple error handler to catch token expiries and change them to a 401, 
      // and return all other errors as a 500. This should almost certainly be improved for
      // a real application.
      app.UseExceptionHandler(appBuilder =>
      {
        appBuilder.Use(async (context, next) =>
          {
            var error = context.Features[typeof(IExceptionHandlerFeature)] as IExceptionHandlerFeature;
            // This should be much more intelligent - at the moment only expired 
            // security tokens are caught - might be worth checking other possible 
            // exceptions such as an invalid signature.
            if (error != null && error.Error is SecurityTokenExpiredException)
            {
              context.Response.StatusCode = 401;
              // What you choose to return here is up to you, in this case a simple 
              // bit of JSON to say you're no longer authenticated.
              context.Response.ContentType = "application/json";
              await context.Response.WriteAsync(
                        JsonConvert.SerializeObject(
                            new { authenticated = false, tokenExpired = true }));
            }
            else if (error != null && error.Error != null)
            {
              context.Response.StatusCode = 500;
              context.Response.ContentType = "application/json";
              // TODO: Shouldn't pass the exception message straight out, change this.
              await context.Response.WriteAsync(
                  JsonConvert.SerializeObject
                  (new { success = false, error = error.Error.Message }));
            }
            // We're not trying to handle anything else so just let the default 
            // handler handle.
            else await next();
          });
      });


      app.UseStaticFiles();

      app.UseMvc();

      bool CreateInitialData = false;
      if (CreateInitialData)
      {
        _logger.LogVerbose("start creating initial data");
        SampleData sd = new SampleData(_logger);
        sd.Initialize(app.ApplicationServices);
        _logger.LogVerbose("initial data created");
      }


    }
Exemple #40
0
        public int Main(string[] args)
        {
#if DEBUG
            if (args.Contains("--debug"))
            {
                args = args.Skip(1).ToArray();
                System.Diagnostics.Debugger.Launch();
            }
#endif

            // Set up logging
            _log = new CommandOutputLogger();

            var app = new CommandLineApplication();
            app.Name = "nuget3";
            app.FullName = ".NET Package Manager";
            app.HelpOption("-h|--help");
            app.VersionOption("--version", GetType().GetTypeInfo().Assembly.GetName().Version.ToString());

            app.Command("restore", restore =>
                {
                    restore.Description = "Restores packages for a project and writes a lock file";

                    var sources = restore.Option("-s|--source <source>", "Specifies a NuGet package source to use during the restore", CommandOptionType.MultipleValue);
                    var packagesDirectory = restore.Option("--packages <packagesDirectory>", "Directory to install packages in", CommandOptionType.SingleValue);
                    var parallel = restore.Option("-p|--parallel <noneOrNumberOfParallelTasks>", $"The number of concurrent tasks to use when restoring. Defaults to {RestoreRequest.DefaultDegreeOfConcurrency}; pass 'none' to run without concurrency.", CommandOptionType.SingleValue);
                    var projectFile = restore.Argument("[project file]", "The path to the project to restore for, either a project.json or the directory containing it. Defaults to the current directory");

                    restore.OnExecute(async () =>
                        {
                            // Figure out the project directory
                            IEnumerable<string> externalProjects = null;

                            PackageSpec project;
                            var projectPath = Path.GetFullPath(projectFile.Value ?? ".");
                            if (string.Equals(PackageSpec.PackageSpecFileName, Path.GetFileName(projectPath), StringComparison.OrdinalIgnoreCase))
                            {
                                _log.LogVerbose($"Reading project file {projectFile.Value}");
                                projectPath = Path.GetDirectoryName(projectPath);
                                project = JsonPackageSpecReader.GetPackageSpec(File.ReadAllText(projectFile.Value), Path.GetFileName(projectPath), projectFile.Value);
                            }
                            else if (MsBuildUtility.IsMsBuildBasedProject(projectPath))
                            {
#if DNXCORE50
                                throw new NotSupportedException();
#else
                                externalProjects = MsBuildUtility.GetProjectReferences(projectPath);

                                projectPath = Path.GetDirectoryName(Path.GetFullPath(projectPath));
                                var packageSpecFile = Path.Combine(projectPath, PackageSpec.PackageSpecFileName);
                                project = JsonPackageSpecReader.GetPackageSpec(File.ReadAllText(packageSpecFile), Path.GetFileName(projectPath), projectFile.Value);
                                _log.LogVerbose($"Reading project file {projectFile.Value}");
#endif
                            }
                            else
                            {
                                var file = Path.Combine(projectPath, PackageSpec.PackageSpecFileName);

                                _log.LogVerbose($"Reading project file {file}");
                                project = JsonPackageSpecReader.GetPackageSpec(File.ReadAllText(file), Path.GetFileName(projectPath), file);
                            }
                            _log.LogVerbose($"Loaded project {project.Name} from {project.FilePath}");

                            // Resolve the root directory
                            var rootDirectory = PackageSpecResolver.ResolveRootDirectory(projectPath);
                            _log.LogVerbose($"Found project root directory: {rootDirectory}");

                            // Resolve the packages directory
                            var packagesDir = packagesDirectory.HasValue() ?
                                packagesDirectory.Value() :
                                Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), ".nuget", "packages");
                            _log.LogVerbose($"Using packages directory: {packagesDir}");

                            var packageSources = sources.Values.Select(s => new PackageSource(s));
                            if (!packageSources.Any())
                            {
                                var settings = Settings.LoadDefaultSettings(projectPath,
                                    configFileName: null,
                                    machineWideSettings: null);
                                var packageSourceProvider = new PackageSourceProvider(settings);
                                packageSources = packageSourceProvider.LoadPackageSources();
                            }

                            var request = new RestoreRequest(
                                project,
                                packageSources,
                                packagesDir);

                            if (externalProjects != null)
                            {
                                foreach (var externalReference in externalProjects)
                                {
                                    request.ExternalProjects.Add(
                                        new ExternalProjectReference(
                                            externalReference,
                                            Path.Combine(Path.GetDirectoryName(externalReference), PackageSpec.PackageSpecFileName),
                                            projectReferences: Enumerable.Empty<string>()));
                                }
                            }


                            // Run the restore
                            if (parallel.HasValue())
                            {
                                int parallelDegree;
                                if (string.Equals(parallel.Value(), "none", StringComparison.OrdinalIgnoreCase))
                                {
                                    request.MaxDegreeOfConcurrency = 1;
                                }
                                else if (int.TryParse(parallel.Value(), out parallelDegree))
                                {
                                    request.MaxDegreeOfConcurrency = parallelDegree;
                                }
                            }
                            if (request.MaxDegreeOfConcurrency <= 1)
                            {
                                _log.LogInformation("Running non-parallel restore");
                            }
                            else
                            {
                                _log.LogInformation($"Running restore with {request.MaxDegreeOfConcurrency} concurrent jobs");
                            }
                            var command = new RestoreCommand(_log);
                            var sw = Stopwatch.StartNew();
                            var result = await command.ExecuteAsync(request);
                            sw.Stop();

                            _log.LogInformation($"Restore completed in {sw.ElapsedMilliseconds:0.00}ms!");

                            return 0;
                        });
                });

            app.Command("diag", diag =>
                {
                    diag.Description = "Diagnostic commands for debugging package dependency graphs";
                    diag.Command("lockfile", lockfile =>
                        {
                            lockfile.Description = "Dumps data from the project lock file";

                            var project = lockfile.Option("--project <project>", "Path containing the project lockfile, or the patht to the lockfile itself", CommandOptionType.SingleValue);
                            var target = lockfile.Option("--target <target>", "View information about a specific project target", CommandOptionType.SingleValue);
                            var library = lockfile.Argument("<library>", "Optionally, get detailed information about a specific library");

                            lockfile.OnExecute(() =>
                                {
                                    var diagnostics = new DiagnosticCommands(_log);
                                    var projectFile = project.HasValue() ? project.Value() : Path.GetFullPath(".");
                                    return diagnostics.Lockfile(projectFile, target.Value(), library.Value);
                                });
                        });
                    diag.OnExecute(() =>
                        {
                            diag.ShowHelp();
                            return 0;
                        });
                });

            app.OnExecute(() =>
                {
                    app.ShowHelp();
                    return 0;
                });

            return app.Execute(args);
        }