• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IApiContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IApiContext的典型用法代码示例。如果您正苦于以下问题:C# IApiContext类的具体用法?C# IApiContext怎么用?C# IApiContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IApiContext类属于命名空间,在下文中一共展示了IApiContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: CreateBackup

        public void CreateBackup(IApiContext apiContext)
        {
            var backup = new JObject
            {
                ["Type"] = "HA4IoT.Backup",
                ["Timestamp"] = DateTime.Now.ToString("O"),
                ["Version"] = 1
            };

            var eventArgs = new BackupEventArgs(backup);
            CreatingBackup?.Invoke(this, eventArgs);

            apiContext.Response = backup;
        }
开发者ID:chkr1011,项目名称:CK.HomeAutomation,代码行数:14,代码来源:BackupService.cs


示例17: Execute

 public void Execute(IApiContext context)
 {
     foreach (var contributor in Contributors)
     {
         try
         {
             if(contributor.Execute(context) == PipelineContinuation.Abort)
                 break;
         }
         catch (Exception ex)
         {
             context.PipelineException = ex;
             break;
         }
     }
 }
开发者ID:jhollingworth,项目名称:Marley,代码行数:16,代码来源:Pipeline.cs


示例18: GetSite

        public async Task<Site> GetSite(IApiContext apiContext)
        {
            if (apiContext.SiteId.GetValueOrDefault(0) == 0)
                throw new Exception("Site ID is missing in api context");

            var tenant = apiContext.Tenant;
            if (tenant == null)
            {
                var tenantResource = new TenantResource();
                tenant = await tenantResource.GetTenantAsync(apiContext.TenantId);
            }

            var site = tenant.Sites.SingleOrDefault(x => x.Id == apiContext.SiteId);
            if (site == null)
                throw new Exception("Site " + apiContext.SiteId + " not found for tenant " + tenant.Name);
            return site;
        }
开发者ID:rocky0904,项目名称:mozu-dotnet-toolkit,代码行数:17,代码来源:SiteHandler.cs


示例19: Execute

        public PipelineContinuation Execute(IApiContext context)
        {
            WriteDataToStream(context.Request);

            var webRequest = context.Request.Request;

            try
            {
                context.Response.Response = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException ex)
            {
                context.Response.Response = (HttpWebResponse)ex.Response;
            }

            return PipelineContinuation.Continue;
        }
开发者ID:jhollingworth,项目名称:Marley,代码行数:17,代码来源:RequestExecutorContributor.cs


示例20: GetEntityListAsync

 public async Task<EntityList> GetEntityListAsync(IApiContext apiContext, String name, string nameSpace)
 {
     var entityListResource = new EntityListResource(apiContext);
     String listFQN = GetListFQN(name, nameSpace);
     EntityList entityList = null;
     try
     {
         entityList = await entityListResource.GetEntityListAsync(listFQN);
     }
     catch (AggregateException ae)
     {
         if (ae.InnerException.GetType() == typeof (ApiException)) throw;
         var aex = (ApiException)ae.InnerException;
         _logger.Error(aex.Message, aex);
         throw aex;
     }
     return entityList;
 }
开发者ID:rocky0904,项目名称:mozu-dotnet-toolkit,代码行数:18,代码来源:EntitySchemaHandler.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IApp类代码示例发布时间:2022-05-24
下一篇:
C# IApiConnection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap