本文整理汇总了C#中IApiContext类的典型用法代码示例。如果您正苦于以下问题:C# IApiContext类的具体用法?C# IApiContext怎么用?C# IApiContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IApiContext类属于命名空间,在下文中一共展示了IApiContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApiPost
private void ApiPost(IApiContext apiContext)
{
var sequence = apiContext.Request["sequence"].ToObject<JArray>();
if (sequence.Count == 0)
{
return;
}
var codeSequence = new LPD433MHzCodeSequence();
foreach (var item in sequence)
{
var code = item.ToObject<JObject>();
var value = (uint)code["value"];
var length = (byte)code["length"];
var repeats = (byte)code["repeats"];
if (value == 0 || length == 0)
{
throw new InvalidOperationException("Value or length is null.");
}
codeSequence.WithCode(new LPD433MHzCode(value, length, repeats));
}
Send(codeSequence);
}
示例2: HandleApiCall
public override void HandleApiCall(IApiContext apiContext)
{
var request = apiContext.Request.ToObject<ApiCallRequest>();
if (!string.IsNullOrEmpty(request.Action))
{
if (request.Action == "nextState")
{
SetState(GetNextState(GetState()));
}
return;
}
if (!string.IsNullOrEmpty(request.State))
{
var stateId = new ComponentState(request.State);
if (!SupportsState(stateId))
{
apiContext.ResultCode = ApiResultCode.InvalidBody;
apiContext.Response["Message"] = "State ID not supported.";
}
SetState(stateId);
}
}
示例3: ProcessEventAsync
public async Task ProcessEventAsync(IApiContext apiContext, Event eventPayLoad)
{
try
{
Trace.CorrelationManager.ActivityId = !String.IsNullOrEmpty(apiContext.CorrelationId)
? Guid.Parse(apiContext.CorrelationId)
: Guid.NewGuid();
_logger.Info(String.Format("Got Event {0} for tenant {1}", eventPayLoad.Topic, apiContext.TenantId));
var eventType = eventPayLoad.Topic.Split('.');
var topic = eventType[0];
if (String.IsNullOrEmpty(topic))
throw new ArgumentException("Topic cannot be null or empty");
var eventCategory = (EventCategory) (Enum.Parse(typeof (EventCategory), topic, true));
var eventProcessor = _container.ResolveKeyed<IEventProcessor>(eventCategory);
await eventProcessor.ProcessAsync(_container, apiContext, eventPayLoad);
}
catch (Exception exc)
{
_emailHandler.SendErrorEmail(new ErrorInfo{Message = "Error Processing Event : "+ JsonConvert.SerializeObject(eventPayLoad), Context = apiContext, Exception = exc});
throw exc;
}
}
示例4: HandleApiCall
public void HandleApiCall(IApiContext apiContext)
{
lock (_syncRoot)
{
apiContext.Response = JObject.FromObject(_schedules);
}
}
示例5: IsAppEnabled
private async Task<bool> IsAppEnabled(IApiContext apiContext)
{
var applicationResource = new ApplicationResource(apiContext);
var application = await applicationResource.ThirdPartyGetApplicationAsync();
return application.Enabled.GetValueOrDefault(false);
}
示例6: Execute
public PipelineContinuation Execute(IApiContext context)
{
ValidateContext(context);
_log.InfoFormat("Creating a web request for {0}", context.Request.Uri);
var request = WebRequest.Create(context.Request.Uri);
request.Timeout = context.Request.Timeout;
request.Method = context.Request.HttpMethod;
if (context.Request.Headers != null)
foreach (var header in context.Request.Headers)
request.Headers[header.Key] = header.Value;
if (context.UseFiddler)
{
_log.InfoFormat("Setting proxy to enable Fiddle");
request.Proxy = new WebProxy("127.0.0.1", 8888);
}
context.Request.Request = request;
return PipelineContinuation.Continue;
}
示例7: GetGeneralSettings
public async Task<GeneralSettings> GetGeneralSettings(IApiContext apiContext, string responseFields = null)
{
if (apiContext.SiteId.GetValueOrDefault(0) == 0)
throw new Exception("Site ID is missing in api context");
var settingResource = new GeneralSettingsResource(apiContext);
return await settingResource.GetGeneralSettingsAsync(responseFields);
}
示例8: GetTimezone
public async Task<TimeZone> GetTimezone(IApiContext apiContext, GeneralSettings generalSettings = null)
{
if (generalSettings == null)
generalSettings = await GetGeneralSettings(apiContext,"siteTimeZone");
var referenceApi = new ReferenceDataResource();
var timeZones = await referenceApi.GetTimeZonesAsync();
return timeZones.Items.SingleOrDefault(x => x.Id.Equals(generalSettings.SiteTimeZone));
}
示例9: History
public void History(IApiContext apiContext)
{
if (apiContext == null) throw new ArgumentNullException(nameof(apiContext));
lock (_syncRoot)
{
apiContext.Response = JObject.FromObject(_history);
}
}
示例10: RestoreBackup
public void RestoreBackup(IApiContext apiContext)
{
if (apiContext.Request.Type != JTokenType.Object)
{
throw new NotSupportedException();
}
var eventArgs = new BackupEventArgs(apiContext.Request);
RestoringBackup?.Invoke(this, eventArgs);
}
示例11: HandleApiCall
public override void HandleApiCall(IApiContext apiContext)
{
var action = (string)apiContext.Request["Duration"];
if (!string.IsNullOrEmpty(action) && action.Equals(ButtonPressedDuration.Long.ToString(), StringComparison.OrdinalIgnoreCase))
{
OnPressedLong();
}
else
{
OnPressedShortlyShort();
}
}
示例12: Execute
public PipelineContinuation Execute(IApiContext context)
{
if(context.Request.Data != null && context.Request.Data.GetType() != typeof(string))
{
var metadata = _resourceSpaceConfig.Get(context.Request.Data.GetType());
var codec = _pipeline.GetCodec(metadata.ContentType);
context.Request.Data = codec.Encode(context.Request.Data);
}
return PipelineContinuation.Continue;
}
示例13: HandleApiCall
public override void HandleApiCall(IApiContext apiContext)
{
var action = (string)apiContext.Request["Action"];
if (action.Equals("detected", StringComparison.OrdinalIgnoreCase))
{
UpdateState(MotionDetectorStateId.MotionDetected);
}
else if (action.Equals("detectionCompleted", StringComparison.OrdinalIgnoreCase))
{
UpdateState(MotionDetectorStateId.Idle);
}
}
示例14: ProcessEventAsync
public async Task ProcessEventAsync(IApiContext apiContext, Event eventPayLoad)
{
try
{
var eventProcessor = _container.Resolve<IGenericEventProcessor>();
await eventProcessor.ProcessEvent(apiContext, eventPayLoad);
}
catch (Exception exc)
{
_emailHandler.SendErrorEmail(new ErrorInfo { Message = "Error Processing Event : " + JsonConvert.SerializeObject(eventPayLoad), Context = apiContext, Exception = exc });
throw;
}
}
示例15: Ask
public void Ask(IApiContext apiContext)
{
var message = (string)apiContext.Request["Message"];
if (string.IsNullOrEmpty(message))
{
apiContext.ResultCode = ApiResultCode.InvalidBody;
return;
}
var inboundMessage = new ApiInboundMessage(DateTime.Now, message);
var answer = ProcessMessage(inboundMessage);
apiContext.Response["Answer"] = answer;
}