本文整理汇总了C#中ICommunicationContext类的典型用法代码示例。如果您正苦于以下问题:C# ICommunicationContext类的具体用法?C# ICommunicationContext怎么用?C# ICommunicationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICommunicationContext类属于命名空间,在下文中一共展示了ICommunicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TaskEndPointHandler
public TaskEndPointHandler(ITaskRetriever taskRetriever, ITaskListRetriever taskListRetriever, IAmACommandProcessor commandProcessor, ICommunicationContext communicationContext)
{
this.taskRetriever = taskRetriever;
this.taskListRetriever = taskListRetriever;
this.commandProcessor = commandProcessor;
this.communicationContext = communicationContext;
}
示例2: StripResponseElement
public PipelineContinuation StripResponseElement(ICommunicationContext context)
{
var passedApiUrl
= (string)context.PipelineData["ApiUrl"];
if (string.IsNullOrEmpty(passedApiUrl))
return PipelineContinuation.Continue;
var xmlDocument
= (XmlDocument)context.PipelineData["ApiXmlResponse"];
// read and remove response header to get result
var responseElement = xmlDocument.SelectSingleNode("/response");
var responseStatusAttribute = responseElement.Attributes["status"];
var innerXml = responseElement.InnerXml;
var stringReader = new StringReader(innerXml);
// get the type
Type generatedType = responseStatusAttribute.InnerText == "ok"
? _typeGenerator.GenerateType(passedApiUrl)
: typeof(Error);
var serializer = new XmlSerializer(generatedType);
object deserialized = serializer.Deserialize(stringReader);
if (responseStatusAttribute.InnerText == "ok")
context.OperationResult = new OperationResult.OK(deserialized);
else
context.OperationResult = new OperationResult.BadRequest { ResponseResource = deserialized };
return PipelineContinuation.Continue;
}
示例3: ResolveCodec
ICodec ResolveCodec(ICommunicationContext context)
{
var codecInstance = context.Response.Entity.Codec;
if (codecInstance != null)
{
Log.WriteDebug("Codec instance with type {0} has already been defined.",
codecInstance.GetType().Name);
}
else
{
context.Response.Entity.Codec =
codecInstance =
DependencyManager.GetService(context.PipelineData.ResponseCodec.CodecType) as ICodec;
}
if (codecInstance == null)
throw new CodecNotFoundException(
$"Codec {context.PipelineData.ResponseCodec.CodecType} couldn't be initialized.");
Log.WriteDebug("Codec {0} selected.", codecInstance.GetType().Name);
if (context.PipelineData.ResponseCodec?.Configuration != null)
codecInstance.Configuration = context.PipelineData.ResponseCodec.Configuration;
return codecInstance;
}
示例4: SetupCommunicationContext
public void SetupCommunicationContext(ICommunicationContext context)
{
Log.WriteDebug("Adding communication context data");
Resolver.AddDependencyInstance<ICommunicationContext>(context, DependencyLifetime.PerRequest);
Resolver.AddDependencyInstance<IRequest>(context.Request, DependencyLifetime.PerRequest);
Resolver.AddDependencyInstance<IResponse>(context.Response, DependencyLifetime.PerRequest);
}
示例5: WriteResponseBuffered
async Task<PipelineContinuation> WriteResponseBuffered(ICommunicationContext context)
{
if (context.Response.Entity.Instance == null)
{
Log.WriteDebug("There was no response entity, not rendering.");
await SendEmptyResponse(context);
return PipelineContinuation.Continue;
}
var codecInstance = ResolveCodec(context);
var writer = CreateWriter(codecInstance);
using (Log.Operation(this, "Generating response entity."))
{
await writer(
context.Response.Entity.Instance,
context.Response.Entity,
context.Request.CodecParameters.ToArray());
await PadErrorMessageForIE(context);
if (context.Response.Entity.Stream.CanSeek)
context.Response.Entity.ContentLength = context.Response.Entity.Stream.Length;
}
return PipelineContinuation.Continue;
}
示例6: GenerateEtag
static string GenerateEtag(ICommunicationContext context, string partialEtag)
{
// we should only include components for the headers present in the Vary header
// can't do it now as Vary is not set by OR, bug to fix in 2.1
return Etag.StrongEtag(partialEtag);
}
示例7: ProcessDecorators
public PipelineContinuation ProcessDecorators(ICommunicationContext context)
{
Uri currentUri = context.Request.Uri;
IList<DecoratorPointer> decorators = CreateDecorators();
/* Whenever we execute the decorators, each decorator gets a say in matching a url.
* Whenever a decorator fails, it is ignored.
* Whenever a decorator succeeds, it is marked as such so that its Apply() method gets called
* Whenever a decorator that succeeded has changed the url, we reprocess all the decorators that failed before with the new url.
* */
for (int i = 0; i < decorators.Count; i++)
{
DecoratorPointer decorator = decorators[i];
Uri processedUri;
if (!decorator.Successful
&& decorator.Decorator.Parse(currentUri, out processedUri))
{
decorator.Successful = true;
if (currentUri != processedUri && processedUri != null)
{
currentUri = processedUri;
i = -1;
continue;
}
}
}
foreach (var decorator in decorators)
{
if (decorator.Successful)
decorator.Decorator.Apply();
}
context.Request.Uri = currentUri;
return PipelineContinuation.Continue;
}
示例8: PageHandler
public PageHandler(IPageRepository pageRepository, ICommunicationContext context, IUriResolver uriResolver, IMarkdown markdown)
{
this.pageRepository = pageRepository;
this.context = context;
this.uriResolver = uriResolver;
this.markdown = markdown;
}
示例9: InitializeContainer
private PipelineContinuation InitializeContainer(ICommunicationContext arg)
{
var container = new TinyIoCAdapter(new TinyIoCContainer());
//HACK! For now dependencies may need to be in both containers to allow resolution
container.Register<IHandleRequests<AddTaskCommand>, AddTaskCommandHandler>().AsMultiInstance();
container.Register<ITaskListRetriever, TaskListRetriever>().AsMultiInstance();
container.Register<ITasksDAO, TasksDAO>().AsMultiInstance();
var logger = LogManager.GetLogger("TaskList");
container.Register<ILog, ILog>(logger);
container.Register<IAmARequestContextFactory, InMemoryRequestContextFactory>().AsMultiInstance();
MessageStoreFactory.InstallRavenDbMessageStore(container);
container.Register<IAmAMessageStore<Message>, RavenMessageStore>().AsSingleton();
container.Register<IAmAMessagingGateway, RMQMessagingGateway>().AsSingleton();
container.Register<Policy>(CommandProcessor.RETRYPOLICY, GetRetryPolicy());
container.Register<Policy>(CommandProcessor.CIRCUITBREAKER, GetCircuitBreakerPolicy());
var commandProcessor = new CommandProcessorFactory(container).Create();
container.Register<IAmACommandProcessor, IAmACommandProcessor>(commandProcessor);
resolver.AddDependencyInstance<IAdaptAnInversionOfControlContainer>(container, DependencyLifetime.Singleton);
resolver.AddDependencyInstance<IAmARequestContextFactory>(new InMemoryRequestContextFactory(), DependencyLifetime.PerRequest);
resolver.AddDependencyInstance<IAmACommandProcessor>(commandProcessor, DependencyLifetime.Singleton);
resolver.AddDependency<ITaskRetriever, TaskRetriever>(DependencyLifetime.Singleton);
resolver.AddDependency<ITaskListRetriever, TaskListRetriever>(DependencyLifetime.Singleton);
return PipelineContinuation.Continue;
}
示例10: OnExecute
protected override void OnExecute(ICommunicationContext context)
{
context.Request.Entity.Errors.AddRange(this.Errors);
context.Response.Entity.Errors.AddRange(context.Request.Entity.Errors);
base.OnExecute(context);
}
示例11: FindResponseCodec
public PipelineContinuation FindResponseCodec(ICommunicationContext context)
{
if (context.Response.Entity.Instance == null || context.PipelineData.ResponseCodec != null)
{
LogNoResponseEntity();
return PipelineContinuation.Continue;
}
string acceptHeader = context.Request.Headers[HEADER_ACCEPT];
IEnumerable<MediaType> acceptedContentTypes =
MediaType.Parse(string.IsNullOrEmpty(acceptHeader) ? "*/*" : acceptHeader);
IType responseEntityType = _typeSystem.FromInstance(context.Response.Entity.Instance);
IEnumerable<CodecRegistration> sortedCodecs = _codecs.FindMediaTypeWriter(responseEntityType,
acceptedContentTypes);
int codecsCount = sortedCodecs.Count();
CodecRegistration negotiatedCodec = sortedCodecs.FirstOrDefault();
if (negotiatedCodec != null)
{
LogCodecSelected(responseEntityType, negotiatedCodec, codecsCount);
context.Response.Entity.ContentType = negotiatedCodec.MediaType.WithoutQuality();
context.PipelineData.ResponseCodec = negotiatedCodec;
}
else
{
context.OperationResult = ResponseEntityHasNoCodec(acceptHeader, responseEntityType);
return PipelineContinuation.RenderNow;
}
return PipelineContinuation.Continue;
}
示例12: ProcessRequest
public override void ProcessRequest(ICommunicationContext ctx)
{
var postDataListID = GetDataListID(ctx);
if(postDataListID != null)
{
new WebPostRequestHandler().ProcessRequest(ctx);
return;
}
var serviceName = GetServiceName(ctx);
var workspaceID = GetWorkspaceID(ctx);
var requestTO = new WebRequestTO { ServiceName = serviceName, WebServerUrl = ctx.Request.Uri.ToString(), Dev2WebServer = String.Format("{0}://{1}", ctx.Request.Uri.Scheme, ctx.Request.Uri.Authority) };
var data = GetPostData(ctx);
if(!String.IsNullOrEmpty(data))
{
requestTO.RawRequestPayload = data;
}
var variables = ctx.Request.BoundVariables;
if(variables != null)
{
foreach(string key in variables)
{
requestTO.Variables.Add(key, variables[key]);
}
}
// Execute in its own thread to give proper context ;)
Thread.CurrentPrincipal = ctx.Request.User;
var responseWriter = CreateForm(requestTO, serviceName, workspaceID, ctx.FetchHeaders());
ctx.Send(responseWriter);
}
示例13: PostExecution
PipelineContinuation PostExecution(ICommunicationContext context)
{
if (context.OperationResult.ResponseResource == null)
return PipelineContinuation.Continue;
var registration = _config.ResourceRegistrations.SingleOrDefault(_ => _.ResourceKey == context.PipelineData.ResourceKey);
if (registration == null || registration.Properties.ContainsKey(Keys.LAST_MODIFIED) == false)
return PipelineContinuation.Continue;
var now = ServerClock.UtcNow();
var mapper = (Func<object, DateTimeOffset?>)registration.Properties[Keys.LAST_MODIFIED];
var lastModified = mapper(context.OperationResult.ResponseResource);
if (lastModified > now)
lastModified = now;
var ifModifiedSinceHeader = context.Request.Headers["if-modified-since"];
if (NoIncompatiblePreconditions(context) &&
ifModifiedSinceHeader != null)
{
DateTimeOffset modifiedSince;
var validIfModifiedSince = DateTimeOffset.TryParse(
ifModifiedSinceHeader,
out modifiedSince);
if (!validIfModifiedSince)
_log.WriteWarning("Invalid If-Modified-Since value, not RFC1123 compliant: {0}", ifModifiedSinceHeader);
else if (lastModified <= modifiedSince)
context.PipelineData[Keys.REWRITE_TO_304] = true;
}
if (lastModified != null)
WriteLastModifiedHeader(context, lastModified);
return PipelineContinuation.Continue;
}
示例14: ExecuteBefore
public PipelineContinuation ExecuteBefore(ICommunicationContext context)
{
if ((this.InRoles == null || this.InRoles.Length == 0) && (this.Users == null || this.Users.Length == 0))
{
return PipelineContinuation.Continue;
}
if (this.ExecuteBefore(context) == PipelineContinuation.Continue)
{
if (this.InRoles != null)
{
if (this.InRoles.Any(role => context.User.IsInRole(role)))
{
return PipelineContinuation.Continue;
}
}
if (this.Users != null)
{
if (this.Users.Any(user => context.User.Identity.Name == user))
{
return PipelineContinuation.Continue;
}
}
}
context.OperationResult = new OperationResult.Unauthorized();
return PipelineContinuation.RenderNow;
}
示例15: ExecuteBefore
public override PipelineContinuation ExecuteBefore(ICommunicationContext context)
{
if ((InRoles == null || InRoles.Length == 0) && (Users == null || Users.Length == 0))
return PipelineContinuation.Continue;
if (base.ExecuteBefore(context) == PipelineContinuation.Continue)
{
try
{
if (InRoles != null)
foreach (string role in InRoles)
if (context.User.IsInRole(role))
return PipelineContinuation.Continue;
if (Users != null)
foreach (string user in Users)
if (context.User.Identity.Name == user)
return PipelineContinuation.Continue;
}
catch
{
// todo: decide where to log this error.
}
}
context.OperationResult = new OperationResult.Unauthorized();
return PipelineContinuation.RenderNow;
}