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


C# Exchange.SendResponse方法代码示例

本文整理汇总了C#中Exchange.SendResponse方法的典型用法代码示例。如果您正苦于以下问题:C# Exchange.SendResponse方法的具体用法?C# Exchange.SendResponse怎么用?C# Exchange.SendResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exchange的用法示例。


在下文中一共展示了Exchange.SendResponse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleRequest

        private void HandleRequest(Request request)
        {
            Exchange exchange = new Exchange(request, Origin.Remote);
            exchange.EndPoint = _proxyEndPoint;

            Response response = null;
            // ignore the request if it is reset or acknowledge
            // check if the proxy-uri is defined
            if (request.Type != MessageType.RST && request.Type != MessageType.ACK
                    && request.HasOption(OptionType.ProxyUri))
            {
                // get the response from the cache
                response = _cacheResource.GetResponse(request);

                // TODO update statistics
                //_statsResource.updateStatistics(request, response != null);
            }

            // check if the response is present in the cache
            if (response != null)
            {
                // link the retrieved response with the request to set the
                // parameters request-specific (i.e., token, id, etc)
                exchange.SendResponse(response);
                return;
            }
            else
            {

                // edit the request to be correctly forwarded if the proxy-uri is
                // set
                if (request.HasOption(OptionType.ProxyUri))
                {
                    try
                    {
                        ManageProxyUriRequest(request);
                    }
                    catch (Exception)
                    {
                        if (log.IsWarnEnabled)
                            log.Warn("Proxy-uri malformed: " + request.GetFirstOption(OptionType.ProxyUri).StringValue);

                        exchange.SendResponse(new Response(StatusCode.BadOption));
                    }
                }

                // handle the request as usual
                if (_proxyCoapResolver != null)
                    _proxyCoapResolver.ForwardRequest(exchange);
            }
        }
开发者ID:rlusian1,项目名称:CoAP.NET,代码行数:51,代码来源:ProxyHttpServer.cs

示例2: HandleRequest

 public override void HandleRequest(Exchange exchange)
 {
     Request request = exchange.Request;
     StringBuilder buffer = new StringBuilder();
     buffer.Append("resource ").Append(Uri).Append(" received request")
         .Append("\n").Append("Code: ").Append(request.Code)
         .Append("\n").Append("Source: ").Append(request.Source)
         .Append("\n").Append("Type: ").Append(request.Type)
         .Append("\n").Append("MID: ").Append(request.ID)
         .Append("\n").Append("Token: ").Append(request.TokenString)
         //.Append("\n").Append(request.Options)
         ;
     Response response = new Response(StatusCode.Content);
     response.PayloadString = buffer.ToString();
     exchange.SendResponse(response);
 }
开发者ID:rlusian1,项目名称:CoAP.NET,代码行数:16,代码来源:MirrorResource.cs

示例3: DeliverRequest

        /// <inheritdoc/>
        public void DeliverRequest(Exchange exchange)
        {
            Request request = exchange.Request;
            IResource resource = FindResource(request.UriPaths);
            if (resource != null)
            {
                CheckForObserveOption(exchange, resource);

                // Get the executor and let it process the request
                IExecutor executor = resource.Executor;
                if (executor != null)
                    executor.Start(() => resource.HandleRequest(exchange));
                else
                    resource.HandleRequest(exchange);
            }
            else
            {
                exchange.SendResponse(new Response(StatusCode.NotFound));
            }
        }
开发者ID:rlusian1,项目名称:CoAP.NET,代码行数:21,代码来源:ServerMessageDeliverer.cs

