本文整理汇总了C#中LoadOperation.Complete方法的典型用法代码示例。如果您正苦于以下问题:C# LoadOperation.Complete方法的具体用法?C# LoadOperation.Complete怎么用?C# LoadOperation.Complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LoadOperation
的用法示例。
在下文中一共展示了LoadOperation.Complete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Exceptions
public void Exceptions()
{
Cities.CityDomainContext cities = new CityDomainContext(TestURIs.Cities);
Action<LoadOperation<City>> loCallback = (op) =>
{
if (op.HasError)
{
op.MarkErrorAsHandled();
}
throw new InvalidOperationException("Fnord!");
};
Action<SubmitOperation> soCallback = (op) =>
{
if (op.HasError)
{
op.MarkErrorAsHandled();
}
throw new InvalidOperationException("Fnord!");
};
Action<InvokeOperation> ioCallback = (op) =>
{
if (op.HasError)
{
op.MarkErrorAsHandled();
}
throw new InvalidOperationException("Fnord!");
};
LoadOperation lo = new LoadOperation<City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, loCallback, null, loCallback);
// verify completion callbacks that throw
ExceptionHelper.ExpectInvalidOperationException(delegate
{
try
{
lo.Complete(DomainClientResult.CreateQueryResult(new Entity[0], new Entity[0], 0, new ValidationResult[0]));
}
catch (Exception ex)
{
Assert.IsTrue(ex.StackTrace.Contains("at OpenRiaServices.DomainServices.Client.Test.OperationTests"), "Stacktrace not preserved.");
throw;
}
}, "Fnord!");
// verify cancellation callbacks for all fx operation types
lo = new LoadOperation<City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, null, null, loCallback);
ExceptionHelper.ExpectInvalidOperationException(delegate
{
lo.Cancel();
}, "Fnord!");
SubmitOperation so = new SubmitOperation(cities.EntityContainer.GetChanges(), soCallback, null, soCallback);
ExceptionHelper.ExpectInvalidOperationException(delegate
{
so.Cancel();
}, "Fnord!");
InvokeOperation io = new InvokeOperation("Fnord", null, null, null, ioCallback);
ExceptionHelper.ExpectInvalidOperationException(delegate
{
io.Cancel();
}, "Fnord!");
}
示例2: Operation_MarkAsHandled
public void Operation_MarkAsHandled()
{
TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc"));
var query = ctxt.CreateQuery<Product>("ThrowGeneralException", null, false, true);
LoadOperation lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null);
EventHandler action = (o, e) =>
{
LoadOperation loadOperation = (LoadOperation)o;
if (loadOperation.HasError)
{
loadOperation.MarkErrorAsHandled();
}
};
lo.Completed += action;
DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace");
lo.Complete(ex);
// verify that calling MarkAsHandled again is a noop
lo.MarkErrorAsHandled();
lo.MarkErrorAsHandled();
// verify that calling MarkAsHandled on an operation not in error
// results in an exception
lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null);
Assert.IsFalse(lo.HasError);
Assert.IsTrue(lo.IsErrorHandled);
ExceptionHelper.ExpectInvalidOperationException(delegate
{
lo.MarkErrorAsHandled();
}, Resource.Operation_HasErrorMustBeTrue);
}
示例3: UnhandledLoadOperationError
public void UnhandledLoadOperationError()
{
TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc"));
var query = ctxt.CreateQuery<Product>("ThrowGeneralException", null, false, true);
LoadOperation lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null);
DomainOperationException expectedException = null;
DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace");
try
{
lo.Complete(ex);
}
catch (DomainOperationException e)
{
expectedException = e;
}
// verify the exception properties
Assert.IsNotNull(expectedException);
Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed, "ThrowGeneralException", ex.Message), expectedException.Message);
Assert.AreEqual(ex.StackTrace, expectedException.StackTrace);
Assert.AreEqual(ex.Status, expectedException.Status);
Assert.AreEqual(ex.ErrorCode, expectedException.ErrorCode);
Assert.AreEqual(false, lo.IsErrorHandled);
// now test again with validation errors
expectedException = null;
ValidationResult[] validationErrors = new ValidationResult[] { new ValidationResult("Foo", new string[] { "Bar" }) };
lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null);
try
{
lo.Complete(validationErrors);
}
catch (DomainOperationException e)
{
expectedException = e;
}
// verify the exception properties
Assert.IsNotNull(expectedException);
Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed_Validation, "ThrowGeneralException"), expectedException.Message);
}