本文整理汇总了C#中OperationResult.AddMessage方法的典型用法代码示例。如果您正苦于以下问题:C# OperationResult.AddMessage方法的具体用法?C# OperationResult.AddMessage怎么用?C# OperationResult.AddMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OperationResult
的用法示例。
在下文中一共展示了OperationResult.AddMessage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override bool Execute()
{
var timer = new Stopwatch();
timer.Start();
Log.LogMessage("NRoles v" + _Metadata.Version);
if (ShowTrace) {
SetUpTraceListener();
}
IOperationResult result;
try {
result = new RoleEngine().Execute(
new RoleEngineParameters(AssemblyPath) {
TreatWarningsAsErrors = TreatWarningsAsErrors,
RunPEVerify = false,
References = References.Split(';')
});
LogMessages(result);
}
catch (Exception ex) {
result = new OperationResult();
result.AddMessage(Error.InternalError());
LogMessages(result);
Log.LogErrorFromException(ex);
}
timer.Stop();
Log.LogMessage("NRoles done, took {0}s", (timer.ElapsedMilliseconds / 1000f));
return result.Success;
}
示例2: CheckComposition
public IOperationResult CheckComposition(TypeDefinition composition)
{
var rolesAndSelfTypes = _extractor.RetrieveRolesSelfTypes(composition);
var nonMatching = rolesAndSelfTypes.Where(rs => !Matches(rs.SelfType, composition));
var result = new OperationResult();
nonMatching.ForEach(rs =>
result.AddMessage(
Error.SelfTypeConstraintNotSetToCompositionType(composition, rs.Role.Resolve(), rs.SelfType)));
return result;
}
示例3: Verify
/// <summary>
/// Checks the assembly for errors and return the result of the operation.
/// </summary>
/// <returns>Result of the operation.</returns>
public IOperationResult Verify()
{
var result = new OperationResult();
var peVerifyPath = _peVerifyPath;
if (!File.Exists(peVerifyPath)) {
result.AddMessage(Error.PEVerifyDoesntExist(peVerifyPath));
return result;
}
if (_assembly != null) {
using (var assemblyFile = new TemporaryFile(Directory.GetCurrentDirectory())) {
_assembly.Write(assemblyFile.FilePath);
Verify(assemblyFile.FilePath, peVerifyPath, result);
}
}
else {
Verify(_assemblyPath, peVerifyPath, result);
}
return result;
}
示例4: CheckRoleDoesntImplementInterfacesExplicitly
private void CheckRoleDoesntImplementInterfacesExplicitly(OperationResult result)
{
var hasOverrides = _roleType.Methods.Any(m => m.HasOverrides);
if (hasOverrides) {
// Note: overrides can also be used in other languages that don't have the concept of explicit interface implementations.
// TODO: This message is too specific for C#
result.AddMessage(Error.RoleHasExplicitInterfaceImplementation(_roleType));
}
}
示例5: CheckRoleDoesntComposeItself
private void CheckRoleDoesntComposeItself(OperationResult result)
{
if (_roleType.RetrieveDirectRoles().Any(role => role.Resolve() == _roleType)) {
result.AddMessage(Error.RoleComposesItself(_roleType));
}
}
示例6: CheckRoleHasNoPlaceholders
private void CheckRoleHasNoPlaceholders(OperationResult result)
{
var members = new List<IMemberDefinition>();
_roleType.Properties.ForEach(m => members.Add(m));
_roleType.Events.ForEach(m => members.Add(m));
_roleType.Methods.ForEach(m => members.Add(m));
members.Where(m => m.IsMarkedAsPlaceholder()).
ForEach(m => result.AddMessage(Error.RoleHasPlaceholder(m)));
}
示例7: CheckRoleHasNoPInvokeMethods
private void CheckRoleHasNoPInvokeMethods(OperationResult result)
{
_roleType.Methods.Where(m => m.IsPInvokeImpl).
ForEach(m => result.AddMessage(Error.RoleHasPInvokeMethod(m)));
}
示例8: Main
static int Main(string[] args)
{
var timer = new Stopwatch();
timer.Start();
bool trace = false;
bool quiet = false;
bool warningsAsErrors = false;
string input = null;
string output = null;
string peVerifyPath = null;
int peVerifyTimeout = 5; // default 5s
bool showHelp = false;
var options = new OptionSet {
{ "h|help", "show options.", h => showHelp = h != null },
{ "q|quiet", "shhh.", q => quiet = q != null },
{ "evilwarnings", "treats warnings as errors.", wae => warningsAsErrors = wae != null },
{ "o|out=", "output to VALUE (default is to overwrite the input file).", o => output = o },
{ "peverifypath=", "path to the PEVerify executable to use to verify the resulting assembly.", (string pvp) => peVerifyPath = pvp },
{ "peverifytimeout=", "sets the timeout in seconds to wait for PEVerify to check the generated assembly.", (int pvt) => peVerifyTimeout = pvt },
{ "trace", "prints trace information (trust me, you don't want to see this).", t => trace = t != null }
};
List<string> unnamed;
try {
unnamed = options.Parse(args);
}
catch (OptionException e) {
ShowError(e.Message);
return -1;
}
if (!quiet) {
Console.WriteLine("NRoles v" + _Metadata.Version);
}
if (showHelp) {
ShowHelp(options);
return 0;
}
if (trace) {
SetUpTraceListener();
}
if (unnamed.Count != 1) {
var invalid = string.Join(", ", unnamed.ToArray());
if (invalid.Length > 0) invalid = " Invalid parameters: " + invalid;
ShowError("Provide valid parameters and one input assembly." + invalid);
return -1;
}
input = unnamed[0];
IOperationResult result;
try {
result = new RoleEngine().Execute(
new RoleEngineParameters(input, output) {
TreatWarningsAsErrors = warningsAsErrors,
RunPEVerify = peVerifyPath != null,
PEVerifyPath = peVerifyPath,
PEVerifyTimeout = peVerifyTimeout
});
}
catch (Exception ex) {
result = new OperationResult();
result.AddMessage(Error.InternalError());
if (trace) {
Console.WriteLine("Failed!");
Console.WriteLine();
Console.WriteLine(ex.ToString());
Console.WriteLine();
if (ex.InnerException != null) {
Console.WriteLine("INNER " + ex.InnerException.Message);
}
var hresult = Marshal.GetHRForException(ex);
Console.WriteLine("HRESULT 0x{0:x}", hresult);
}
}
timer.Stop();
result.Messages.ForEach(message => Console.WriteLine(message));
if (!quiet) {
// TODO: print statistics? timing, number of roles, number of compositions, etc... <= these would be like info messages...
Console.WriteLine("Done, took {0}s", (timer.ElapsedMilliseconds / 1000f));
}
if (!result.Success) return -1;
return 0;
}