示例4: ProcessUpdateRequest

        private void ProcessUpdateRequest(Exchange exchange)
        {
            Request request = exchange.Request;
            Guid clientID;
            Response response;
            if (StringUtils.GuidTryDecode(request.UriPath.Substring(4), out clientID))
            {
                LWM2MClient client = BusinessLogicFactory.Clients.GetClient(clientID);
                if (client == null)
                {
                    response = Response.CreateResponse(request, StatusCode.NotFound);
                }
                else
                {
                    client.Parse(request.UriQueries);
                    BusinessLogicFactory.Clients.UpdateClientActivity(client);
                    client.Address = request.Source;
                    client.EndPoint = exchange.EndPoint;
                    bool updatedLifeTime = false;
                    if ((request.ContentType == (int)MediaType.ApplicationLinkFormat) || (request.ContentType == -1))
                    {
                        if (request.PayloadSize > 0)
                        {
                            ObjectTypes objectTypes = new ObjectTypes();
                            objectTypes.Parse(request.PayloadString);
                            if (ObjectTypes.Compare(client.SupportedTypes, objectTypes) != 0)
                            {
                                client.SupportedTypes = objectTypes;
                                if (client.ClientID != Guid.Empty)
                                {
                                    DataAccessFactory.Clients.SaveClient(client, TObjectState.Add);
                                    updatedLifeTime = true;
                                }
                                BusinessLogicFactory.Clients.ClientChangedSupportedTypes(client);
                            }
                        }
                    }
                    if (!updatedLifeTime)
                    {
                        BusinessLogicFactory.Clients.UpdateClientLifetime(client.ClientID, client.Lifetime);
                    }
                    response = Response.CreateResponse(request, StatusCode.Changed);

                    ApplicationEventLog.Write(LogLevel.Information, string.Concat("Client update ", client.Name, " address ", client.Address.ToString()));
                }
            }
            else
            {
                ApplicationEventLog.WriteEntry(string.Concat("Invalid update location", request.UriPath));
                response = Response.CreateResponse(request, StatusCode.BadRequest);
            }
            exchange.SendResponse(response);
        }
开发者ID:CreatorDev,项目名称:DeviceServer,代码行数:53,代码来源:Server.cs

示例5: ProcessRegisterRequest

        private void ProcessRegisterRequest(Exchange exchange)
        {
            Request request = exchange.Request;
            LWM2MClient client = new LWM2MClient();
            client.Server = _ServerEndPoint;
            client.Address = request.Source;
            client.Parse(request.UriQueries);
            ObjectTypes objectTypes = new ObjectTypes();
            objectTypes.Parse(request.PayloadString);
            client.SupportedTypes = objectTypes;
            client.EndPoint = exchange.EndPoint;
            if (_SecureChannel != null)
            {
                CertificateInfo certificateInfo = _SecureChannel.GetClientCertificateInfo(client.Address);
                if (certificateInfo == null)
                {
                    string pskIdentity = _SecureChannel.GetClientPSKIdentity(client.Address);
                    if (!string.IsNullOrEmpty(pskIdentity))
                    {
                        Guid clientID;
                        PSKIdentity identity = DataAccessFactory.Identities.GetPSKIdentity(pskIdentity);
                        if (identity != null)
                        {
                            if (StringUtils.GuidTryDecode(pskIdentity, out clientID))
                            {
                                client.ClientID = clientID;
                            }
                            client.OrganisationID = identity.OrganisationID;
                        }
                    }
                }
                else
                {
                    Console.WriteLine(certificateInfo.Subject.CommonName);
                    Console.WriteLine(certificateInfo.Subject.Organistion);
                    Guid clientID;
                    if (Guid.TryParse(certificateInfo.Subject.CommonName,  out clientID))
                    {
                        client.ClientID = clientID;
                    }
                    int organisationID;
                    if (int.TryParse(certificateInfo.Subject.Organistion, out organisationID))
                    {
                        client.OrganisationID = organisationID;
                    }
                }
            }
            if (client.ClientID != Guid.Empty && (client.OrganisationID > 0 || !SecureOnly) && !DataAccessFactory.Clients.IsBlacklisted(client.ClientID))
            {
                BusinessLogicFactory.Clients.AddClient(client);
            }

            Response response = Response.CreateResponse(request, StatusCode.Created);
            //response.AddOption(Option.Create(OptionType.LocationPath, string.Concat("rd/",StringUtils.GuidEncode(client.ClientID))));
            response.AddOption(Option.Create(OptionType.LocationPath, "rd"));
            response.AddOption(Option.Create(OptionType.LocationPath, StringUtils.GuidEncode(client.ClientID)));

            exchange.SendResponse(response);

            ApplicationEventLog.Write(LogLevel.Information, string.Concat("Client registered ", client.Name, " address ", client.Address.ToString()));
        }
