当前位置: 首页>>代码示例>>C#>>正文


C# IApiContext类代码示例

本文整理汇总了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);
        }
开发者ID:chkr1011,项目名称:CK.HomeAutomation,代码行数:27,代码来源:LPD433MhzSignalSender.cs

示例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);
            }
        }
开发者ID:chkr1011,项目名称:CK.HomeAutomation,代码行数:26,代码来源:StateMachine.cs

示例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;
            }
        }
开发者ID:rocky0904,项目名称:mozu-dotnet-toolkit,代码行数:27,代码来源:EventService.cs

示例4: HandleApiCall

 public void HandleApiCall(IApiContext apiContext)
 {
     lock (_syncRoot)
     {
         apiContext.Response = JObject.FromObject(_schedules);
     }
 }
开发者ID:chkr1011,项目名称:CK.HomeAutomation,代码行数:7,代码来源:SchedulerService.cs

示例5: IsAppEnabled

        private async Task<bool> IsAppEnabled(IApiContext apiContext)
        {
            var applicationResource = new ApplicationResource(apiContext);
            var application = await applicationResource.ThirdPartyGetApplicationAsync();

            return application.Enabled.GetValueOrDefault(false);
        }
开发者ID:kevinwrightleft,项目名称:mozu-dotnet,代码行数:7,代码来源:EventService.cs

示例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;
        }
开发者ID:jhollingworth,项目名称:Marley,代码行数:25,代码来源:RequestBuilderContributor.cs

示例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);
        }
开发者ID:rocky0904,项目名称:mozu-dotnet-toolkit,代码行数:8,代码来源:SiteHandler.cs

示例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));
        }
开发者ID:rocky0904,项目名称:mozu-dotnet-toolkit,代码行数:9,代码来源:SiteHandler.cs

示例9: History

        public void History(IApiContext apiContext)
        {
            if (apiContext == null) throw new ArgumentNullException(nameof(apiContext));

            lock (_syncRoot)
            {
                apiContext.Response = JObject.FromObject(_history);
            }
        }
开发者ID:chkr1011,项目名称:CK.HomeAutomation,代码行数:9,代码来源:UdpLogger.cs

示例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);
        }
开发者ID:chkr1011,项目名称:CK.HomeAutomation,代码行数:10,代码来源:BackupService.cs

示例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();
     }
 }
开发者ID:chkr1011,项目名称:CK.HomeAutomation,代码行数:12,代码来源:Button.cs

示例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;
        }
开发者ID:jhollingworth,项目名称:Marley,代码行数:12,代码来源:RequestSerializerContributor.cs

示例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);
            }
        }
开发者ID:chkr1011,项目名称:CK.HomeAutomation,代码行数:13,代码来源:MotionDetector.cs

示例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;
     }
 }
开发者ID:rocky0904,项目名称:mozu-dotnet-toolkit,代码行数:13,代码来源:GenericEventService.cs

示例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;
        }
开发者ID:chkr1011,项目名称:CK.HomeAutomation,代码行数:14,代码来源:PersonalAgentService.cs


注:本文中的IApiContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。