/// <summary> /// Add the id to the bundle /// </summary> /// <param name="Id"></param> public void AddFileId(Messages.PutBytesMessage message) { List <byte> Id = new List <byte>(); for (int i = 0; i < 4; i++) { Id.Add(message.Result[i + 1]); } switch (Status) { case UploadStatus.eResource: if (ResourceId.Count == 0) { ResourceId = Id; } break; case UploadStatus.eBinary: if (BinaryId.Count == 0) { BinaryId = Id; } break; } }
/// <summary> /// Creates an incoming message. /// </summary> /// <param name="endpoint">The endpoint.</param> /// <param name="payload">The payload.</param> /// <returns>A specific message type</returns> public static P3bbleMessage CreateMessage(Endpoint endpoint, List<byte> payload) { P3bbleMessage frame = null; switch (endpoint) { case Endpoint.Ping: frame = new PingMessage(); break; case Endpoint.Version: frame = new VersionMessage(); break; case Endpoint.Time: frame = new TimeMessage(); break; case Endpoint.Logs: frame = new LogsMessage(); break; case Endpoint.AppManager: frame = new AppManagerMessage(); break; case Endpoint.MusicControl: frame = new MusicMessage(); break; case Endpoint.ApplicationMessage: frame = new AppMessage(endpoint); break; case Endpoint.PutBytes: frame = new PutBytesMessage(); break; } if (frame != null) { frame.GetContentFromMessage(payload); } return frame; }
/// <summary> /// Handles the state message. /// </summary> /// <param name="message">The message response.</param> /// <returns>True when the PutBytes process has completed (either successfully or not), false if further processing is required</returns> internal bool HandleStateMessage(PutBytesMessage message) { if (message.Result[0] != 1) { this.Errored = true; } ServiceLocator.Logger.WriteLine("PutBytes >>> incoming message for " + this._state.ToString()); switch (this._state) { case PutBytesState.WaitForToken: if (this.Errored) { return true; } byte[] tokenArray = new byte[message.Result.Count - 1]; message.Result.CopyTo(1, tokenArray, 0, tokenArray.Length); if (BitConverter.IsLittleEndian) { Array.Reverse(tokenArray); } this._token = BitConverter.ToUInt32(tokenArray, 0); this._leftToSend = this._buffer.Count; // next step is we start sending data - like PutBytesClient.send() // the continuation is in AddContentToMessage this._state = PutBytesState.InProgress; break; case PutBytesState.InProgress: if (this.Errored) { this._state = PutBytesState.Abort; } else { if (this._leftToSend > 0) { // Still more to send, so we return false and the next chunk will go ServiceLocator.Logger.WriteLine(string.Format("Sent {0} of {1} bytes", this._buffer.Count - this._leftToSend, this._buffer.Count)); if (this._progressHandler != null) { // From PutBytes, we send the number of bytes we just sent rather than a percentage... this._progressHandler(this._lastChunkSize); } return false; } else { // next step is we send the commit message like PutBytesClient.commit() // the continuation is in AddContentToMessage this._state = PutBytesState.Commit; } } break; case PutBytesState.Commit: if (this.Errored) { this._state = PutBytesState.Abort; } else { // next step is we send the commit message like PutBytesClient.commit() // the continuation is in AddContentToMessage this._state = PutBytesState.Complete; } break; case PutBytesState.Complete: if (this.Errored) { this._state = PutBytesState.Abort; } else { this.Completed = true; return true; } break; } return false; }
/// <summary> /// Handles the state message. /// </summary> /// <param name="message">The message response.</param> /// <returns>True when the PutBytes process has completed (either successfully or not), false if further processing is required</returns> internal bool HandleStateMessage(PutBytesMessage message) { if (message.Result[0] != 1) { this.Errored = true; } ServiceLocator.Logger.WriteLine("PutBytes >>> incoming message for " + this._state.ToString()); switch (this._state) { case PutBytesState.WaitForToken: if (this.Errored) { return(true); } byte[] tokenArray = new byte[message.Result.Count - 1]; message.Result.CopyTo(1, tokenArray, 0, tokenArray.Length); if (BitConverter.IsLittleEndian) { Array.Reverse(tokenArray); } this._token = BitConverter.ToUInt32(tokenArray, 0); this._leftToSend = this._buffer.Count; // next step is we start sending data - like PutBytesClient.send() // the continuation is in AddContentToMessage this._state = PutBytesState.InProgress; break; case PutBytesState.InProgress: if (this.Errored) { this._state = PutBytesState.Abort; } else { if (this._leftToSend > 0) { // Still more to send, so we return false and the next chunk will go ServiceLocator.Logger.WriteLine(string.Format("Sent {0} of {1} bytes", this._buffer.Count - this._leftToSend, this._buffer.Count)); if (this._progressHandler != null) { // From PutBytes, we send the number of bytes we just sent rather than a percentage... this._progressHandler(this._lastChunkSize); } return(false); } else { // next step is we send the commit message like PutBytesClient.commit() // the continuation is in AddContentToMessage this._state = PutBytesState.Commit; } } break; case PutBytesState.Commit: if (this.Errored) { this._state = PutBytesState.Abort; } else { // next step is we send the commit message like PutBytesClient.commit() // the continuation is in AddContentToMessage this._state = PutBytesState.Complete; } break; case PutBytesState.Complete: if (this.Errored) { this._state = PutBytesState.Abort; } else { this.Completed = true; return(true); } break; } return(false); }