开发者ID:CreatorDev,项目名称:DeviceServer,代码行数:61,代码来源:Server.cs

示例6: ProcessDeregisterRequest

        private void ProcessDeregisterRequest(Exchange exchange)
        {
            Request request = exchange.Request;
            Guid clientID = StringUtils.GuidDecode(request.UriPath.Substring(4));
            LWM2MClient client = BusinessLogicFactory.Clients.GetClient(clientID);
            Response response;
            if (client == null)
            {
                response = Response.CreateResponse(request, StatusCode.NotFound);
            }
            else
            {
                client.Lifetime = DateTime.UtcNow;
                BusinessLogicFactory.Clients.UpdateClientLifetime(client.ClientID, DateTime.UtcNow);
                BusinessLogicFactory.Clients.UpdateClientActivity(client.ClientID, DateTime.UtcNow);
                BusinessLogicFactory.Clients.DeleteClient(clientID);
                response = Response.CreateResponse(request, StatusCode.Deleted);

                ApplicationEventLog.Write(LogLevel.Information, string.Concat("Client deregister ", client.Name, " address ", client.Address.ToString()));
            }
            exchange.SendResponse(response);
        }
开发者ID:CreatorDev,项目名称:DeviceServer,代码行数:22,代码来源:Server.cs

示例7: FindResource

 void IMessageDeliverer.DeliverRequest(Exchange exchange)
 {
     Request request = exchange.Request;
     IResource resource = FindResource(request.UriPaths);
     if (resource == null)
     {
         if ((request.Method == Method.GET) || (request.Method == Method.DELETE))
         {
             exchange.SendResponse(new Response(StatusCode.NotFound));
         }
         else
         {
             resource = FindParentResource(request.UriPaths);
             if (resource == null)
             {
                 exchange.SendResponse(new Response(StatusCode.NotFound));
             }
             else
             {
                 resource.HandleRequest(exchange);
             }
         }
     }
     else
         _MessageDeliverer.DeliverRequest(exchange);
 }
开发者ID:CreatorDev,项目名称:DeviceServer,代码行数:26,代码来源:Client.cs

示例8: HandleRequest

 public override void HandleRequest(Exchange exchange)
 {
     exchange.SendAccept();
     Response response = ForwardRequest(exchange.Request);
     exchange.SendResponse(response);
 }
开发者ID:rlusian1,项目名称:CoAP.NET,代码行数:6,代码来源:ForwardingResource.cs

示例9: ProcessPOST

            private void ProcessPOST(Exchange exchange)
            {
                String payload = exchange.Request.PayloadString;
                if (_test.request_short)
                    Assert.AreEqual(payload, SHORT_POST_REQUEST);
                else
                    Assert.AreEqual(payload, LONG_POST_REQUEST);

                Response response = new Response(StatusCode.Changed);
                if (_test.respond_short)
                    response.SetPayload(SHORT_POST_RESPONSE);
                else
                    response.SetPayload(LONG_POST_RESPONSE);
                exchange.SendResponse(response);
            }
开发者ID:rlusian1,项目名称:CoAP.NET,代码行数:15,代码来源:BlockwiseTransferTest.cs

示例10: ProcessGET

 private void ProcessGET(Exchange exchange)
 {
     Response response = new Response(StatusCode.Content);
     if (_test.respond_short)
         response.SetPayload(SHORT_GET_RESPONSE);
     else response.SetPayload(LONG_GET_RESPONSE);
     exchange.SendResponse(response);
 }
开发者ID:rlusian1,项目名称:CoAP.NET,代码行数:8,代码来源:BlockwiseTransferTest.cs

示例11: ProcessRequestBootstrap

 private void ProcessRequestBootstrap(Exchange exchange)
 {
     Request request = exchange.Request;
     LWM2MClient client = new LWM2MClient();  // TODO: fix warning
     client.Address = request.Source;
     client.EndPoint = exchange.EndPoint;
     client.Parse(request.UriQueries);
     BusinessLogicFactory.Clients.AddClient(client);
     Response response = Response.CreateResponse(request, StatusCode.Changed);
     exchange.SendResponse(response);
 }
开发者ID:CreatorDev,项目名称:DeviceServer,代码行数:11,代码来源:BootstrapServer.cs


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