本文整理汇总了C#中LoggerResult.Error方法的典型用法代码示例。如果您正苦于以下问题:C# LoggerResult.Error方法的具体用法?C# LoggerResult.Error怎么用?C# LoggerResult.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LoggerResult
的用法示例。
在下文中一共展示了LoggerResult.Error方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLocalLogger
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"));
}
示例2: Convert
/// <summary>
/// Converts the specified hlsl source code to glsl.
/// </summary>
/// <param name="hlslSourcecode">The HLSL source code.</param>
/// <param name="hlslEntryPoint">The HLSL entry point.</param>
/// <param name="stage">The stage to convert.</param>
/// <param name="shader">The shader.</param>
/// <param name="inputHlslFilepath">The input HLSL filepath.</param>
/// <returns>
/// The resulting glsl AST tree.
/// </returns>
public global::SiliconStudio.Shaders.Ast.Shader Convert(string hlslSourcecode, string hlslEntryPoint, PipelineStage stage, string inputHlslFilepath, IDictionary<int, string> inputAttributeNames, LoggerResult log)
{
try
{
// Convert from Framework.Graphics ShaderMacro to Framework.Shaders ShaderMacro
var macros = new global::SiliconStudio.Shaders.Parser.ShaderMacro[Macros.Count];
for (int index = 0; index < Macros.Count; index++)
macros[index] = new global::SiliconStudio.Shaders.Parser.ShaderMacro(Macros[index].Name, Macros[index].Definition);
var result = HlslParser.TryPreProcessAndParse(hlslSourcecode, inputHlslFilepath, macros, IncludeDirectories);
if (result.HasErrors)
{
log.Error(result.ToString());
return null;
}
// Prepare the shader before type inference analysis
HlslToGlslConvertor.Prepare(result.Shader);
HlslSemanticAnalysis.Run(result);
// If there are any type inference analysis, just display all errors but ytu
if (result.HasErrors)
{
log.Error(result.ToString());
return null;
}
return Convert(result, hlslEntryPoint, stage, inputHlslFilepath, inputAttributeNames, log);
}
catch (Exception ex)
{
log.Error("Unexpected error while converting file [{0}] with entry point [{1}]", ex, inputHlslFilepath, hlslEntryPoint);
}
return null;
}
示例3: UpdateReflection
private void UpdateReflection(ShaderBytecode shaderBytecode, EffectReflection effectReflection, LoggerResult log)
{
var shaderReflectionRaw = new SharpDX.D3DCompiler.ShaderReflection(shaderBytecode);
var shaderReflectionRawDesc = shaderReflectionRaw.Description;
// Constant Buffers
for (int i = 0; i < shaderReflectionRawDesc.ConstantBuffers; ++i)
{
var constantBufferRaw = shaderReflectionRaw.GetConstantBuffer(i);
var constantBufferRawDesc = constantBufferRaw.Description;
var linkBuffer = effectReflection.ConstantBuffers.FirstOrDefault(buffer => buffer.Name == constantBufferRawDesc.Name && buffer.Stage == ShaderStage.None);
var constantBuffer = GetConstantBufferReflection(constantBufferRaw, ref constantBufferRawDesc, linkBuffer, log);
constantBuffer.Stage = shaderBytecode.Stage;
effectReflection.ConstantBuffers.Add(constantBuffer);
}
// BoundResources
for (int i = 0; i < shaderReflectionRawDesc.BoundResources; ++i)
{
var boundResourceDesc = shaderReflectionRaw.GetResourceBindingDescription(i);
string linkKeyName = null;
foreach (var linkResource in effectReflection.ResourceBindings)
{
if (linkResource.Param.RawName == boundResourceDesc.Name && linkResource.Stage == ShaderStage.None)
{
linkKeyName = linkResource.Param.KeyName;
break;
}
}
if (linkKeyName == null)
{
log.Error("Resource [{0}] has no link", boundResourceDesc.Name);
}
else
{
var binding = GetResourceBinding(boundResourceDesc, linkKeyName, log);
binding.Stage = shaderBytecode.Stage;
effectReflection.ResourceBindings.Add(binding);
}
}
}
示例4: ConvertVariableValueType
private EffectParameterType ConvertVariableValueType(ShaderVariableType type, LoggerResult log)
{
EffectParameterType effectParameterType;
if (!MapTypes.TryGetValue(type, out effectParameterType))
{
log.Error("Type [{0}] from D3DCompiler not supported", type);
}
return effectParameterType;
}
示例5: GetConstantBufferReflection
private ShaderConstantBufferDescription GetConstantBufferReflection(ConstantBuffer constantBufferRaw, ref ConstantBufferDescription constantBufferRawDesc, ShaderConstantBufferDescription linkBuffer, LoggerResult log)
{
var constantBuffer = new ShaderConstantBufferDescription
{
Name = constantBufferRawDesc.Name,
Size = constantBufferRawDesc.Size,
};
switch (constantBufferRawDesc.Type)
{
case SharpDX.D3DCompiler.ConstantBufferType.ConstantBuffer:
constantBuffer.Type = ConstantBufferType.ConstantBuffer;
break;
case SharpDX.D3DCompiler.ConstantBufferType.TextureBuffer:
constantBuffer.Type = ConstantBufferType.TextureBuffer;
break;
default:
constantBuffer.Type = ConstantBufferType.Unknown;
break;
}
// ConstantBuffers variables
var members = new List<EffectParameterValueData>();
for (int i = 0; i < constantBufferRawDesc.VariableCount; i++)
{
var variable = constantBufferRaw.GetVariable(i);
var variableType = variable.GetVariableType();
var variableDescription = variable.Description;
var variableTypeDescription = variableType.Description;
var parameter = new EffectParameterValueData()
{
Param =
{
Class = (EffectParameterClass)variableTypeDescription.Class,
Type = ConvertVariableValueType(variableTypeDescription.Type, log),
RawName = variableDescription.Name,
},
Offset = variableDescription.StartOffset,
Size = variableDescription.Size,
Count = variableTypeDescription.ElementCount == 0 ? 1 : variableTypeDescription.ElementCount,
RowCount = (byte)variableTypeDescription.RowCount,
ColumnCount = (byte)variableTypeDescription.ColumnCount,
};
if (variableTypeDescription.Offset != 0)
{
log.Error("Unexpected offset [{0}] for variable [{1}] in constant buffer [{2}]", variableTypeDescription.Offset, variableDescription.Name, constantBuffer.Name);
}
bool bindingNotFound = true;
// Retrieve Link Member
foreach (var binding in linkBuffer.Members)
{
if (binding.Param.RawName == variableDescription.Name)
{
// TODO: should we replicate linkMember.Count/RowCount/ColumnCount? or use what is retrieved by D3DCompiler reflection
parameter.Param.KeyName = binding.Param.KeyName;
bindingNotFound = false;
break;
}
}
if (bindingNotFound)
{
log.Error("Variable [{0}] in constant buffer [{1}] has no link", variableDescription.Name, constantBuffer.Name);
}
members.Add(parameter);
}
constantBuffer.Members = members.ToArray();
return constantBuffer;
}
示例6: AddExitingProject
/// <summary>
/// Adds an exiting project to this package.
/// </summary>
/// <param name="pathToMsproj">The path to msproj.</param>
/// <param name="logger">The logger.</param>
public void AddExitingProject(UFile pathToMsproj, LoggerResult logger)
{
if (pathToMsproj == null) throw new ArgumentNullException("pathToMsproj");
if (logger == null) throw new ArgumentNullException("logger");
if (!pathToMsproj.IsAbsolute) throw new ArgumentException("Expecting relative path", "pathToMsproj");
try
{
// Load a project without specifying a platform to make sure we get the correct platform type
var msProject = VSProjectHelper.LoadProject(pathToMsproj, platform: "NoPlatform");
var projectType = VSProjectHelper.GetProjectTypeFromProject(msProject);
if (!projectType.HasValue)
{
logger.Error("This project is not a project created with the editor");
}
else
{
var platformType = VSProjectHelper.GetPlatformTypeFromProject(msProject) ?? PlatformType.Shared;
var projectReference = new ProjectReference()
{
Id = VSProjectHelper.GetProjectGuid(msProject),
Location = pathToMsproj.MakeRelative(RootDirectory),
Type = projectType.Value
};
// Add the ProjectReference only for the compatible profiles (same platform or no platform)
foreach (var profile in Profiles.Where(profile => platformType == profile.Platform))
{
profile.ProjectReferences.Add(projectReference);
}
}
}
catch (Exception ex)
{
logger.Error("Unexpected exception while loading project [{0}]", ex, pathToMsproj);
}
}
示例7: Save
/// <summary>
/// Saves all packages and assets.
/// </summary>
/// <param name="log">The <see cref="LoggerResult"/> in which to report result.</param>
public void Save(LoggerResult log, PackageSaveParameters saveParameters = null)
{
bool packagesSaved = false;
//var clock = Stopwatch.StartNew();
using (var profile = Profiler.Begin(PackageSessionProfilingKeys.Saving))
{
try
{
saveParameters = saveParameters ?? PackageSaveParameters.Default();
var assetsOrPackagesToRemove = BuildAssetsOrPackagesToRemove();
// Compute packages that have been renamed
// TODO: Disable for now, as not sure if we want to delete a previous package
//foreach (var package in packagesCopy)
//{
// var newPackage = packages.Find(package.Id);
// if (newPackage != null && package.PackagePath != null && newPackage.PackagePath != package.PackagePath)
// {
// assetsOrPackagesToRemove[package.PackagePath] = package;
// }
//}
// Depending on saveParameters, select the list of source file operations to do
List<SourceFileOperation> sourceFileOperations;
switch (saveParameters.SaveSourceFileOperations)
{
case PackageSaveSourceFileOperations.All:
sourceFileOperations = BuildSourceFileOperations(assetsOrPackagesToRemove);
break;
case PackageSaveSourceFileOperations.ReversibleOnly:
sourceFileOperations = BuildSourceFileOperations(assetsOrPackagesToRemove).Where(x => !x.Irreversible).ToList();
break;
case PackageSaveSourceFileOperations.None:
sourceFileOperations = new List<SourceFileOperation>();
break;
default:
throw new ArgumentOutOfRangeException();
}
// If package are not modified, return immediately
if (!CheckModifiedPackages() && assetsOrPackagesToRemove.Count == 0 && sourceFileOperations.Count == 0)
{
return;
}
// Suspend tracking when saving as we don't want to receive
// all notification events
if (dependencies != null)
{
dependencies.BeginSavingSession();
}
// Return immediately if there is any error
if (log.HasErrors)
{
return;
}
// Perform source file operations
foreach (var sourceFileOperation in sourceFileOperations)
{
switch (sourceFileOperation.Type)
{
case SourceFileOperationType.Move:
try
{
// Move target already exists: try to copy and then delete
if (File.Exists(sourceFileOperation.Destination))
{
// Use upper try/catch
File.Copy(sourceFileOperation.Source, sourceFileOperation.Destination, true);
// Try to delete source
try
{
File.Delete(sourceFileOperation.Source);
}
catch (Exception ex)
{
// File locked?
log.Warning(sourceFileOperation.AssetItem.Package, sourceFileOperation.AssetItem.ToReference(), AssetMessageCode.AssetCannotDelete, ex, sourceFileOperation.Source);
}
}
else
{
try
{
File.Move(sourceFileOperation.Source, sourceFileOperation.Destination);
}
catch (Exception ex)
{
// Could not Move, revert back to a Copy instead
// Use upper try/catch
File.Copy(sourceFileOperation.Source, sourceFileOperation.Destination, true);
log.Warning(sourceFileOperation.AssetItem.Package, sourceFileOperation.AssetItem.ToReference(), AssetMessageCode.AssetCannotDelete, ex,
//.........这里部分代码省略.........
示例8: Save
/// <summary>
/// Saves all packages and assets.
/// </summary>
/// <param name="log">The <see cref="LoggerResult"/> in which to report result.</param>
public void Save(LoggerResult log)
{
bool packagesSaved = false;
//var clock = Stopwatch.StartNew();
using (var profile = Profiler.Begin(PackageSessionProfilingKeys.Saving))
{
try
{
// Grab all previous assets
var previousAssets = new Dictionary<Guid, AssetItem>();
foreach (var assetItem in packagesCopy.SelectMany(package => package.Assets))
{
previousAssets[assetItem.Id] = assetItem;
}
// Grab all new assets
var newAssets = new Dictionary<Guid, AssetItem>();
foreach (var assetItem in LocalPackages.SelectMany(package => package.Assets))
{
newAssets[assetItem.Id] = assetItem;
}
// Compute all assets that were removed
var assetsOrPackagesToRemove = new Dictionary<UFile, object>();
foreach (var assetIt in previousAssets)
{
var asset = assetIt.Value;
AssetItem newAsset;
if (!newAssets.TryGetValue(assetIt.Key, out newAsset) || newAsset.Location != asset.Location)
{
assetsOrPackagesToRemove[asset.FullPath] = asset;
}
}
// Compute packages that have been renamed
// TODO: Disable for now, as not sure if we want to delete a previous package
//foreach (var package in packagesCopy)
//{
// var newPackage = packages.Find(package.Id);
// if (newPackage != null && package.PackagePath != null && newPackage.PackagePath != package.PackagePath)
// {
// assetsOrPackagesToRemove[package.PackagePath] = package;
// }
//}
// If package are not modified, return immediately
if (!CheckModifiedPackages() && assetsOrPackagesToRemove.Count == 0)
{
return;
}
// Suspend tracking when saving as we don't want to receive
// all notification events
if (dependencies != null)
{
dependencies.BeginSavingSession();
}
// Return immediately if there is any error
if (log.HasErrors)
{
return;
}
// Delete previous files
foreach (var fileIt in assetsOrPackagesToRemove)
{
var assetPath = fileIt.Key;
var assetItemOrPackage = fileIt.Value;
if (File.Exists(assetPath))
{
try
{
File.Delete(assetPath);
}
catch (Exception ex)
{
var assetItem = assetItemOrPackage as AssetItem;
if (assetItem != null)
{
log.Error(assetItem.Package, assetItem.ToReference(), AssetMessageCode.AssetCannotDelete, ex, assetPath);
}
else
{
var package = assetItemOrPackage as Package;
if (package != null)
{
log.Error(package, null, AssetMessageCode.AssetCannotDelete, ex, assetPath);
}
}
}
}
}
//.........这里部分代码省略.........
示例9: CheckDependencies
/// <summary>
/// Checks the package.
/// </summary>
/// <returns>LoggerResult.</returns>
public LoggerResult CheckDependencies()
{
var log = new LoggerResult();
// Can only check dependencies if we are inside a session
if (package.Session == null)
{
return log;
}
// If ProjetcPath is null, the package was not saved.
if (Parameters.ConvertUPathTo == UPathType.Relative && package.FullPath == null)
{
log.Error(package, null, AssetMessageCode.PackageFilePathNotSet);
return log;
}
// 1. Check all store package references
foreach (var packageDependency in package.Meta.Dependencies)
{
// Try to find the package reference
var subPackage = package.Session.Packages.Find(packageDependency);
if (subPackage == null)
{
// Originally we were fixing DefaultPackage version, but it should now be handled by package upgraders
log.Error(package, null, AssetMessageCode.PackageNotFound, packageDependency);
}
}
// 2. Check all local package references
foreach (var packageReference in package.LocalDependencies)
{
// Try to find the package reference
var newSubPackage = package.Session.Packages.Find(packageReference.Id);
if (newSubPackage == null)
{
log.Error(package, null, AssetMessageCode.PackageNotFound, packageReference.Location);
continue;
}
if (newSubPackage.FullPath == null || newSubPackage.IsSystem)
{
continue;
}
// If package was found, check that the path is correctly setup
var pathToSubPackage = Parameters.ConvertUPathTo == UPathType.Relative ? newSubPackage.FullPath.MakeRelative(package.RootDirectory) : newSubPackage.FullPath;
if (packageReference.Location != pathToSubPackage)
{
// Modify package path to be relative if different
packageReference.Location = pathToSubPackage;
if (Parameters.SetDirtyFlagOnAssetWhenFixingUFile)
{
package.IsDirty = true;
}
}
}
// TODO: Check profiles
return log;
}
示例10: Convert
/// <summary>
/// Converts the specified hlsl source code to glsl.
/// </summary>
/// <param name="hlslEntryPoint">The HLSL entry point.</param>
/// <param name="stage">The stage to convert.</param>
/// <param name="shader">The shader.</param>
/// <param name="inputHlslFilepath">The input HLSL filepath.</param>
/// <returns>
/// The resulting glsl AST tree.
/// </returns>
private global::SiliconStudio.Shaders.Ast.Shader Convert(ParsingResult result, string hlslEntryPoint, PipelineStage stage, string inputHlslFilepath, LoggerResult log)
{
try
{
var convertor = new HlslToGlslConvertor(hlslEntryPoint, stage, ShaderModel.Model40) // TODO HARDCODED VALUE to change
{
KeepConstantBuffer = !isOpenGLES || isOpenGLES3,
TextureFunctionsCompatibilityProfile = isOpenGLES && !isOpenGLES3,
NoSwapForBinaryMatrixOperation = true,
UseBindingLayout = false,
UseLocationLayout = false,
UseSemanticForVariable = true,
IsPointSpriteShader = false,
ViewFrustumRemap = true,
FlipRenderTargetFlag = "ParadoxFlipRendertarget",
KeepNonUniformArrayInitializers = !isOpenGLES,
IsOpenGLES2 = isOpenGLES && !isOpenGLES3
};
convertor.Run(result);
// After the converter we display the errors but we don't stop writing output glsl
if (result.HasErrors)
{
//DisplayError(log, result, "Error while converting file:");
}
return result.Shader;
}
catch (Exception ex)
{
log.Error("Unexpected error while converting file [{0}] with entry point [{1}]", ex, inputHlslFilepath, hlslEntryPoint);
return null;
}
}
示例11: LockProcessAndAddDataToLogger
/// <summary>
/// Lock the process and save the string.
/// </summary>
/// <param name="process">The current process.</param>
/// <param name="logger">Logger were out current process.</param>
/// <param name="isError">Is this the error output or the standard one?</param>
/// <param name="args">arguments of the process.</param>
private static void LockProcessAndAddDataToLogger(Process process, LoggerResult logger, bool isError, DataReceivedEventArgs args)
{
if (!string.IsNullOrEmpty(args.Data))
{
lock (process)
{
if (isError)
logger.Error(args.Data);
else
logger.Info(args.Data);
}
}
}
示例12: ValidateConstantBufferReflection
private void ValidateConstantBufferReflection(ConstantBuffer constantBufferRaw, ref ConstantBufferDescription constantBufferRawDesc, EffectConstantBufferDescription constantBuffer, LoggerResult log)
{
switch (constantBufferRawDesc.Type)
{
case SharpDX.D3DCompiler.ConstantBufferType.ConstantBuffer:
if (constantBuffer.Type != ConstantBufferType.ConstantBuffer)
log.Error($"Invalid buffer type for {constantBuffer.Name}: {constantBuffer.Type} instead of {ConstantBufferType.ConstantBuffer}");
break;
case SharpDX.D3DCompiler.ConstantBufferType.TextureBuffer:
if (constantBuffer.Type != ConstantBufferType.TextureBuffer)
log.Error($"Invalid buffer type for {constantBuffer.Name}: {constantBuffer.Type} instead of {ConstantBufferType.TextureBuffer}");
break;
default:
if (constantBuffer.Type != ConstantBufferType.Unknown)
log.Error($"Invalid buffer type for {constantBuffer.Name}: {constantBuffer.Type} instead of {ConstantBufferType.Unknown}");
break;
}
// ConstantBuffers variables
for (int i = 0; i < constantBufferRawDesc.VariableCount; i++)
{
var variable = constantBufferRaw.GetVariable(i);
var variableType = variable.GetVariableType();
var variableDescription = variable.Description;
var variableTypeDescription = variableType.Description;
if (variableTypeDescription.Offset != 0)
{
log.Error("Unexpected offset [{0}] for variable [{1}] in constant buffer [{2}]", variableTypeDescription.Offset, variableDescription.Name, constantBuffer.Name);
}
var binding = constantBuffer.Members[i];
// Retrieve Link Member
if (binding.RawName != variableDescription.Name)
{
log.Error("Variable [{0}] in constant buffer [{1}] has no link", variableDescription.Name, constantBuffer.Name);
}
else
{
var parameter = new EffectValueDescription()
{
Type =
{
Class = (EffectParameterClass)variableTypeDescription.Class,
Type = ConvertVariableValueType(variableTypeDescription.Type, log),
Elements = variableTypeDescription.ElementCount,
RowCount = (byte)variableTypeDescription.RowCount,
ColumnCount = (byte)variableTypeDescription.ColumnCount,
},
RawName = variableDescription.Name,
Offset = variableDescription.StartOffset,
Size = variableDescription.Size,
};
if (parameter.Offset != binding.Offset
|| parameter.Size != binding.Size
|| parameter.Type.Elements != binding.Type.Elements
|| ((parameter.Type.Class != EffectParameterClass.Struct) && // Ignore columns/rows if it's a struct (sometimes it contains weird data)
(parameter.Type.RowCount != binding.Type.RowCount || parameter.Type.ColumnCount != binding.Type.ColumnCount)))
{
log.Error("Variable [{0}] in constant buffer [{1}] binding doesn't match what was expected", variableDescription.Name, constantBuffer.Name);
}
}
}
if (constantBuffer.Size != constantBufferRawDesc.Size)
{
log.Error($"Error precomputing buffer size for {constantBuffer.Name}: {constantBuffer.Size} instead of {constantBufferRawDesc.Size}");
}
}
示例13: Save
/// <summary>
/// Saves all packages and assets.
/// </summary>
/// <param name="log">The <see cref="LoggerResult"/> in which to report result.</param>
/// <param name="saveParameters">The parameters for the save operation.</param>
public void Save(LoggerResult log, PackageSaveParameters saveParameters = null)
{
bool packagesSaved = false;
//var clock = Stopwatch.StartNew();
using (var profile = Profiler.Begin(PackageSessionProfilingKeys.Saving))
{
var packagesDirty = false;
try
{
saveParameters = saveParameters ?? PackageSaveParameters.Default();
var assetsOrPackagesToRemove = BuildAssetsOrPackagesToRemove();
// Compute packages that have been renamed
// TODO: Disable for now, as not sure if we want to delete a previous package
//foreach (var package in packagesCopy)
//{
// var newPackage = packages.Find(package.Id);
// if (newPackage != null && package.PackagePath != null && newPackage.PackagePath != package.PackagePath)
// {
// assetsOrPackagesToRemove[package.PackagePath] = package;
// }
//}
// If package are not modified, return immediately
if (!CheckModifiedPackages() && assetsOrPackagesToRemove.Count == 0)
{
return;
}
// Suspend tracking when saving as we don't want to receive
// all notification events
dependencies?.BeginSavingSession();
sourceTracker?.BeginSavingSession();
// Return immediately if there is any error
if (log.HasErrors)
return;
//batch projects
var vsProjs = new Dictionary<string, Project>();
// Delete previous files
foreach (var fileIt in assetsOrPackagesToRemove)
{
var assetPath = fileIt.Key;
var assetItemOrPackage = fileIt.Value;
var assetItem = assetItemOrPackage as AssetItem;
if (File.Exists(assetPath))
{
try
{
//If we are within a csproj we need to remove the file from there as well
if (assetItem?.SourceProject != null)
{
var projectAsset = assetItem.Asset as IProjectAsset;
if (projectAsset != null)
{
var projectInclude = assetItem.GetProjectInclude();
Project project;
if (!vsProjs.TryGetValue(assetItem.SourceProject, out project))
{
project = VSProjectHelper.LoadProject(assetItem.SourceProject);
vsProjs.Add(assetItem.SourceProject, project);
}
var projectItem = project.Items.FirstOrDefault(x => (x.ItemType == "Compile" || x.ItemType == "None") && x.EvaluatedInclude == projectInclude);
if (projectItem != null)
{
project.RemoveItem(projectItem);
}
//delete any generated file as well
var generatorAsset = assetItem.Asset as IProjectFileGeneratorAsset;
if (generatorAsset != null)
{
var generatedAbsolutePath = assetItem.GetGeneratedAbsolutePath().ToWindowsPath();
File.Delete(generatedAbsolutePath);
var generatedInclude = assetItem.GetGeneratedInclude();
var generatedItem = project.Items.FirstOrDefault(x => (x.ItemType == "Compile" || x.ItemType == "None") && x.EvaluatedInclude == generatedInclude);
if (generatedItem != null)
{
project.RemoveItem(generatedItem);
}
}
}
}
File.Delete(assetPath);
}
catch (Exception ex)
//.........这里部分代码省略.........