private async Task UpdateAssetsFromSource(IEnumerable <AssetViewModel> assets) { var logger = new LoggerResult(); var workProgress = new WorkProgressViewModel(ServiceProvider, logger) { Title = "Update assets from source", KeepOpen = KeepOpen.OnWarningsOrErrors, IsIndeterminate = true, IsCancellable = false, }; workProgress.RegisterProgressStatus(logger, true); workProgress.ServiceProvider.Get <IEditorDialogService>().ShowProgressWindow(workProgress, 500); var undoRedo = ServiceProvider.Get <IUndoRedoService>(); using (var transaction = undoRedo.CreateTransaction()) { var tasks = new List <Task>(); foreach (var asset in assets) { logger.Verbose($"Updating {asset.Url}..."); var task = asset.Sources.UpdateAssetFromSource(logger); // Continuation might swallow exceptions, careful to keep the original task like this task.ContinueWith(x => logger.Verbose($"{asset.Url} updated")).Forget(); tasks.Add(task); } await Task.WhenAll(tasks); logger.Info("Update completed..."); undoRedo.SetName(transaction, $"Update {tasks.Count} asset(s) from their source(s)"); } await workProgress.NotifyWorkFinished(false, logger.HasErrors); }
public void TestLocalLogger() { var log = new LoggerResult(); log.Info("#0"); Assert.That(log.Messages.Count, Is.EqualTo(1)); Assert.That(log.Messages[0].Type, Is.EqualTo(LogMessageType.Info)); Assert.That(log.Messages[0].Text, Is.EqualTo("#0")); log.Info("#{0}", 1); Assert.That(log.Messages.Count, Is.EqualTo(2)); Assert.That(log.Messages[1].Type, Is.EqualTo(LogMessageType.Info)); Assert.That(log.Messages[1].Text, Is.EqualTo("#1")); Assert.That(log.HasErrors, Is.False); log.Error("#2"); Assert.That(log.Messages.Count, Is.EqualTo(3)); Assert.That(log.Messages[2].Type, Is.EqualTo(LogMessageType.Error)); Assert.That(log.Messages[2].Text, Is.EqualTo("#2")); Assert.That(log.HasErrors, Is.True); log.Error("#{0}", 3); Assert.That(log.Messages.Count, Is.EqualTo(4)); Assert.That(log.Messages[3].Type, Is.EqualTo(LogMessageType.Error)); Assert.That(log.Messages[3].Text, Is.EqualTo("#3")); // Activate log from Info to Fatal. Verbose won't be logged. log.ActivateLog(LogMessageType.Info); log.Verbose("#4"); Assert.That(log.Messages.Count, Is.EqualTo(4)); // Activate log from Verbose to Fatal. Verbose will be logged log.ActivateLog(LogMessageType.Verbose); log.Verbose("#4"); Assert.That(log.Messages.Count, Is.EqualTo(5)); // Activate log from Info to Fatal and only Debug. Verbose won't be logged. log.ActivateLog(LogMessageType.Info); log.ActivateLog(LogMessageType.Debug, true); log.Verbose("#5"); log.Debug("#6"); Assert.That(log.Messages.Count, Is.EqualTo(6)); Assert.That(log.Messages[5].Text, Is.EqualTo("#6")); }
public void TestLocalLogger() { var log = new LoggerResult(); log.Info("#0"); Assert.Single(log.Messages); Assert.Equal(LogMessageType.Info, log.Messages[0].Type); Assert.Equal("#0", log.Messages[0].Text); log.Info("#1"); Assert.Equal(2, log.Messages.Count); Assert.Equal(LogMessageType.Info, log.Messages[1].Type); Assert.Equal("#1", log.Messages[1].Text); Assert.False(log.HasErrors); log.Error("#2"); Assert.Equal(3, log.Messages.Count); Assert.Equal(LogMessageType.Error, log.Messages[2].Type); Assert.Equal("#2", log.Messages[2].Text); Assert.True(log.HasErrors); log.Error("#3"); Assert.Equal(4, log.Messages.Count); Assert.Equal(LogMessageType.Error, log.Messages[3].Type); Assert.Equal("#3", log.Messages[3].Text); // Activate log from Info to Fatal. Verbose won't be logged. log.ActivateLog(LogMessageType.Info); log.Verbose("#4"); Assert.Equal(4, log.Messages.Count); // Activate log from Verbose to Fatal. Verbose will be logged log.ActivateLog(LogMessageType.Verbose); log.Verbose("#4"); Assert.Equal(5, log.Messages.Count); // Activate log from Info to Fatal and only Debug. Verbose won't be logged. log.ActivateLog(LogMessageType.Info); log.ActivateLog(LogMessageType.Debug, true); log.Verbose("#5"); log.Debug("#6"); Assert.Equal(6, log.Messages.Count); Assert.Equal("#6", log.Messages[5].Text); }
private EffectBytecodeCompilerResult CompileBytecode(ShaderMixinSource mixinTree, CompilerParameters compilerParameters, ObjectId mixinObjectId, DatabaseFileProvider database, string compiledUrl) { // Open the database for writing var log = new LoggerResult(); // Note: this compiler is expected to not be async and directly write stuff in localLogger var compiledShader = base.Compile(mixinTree, compilerParameters).WaitForResult(); compiledShader.CompilationLog.CopyTo(log); // If there are any errors, return immediately if (log.HasErrors) { lock (compilingShaders) { compilingShaders.Remove(mixinObjectId); } return(new EffectBytecodeCompilerResult(null, log)); } // Compute the bytecodeId var newBytecodeId = compiledShader.Bytecode.ComputeId(); // Check if we really need to store the bytecode lock (bytecodes) { // Using custom serialization to the database to store an object with a custom id // TODO: Check if we really need to write the bytecode everytime even if id is not changed var memoryStream = new MemoryStream(); compiledShader.Bytecode.WriteTo(memoryStream); memoryStream.Position = 0; database.ObjectDatabase.Write(memoryStream, newBytecodeId, true); database.AssetIndexMap[compiledUrl] = newBytecodeId; // Save bytecode Id to the database cache as well memoryStream.SetLength(0); memoryStream.Write((byte[])newBytecodeId, 0, ObjectId.HashSize); memoryStream.Position = 0; database.ObjectDatabase.Write(memoryStream, mixinObjectId, true); if (!bytecodes.ContainsKey(newBytecodeId)) { log.Verbose("New effect compiled #{0} [{1}] (db: {2})\r\n{3}", effectCompileCount, mixinObjectId, newBytecodeId, compilerParameters.ToStringPermutationsDetailed()); Interlocked.Increment(ref effectCompileCount); // Replace or add new bytecode bytecodes[newBytecodeId] = compiledShader.Bytecode; } } lock (compilingShaders) { compilingShaders.Remove(mixinObjectId); } return(compiledShader); }
private EffectBytecodeCompilerResult CompileBytecode(ShaderMixinSource mixinTree, EffectCompilerParameters effectParameters, CompilerParameters compilerParameters, ObjectId mixinObjectId, DatabaseFileProvider database, string compiledUrl) { // Open the database for writing var log = new LoggerResult(); var effectLog = GlobalLogger.GetLogger("EffectCompilerCache"); if (CompileSynchronization.IsSet) { CompileSynchronization.Reset(1); } else { CompileSynchronization.AddCount(); } // Note: this compiler is expected to not be async and directly write stuff in localLogger var compiledShader = base.Compile(mixinTree, effectParameters, compilerParameters).WaitForResult(); compiledShader.CompilationLog.CopyTo(log); // If there are any errors, return immediately if (log.HasErrors) { lock (compilingShaders) { compilingShaders.Remove(mixinObjectId); } log.CopyTo(effectLog); return(new EffectBytecodeCompilerResult(null, log)); } // Compute the bytecodeId var newBytecodeId = compiledShader.Bytecode.ComputeId(); // Check if we really need to store the bytecode lock (bytecodes) { // Using custom serialization to the database to store an object with a custom id // TODO: Check if we really need to write the bytecode everytime even if id is not changed var memoryStream = new MemoryStream(); compiledShader.Bytecode.WriteTo(memoryStream); // Write current cache at the end (not part of the pure bytecode, but we use this as meta info) var writer = new BinarySerializationWriter(memoryStream); writer.Write(CurrentCache); memoryStream.Position = 0; database.ObjectDatabase.Write(memoryStream, newBytecodeId, true); database.ContentIndexMap[compiledUrl] = newBytecodeId; // Save bytecode Id to the database cache as well memoryStream.SetLength(0); memoryStream.Write((byte[])newBytecodeId, 0, ObjectId.HashSize); memoryStream.Position = 0; database.ObjectDatabase.Write(memoryStream, mixinObjectId, true); if (!bytecodes.ContainsKey(newBytecodeId)) { log.Verbose($"New effect compiled #{effectCompileCount} [{mixinObjectId}] (db: {newBytecodeId})\r\n{compilerParameters?.ToStringPermutationsDetailed()}"); Interlocked.Increment(ref effectCompileCount); // Replace or add new bytecode bytecodes[newBytecodeId] = new KeyValuePair <EffectBytecode, EffectBytecodeCacheLoadSource>(compiledShader.Bytecode, EffectBytecodeCacheLoadSource.JustCompiled); } } CompileSynchronization.Signal(); lock (compilingShaders) { compilingShaders.Remove(mixinObjectId); } log.CopyTo(effectLog); return(compiledShader); }
private EffectBytecodeCompilerResult CompileBytecode(ShaderMixinSource mixinTree, EffectCompilerParameters effectParameters, CompilerParameters compilerParameters, ObjectId mixinObjectId, DatabaseFileProvider database, string compiledUrl) { // Open the database for writing var log = new LoggerResult(); // Note: this compiler is expected to not be async and directly write stuff in localLogger var compiledShader = base.Compile(mixinTree, effectParameters, compilerParameters).WaitForResult(); compiledShader.CompilationLog.CopyTo(log); // If there are any errors, return immediately if (log.HasErrors) { lock (compilingShaders) { compilingShaders.Remove(mixinObjectId); } return new EffectBytecodeCompilerResult(null, log); } // Compute the bytecodeId var newBytecodeId = compiledShader.Bytecode.ComputeId(); // Check if we really need to store the bytecode lock (bytecodes) { // Using custom serialization to the database to store an object with a custom id // TODO: Check if we really need to write the bytecode everytime even if id is not changed var memoryStream = new MemoryStream(); compiledShader.Bytecode.WriteTo(memoryStream); memoryStream.Position = 0; database.ObjectDatabase.Write(memoryStream, newBytecodeId, true); database.AssetIndexMap[compiledUrl] = newBytecodeId; // Save bytecode Id to the database cache as well memoryStream.SetLength(0); memoryStream.Write((byte[])newBytecodeId, 0, ObjectId.HashSize); memoryStream.Position = 0; database.ObjectDatabase.Write(memoryStream, mixinObjectId, true); if (!bytecodes.ContainsKey(newBytecodeId)) { log.Verbose("New effect compiled #{0} [{1}] (db: {2})\r\n{3}", effectCompileCount, mixinObjectId, newBytecodeId, compilerParameters?.ToStringPermutationsDetailed()); Interlocked.Increment(ref effectCompileCount); // Replace or add new bytecode bytecodes[newBytecodeId] = compiledShader.Bytecode; } } lock (compilingShaders) { compilingShaders.Remove(mixinObjectId); } return compiledShader; }