private static BaseResponse GetResponse(Methods methodCalled, returntype sfgReturn) { string className = "SFGWrapper.HeartbeatTranslators"; BaseResponse baseResponse = new BaseResponse(); foreach (var item in sfgReturn.error) { Message ahError = new Message(item.errno, MessageSources.Heartbeat); foreach (string message in item.errmsg) { ahError.SfgMessages.Add(message); } baseResponse.Messages.Add(ahError); } switch (methodCalled) { case Methods.PING: PingResponse heartbeatServiceResponse = new PingResponse(); heartbeatServiceResponse.Success = sfgReturn.success; baseResponse.TypedResponse = heartbeatServiceResponse; break; } baseResponse.TypedResponse.Success = sfgReturn.success; baseResponse.TypedResponse.Info = Utilities.GetInfo(sfgReturn.response.INFO); baseResponse.TypedResponse.MemoryUsed = sfgReturn.response.MEMORY_USED; baseResponse.TypedResponse.Protocol = sfgReturn.response.PROTOCOL; baseResponse.TypedResponse.RoundtripTime = sfgReturn.response.ROUNDTRIP_TIME; baseResponse.TypedResponse.Server = sfgReturn.response.SERVER; baseResponse.TypedResponse.TimeElapsed = sfgReturn.response.TIME_ELAPSED; baseResponse.TypedResponse.Version = sfgReturn.response.VERSION; return baseResponse; }
public override IActionResult Ping() { PingResponse response = new PingResponse() { Message = "The server is working." }; return(StatusCode(200, response)); }
public override IActionResult Echo(EchoRequest echoRequest) { PingResponse response = new PingResponse() { Message = echoRequest.Message }; return(StatusCode(200, response)); }
private static void ImprimeResponse(PingResponse reply) { Console.ForegroundColor = ConsoleColor.Blue; Console.BackgroundColor = ConsoleColor.White; Console.Write($"{reply.Timestamp.ToDateTime().ToString()} Server:"); Console.ResetColor(); Console.WriteLine($" {reply.Response}\n"); }
public void MSASCMD_S11_TC01_Ping_Status3() { #region Change a new user to call ActiveSync operation with a new DeviceID. this.CMDAdapter.SwitchUser(this.User3Information.UserName, this.User3Information.UserPassword, this.User3Information.UserDomain); // Record user that uses new DeviceID this.CMDAdapter.ChangeDeviceID("NewDevice"); this.RecordDeviceInfoChanged(); #endregion #region Calls FolderSync command before sending ping request this.FolderSync(); #endregion #region Create a Ping request without Folder element PingRequest pingRequest = CreatePingRequest(this.User3Information.NotesCollectionId, Request.PingFolderClass.Notes); pingRequest.RequestData.Folders = null; PingResponse pingReponse = this.CMDAdapter.Ping(pingRequest); #endregion #region Verify Requirements MS-ASCMD_R4240, MS-ASCMD_R4241 // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4240"); // Verify MS-ASCMD requirement: MS-ASCMD_R4240 Site.CaptureRequirementIfAreEqual <int>( 3, int.Parse(pingReponse.ResponseData.Status), 4240, @"[In Status(Ping)] [When the scope is Global], [the cause of the status value 3 is] The Ping command request did not specify all the necessary parameters."); #region Create a Ping request with Folder element and HeartbeatInterval element PingRequest pingRequestWithRequireElement = CreatePingRequest(this.User3Information.NotesCollectionId, Request.PingFolderClass.Notes); PingResponse pingResponseWithRequireElement = this.CMDAdapter.Ping(pingRequestWithRequireElement); Site.Assert.IsNotNull(pingResponseWithRequireElement.ResponseData.Status, "If Ping command executes successfully, server will return status code."); #endregion #region Create a Ping request with Folder element and without HeartbeatInterval element PingRequest pingRequestWithoutHeartBeatIntervalElement = CreatePingRequest(this.User3Information.NotesCollectionId, Request.PingFolderClass.Notes); pingRequestWithoutHeartBeatIntervalElement.RequestData.HeartbeatInterval = null; PingResponse pingReponseWithoutHeartBeatIntervalElement = this.CMDAdapter.Ping(pingRequestWithoutHeartBeatIntervalElement); #endregion // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4241"); // Verify MS-ASCMD requirement: MS-ASCMD_R4241 Site.CaptureRequirementIfIsTrue( int.Parse(pingReponse.ResponseData.Status) == 3 && int.Parse(pingReponseWithoutHeartBeatIntervalElement.ResponseData.Status) != 3, 4241, @"[In Status(Ping)] [When the scope is Global], [the cause of the status value 3 is] The client MUST issue a Ping request that includes both the heartbeat interval and the folder list at least once."); #endregion #region Delete ActiveSync device in User3's mail account this.ClearDevice(this.User3Information.UserName, this.User3Information.UserPassword, this.User3Information.UserDomain); #endregion }
public async Task Can_receive_incoming_ping_responses() { var messageObserver = new TestMessageObserver <PingResponse>(_logger); var protocolMessage = new PingResponse().ToProtocolMessage(_pid, _guid); await InitialisePeerServiceAndSendMessage(messageObserver, protocolMessage).ConfigureAwait(false); messageObserver.SubstituteObserver.Received().OnNext(Arg.Any <PingResponse>()); }
public string Ping() { PingRequest inValue = new PingRequest(); inValue.Body = new PingRequestBody(); PingResponse retVal = ((IServiceContract)(this)).Ping(inValue); return(retVal.Body.PingResult); }
public async Task Ping(AuthorizationTokenContainer authorizationTokenCtr, PingRequest pingRequest) { GetPlayerByAccessTokenResponse playerByAccessTokenResponse = _authService.GetPlayerByAccessToken(authorizationTokenCtr.Token); var result = new PingResponse(); result.PingId = pingRequest.PingId; result.Error = null; result.Success = true; await Clients.Caller.ReceivePingResponse(result); }
public PingResponse ping() { PingResponse ret = new PingResponse(msclPINVOKE.WirelessNode_ping(swigCPtr), true); if (msclPINVOKE.SWIGPendingException.Pending) { throw msclPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public ActionResult <PingResponse> Ping() { var response = new PingResponse { Version = _option.HostVersion(), Status = _executionContext.State.ToString(), }; return(Ok(response)); }
public override async Task <IMessage <PingResponse> > PingNoPayload(IMessage <Bond.Void> v, ServerCallContext context) { await Task.Delay(MaxDelayMilliseconds); var response = new PingResponse { Payload = "Ping with no payload" }; return(Message.From(response)); }
public Task Ping(string replyMessage) { var response = new PingResponse() { PingMessage = replyMessage, ReceivedAt = DateTime.UtcNow }; return(Clients.Caller.SendAsync(SignalrMethodNames.Ping, response)); }
private void OnMessage(string routingKey, byte[] msg) { _log.LogInformation("Received ping request in pbx listener"); var req = PingRequest.Parser.ParseFrom(msg); var resp = new PingResponse { PingCookie = req.PingCookie }; _ch.Publish(PBXConnectorTopics.PbxPingResponse, resp); }
public void PingTimeout() { bool pingSuccessful = false; var ping = new Ping(node.Id) { TransactionId = transactionId }; bool timedOutPingSuccessful = false; var timedOutPing = new Ping(node.Id) { TransactionId = (BEncodedNumber)5 }; listener.MessageSent += (data, endpoint) => { engine.MessageLoop.DhtMessageFactory.TryDecodeMessage(BEncodedValue.Decode <BEncodedDictionary> (data), out DhtMessage message); if (message.TransactionId.Equals(ping.TransactionId)) { var response = new PingResponse(node.Id, transactionId); listener.RaiseMessageReceived(response, endpoint); } }; engine.MessageLoop.QuerySent += (o, e) => { // This ping should not time out. if (e.Query.TransactionId.Equals(ping.TransactionId)) { pingSuccessful = !e.TimedOut; } // This ping should time out. if (e.Query.TransactionId.Equals(timedOutPing.TransactionId)) { timedOutPingSuccessful = e.TimedOut; } }; // Send the ping which will be responded to Assert.IsTrue(engine.SendQueryAsync(ping, node).Wait(1000), "#0a"); Assert.AreEqual(0, node.FailedCount, "#0b"); engine.MessageLoop.Timeout = TimeSpan.Zero; node.Seen(TimeSpan.FromHours(1)); // Send a ping which will time out Assert.IsTrue(engine.SendQueryAsync(timedOutPing, node).Wait(1000), "#0c"); Assert.AreEqual(4, node.FailedCount, "#1"); Assert.AreEqual(NodeState.Bad, node.State, "#2"); Assert.IsTrue(node.LastSeen >= TimeSpan.FromHours(1), "#3"); Assert.IsTrue(pingSuccessful, "#4"); Assert.IsTrue(pingSuccessful, "#5"); }
public Task Ping(string replyMessage) { var response = new PingResponse { PingMessage = replyMessage, UserName = Context.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value, ReceivedAt = DateTime.UtcNow }; return(Clients.Caller.SendAsync(SignalrMethodNames.Ping, response)); }
public ActionResult <PingResponse> Ping() { PingResponse pingResponse = GetResponse(); return(_serviceStatus.Level switch { ServiceStatusLevel.Running => Ok(pingResponse), ServiceStatusLevel.Ready => Ok(pingResponse), _ => StatusCode((int)HttpStatusCode.ServiceUnavailable, pingResponse), });
private async void OnBadPing() { if (_pebble == null || _pebble.IsAlive == false) { return; } PingResponse pingResponse = await _pebble.BadPingAsync(); PingResponse = pingResponse.ErrorMessage; }
public void NodeReplaceTest() { engine.TimeOut = TimeSpan.FromMilliseconds(25); ManualResetEvent handle = new ManualResetEvent(false); Bucket b = new Bucket(); for (int i = 0; i < Bucket.MaxCapacity; i++) { Node n = new Node(NodeId.Create(), new IPEndPoint(IPAddress.Any, i)); n.LastSeen = DateTime.UtcNow; b.Add(n); } b.Nodes[3].LastSeen = DateTime.UtcNow.AddDays(-5); b.Nodes[1].LastSeen = DateTime.UtcNow.AddDays(-4); b.Nodes[5].LastSeen = DateTime.UtcNow.AddDays(-3); engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e) { if (!e.TimedOut) { return; } b.Nodes.Sort(); if ((e.EndPoint.Port == 3 && nodeCount == 0) || (e.EndPoint.Port == 1 && nodeCount == 1) || (e.EndPoint.Port == 5 && nodeCount == 2)) { Node n = b.Nodes.Find(delegate(Node no) { return(no.EndPoint.Port == e.EndPoint.Port); }); n.Seen(); PingResponse response = new PingResponse(n.Id, e.Query.TransactionId); DhtEngine.MainLoop.Queue(delegate { //System.Threading.Thread.Sleep(100); Console.WriteLine("Faking the receive"); listener.RaiseMessageReceived(response, node.EndPoint); }); nodeCount++; } }; ReplaceNodeTask task = new ReplaceNodeTask(engine, b, null); // FIXME: Need to assert that node 0.0.0.0:0 is the one which failed - i.e. it should be replaced task.Completed += delegate(object o, TaskCompleteEventArgs e) { handle.Set(); }; task.Execute(); #if NETSTANDARD1_5 Assert.True(handle.WaitOne(4000), "#10"); #else Assert.True(handle.WaitOne(4000, false), "#10"); #endif }
public void BucketRefreshTest() { var nodes = new List <Node>(); for (var i = 0; i < 5; i++) { nodes.Add(new Node(NodeId.Create(), new IPEndPoint(IPAddress.Any, i))); } _engine.TimeOut = TimeSpan.FromMilliseconds(25); _engine.BucketRefreshTimeout = TimeSpan.FromMilliseconds(75); _engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e) { DhtEngine.MainLoop.Queue(() => { if (!e.TimedOut) { return; } var current = nodes.Find(n => n.EndPoint.Port.Equals(e.EndPoint.Port)); if (current == null) { return; } if (e.Query is Ping) { var r = new PingResponse(current.Id, e.Query.TransactionId); _listener.RaiseMessageReceived(r, current.EndPoint); } else if (e.Query is FindNode) { var response = new FindNodeResponse(current.Id, e.Query.TransactionId) { Nodes = string.Empty }; _listener.RaiseMessageReceived(response, current.EndPoint); } }); }; _engine.Add(nodes); _engine.Start(); Thread.Sleep(500); foreach (var bucket in _engine.RoutingTable.Buckets) { Assert.IsTrue(bucket.LastChanged > DateTime.UtcNow.AddSeconds(-2)); Assert.IsTrue(bucket.Nodes.Exists(n => n.LastSeen > DateTime.UtcNow.AddMilliseconds(-900))); } }
/// <summary> /// Saves the specified ping response. /// </summary> /// <param name="pingResponse">The ping response.</param> public void Save(PingResponse pingResponse) { if (pingResponse == null) { throw new ArgumentNullException("pingResponse"); } pingResponse.ApplicationServerId = pingResponse.ApplicationServer.Id; new GenericData().Save(pingResponse); }
public void FromByteArray_Returns_Expected_Data(int token) { var msg = new MessageBuilder() .WriteCode(MessageCode.Distributed.Ping) .WriteInteger(token) .Build(); var response = PingResponse.FromByteArray(msg); Assert.Equal(token, response.Token); }
public override Task <PingResponse> Ping(PingRequest request, ServerCallContext context) { var response = new PingResponse() { ResponseBase = CreateResponseBase() }; ExecutionTime.Run(() => response.ResponseMessage = request.Message, out TimeSpan elapsed); response.ResponseBase.ExecutionTime = elapsed.Milliseconds; return(Task.FromResult(response)); }
public void MSASCMD_S11_TC05_Ping_Status7_Outdate() { #region Change a new user to call ActiveSync operation with a new DeviceID. this.CMDAdapter.SwitchUser(this.User3Information.UserName, this.User3Information.UserPassword, this.User3Information.UserDomain); // Record user that uses new DeviceID this.RecordDeviceInfoChanged(); this.CMDAdapter.ChangeDeviceID("FirstDeviceID"); #endregion #region Sync user folder changes this.FolderSync(); #endregion #region Switch to new device and create one folder this.CMDAdapter.ChangeDeviceID("SecondDeviceID"); string folderSynKey = this.GetFolderSyncKey(); // Create one mail type folder string newFolderName = Guid.NewGuid().ToString().Replace("-", string.Empty); FolderCreateRequest folderCreateRequest = Common.CreateFolderCreateRequest(folderSynKey, 12, newFolderName, this.User1Information.InboxCollectionId); FolderCreateResponse folderCreateResponse = this.CMDAdapter.FolderCreate(folderCreateRequest); Site.Assert.AreEqual <int>( 1, int.Parse(folderCreateResponse.ResponseData.Status), "After folder create success, server should return status 1"); #endregion #region Switch back to old device and send one ping request this.CMDAdapter.ChangeDeviceID("FirstDeviceID"); PingRequest pingRequest = CreatePingRequest(this.User1Information.InboxCollectionId, Request.PingFolderClass.Email); PingResponse pingResponse = this.CMDAdapter.Ping(pingRequest); #endregion // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4257"); // Verify MS-ASCMD requirement: MS-ASCMD_R4257 Site.CaptureRequirementIfAreEqual <int>( 7, int.Parse(pingResponse.ResponseData.Status), 4257, @"[In Status(Ping)] [When the scope is Global], [the cause of the status value 7 is] The folder hierarchy is out of date."); #region Record new created folder collection ID. // Get new created folder collection ID FolderSyncRequest folderSyncRequestForNewFolder = Common.CreateFolderSyncRequest("0"); FolderSyncResponse folderSyncResponseForNewFolder = this.CMDAdapter.FolderSync(folderSyncRequestForNewFolder); // Gets the server ID for new folder after change DeviceID. string serverId = TestSuiteBase.GetCollectionId(folderSyncResponseForNewFolder, newFolderName); TestSuiteBase.RecordCaseRelativeFolders(this.User3Information, serverId); #endregion }
/// <summary> /// Pings the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns><see cref="PingResponse"/> instance that contains the operation result.</returns> public virtual PingResponse Ping(PingRequest request) { PingResponse response = new PingResponse(); AbstractPostRequestStrategy <PingRequest, PingResponse> requestStrategy = new PingRequestStrategy(request); requestStrategy.SendRequest(); response = requestStrategy.RestResponse.Data; return(response); }
private ObjectResult ReturnNotAvailable() { _logger.LogInformation($"Predict is starting up"); var response = new PingResponse { Version = _option.HostVersion(), Status = _executionContext.State.ToString(), }; return(StatusCode((int)HttpStatusCode.ServiceUnavailable, response)); }
public async Task BucketRefreshTest() { List <Node> nodes = new List <Node> (); for (int i = 0; i < 5; i++) { nodes.Add(new Node(NodeId.Create(), new IPEndPoint(IPAddress.Any, i))); } listener.MessageSent += (data, endpoint) => { engine.MessageLoop.DhtMessageFactory.TryDecodeMessage(BEncodedValue.Decode <BEncodedDictionary> (data), out DhtMessage message); Node current = nodes.Find(n => n.EndPoint.Port.Equals(endpoint.Port)); if (current == null) { return; } if (message is Ping) { PingResponse r = new PingResponse(current.Id, message.TransactionId); listener.RaiseMessageReceived(r, current.EndPoint); } else if (message is FindNode) { FindNodeResponse response = new FindNodeResponse(current.Id, message.TransactionId); response.Nodes = ""; listener.RaiseMessageReceived(response, current.EndPoint); } }; foreach (var n in nodes) { engine.RoutingTable.Add(n); } foreach (Bucket b in engine.RoutingTable.Buckets) { b.Changed(TimeSpan.FromDays(1)); foreach (var n in b.Nodes) { n.Seen(TimeSpan.FromDays(1)); } } await engine.RefreshBuckets(); foreach (Bucket b in engine.RoutingTable.Buckets) { Assert.IsTrue(b.LastChanged < TimeSpan.FromHours(1)); Assert.IsTrue(b.Nodes.Exists(n => n.LastSeen < TimeSpan.FromHours(1))); } }
public void PingResponseDecode() { PingEncode(); MessageFactory.RegisterSend(message); string text = "d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re"; PingResponse m = (PingResponse)Decode(text); Assert.AreEqual(infohash, m.Id); Compare(m, "d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re"); }
private void OnPingRequest(OperationRequest operationRequest, SendParameters sendParameters) { PingRequest operation = new PingRequest(this.Protocol, operationRequest); if (this.ValidateInternalOperation(operation, sendParameters)) { int tickCount = Environment.TickCount; PingResponse dataContract = new PingResponse(operation.ClientTimeStamp, tickCount); OperationResponse operationResponse = new OperationResponse(operation.OperationRequest.OperationCode, dataContract); this.SendInternalOperationResponse(operationResponse, sendParameters); } }
public void ToByteArray_Constructs_The_Correct_Message(int token) { var msg = new PingResponse(token).ToByteArray(); var reader = new MessageReader <MessageCode.Distributed>(msg); var code = reader.ReadCode(); Assert.Equal(MessageCode.Distributed.Ping, code); Assert.Equal(4 + 1 + 4, msg.Length); Assert.Equal(token, reader.ReadInteger()); }
public void FromByteArray_Throws_MessageException_On_Code_Mismatch() { var msg = new MessageBuilder() .WriteCode(MessageCode.Distributed.BranchLevel) .WriteInteger(1) .Build(); var ex = Record.Exception(() => PingResponse.FromByteArray(msg)); Assert.NotNull(ex); Assert.IsType <MessageException>(ex); }
public PingResponse PingStatus(string id = null) { if (id != null) { _apiId = id; } var resp = new WebClient().DownloadString($"{BaseUrl}/status/{_apiId}"); var model = new PingResponse(resp); return(model); }
public override async Task<IMessage<PingResponse>> PingAsync(IMessage<PingRequest> param, CancellationToken ct) { PingRequest request = param.Payload.Deserialize(); if (request.DelayMilliseconds > 0) { UInt16 delayMs = Math.Min(MaxDelayMilliseconds, request.DelayMilliseconds); await Task.Delay(delayMs); } var response = new PingResponse { Payload = string.Concat(request.Payload.Reverse()) }; return Message.FromPayload(response); }
public PingResponse Any(PingRequest request) { if (request.MSTimeBeforeResponse != 0) { Thread.Sleep(request.MSTimeBeforeResponse); } #if DEBUG if (request.ThrowException) { throw new Exception("Forced exception."); } #endif var versionResponse = new PingResponse { FullVersion = GetApplicationVersion() }; return (versionResponse); }
public override async Task<IMessage<PingResponse>> PingAsync(IMessage<PingRequest> param, CancellationToken ct) { PingRequest request = param.Payload.Deserialize(); if (request.DelayMilliseconds > 0) { UInt16 delayMs = Math.Min(MaxDelayMilliseconds, request.DelayMilliseconds); await Task.Delay(delayMs); } if (request.Payload.Contains("4")) { return Message.FromError<PingResponse>(new Error { error_code = 4, message = "Four? Why would you think I like the number 4? Reverse likes 4, but not me.", }); } var response = new PingResponse { Payload = request.Payload }; return Message.FromPayload(response); }
static PingResponse() { Instance = new PingResponse(); }
/// <summary>Retrieves the user's application key</summary> public KeyResponse GetKey(string MobileKey) { string url = "http://api.ping.fm/v1/user.key"; string postdata = "api_key={0}&mobile_key={1}"; postdata = string.Format(postdata, api_key, MobileKey); string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); KeyResponse r = (KeyResponse)DeserializeObject(xr, typeof(KeyResponse)); xr.Close(); mLastResponse = r; return r; }
public PingResponse TPost(string Trigger, string Title, string Body, bool debug) { string url = "http://api.ping.fm/v1/user.tpost"; string postdata = "api_key={0}&user_app_key={1}"; postdata = string.Format(postdata, api_key, user_application_key); if (!string.IsNullOrEmpty(Trigger)) postdata += "&trigger=" + Trigger; if (!string.IsNullOrEmpty(Title)) postdata += "&title=" + UrlEncode(Title); if (!string.IsNullOrEmpty(Body)) postdata += "&body=" + UrlEncode(Body); if (debug) postdata += "&debug=1"; string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); PingResponse r = (PingResponse)DeserializeObject(xr, typeof(PingResponse)); xr.Close(); mLastResponse = r; return r; }
/// <summary>Returns the last X messages a user has posted through Ping.fm.</summary> /// <param name="limit">Number of messages to query</param> /// <param name="order">Order of results (ASC/DESC)</param> public LatestResponse GetLatest(int limit, string order) { string url = "http://api.ping.fm/v1/user.latest"; string postdata = "api_key={0}&user_app_key={1}"; postdata = string.Format(postdata, api_key, user_application_key); if (limit > -1) postdata += "&limit=" + limit.ToString(); if (!string.IsNullOrEmpty(order)) postdata += "&order=" + order; string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); LatestResponse r = (LatestResponse)DeserializeObject(xr, typeof(LatestResponse)); xr.Close(); //if (r != null) r.DecodeMessages(); mLastResponse = r; return r; }
/// <summary>Clears the LastResponse, WebException, and DeserializeException</summary> public void Reset() { mLastResponse = null; WebException = null; DeserializeException = null; }
public PingResponse Post(string Method, string Title, string Body, string Service, string Media, bool debug) { string url = "http://api.ping.fm/v1/user.post"; string postdata = "api_key={0}&user_app_key={1}&post_method={2}"; if (string.IsNullOrEmpty(Method)) Method = "default"; postdata = string.Format(postdata, api_key, user_application_key, Method); if (!string.IsNullOrEmpty(Title)) postdata += "&title=" + UrlEncode(Title); if (!string.IsNullOrEmpty(Body)) postdata += "&body=" + UrlEncode(Body); if (!string.IsNullOrEmpty(Service)) postdata+="&service=" + Service; if (!string.IsNullOrEmpty(Media)) postdata+="&media=" + Media; if (debug) postdata += "&debug=1"; string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); PingResponse r = (PingResponse)DeserializeObject(xr, typeof(PingResponse)); xr.Close(); mLastResponse = r; return r; }
/// <summary>Resolve a URL shortened by Ping.fm</summary> public UrlResolveResponse UrlResolve(string ShortURL) { string url = "http://api.ping.fm/v1/url.resolve"; string postdata = "api_key={0}&user_app_key={1}&short_url={2}"; postdata = string.Format(postdata, api_key, user_application_key, UrlEncode(ShortURL)); string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); UrlResolveResponse r = (UrlResolveResponse)DeserializeObject(xr, typeof(UrlResolveResponse)); xr.Close(); mLastResponse = r; return r; }
public MessageResponse GetMessage(string MessageID) { string url = "http://api.ping.fm/v1/user.message"; string postdata = "api_key={0}&user_app_key={1}&message_id={2}"; postdata = string.Format(postdata, api_key, user_application_key, MessageID); string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); MessageResponse r = (MessageResponse)DeserializeObject(xr, typeof(MessageResponse)); xr.Close(); //if (r != null && r.Message != null) r.Message.Decode(); mLastResponse = r; return r; }
/// <summary> /// Call Ping command to request that the server monitor specified folder for changes. /// </summary> /// <param name="collectionId">The CollectionId of the server monitor specified folder.</param> /// <returns>The response of Ping command.</returns> protected PingResponse CallPingCommand(string collectionId) { // Create the Ping command request Request.PingFolder[] pingFolders = new Request.PingFolder[1]; pingFolders[0] = new Request.PingFolder { Class = Request.PingFolderClass.Email, Id = collectionId }; PingRequest pingRequest = Common.CreatePingRequest(pingFolders, "80"); // Call Ping command by HTTP POST. SendStringResponse pingResponseString = this.HTTPAdapter.HTTPPOST(CommandName.Ping, null, pingRequest.GetRequestDataSerializedXML()); PingResponse pingResponse = new PingResponse { ResponseDataXML = pingResponseString.ResponseDataXML }; pingResponse.DeserializeResponseData(); return pingResponse; }
public PingCompletedEventArgs(PingResponse pingResponse, DateTime endDateTime) { this.pingResponse = pingResponse; this.endDateTime = endDateTime; }
/// <summary>Posts a message to the user’s Ping.fm services.</summary> public PingResponse Post(OutgoingMessage message) { string url = "http://api.ping.fm/v1/user.post"; string postdata = "api_key={0}&user_app_key={1}"; string method = message.Method; EncodeDelegate encoder = UrlEncode; postdata = string.Format(postdata, api_key, user_application_key, method); if (message.Encoding == PingEncoding.Base64) { postdata += "&encoding=base64"; encoder = Base64Encode; } if (string.IsNullOrEmpty(message.Trigger)) { if (string.IsNullOrEmpty(method)) method = "default"; postdata += "&post_method=" + UrlEncode(method); } else { url = "http://api.ping.fm/v1/user.tpost"; postdata += "&trigger=" + UrlEncode(message.Trigger); } if (!string.IsNullOrEmpty(message.Title)) postdata += "&title=" + encoder(message.Title); if (!string.IsNullOrEmpty(message.Body)) postdata += "&body=" + encoder(message.Body); if (!string.IsNullOrEmpty(message.Service)) postdata += "&service=" + UrlEncode(message.Service); if (!string.IsNullOrEmpty(message.Exclude)) postdata += "&exclude=" + UrlEncode(message.Exclude); if (!string.IsNullOrEmpty(message.Location)) postdata += "&location=" + encoder(message.Location); if (!string.IsNullOrEmpty(message.Tags)) postdata += "&tags=" + encoder(message.Tags); if (!string.IsNullOrEmpty(message.Mood)) postdata += "&mood=" + encoder(message.Mood); if (message.Debug) postdata += "&debug=1"; if (message.MediaFilenames != null) foreach (string s in message.MediaFilenames) postdata += "&media=" + Base64Encode(GetMediaContent(s)); string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); PingResponse r = (PingResponse)DeserializeObject(xr, typeof(PingResponse)); xr.Close(); mLastResponse = r; return r; }
/// <summary> /// This method is used to verify the Ping response related requirements. /// </summary> /// <param name="pingResponse">Ping command response.</param> private void VerifyPingCommand(PingResponse pingResponse) { Site.Assert.IsTrue(this.activeSyncClient.ValidationResult, "The schema validation result should be true."); Site.Assert.IsNotNull(pingResponse.ResponseData, "The Ping element should not be null."); #region Capture code for Ping // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R3676"); // If the schema validation result is true and Ping is not null, this requirement can be verified. Site.CaptureRequirement( 3676, @"[In Ping] The Ping element is a required element in Ping command requests and responses that identifies the body of the HTTP POST as containing a Ping command (section 2.2.2.12)."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2388"); // If the schema validation result is true and Ping is not null, this requirement can be verified. Site.CaptureRequirement( 2388, @"[In Ping] None [Element Ping in Ping command response has no parent element.]"); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2389"); // If the schema validation result is true and Ping is not null, this requirement can be verified. Site.CaptureRequirement( 2389, @"[In Ping] Element Ping in Ping command response, the child elements are HeartbeatInterval, Folders, MaxFolders (section 2.2.3.96), Status (section 2.2.3.167.10)."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2390"); // If the schema validation result is true and Ping is not null, this requirement can be verified. Site.CaptureRequirement( 2390, @"[In Ping] Element Ping in Ping command response, the data type is container."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2391"); // If the schema validation result is true and Ping is not null, this requirement can be verified. Site.CaptureRequirement( 2391, @"[In Ping] Element Ping in Ping command response, the number allowed is 1…1 (required)."); this.VerifyContainerDataType(); #endregion #region Capture code for Status // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4227"); // If the schema validation result is true, this requirement can be verified. Site.CaptureRequirement( 4227, @"[In Status(Ping)] The Status element is a required child element of the Ping element in Ping command responses that indicates the success or failure of the Ping command request (section 2.2.2.11)."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2739"); // If the schema validation result is true, this requirement can be verified. Site.CaptureRequirement( 2739, @"[In Status(Ping)] Element Status in Ping command response, the parent element is Ping (section 2.2.3.130)."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2740"); // If the schema validation result is true, this requirement can be verified. Site.CaptureRequirement( 2740, @"[In Status(Ping)] None [Element Status in Ping command response has no child element.]"); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2742"); // If the schema validation result is true, this requirement can be verified. Site.CaptureRequirement( 2742, @"[In Status(Ping)] Element Status in Ping command response, the number allowed is 1…1 (required)."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2741"); // Verify MS-ASCMD requirement: MS-ASCMD_R2741 // If the schema validation result is true, this requirement can be verified. Site.CaptureRequirement( 2741, @"[In Status(Ping)] Element Status in Ping command response, the data type is unsignedByte ([MS-ASDTYPE] section 2.8)."); Common.VerifyActualValues("Status(Ping)", AdapterHelper.ValidStatus(new string[] { "1", "2", "3", "4", "5", "6", "7", "8" }), pingResponse.ResponseData.Status.ToString(), this.Site); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4231"); // Verify MS-ASCMD requirement: MS-ASCMD_R4231 // If above Common.VerifyActualValues method is not failed, this requirement can be verified. Site.CaptureRequirement( 4231, @"[In Status(Ping)] The following table lists the status codes [1,2,3,4,5,6,7,8] for the Ping command (section 2.2.2.12). For information about the scope of the status value and for status values common to all ActiveSync commands, see section 2.2.4."); this.VerifyIntegerDataType(); #endregion #region Capture code for HeartbeatInterval if (pingResponse.ResponseData.HeartbeatInterval != null) { // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1780"); // If the schema validation result is true and HeartbeatInterval(Ping) is not null, this requirement can be verified. Site.CaptureRequirement( 1780, @"[In HeartbeatInterval(Ping)] Element HeartbeatInterval in Ping command response, the parent element is Ping."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1781"); // If the schema validation result is true and HeartbeatInterval(Ping) is not null, this requirement can be verified. Site.CaptureRequirement( 1781, @"[In HeartbeatInterval(Ping)] None [ement HeartbeatInterval in Ping command response has no child element.]"); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1783"); // If the schema validation result is true and HeartbeatInterval(Ping) is not null, this requirement can be verified. Site.CaptureRequirement( 1783, @"[In HeartbeatInterval(Ping)] Ement HeartbeatInterval in Ping command response, the number allowed is 0...1 (optional)."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1782"); // Verify MS-ASCMD requirement: MS-ASCMD_R1782 Site.CaptureRequirementIfAreEqual<Type>( typeof(int), Convert.ToInt32(pingResponse.ResponseData.HeartbeatInterval).GetType(), 1782, @"[In HeartbeatInterval(Ping)] Element HeartbeatInterval in Ping command response, the data type is integer."); this.VerifyIntegerDataType(); } #endregion #region Capture code for Folders if (pingResponse.ResponseData.Folders != null && pingResponse.ResponseData.Folders.Length > 0) { // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1707"); // If the schema validation result is true and Folders is not null, this requirement can be verified. Site.CaptureRequirement( 1707, @"[In Folders(Ping)] Element Folders in Ping command response, the parent element is Ping."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1708"); // If the schema validation result is true and Folders is not null, this requirement can be verified. Site.CaptureRequirement( 1708, @"[In Folders(Ping)] Element Folders in Ping command response, the child element is Folder."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1709"); // If the schema validation result is true and Folders is not null, this requirement can be verified. Site.CaptureRequirement( 1709, @"[In Folders(Ping)] Element Folders in Ping command response, the data type is container."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1710"); // If the schema validation result is true and Folders is not null, this requirement can be verified. Site.CaptureRequirement( 1710, @"[In Folders(Ping)] Element Folders in Ping command response, the number allowed is 0...1 (optional)."); this.VerifyContainerDataType(); foreach (string folder in pingResponse.ResponseData.Folders) { #region Capture code for Folder Site.Assert.IsNotNull(folder, "The Folder element of the Folders element should not be null."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R3082"); // If the schema validation result is true and Folder is not null, this requirement can be verified. Site.CaptureRequirement( 3082, @"[In Folders(Ping)] The Folder element is a required child element of the Folders element in Ping command responses that identifies the folder that is being described by the returned status code."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1675"); // If the schema validation result is true and Folder is not null, this requirement can be verified. Site.CaptureRequirement( 1675, @"[In Folders(Ping)] Element Folder in Ping command response (section 2.2.2.12), the parent element is Folders (section 2.2.3.70)."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1676"); // If the schema validation result is true and Folder is not null, this requirement can be verified. Site.CaptureRequirement( 1676, @"[In Folders(Ping)] None [Element Folder in Ping command response has no child element.]"); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1677"); // If the schema validation result is true and Folder is not null, this requirement can be verified. Site.CaptureRequirement( 1677, @"[In Folders(Ping)] Element Folder in Ping command response, the data type is string ([MS-ASDTYPE] section 2.7)."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1678"); // If the schema validation result is true and Folder is not null, this requirement can be verified. Site.CaptureRequirement( 1678, @"[In Folders(Ping)] Element Folder in Ping command response, the number allowed is 1...N (required)."); this.VerifyStringDataType(); #endregion } } #endregion }
/// <summary>Validates the given user’s application key.</summary> public PingResponse Validate() { string url = "http://api.ping.fm/v1/user.validate"; string postdata = "api_key={0}&user_app_key={1}"; postdata = string.Format(postdata, api_key, user_application_key); string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); PingResponse r = (PingResponse)DeserializeObject(xr, typeof(PingResponse)); xr.Close(); mLastResponse = r; return r; }