/// <summary> /// Gets a decimal based on a static decimal as a string, or a pointer to a property of given event. /// </summary> /// <param name="logger">Logging instance for logging programs.</param> /// <param name="value">The value to parse</param> /// <param name="eventData">The event to fetch the value from should the "value" point to an event property.</param> /// <returns></returns> public static decimal? GetDecimal(ILogger logger, string value, LogEventData eventData) { decimal result; if (!decimal.TryParse(value, NumberStyles.Float, CultureInfo.GetCultureInfo("en-us"), out result)) { if (eventData.Properties.ContainsKey(value)) { var p = eventData.Properties[value]; if (p is TimeSpan) { result = ((TimeSpan)p).Milliseconds; } else { try { result = Convert.ToDecimal(p); } catch (FormatException) { logger.Warning("Unable to send value to Ducksboard. Could not parse event property {EventPropertyKey} with value {Value} to decimal.", value, eventData.Properties[value]); return null; } } } else { logger.Warning("Unable to send value to Ducksboard. Could not parse {Value}. Expected an decimal or an event property key."); return null; } } return result; }
public T Get <T>() where T : ConfigurationItemBase, new() { T result; try { var reader = Element.CreateReader(); var xRoot = new XmlRootAttribute { ElementName = ConfigurationConstants.ConfigurationEntityTag, IsNullable = true }; var serializer = new XmlSerializer(typeof(T), xRoot); result = (T)serializer.Deserialize(reader); } catch (Exception ex) { _logger?.Warning($"Deserialisation of local configuration item '{Id}' with type '{typeof(T).Name}' failed."); _logger?.Warning(ex); result = new T { Id = Id }; } return(result); }
private void FtpClientOnLogEvent(FtpTraceLevel level, string message) { if (string.IsNullOrWhiteSpace(message)) { return; } int indexOf = message.IndexOf("at System.Net.Sockets.Socket", StringComparison.Ordinal); if (indexOf >= 0) { message = message.Substring(0, indexOf).Trim(); } const string messageTemplate = "{FtpMessage}"; switch (level) { case FtpTraceLevel.Info: _logger?.Debug(messageTemplate, message); break; case FtpTraceLevel.Error: _logger?.Warning(messageTemplate, message); break; case FtpTraceLevel.Verbose: _logger?.Debug(messageTemplate, message); break; case FtpTraceLevel.Warn: _logger?.Warning(messageTemplate, message); break; } }
public static void LogPredicateDeserializationFailure(DataModelConditionPredicate dataModelConditionPredicate, JsonException exception) { _logger?.Warning( exception, "Failed to deserialize display condition predicate {left} {operator} {right}", dataModelConditionPredicate.Entity.LeftPath?.Path, dataModelConditionPredicate.Entity.OperatorType, dataModelConditionPredicate.Entity.RightPath?.Path ); }
public bool CheckEnvironment() { Logger?.Trace("Git environment check..."); gitExec = FindGitBinary(); if (gitExec == null) { Logger?.Warning(" git executable not found."); return(false); } return(true); }
private void CheckResponseTokenForErrors(TokenResponse token) { if (token.IsHttpError) { _logger?.Warning("Could not authenticate with RelayServer. relay-server={RelayServerUri}, relay-server-connection-instance-id={RelayServerConnectionInstanceId}, status-code={ConnectionHttpStatusCode}, reason={ConnectionErrorReason}", Uri, RelayServerConnectionInstanceId, token.HttpErrorStatusCode, token.HttpErrorReason); throw new AuthenticationException("Could not authenticate with RelayServer: " + token.HttpErrorReason); } if (token.IsError) { _logger?.Warning("Could not authenticate with RelayServer. relay-server={RelayServerUri}, relay-server-connection-instance-id={RelayServerConnectionInstanceId}, reason={ConnectionErrorReason}", Uri, RelayServerConnectionInstanceId, token.Error); throw new AuthenticationException("Could not authenticate with RelayServer: " + token.Error); } }
protected bool AwaitAddingValue(string key, string region) { string qualifiedKey = GetQualifiedKey(key, region); // Check if another thread is adding a value for the key/region: EventWaitHandle addingEvent; if (!AddingEvents.TryGetValue(qualifiedKey, out addingEvent)) { return(false); } _logger?.Debug("Awaiting adding of value for key '{0}' in region '{1}' ...", key, region); if (!addingEvent.WaitOne(WaitForAddingTimeout)) { // To facilitate diagnosis of deadlock conditions, first log a warning and then wait another timeout period. _logger?.Warning("Waiting for adding of value for key '{0}' in cache region '{1}' for {2} seconds.", key, region, WaitForAddingTimeout / 1000); if (!addingEvent.WaitOne(WaitForAddingTimeout)) { throw new DxaCacheAgentException( $"Timeout waiting for adding of value for key '{key}' in cache region '{region}'."); } } _logger?.Debug("Done awaiting."); return(true); }
public async Task <IHttpActionResult> Forward() { var claimsPrincipal = (ClaimsPrincipal)RequestContext.Principal; var onPremiseId = claimsPrincipal.FindFirst(AuthorizationServerProvider.OnPremiseIdClaimName)?.Value; Request.GetCallCancelled().Register(() => _logger?.Warning("Disconnect during receiving on-premise response detected. link-id={LinkId}", onPremiseId)); var requestStream = await Request.Content.ReadAsStreamAsync().ConfigureAwait(false); OnPremiseConnectorResponse response = null; if (Request.Headers.TryGetValues("X-TTRELAY-METADATA", out var headerValues)) { response = JToken.Parse(headerValues.First()).ToObject <OnPremiseConnectorResponse>(); using (var stream = _postDataTemporaryStore.CreateResponseStream(response.RequestId)) { await requestStream.CopyToAsync(stream).ConfigureAwait(false); response.ContentLength = stream.Length; } } else { // this is a legacy on-premise connector (v1) response = await ForwardLegacyResponse(Encoding.UTF8, requestStream).ConfigureAwait(false); } _logger?.Verbose("Received on-premise response. request-id={RequestId}, content-length={ResponseContentLength}", response.RequestId, response.ContentLength); _backendCommunication.SendOnPremiseTargetResponse(response.OriginId, response); return(Ok()); }
public static void SafeSetSuccess(TaskCompletionSource promise, ILogger logger) { if (promise != TaskCompletionSource.Void && !promise.TryComplete()) { logger.Warning("Failed to complete task successfully because it is done already: {0}", promise); } }
/// <summary> /// Checks and warns about deprecated environment variables. /// </summary> /// <returns></returns> public void CheckDeprecatedVariables(ILogger logger) { _logger = logger; // List with pairs of deprecated and new/replacement options. // If newOption is null, warning will not suggest using it instead. var deprecatedOptions = new List <(string deprecatedOption, string newOption)> { // Deprecated on 2020-09-17. (PcsVariable.PCS_DEFAULT_PUBLISH_MAX_OUTGRESS_MESSAGES, PcsVariable.PCS_DEFAULT_PUBLISH_MAX_EGRESS_MESSAGE_QUEUE), // TODO: Add rest of deprecated PCS variables, }; // Warn about deprecated option and optionally suggest using new one. foreach (var option in deprecatedOptions) { if (!string.IsNullOrEmpty(Configuration.GetValue <string>(option.deprecatedOption))) { string warning = @$ "The parameter or environment variable '{option.deprecatedOption}' has been deprecated and will be removed in a future version. "; warning += !string.IsNullOrEmpty(option.newOption) ? @$ "Please use '{option.newOption}' instead." : ""; _logger?.Warning(warning); } } }
protected override void OnBadPacketReceived(ReadOnlySpan <byte> packet, DateTime recivedTime, Exception exception) { const string message = "{id} Bad packet received.\nPacket({length}): {packet}"; byte[] packetBin = packet.ToArray(); var packetStr = string.Join(", ", packetBin); if (exception != null) { _logger?.Warning(exception, message, Id, packet.Length, packetStr); } else { _logger?.Warning(message, Id, packet.Length, packetStr); } }
public void RegisterInterceptors(ContainerBuilder builder) { var assembly = _customCodeAssemblyLoader.Assembly; if (assembly == null) { return; } try { _logger?.Debug("Trying to register interceptors from custom code assembly. assembly-path={CustomCodeAssemblyPath}", _configuration.CustomCodeAssemblyPath); if (!RegisterInterceptors(builder, typeof(IOnPremiseRequestInterceptor), typeof(IOnPremiseResponseInterceptor))) { _logger?.Warning("No interceptors could be registered. assembly-path={CustomCodeAssemblyPath}", _configuration.CustomCodeAssemblyPath); return; } _logger?.Information("Successfully registered interceptors from {CustomCodeAssemblyPath}", _configuration.CustomCodeAssemblyPath); } catch (Exception ex) { _logger?.Error(ex, "There was an error loading the interceptors. assembly-path={CustomCodeAssemblyPath}", _configuration.CustomCodeAssemblyPath); } }
public async Task <Message> ReadFileAsync(string path, string fileName) { Message outputMessage = null; var fullPath = Path.Combine(path, fileName).Replace('\\', '/'); var retries = 0; var retryCount = RetryCount; while (retries <= retryCount) { retries++; var sleepTime = (int)Math.Pow(retries, retries) * 1000; try { outputMessage = await ReadAsync(path, fileName); break; } catch (Exception ex) { // If this is not the last retry, log a warning. if (retries <= retryCount) { _logger?.Warning($"Reading the file '{fullPath}' failed. Retrying {retries}/{retryCount} in {sleepTime} ms."); } // Otherwise, throw an exception else if (retryCount == 0) { throw new Exception($"Reading the file '{fullPath}' failed.", ex); } else { throw new Exception($"Reading the file '{fullPath}' failed after {retryCount} retries.", ex); } } // Sleep before retrying: await Task.Factory.StartNew(() => { Thread.Sleep(sleepTime); }); } return(outputMessage); }
public static void SafeSetFailure(TaskCompletionSource promise, Exception cause, ILogger logger) { if (promise != TaskCompletionSource.Void && !promise.TrySetException(cause)) { logger.Warning( "Failed to set exception on task successfully because it is done already: {0}; Cause: {1}", promise, cause); } }
public bool CheckEnvironment() { Logger?.Trace("Subversion environment check..."); svnExec = FindSvnBinary(); if (svnExec == null) { Logger?.Warning(" svn executable not found."); return(false); } svnversionExec = Path.Combine(Path.GetDirectoryName(svnExec), svnversionExeName); if (!File.Exists(svnversionExec)) { Logger?.Warning(" svnversion executable not found."); return(false); } return(true); }
public void SetConfiguration(XElement element, object changeSource = null) { Guid id; try { id = (Guid)element.Attribute("Id"); } catch (Exception ex) { _logger?.Warning("Attempt was made to persist configuration without Id."); throw new ArgumentException("Unable to persist XElement without Id.", ex); } var agent = GetConfigurationAgent(id); agent.Update(element); }
private void TryLogRequest(IRestRequest restRequest, IRequest request, IRestClient restClient, string configurationKey) { try { var restClientLogProperty = new { RequestContent = request.GetRequestContentForLogging(JsonConvert.SerializeObject(request)), HttpRequestUrl = restClient.BuildUri(restRequest).ToString(), HttpRequestType = restRequest.Method }; _logger?.ForContext("RestClient", restClientLogProperty, destructureObjects: true) ?.Information("Rest request sent to {ConfigurationKey}", configurationKey); } catch (Exception e) { _logger?.Warning(e, "There was a problem logging the rest request"); } }
public static void DoAfter(this ICommandAspect aspect, ILogger logger, object parameter) { try { aspect?.After(parameter); } catch (Exception ex) { logger?.Warning(ex); } }
/// <summary> /// <see cref="IVizDatasourceService.LoadVizDatasourceReportAsync"/> /// </summary> public async Task LoadVizDatasourceReportAsync(string delimiter = ",") { _logger?.Debug($"Loading Viz datasource report {_settingsMonitor.CurrentValue.ReportOutputPath}"); using (var sr = new StreamReader(_settingsMonitor.CurrentValue.ReportOutputPath)) using (var cr = new CsvReader(sr, CultureInfo.InvariantCulture)) { await cr.ReadAsync().ConfigureAwait(false); cr.ReadHeader(); while (await cr.ReadAsync().ConfigureAwait(false)) { var name = GetValidName(cr.GetField("Name")); var serverName = cr.GetField("Server"); var serverPort = cr.GetField("Port"); bool.TryParse(cr.GetField("HasEmbeddedPassword"), out bool hasEmbeddedPassword); var username = cr.GetField("Username"); var password = cr.GetField("Password"); if (name.StartsWith("#") || String.IsNullOrWhiteSpace(username) || String.IsNullOrWhiteSpace(password)) { continue; } if (String.IsNullOrWhiteSpace(name) || String.IsNullOrWhiteSpace(serverName) || !hasEmbeddedPassword || String.IsNullOrWhiteSpace(password)) { throw new Exception($"Invalid record: {cr.Context.RawRow}, {cr.Context.RawRecord}"); } var vizDatasource = _vizDatasources.SingleOrDefault( v => v.Name.EqualsIgnoreCase(name) && v.VizConnectionDetail.ServerName.EqualsIgnoreCase(serverName) && v.VizConnectionDetail.Username.EqualsIgnoreCase(username) ); if (vizDatasource == null) { throw new Exception( $"Unable to find datasource for line: {cr.Context.RawRow}, {cr.Context.RawRecord}" ); } vizDatasource.VizConnectionDetail.Password = password; } } if (_vizDatasources.Any(v => String.IsNullOrWhiteSpace(v.VizConnectionDetail.Password))) { _logger?.Warning("Datasources without passwords still present after load"); } }
/// <summary> /// Utility function to check that the texture size is supported on the graphics platform for the provided graphics profile. /// </summary> /// <param name="parameters">The import parameters</param> /// <param name="textureSizeRequested">The texture size requested.</param> /// <param name="logger">The logger.</param> /// <returns>true if the texture size is supported</returns> /// <exception cref="System.ArgumentOutOfRangeException">graphicsProfile</exception> public static Size2 FindBestTextureSize(ImportParameters parameters, Size2 textureSizeRequested, ILogger logger = null) { var textureSize = textureSizeRequested; // compressed DDS files has to have a size multiple of 4. if (parameters.GraphicsPlatform == GraphicsPlatform.Direct3D11 && parameters.DesiredFormat == TextureFormat.Compressed && ((textureSizeRequested.Width % 4) != 0 || (textureSizeRequested.Height % 4) != 0)) { textureSize.Width = unchecked ((int)(((uint)(textureSizeRequested.Width + 3)) & ~(uint)3)); textureSize.Height = unchecked ((int)(((uint)(textureSizeRequested.Height + 3)) & ~(uint)3)); } var maxTextureSize = 0; // determine if the desired size if valid depending on the graphics profile switch (parameters.GraphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: if (parameters.GenerateMipmaps && (!MathUtil.IsPow2(textureSize.Width) || !MathUtil.IsPow2(textureSize.Height))) { // TODO: TEMPORARY SETUP A MAX TEXTURE OF 1024. THIS SHOULD BE SPECIFIED DONE IN THE ASSET INSTEAD textureSize.Width = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Width), 1024); textureSize.Height = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Height), 1024); logger?.Warning("Graphic profiles 9.1/9.2/9.3 do not support mipmaps with textures that are not power of 2. Asset is automatically resized to " + textureSize); } maxTextureSize = parameters.GraphicsProfile >= GraphicsProfile.Level_9_3 ? 4096 : 2048; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: maxTextureSize = 8192; break; case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: maxTextureSize = 16384; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } if (textureSize.Width > maxTextureSize || textureSize.Height > maxTextureSize) { logger?.Error("Graphic profile {0} do not support texture with resolution {2} x {3} because it is larger than {1}. " + "Please reduce texture size or upgrade your graphic profile.", parameters.GraphicsProfile, maxTextureSize, textureSize.Width, textureSize.Height); return(new Size2(Math.Min(textureSize.Width, maxTextureSize), Math.Min(textureSize.Height, maxTextureSize))); } return(textureSize); }
protected virtual void ChildNeedsRedraw(Element child) { if (Parent != null) { RequestRedraw(); } else { logger?.Warning("During child redraw request on {$Element} for {$Child}: Could not queue redraw becase there is no parent!", this, child); } }
public void Trace(IOnPremiseConnectorRequest request, IOnPremiseConnectorResponse response, Guid traceConfigurationId) { try { if (!Directory.Exists(_configuration.TraceFileDirectory)) { Directory.CreateDirectory(_configuration.TraceFileDirectory); } var filenamePrefix = $"{Path.Combine(_configuration.TraceFileDirectory, traceConfigurationId.ToString())}-{DateTime.Now.Ticks}"; _traceFileWriter.WriteHeaderFileAsync(filenamePrefix + _ON_PREMISE_CONNECTOR_HEADER_EXTENSION, request.HttpHeaders); _traceFileWriter.WriteContentFileAsync(filenamePrefix + _ON_PREMISE_CONNECTOR_CONTENT_EXTENSION, request.Body); _traceFileWriter.WriteHeaderFileAsync(filenamePrefix + _ON_PREMISE_TARGET_HEADER_EXTENSION, response.HttpHeaders); _traceFileWriter.WriteContentFileAsync(filenamePrefix + _ON_PREMISE_TARGET_CONTENT_EXTENSION, response.Body); } catch (Exception ex) { _logger?.Warning(ex, "Could not create trace"); } }
public static string GetMailboxFromAddress(string address, ILogger logger = null) { Match mailboxPart = s_addressPart.Match(address); if (!mailboxPart.Success) { logger?.Warning($"Unable to parse Mailbox: {address}"); return(null); } return(mailboxPart.Groups[1].Value); }
/// <summary> /// Invokes generators to return list of generated data /// </summary> /// <returns>Data from generators</returns> public IEnumerable <GeneratorData> Generate() { logger?.Info("Loading Wakatime Data..."); if (string.IsNullOrWhiteSpace(DataFilePath)) { logger?.Error("You passed empty file path!"); return(null); } logger?.Info("Parsing data..."); var dataAnalyzer = new DataAnalyzer(DataFilePath); logger?.Info("Started generating..."); var generatorDatas = new List <GeneratorData>(); foreach (var generator in generators) { logger?.Info($"Invoking {generator.GetType().Name}..."); try { var data = generator.Generate(dataAnalyzer, logger); if (data is null) { logger?.Warning("Returned null value"); continue; } generatorDatas.Add(data); } catch (Exception ex) { if (logger is null) { throw; } else { logger?.Error(ex.Message); } } } logger?.Info("Done!"); return(generatorDatas); }
private IPAddress GetRemoteIpAddress(IOnPremiseConnectorRequest request, HttpRequestMessage message) { try { return(message.GetRemoteIpAddress()); } catch (Exception ex) { _logger?.Warning(ex, "Could not fetch remote IP address. request-id={RequestId}", request.RequestId); } return(null); }
public void ConfigureServices(IServiceCollection services) { foreach (var starterType in initializers.Keys.ToArray()) { try { var starterObject = GetInitializer(starterType); var configureServices = starterType.GetMethod("ConfigureServices"); if (configureServices != null) { configureServices.Invoke( starterObject, new object[] { services } ); } } catch (Exception e) { log?.Warning(e, "ConfigureLibraryServices"); } } }
public static void LogException(ILogger log, Exception ex, ErrorDataContract error, HttpStatusCode code) { if (ex == null) return; log.Warning(@"[Exception][Type:{0}][Err:{1}][HTTPStatus:{2}][Message:{3}][CorrId:{4}] *********************** DevMessage *********************** {5} ********************************************************** Exception: {6}", ex.GetType().Name, error.FaultCode, code, error.Message, error.CorrelationId, error.DeveloperMessage, ex); }
/// <summary> /// Utility function to check that the texture size is supported on the graphics platform for the provided graphics profile. /// </summary> /// <param name="textureFormat">The desired type of format for the output texture</param> /// <param name="platform">The graphics platform</param> /// <param name="graphicsProfile">The graphics profile</param> /// <param name="textureSizeInput">The texture size input.</param> /// <param name="textureSizeRequested">The texture size requested.</param> /// <param name="generateMipmaps">Indicate if mipmaps should be generated for the output texture</param> /// <param name="logger">The logger.</param> /// <returns>true if the texture size is supported</returns> /// <exception cref="System.ArgumentOutOfRangeException">graphicsProfile</exception> public static Size2 FindBestTextureSize(TextureFormat textureFormat, GraphicsPlatform platform, GraphicsProfile graphicsProfile, Size2 textureSizeInput, Size2 textureSizeRequested, bool generateMipmaps, ILogger logger) { var textureSize = textureSizeRequested; // compressed DDS files has to have a size multiple of 4. if (platform == GraphicsPlatform.Direct3D11 && textureFormat == TextureFormat.Compressed && ((textureSizeRequested.Width % 4) != 0 || (textureSizeRequested.Height % 4) != 0)) { textureSize.Width = unchecked((int)(((uint)(textureSizeRequested.Width + 3)) & ~(uint)3)); textureSize.Height = unchecked((int)(((uint)(textureSizeRequested.Height + 3)) & ~(uint)3)); } var maxTextureSize = 0; // determine if the desired size if valid depending on the graphics profile switch (graphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: if (generateMipmaps && (!IsPowerOfTwo(textureSize.Width) || !IsPowerOfTwo(textureSize.Height))) { // TODO: TEMPORARY SETUP A MAX TEXTURE OF 1024. THIS SHOULD BE SPECIFIED DONE IN THE ASSET INSTEAD textureSize.Width = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Width), 1024); textureSize.Height = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Height), 1024); logger.Warning("Graphic profiles 9.1/9.2/9.3 do not support mipmaps with textures that are not power of 2. Asset is automatically resized to " + textureSize); } maxTextureSize = graphicsProfile >= GraphicsProfile.Level_9_3 ? 4096 : 2048; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: maxTextureSize = 8192; break; case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: maxTextureSize = 16384; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } if (textureSize.Width > maxTextureSize || textureSize.Height > maxTextureSize) { logger.Error("Graphic profile {0} do not support texture with resolution {2} x {3} because it is larger than {1}. " + "Please reduce texture size or upgrade your graphic profile.", graphicsProfile, maxTextureSize, textureSize.Width, textureSize.Height); return new Size2(Math.Min(textureSize.Width, maxTextureSize), Math.Min(textureSize.Height, maxTextureSize)); } return textureSize; }
public static void DisposeExceptionSafe(this IDisposable disposable, ILogger logger) { if (disposable == null) return; if (logger == null) throw new ArgumentNullException(nameof(logger)); try { disposable.Dispose(); } catch (Exception e) { logger.Warning(e, $"Failed to dispose '{disposable.GetType().Name}'"); } }
public static MethodDefinition Find(ModuleDefinition module, ILogger logger) { foreach (var method in module.GetAllTypes().SelectMany(t => t.GetMethods()) .Where(m => m.CustomAttributes.Any(a => a.AttributeType.FullName == "AutoDI.SetupMethodAttribute"))) { if (!method.IsStatic) { logger?.Warning($"Setup method '{method.FullName}' must be static"); return(null); } if (!method.IsPublic && !method.IsAssembly) { logger?.Warning($"Setup method '{method.FullName}' must be public or internal"); return(null); } if (method.Parameters.Count != 1 || method.Parameters[0].ParameterType.FullName != ModuleWeaver.Imports.AutoDIImport.IApplicationBuilderImport.TypeName) { logger?.Warning($"Setup method '{method.FullName}' must take a single parameter of type '{ModuleWeaver.Imports.AutoDIImport.IApplicationBuilderImport.TypeName}'"); return(null); } return(method); } return(null); }
public void RegisterModule(ContainerBuilder builder) { var assembly = Assembly; if (assembly == null) { return; } try { var types = GetTypes(assembly, typeof(IModule)); if (types.Length == 0) { _logger?.Information("Custom code assembly does not provide a DI module. Trying to load individual types later."); return; } if (types.Length > 1) { _logger?.Warning("The custom code assembly needs to provide a maximum of one (1) DI module, but more were found. module-count={ModuleCount}", types.Length); return; } builder.RegisterModule((IModule)Activator.CreateInstance(types.Single())); _logger?.Information("Successfully registered DI module from {CustomCodeAssemblyPath}", _configuration.CustomCodeAssemblyPath); _configuration.CustomCodeAssemblyPath = null; _assembly = null; } catch (Exception ex) { _logger?.Error(ex, "There was an error loading the DI module. assembly-path={CustomCodeAssemblyPath}", _configuration.CustomCodeAssemblyPath); } }
private void PurgeRepository(long obj) { var itemsToPurge = _repository .Where(x => x.PushDateTime > DateTime.Now.AddMinutes(-1 * numMinutesPurge)); foreach (var itemToPurge in itemsToPurge) { _logger?.Warning($"Purging Route Request from Repository " + $"(Source: {itemToPurge.SourceNode}, " + $"Destination: {itemToPurge.DestinationNode}, " + $"Name:{itemToPurge.Name})."); _repository.Remove(itemToPurge); } }
private static async Task<bool> RestartHandler(Exception ex, int retryCount, ILogger logger, IComponentIdentity component) { try { bool doDelay = retryCount % 5 == 0; if (doDelay) { await logger.Warning( $"Error occurred in component {component.FullyQualifiedName}. Restarting in 30 seconds.", ex); await Task.Delay(TimeSpan.FromSeconds(30)); } else { await logger.Warning($"Error occurred in component {component.FullyQualifiedName}. Restarting immediately.", ex); } } catch (Exception) { // swallow any issues } return true; }
public IHttpActionResult Get(string requestId) { _logger?.Verbose("Getting request data. request-id={RequestId}", requestId); var stream = _temporaryStore.GetRequestStream(requestId); if (stream == null) { _logger?.Warning("No request data found. request-id={RequestId}", requestId); return(NotFound()); } return(new ResponseMessageResult(new HttpResponseMessage() { Content = new StreamContent(stream, 0x10000) })); }
/// <summary> /// Fixes up the <see cref="CollectionItemIdentifiers"/> of a collection by generating new ids if there are any duplicate. /// </summary> /// <param name="collection">The collection to fix up.</param> /// <remarks>This method doesn't handle collections in derived objects that will be desynchronized afterwards.</remarks> private void Fixup(object collection) { CollectionItemIdentifiers itemIds; if (CollectionItemIdHelper.TryGetCollectionItemIds(collection, out itemIds)) { var items = new HashSet <ItemId>(); var localCopy = new CollectionItemIdentifiers(); itemIds.CloneInto(localCopy, null); foreach (var id in localCopy) { if (!items.Add(id.Value)) { logger?.Warning($"Duplicate item identifier [{id.Value}] in collection {CurrentPath} of asset [{assetItem.Location}]. Generating a new identifier to remove the duplicate entry."); itemIds[id.Key] = ItemId.New(); } } } }
/// <summary> /// Utility function to check that the texture size is supported on the graphics platform for the provided graphics profile. /// </summary> /// <param name="parameters">The import parameters</param> /// <param name="textureSizeRequested">The texture size requested.</param> /// <param name="logger">The logger.</param> /// <returns>true if the texture size is supported</returns> /// <exception cref="System.ArgumentOutOfRangeException">graphicsProfile</exception> public static Size2 FindMaximumTextureSize(ImportParameters parameters, Size2 textureSize, ILogger logger = null) { var maxTextureSize = 0; // determine if the desired size if valid depending on the graphics profile switch (parameters.GraphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: if (parameters.GenerateMipmaps && (!MathUtil.IsPow2(textureSize.Width) || !MathUtil.IsPow2(textureSize.Height))) { // TODO: TEMPORARY SETUP A MAX TEXTURE OF 1024. THIS SHOULD BE SPECIFIED DONE IN THE ASSET INSTEAD textureSize.Width = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Width), 1024); textureSize.Height = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Height), 1024); logger?.Warning("Graphic profiles 9.1/9.2/9.3 do not support mipmaps with textures that are not power of 2. Asset is automatically resized to " + textureSize); } maxTextureSize = parameters.GraphicsProfile >= GraphicsProfile.Level_9_3 ? 4096 : 2048; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: maxTextureSize = 8192; break; case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: maxTextureSize = 16384; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } if (textureSize.Width > maxTextureSize || textureSize.Height > maxTextureSize) { logger?.Error($"Graphic profile {parameters.GraphicsProfile} do not support texture with resolution {textureSize.Width} x {textureSize.Height} because it is larger than {maxTextureSize}. Please reduce texture size or upgrade your graphic profile."); return(new Size2(Math.Min(textureSize.Width, maxTextureSize), Math.Min(textureSize.Height, maxTextureSize))); } return(textureSize); }
public IEnumerable <string> GetDeviceUrls() { List <string> urls; tobii_error_t result; result = Interop.tobii_enumerate_local_device_urls(_apiHandle, out urls); if (result != tobii_error_t.TOBII_ERROR_NO_ERROR) { _logger?.Error("Failed to get list of devices. " + result); return(null); } if (urls.Count == 0) { _logger?.Warning("No eye trackers found. Result: " + result); return(null); } return(urls); }
private static void Main(string[] args) { _logger = new ConsoleLogger(); if (args.Length != 3) { _logger.Warning("Format is: TestApplication.exe username password sitecollectionurl"); return; } string username = args[0]; string password = args[1]; string webUrl = args[2]; SecureString securePassword = GetSecureStringFromString(password); using (var clientContext = new ClientContext(webUrl)) { clientContext.Credentials = new SharePointOnlineCredentials(username, securePassword); var migrator = new Migrator(clientContext, _logger); migrator.Migrate(Assembly.GetAssembly(typeof(ShowTitle))); } }
internal static void UpdateAssetReferences(AssetItem assetItem, IEnumerable<AssetReferenceLink> assetReferences, ILogger log, AssetAnalysisParameters parameters) { var package = assetItem.Package; var packageName = package.FullPath?.GetFileName() ?? "(Undefined path)"; bool shouldSetDirtyFlag = false; // Update reference foreach (var assetReferenceLink in assetReferences.Where(link => link.Reference is IReference)) { var contentReference = (IReference)assetReferenceLink.Reference; // Update Asset references (AssetReference, AssetBase, reference) var id = contentReference.Id; var newItemReference = package.FindAsset(id); // If asset was not found by id try to find by its location if (newItemReference == null) { newItemReference = package.FindAsset(contentReference.Location); if (newItemReference != null) { // If asset was found by its location, just emit a warning log.Warning(package, contentReference, AssetMessageCode.AssetReferenceChanged, contentReference, newItemReference.Id); } } // If asset was not found, display an error or a warning if (newItemReference == null) { if (parameters.IsLoggingAssetNotFoundAsError) { log.Error(package, contentReference, AssetMessageCode.AssetForPackageNotFound, contentReference, packageName); var packageFound = package.Session.Packages.FirstOrDefault(x => x.FindAsset(contentReference.Location) != null); if (packageFound != null) { log.Warning(package, contentReference, AssetMessageCode.AssetFoundInDifferentPackage, contentReference, packageFound.FullPath.GetFileName()); } } else { log.Warning(package, contentReference, AssetMessageCode.AssetForPackageNotFound, contentReference, packageName); } continue; } // Only update location that are actually different var newLocationWithoutExtension = newItemReference.Location; if (newLocationWithoutExtension != contentReference.Location || newItemReference.Id != contentReference.Id) { assetReferenceLink.UpdateReference(newItemReference.Id, newLocationWithoutExtension); shouldSetDirtyFlag = true; } } // Setting the dirty flag is an heavy operation, we want to do it only once if (shouldSetDirtyFlag) { assetItem.IsDirty = true; } }
private void LogAll(ILogger logger) { logger.Error("Error Logged"); logger.Warning("Warning Logged"); logger.Information("Information Logged"); logger.Debug("Debug Logged"); }
internal static void UpdateAssetReferences(AssetItem assetItem, IEnumerable<AssetReferenceLink> assetReferences, ILogger log, AssetAnalysisParameters parameters) { var package = assetItem.Package; // Update reference foreach (var assetReferenceLink in assetReferences.Where(link => link.Reference is IContentReference)) { var contentReference = (IContentReference)assetReferenceLink.Reference; // If the content reference is an asset base that is in fact a root import, just skip it if ((contentReference is AssetBase) && ((AssetBase)contentReference).IsRootImport) { continue; } // Update Asset references (AssetReference, AssetBase, ContentReference) var id = contentReference.Id; var newItemReference = package.FindAsset(id); // If asset was not found by id try to find by its location if (newItemReference == null) { newItemReference = package.FindAsset(contentReference.Location); if (newItemReference != null) { // If asset was found by its location, just emit a warning log.Warning(package, contentReference, AssetMessageCode.AssetReferenceChanged, contentReference, newItemReference.Id); } } // If asset was not found, display an error or a warning if (newItemReference == null) { if (parameters.IsLoggingAssetNotFoundAsError) { log.Error(package, contentReference, AssetMessageCode.AssetNotFound, contentReference); } else { log.Warning(package, contentReference, AssetMessageCode.AssetNotFound, contentReference); } continue; } // Only update location that are actually different var newLocationWithoutExtension = newItemReference.Location; if (newLocationWithoutExtension != contentReference.Location || newItemReference.Id != contentReference.Id) { assetReferenceLink.UpdateReference(newItemReference.Id, newLocationWithoutExtension); assetItem.IsDirty = true; } } }
/// <summary> /// Generates this project template to the specified output directory. /// </summary> /// <param name="outputDirectory">The output directory.</param> /// <param name="projectName">Name of the project.</param> /// <param name="projectGuid">The project unique identifier.</param> /// <param name="log">The log to output errors to.</param> /// <param name="options">The options arguments that will be made available through the Session property in each template.</param> /// <param name="generatedOutputFiles">The generated files.</param> /// <exception cref="System.ArgumentNullException">outputDirectory /// or /// projectName</exception> /// <exception cref="System.InvalidOperationException">FilePath cannot be null on this instance</exception> public void Generate(string outputDirectory, string projectName, Guid projectGuid, ILogger log, Dictionary<string, object> options = null, List<string> generatedOutputFiles = null ) { if (outputDirectory == null) throw new ArgumentNullException("outputDirectory"); if (projectName == null) throw new ArgumentNullException("projectName"); if (log == null) throw new ArgumentNullException("log"); if (FilePath == null) throw new InvalidOperationException("FilePath cannot be null on this instance"); try { // Check Project template filepath var templateDirectory = new FileInfo(FilePath).Directory; if (templateDirectory == null || !templateDirectory.Exists) { log.Error("Invalid ProjectTemplate directory [{0}]", FilePath); return; } // Creates the output directory var directory = new DirectoryInfo(outputDirectory); if (!directory.Exists) { directory.Create(); } // Create expando object from options valid for the whole life of generating a project template var expandoOptions = new ExpandoObject(); var expandoOptionsAsDictionary = (IDictionary<string, object>)expandoOptions; expandoOptionsAsDictionary["ProjectName"] = projectName; expandoOptionsAsDictionary["ProjectGuid"] = projectGuid; if (options != null) { foreach (var option in options) { expandoOptionsAsDictionary[option.Key] = option.Value; } } var engine = new TemplatingEngine(); // In case this project template is dynamic, we need to generate its content first through T4 if (IsDynamicTemplate) { var content = File.ReadAllText(FilePath); var host = new ProjectTemplatingHost(log, FilePath, templateDirectory.FullName, expandoOptions, Assemblies.Select(assembly => assembly.FullPath)); var newTemplateAsString = engine.ProcessTemplate(content, host); Files.Clear(); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(newTemplateAsString))) { var newTemplate = (ProjectTemplate)YamlSerializer.Deserialize(stream); Files.AddRange(newTemplate.Files); } } // Iterate on each files foreach (var fileItem in Files) { if (fileItem.Source == null) { log.Warning("Invalid empty file item [{0}] with no source location", fileItem); continue; } var sourceFilePath = System.IO.Path.Combine(templateDirectory.FullName, fileItem.Source); var targetLocation = fileItem.Target ?? fileItem.Source; if (Path.IsPathRooted(targetLocation)) { log.Error("Invalid file item [{0}]. TargetLocation must be a relative path", fileItem); continue; } var targetLocationExpanded = Expand(targetLocation, expandoOptionsAsDictionary, log); // If this is a template file, turn template on by default if (fileItem.IsTemplate) { var targetPath = Path.GetDirectoryName(targetLocationExpanded); var targetFileName = Path.GetFileName(targetLocationExpanded); targetLocationExpanded = targetPath != null ? Path.Combine(targetPath, targetFileName) : targetFileName; } var targetFilePath = Path.Combine(outputDirectory, targetLocationExpanded); try { // Make sure that the target directory does exist var targetDirectory = new FileInfo(targetFilePath).Directory; if (!targetDirectory.Exists) { targetDirectory.Create(); } bool fileGenerated = false; if (fileItem.IsTemplate) { var content = File.ReadAllText(sourceFilePath); var host = new ProjectTemplatingHost(log, sourceFilePath, templateDirectory.FullName, expandoOptions, Assemblies.Select(assembly => assembly.FullPath)); var newContent = engine.ProcessTemplate(content, host); if (newContent != null) { fileGenerated = true; File.WriteAllText(targetFilePath, newContent); } } else { fileGenerated = true; File.Copy(sourceFilePath, targetFilePath, true); } if (generatedOutputFiles != null && fileGenerated) { generatedOutputFiles.Add(targetFilePath); } } catch (Exception ex) { log.Error("Unexpected exception while processing [{0}]", fileItem, ex); } } } catch (Exception ex) { log.Error("Unexpected exception while processing project template [{0}] to directory [{1}]", projectName, outputDirectory, ex); } }
private static string Expand(string str, IDictionary<string, object> properties, ILogger log) { if (str == null) throw new ArgumentNullException("str"); if (properties == null) throw new ArgumentNullException("properties"); return ExpandRegex.Replace(str, match => { var propertyName = match.Groups[1].Value; object propertyValue; if (properties.TryGetValue(propertyName, out propertyValue)) { return propertyValue == null ? string.Empty : propertyValue.ToString(); } log.Warning("Unable to replace property [{0}] not found in options"); return match.Value; }); }
private Response ReadJsonResponse(JsonReader json, long token, ILogger logger) { Spec.Response retval = new Spec.Response(); retval.token = token; if (!json.Read() || json.CurrentToken != JsonToken.ObjectStart) throw new RethinkDbInternalErrorException("Expected a readable JSON object in response"); while (true) { if (!json.Read()) throw new RethinkDbInternalErrorException("Unexpected end-of-frame reading JSON response"); if (json.CurrentToken == JsonToken.ObjectEnd) break; if (json.CurrentToken != JsonToken.MemberName) throw new RethinkDbInternalErrorException("Unexpected JSON state"); string property = (string)json.CurrentTokenValue; if (property == "t") retval.type = ReadResponseType(json); else if (property == "r") retval.response.AddRange(ReadDatumArray(json)); else if (property == "b") retval.backtrace = ReadBacktrace(json); else if (property == "p") logger.Warning("Profiling is not currently supported by rethinkdb-net; profiling data will be discarded"); else logger.Information("Unexpected property {0} in JSON response; ignoring", property); } return retval; }
/// <summary> /// Runs some tasks. /// </summary> /// <param name="tasks">The tasks.</param> /// <param name="logger">The logger.</param> /// <param name="runningIfTasks">true if running the "if" tasks.</param> /// <param name="result">The result.</param> /// <returns><c>true</c> if all the tasks are successul; <c>false</c> otherwise.</returns> private bool RunTasks(ITask[] tasks, ILogger logger, bool runningIfTasks, IIntegrationResult result) { // Launch each task var successCount = 0; var failureCount = 0; for (var loop = 0; loop < tasks.Length; loop++) { var taskName = string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0} [{1}]", tasks[loop].GetType().Name, loop); logger.Debug("Starting task '{0}'", taskName); try { // Start the actual task var taskResult = result.Clone(); var task = tasks[loop]; this.RunTask(task, taskResult, new RunningSubTaskDetails(loop, runningIfTasks, result)); result.Merge(taskResult); } catch (Exception error) { // Handle any error details result.ExceptionResult = error; result.Status = IntegrationStatus.Failure; logger.Warning("Task '{0}' failed!", taskName); } // Record the results if (result.Status == IntegrationStatus.Success) { successCount++; } else { failureCount++; if (!ContinueOnFailure) break; } } logger.Info("Tasks completed: {0} successful, {1} failed", successCount, failureCount); return failureCount == 0; }
/// <summary> /// Loads the templates. /// </summary> /// <param name="log">The log result.</param> private void LoadTemplates(ILogger log) { foreach (var templateDir in TemplateFolders) { foreach (var filePath in templateDir.Files) { try { var file = new FileInfo(filePath); if (!file.Exists) { log.Warning("Template [{0}] does not exist ", file); continue; } var templateDescription = AssetSerializer.Load<TemplateDescription>(file.FullName); templateDescription.FullPath = file.FullName; Templates.Add(templateDescription); } catch (Exception ex) { log.Error("Error while loading template from [{0}]", ex, filePath); } } } }
/// <summary> /// Refreshes this package from the disk by loading or reloading all assets. /// </summary> /// <param name="log">The log.</param> /// <param name="cancelToken">The cancel token.</param> /// <returns>A logger that contains error messages while refreshing.</returns> /// <exception cref="System.InvalidOperationException">Package RootDirectory is null /// or /// Package RootDirectory [{0}] does not exist.ToFormat(RootDirectory)</exception> public void LoadTemporaryAssets(ILogger log, CancellationToken? cancelToken = null) { if (log == null) throw new ArgumentNullException("log"); // If FullPath is null, then we can't load assets from disk, just return if (FullPath == null) { log.Warning("Fullpath not set on this package"); return; } // Clears the assets already loaded and reload them TemporaryAssets.Clear(); // List all package files on disk var listFiles = ListAssetFiles(log, this, cancelToken); var progressMessage = String.Format("Loading Assets from Package [{0}]", FullPath.GetFileNameWithExtension()); // Display this message at least once if the logger does not log progress (And it shouldn't in this case) var loggerResult = log as LoggerResult; if (loggerResult == null || !loggerResult.IsLoggingProgressAsInfo) { log.Info(progressMessage); } // Update step counter for log progress for (int i = 0; i < listFiles.Count; i++) { var fileUPath = listFiles[i].Item1; var sourceFolder = listFiles[i].Item2; if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested) { log.Warning("Skipping loading assets. PackageSession.Load cancelled"); break; } // Update the loading progress if (loggerResult != null) { loggerResult.Progress(progressMessage, i, listFiles.Count); } // Try to load only if asset is not already in the package or assetRef.Asset is null var assetPath = fileUPath.MakeRelative(sourceFolder).GetDirectoryAndFileName(); try { // An exception can occur here, so we make sure that loading a single asset is not going to break // the loop var assetFullPath = fileUPath.FullPath; var asset = LoadAsset(log, assetFullPath, assetPath, fileUPath); // Create asset item var assetItem = new AssetItem(assetPath, asset) { IsDirty = false, Package = this, SourceFolder = sourceFolder.MakeRelative(RootDirectory) }; // Set the modified time to the time loaded from disk assetItem.ModifiedTime = File.GetLastWriteTime(assetFullPath); FixAssetImport(assetItem); // Add to temporary assets TemporaryAssets.Add(assetItem); } catch (Exception ex) { int row = 1; int column = 1; var yamlException = ex as YamlException; if (yamlException != null) { row = yamlException.Start.Line + 1; column = yamlException.Start.Column; } var module = log.Module; var assetReference = new AssetReference<Asset>(Guid.Empty, fileUPath.FullPath); // TODO: Change this instead of patching LoggerResult.Module, use a proper log message if (loggerResult != null) { loggerResult.Module = "{0}({1},{2})".ToFormat(Path.GetFullPath(fileUPath.FullPath), row, column); } log.Error(this, assetReference, AssetMessageCode.AssetLoadingFailed, ex, fileUPath, ex.Message); if (loggerResult != null) { loggerResult.Module = module; } } } }
/// <summary> /// Refreshes this package from the disk by loading or reloading all assets. /// </summary> /// <param name="log">The log.</param> /// <param name="assetFiles">The asset files (loaded from <see cref="ListAssetFiles"/> if null).</param> /// <param name="cancelToken">The cancel token.</param> /// <returns>A logger that contains error messages while refreshing.</returns> /// <exception cref="System.InvalidOperationException">Package RootDirectory is null /// or /// Package RootDirectory [{0}] does not exist.ToFormat(RootDirectory)</exception> public void LoadTemporaryAssets(ILogger log, IList<PackageLoadingAssetFile> assetFiles = null, CancellationToken? cancelToken = null) { if (log == null) throw new ArgumentNullException("log"); // If FullPath is null, then we can't load assets from disk, just return if (FullPath == null) { log.Warning("Fullpath not set on this package"); return; } // Clears the assets already loaded and reload them TemporaryAssets.Clear(); // List all package files on disk if (assetFiles == null) assetFiles = ListAssetFiles(log, this, cancelToken); var progressMessage = String.Format("Loading Assets from Package [{0}]", FullPath.GetFileNameWithExtension()); // Display this message at least once if the logger does not log progress (And it shouldn't in this case) var loggerResult = log as LoggerResult; if (loggerResult == null || !loggerResult.IsLoggingProgressAsInfo) { log.Info(progressMessage); } // Update step counter for log progress for (int i = 0; i < assetFiles.Count; i++) { var fileUPath = assetFiles[i].FilePath; var sourceFolder = assetFiles[i].SourceFolder; if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested) { log.Warning("Skipping loading assets. PackageSession.Load cancelled"); break; } // Update the loading progress if (loggerResult != null) { loggerResult.Progress(progressMessage, i, assetFiles.Count); } // Check if asset has been deleted by an upgrader if (assetFiles[i].Deleted) { IsDirty = true; filesToDelete.Add(assetFiles[i].FilePath); continue; } // An exception can occur here, so we make sure that loading a single asset is not going to break // the loop try { AssetMigration.MigrateAssetIfNeeded(log, assetFiles[i]); // Try to load only if asset is not already in the package or assetRef.Asset is null var assetPath = fileUPath.MakeRelative(sourceFolder).GetDirectoryAndFileName(); var assetFullPath = fileUPath.FullPath; var assetContent = assetFiles[i].AssetContent; var asset = LoadAsset(log, assetFullPath, assetPath, fileUPath, assetContent); // Create asset item var assetItem = new AssetItem(assetPath, asset) { IsDirty = assetContent != null, Package = this, SourceFolder = sourceFolder.MakeRelative(RootDirectory) }; // Set the modified time to the time loaded from disk if (!assetItem.IsDirty) assetItem.ModifiedTime = File.GetLastWriteTime(assetFullPath); // TODO: Let's review that when we rework import process // Not fixing asset import anymore, as it was only meant for upgrade // However, it started to make asset dirty, for ex. when we create a new texture, choose a file and reload the scene later // since there was no importer id and base. //FixAssetImport(assetItem); // Add to temporary assets TemporaryAssets.Add(assetItem); } catch (Exception ex) { int row = 1; int column = 1; var yamlException = ex as YamlException; if (yamlException != null) { row = yamlException.Start.Line + 1; column = yamlException.Start.Column; } var module = log.Module; var assetReference = new AssetReference<Asset>(Guid.Empty, fileUPath.FullPath); // TODO: Change this instead of patching LoggerResult.Module, use a proper log message if (loggerResult != null) { loggerResult.Module = "{0}({1},{2})".ToFormat(Path.GetFullPath(fileUPath.FullPath), row, column); } log.Error(this, assetReference, AssetMessageCode.AssetLoadingFailed, ex, fileUPath, ex.Message); if (loggerResult != null) { loggerResult.Module = module; } } } }
/// <summary> /// Refreshes this package from the disk by loading or reloading all assets. /// </summary> /// <param name="log">The log.</param> /// <param name="assetFiles">The asset files (loaded from <see cref="ListAssetFiles"/> if null).</param> /// <param name="cancelToken">The cancel token.</param> /// <param name="filterFunc">A function that will filter assets loading</param> /// <returns>A logger that contains error messages while refreshing.</returns> /// <exception cref="System.InvalidOperationException">Package RootDirectory is null /// or /// Package RootDirectory [{0}] does not exist.ToFormat(RootDirectory)</exception> public void LoadTemporaryAssets(ILogger log, IList<PackageLoadingAssetFile> assetFiles = null, CancellationToken? cancelToken = null, Func<PackageLoadingAssetFile, bool> filterFunc = null) { if (log == null) throw new ArgumentNullException(nameof(log)); // If FullPath is null, then we can't load assets from disk, just return if (FullPath == null) { log.Warning("Fullpath not set on this package"); return; } // Clears the assets already loaded and reload them TemporaryAssets.Clear(); // List all package files on disk if (assetFiles == null) assetFiles = ListAssetFiles(log, this, cancelToken); var progressMessage = $"Loading Assets from Package [{FullPath.GetFileNameWithExtension()}]"; // Display this message at least once if the logger does not log progress (And it shouldn't in this case) var loggerResult = log as LoggerResult; if (loggerResult == null || !loggerResult.IsLoggingProgressAsInfo) { log.Info(progressMessage); } var context = new AssetMigrationContext(this, log); // Update step counter for log progress var tasks = new List<System.Threading.Tasks.Task>(); for (int i = 0; i < assetFiles.Count; i++) { var assetFile = assetFiles[i]; if (filterFunc != null && !filterFunc(assetFile)) { continue; } // Update the loading progress loggerResult?.Progress(progressMessage, i, assetFiles.Count); var task = cancelToken.HasValue ? System.Threading.Tasks.Task.Factory.StartNew(() => LoadAsset(context, assetFile, loggerResult), cancelToken.Value) : System.Threading.Tasks.Task.Factory.StartNew(() => LoadAsset(context, assetFile, loggerResult)); tasks.Add(task); } if (cancelToken.HasValue) { System.Threading.Tasks.Task.WaitAll(tasks.ToArray(), cancelToken.Value); } else { System.Threading.Tasks.Task.WaitAll(tasks.ToArray()); } // DEBUG // StaticLog.Info("[{0}] Assets files loaded in {1}", assetFiles.Count, clock.ElapsedMilliseconds); if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested) { log.Warning("Skipping loading assets. PackageSession.Load cancelled"); } }
/// <summary> /// Fix and/or remove invalid RootAssets entries. /// Note: at some point, we might want to make IContentReference be part of the same workflow as standard asset references. /// </summary> /// <param name="rootAssets">The root assets to check.</param> /// <param name="referencedPackage">The package where to look for root reference.</param> /// <param name="log">The logger.</param> private void ProcessRootAssetReferences(RootAssetCollection rootAssets, Package referencedPackage, ILogger log) { foreach (var rootAsset in rootAssets.ToArray()) { // Update Asset references (AssetReference, AssetBase, ContentReference) var id = rootAsset.Id; var newItemReference = referencedPackage.Assets.Find(id); // If asset was not found by id try to find by its location if (newItemReference == null) { newItemReference = referencedPackage.Assets.Find(rootAsset.Location); if (newItemReference != null) { // If asset was found by its location, just emit a warning log.Warning(package, rootAsset, AssetMessageCode.AssetReferenceChanged, rootAsset, newItemReference.Id); } } // If asset was not found, remove the reference if (newItemReference == null) { log.Warning(package, rootAsset, AssetMessageCode.AssetNotFound, rootAsset); rootAssets.Remove(rootAsset.Id); package.IsDirty = true; continue; } // Only update location that are actually different var newLocationWithoutExtension = newItemReference.Location; if (newLocationWithoutExtension != rootAsset.Location || newItemReference.Id != rootAsset.Id) { rootAssets.Remove(rootAsset.Id); rootAssets.Add(new AssetReference<Asset>(newItemReference.Id, newLocationWithoutExtension)); package.IsDirty = true; } } }
//---------------------------------------------------------------------------- private List<string> SendMessages(ILogger testLogger) { // We send two blocks of messages, validating so the internal rolling file. Random r = new Random(); string currentMsg = null; List<string> initialList = new List<string>(); //---------- currentMsg = "Message A-" + r.Next().ToString(); initialList.Add(currentMsg); testLogger.Warning(currentMsg); currentMsg = "Message B-" + r.Next().ToString(); initialList.Add(currentMsg); testLogger.Warning(currentMsg); //---------- // Waiting to give time to send... System.Threading.Thread.Sleep(10000); //---------- currentMsg = "Message C-" + r.Next().ToString(); initialList.Add(currentMsg); testLogger.Warning(currentMsg); currentMsg = "Message D-" + r.Next().ToString(); initialList.Add(currentMsg); testLogger.Warning(currentMsg); //---------- // Waiting to give time to send... System.Threading.Thread.Sleep(10000); //---------- return initialList; }