private RequestConnection CreateRequest() { RequestConnection request = new RequestConnection { user = "******", applicationID = "1" }; return(request); }
public async Task <ICtsResponse> GetCtsResponseAsync() { PfWebConsultaNovedadEnvioMailClient client = new PfWebConsultaNovedadEnvioMailClient(); EndpointAddress endpoint = new EndpointAddress("http://172.28.195.215:9080/COBISCorp.eCOBIS.PfWebConsultaNovedadEnvioMail.Service/PfWebConsultaNovedadEnvioMailWSService"); client = new PfWebConsultaNovedadEnvioMailClient(PfWebConsultaNovedadEnvioMailClient.EndpointConfiguration.PfWebConsultaNovedadEnvioMailWSPort, endpoint); PfWebConsultaNovedadEnvioMailResponse response; using (var scope = new FlowingOperationContextScope(client.InnerChannel)) { // Add a SOAP Header to an outgoing request MessageHeaders messageHeadersElement = OperationContext.Current.OutgoingMessageHeaders; messageHeadersElement.Add(new Security() { UsernameToken = new UsernameToken() { Username = "******", Password = "" } }); RequestConnection requestConnection = new RequestConnection { user = "******", applicationID = "1" }; Fil fil = new Fil { inPfWebConsultaNovedadEnvioMailFil = new PfWebConsultaNovedadEnvioMailFil { isSiguiente = 0 } }; PfWebConsultaNovedadEnvioMailRequest request = new PfWebConsultaNovedadEnvioMailRequest() { requestConnection = requestConnection, fil = fil }; //response = client.PfWebConsultaNovedadEnvioMailAsync(request, fil).GetAwaiter().GetResult(); //response = await client.PfWebConsultaNovedadEnvioMailAsync(request, fil).ContinueOnScope(scope); response = await client.PfWebConsultaNovedadEnvioMailAsync(request).ContinueOnScope(scope); //response = client.PfWebConsultaNovedadEnvioMailAsync(request).GetAwaiter().GetResult(); } parser = new MailNewsParser(response.executeResponse); ICtsResponse ctsResponse = new MailNewsResponse(); return(ctsResponse); }
public RESTReplyData user_connections_request_post(RESTRequestData pReq, List <string> pArgs) { RESTReplyData replyData = new RESTReplyData(); // The HTTP response info ResponseBody respBody = new ResponseBody(); if (Accounts.Instance.TryGetAccountWithAuthToken(pReq.AuthToken, out AccountEntity aAccount)) { bodyUserConnectionRequestPost request = pReq.RequestBodyObject <bodyUserConnectionRequestPost>(); // The script looks for two types of 'connection' responses. // If is sees data.connection == "pending", it trys again and eventually times out // If data.connection has an object, it uses 'new_connection' and 'username' // Connection handles are the in-world nodeId's string thisNode = request.user_connection_request.node_id; string otherNode = request.user_connection_request.proposed_node_id; // BEGIN sanity check DEBUG DEBUG { // Connections use node id's to identify the two avatars, I guess because, the // world does not have access to the account identity. // This debugging code prints out whether the passed nodeIds match the loction // nodeIds that we have to verify that the connection nodeIds are really the // same ones as passed in the location. // All this debugging output can go away once nodeId usage is understood. Context.Log.Debug("{0} connection_request: request from account '{1}' node={2}, proposed={3}", _logHeader, aAccount.Username, thisNode, otherNode); if (aAccount.Location != null) { if (aAccount.Location.NodeID == thisNode) { Context.Log.Debug("{0} connection_request: request from account '{1}' and Location.NodeId matches main node", _logHeader, aAccount.Username); } else { if (aAccount.Location.NodeID == otherNode) { Context.Log.Debug("{0} connection_request: request from account '{1}' and Location.NodeId matches proposed node", _logHeader, aAccount.Username); } else { Context.Log.Debug("{0} connection_request: request from account '{1}' and Location.NodeId does not match either nodes", _logHeader, aAccount.Username); } } } else { Context.Log.Debug("{0} connection_request: request from account '{1}' and no location info", _logHeader, aAccount.Username); } } // END sanity check DEBUG DEBUG try { // This returns all the RequestConnection's that have my ID in them RequestConnection previousAsk = RequestConnection.GetNodeRequests(thisNode) // Find the ones that have me and the other requestor .Where(req => { return((req.Body.node_id == thisNode && req.Body.proposed_node_id == otherNode) || (req.Body.node_id == otherNode && req.Body.proposed_node_id == thisNode)); // Pick the one (there should be only one) }).FirstOrDefault(); if (previousAsk != null) { Context.Log.Debug("{0} connection_request: existing request found", _logHeader); // We have a pending connection request for this person // Mark myself as accepting if (previousAsk.Body.node_id == thisNode) { if (!previousAsk.Body.node_accepted) { previousAsk.Body.node_accepted = true; previousAsk.Updated(); } } else { if (!previousAsk.Body.proposed_node_accepted) { previousAsk.Body.proposed_node_accepted = true; previousAsk.Updated(); } // I'm in the 'proposed node' position. // Straighten out the node variables for simplier logic after this var tmp = otherNode; otherNode = thisNode; thisNode = tmp; // after this, "thisNode" is always this account Context.Log.Debug("{0} connection_request: found request was from other account", _logHeader); } // If both accepted, the connection is complete if (previousAsk.Body.node_accepted && previousAsk.Body.proposed_node_accepted) { if (Accounts.Instance.TryGetAccountWithNodeId(otherNode, out AccountEntity oOtherAccount)) { aAccount.AddConnection(oOtherAccount); aAccount.Updated(); oOtherAccount.AddConnection(aAccount); oOtherAccount.Updated(); respBody.Data = new { connection = new { new_connection = true, // says whether a new or pre-existing connection username = oOtherAccount.Username } }; } else { // Can't find the other account... shouldn't happen respBody.RespondFailure("Both agreed but cannot find other account entity"); } } else { // Both haven't accepted so tell the requestor that the request is pending respBody.Data = new Dictionary <string, string>() { { "connection", "pending" } }; } } else { // There was no previous ask so create the request. Context.Log.Debug("{0} connection_request: creating connection request from '{1}", _logHeader, aAccount.Username); RequestConnection newReq = new RequestConnection(); newReq.Body.node_id = thisNode; newReq.Body.requestor_accountId = aAccount.AccountID; newReq.Body.proposed_node_id = otherNode; newReq.Body.node_accepted = true; newReq.ExpireIn(TimeSpan.FromSeconds(Context.Params.P <int>(AppParams.P_CONNECTION_REQUEST_SECONDS))); newReq.AddAndUpdate(); // Both haven't accepted so tell the requestor that the request is pending respBody.Data = new Dictionary <string, string>() { { "connection", "pending" } }; } } catch { } } else { Context.Log.Error("{0} POST user/connection_request for unauthorized user. Token={1}", _logHeader, pReq.AuthToken); respBody.RespondFailure("Unauthorized"); } replyData.SetBody(respBody, pReq); return(replyData); }