public IHttpActionResult CheckTransactionPassword(long account_number, string transaction_password) { try { string password = db.AccountHolders.Where(a => a.account_number == account_number).Select(a => a.transaction_password).ToList()[0]; System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(password); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string decrypt_transaction_password = new String(decoded_char); if (decrypt_transaction_password == transaction_password) { return(Ok("Passwords Match")); } else { return(Ok("Error")); } } catch (Exception e) { return(Ok("Error")); } }
public object GetRealObject (StreamingContext context) { if (this.realObject == null) this.realObject = this.encoding.GetDecoder (); return this.realObject; }
public void OnDataReceived(IAsyncResult asyn) { SocketPacket socketData = (SocketPacket)asyn.AsyncState; try { int rx = socketData.currentSocket.EndReceive(asyn); char[] chars = new char[rx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars( socketData.dataBuffer, 0, rx, chars, 0 ); string data = new String(chars); if (OnData != null) { OnData(this, new DataEventArgs(data, socketData)); } WaitForData(); } catch (ObjectDisposedException) { // System.Diagnostics.Debugger.Log(0,"1","\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { // MessageBox.Show (se.Message ); } }
//--------------------------------------- public string slice(int pos, int len) { System.Text.Decoder dec = System.Text.Encoding.Default.GetDecoder(); char[] text = new char[len]; dec.GetChars(theBuff, pos, len, text, 0); return(new string(text)); }
// This the call back function which will be invoked when the socket // detects any client writing of data on the stream public void OnDataReceived(IAsyncResult asyn) { SocketPacket socketData = (SocketPacket)asyn.AsyncState; try { // Complete the BeginReceive() asynchronous call by EndReceive() method // which will return the number of characters written to the stream // by the client int iRx = socketData.m_currentSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; // Extract the characters as a buffer System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); UpdateLogControl("Client " + socketData.m_clientNumber + ": " + szData); //Send back a reply to the client //string replyMsg = ""; //UpdateLogControl("Server Reply: " + replyMsg); //Convert the reply to byte array //byte[] byData = System.Text.Encoding.ASCII.GetBytes(replyMsg); //Socket workerSocket = (Socket)socketData.m_currentSocket; //workerSocket.Send(byData); WaitForData(socketData.m_currentSocket, socketData.m_clientNumber); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { CheckDisconnect(se, socketData.m_clientNumber); } }
public string base64Decode(object obj) { try { string data = obj != null?obj.ToString() : string.Empty; if (string.IsNullOrEmpty(data)) { return(string.Empty); } System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(data); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); } catch (Exception e) { throw new Exception("Error in base64Decode" + e.Message); } }
// This the call back function which will be invoked when the socket // detects any client writing of data on the stream public void OnDataReceived(IAsyncResult asyn) { try { SocketPacket socketData = (SocketPacket)asyn.AsyncState; int iRx = 0; // Complete the BeginReceive() asynchronous call by EndReceive() method // which will return the number of characters written to the stream // by the client iRx = socketData.m_currentSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); richTextBoxReceivedMsg.AppendText(szData); // Continue the waiting for data on the Socket WaitForData(socketData.m_currentSocket); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { MessageBox.Show(se.Message); } }
/// <summary>Reads a NULL-terminated string from the current stream.</summary> /// <returns>The string being read without the terminating NULL.</returns> /// <exception cref="System.IO.EndOfStreamException">The end of the stream is reached.</exception> /// <exception cref="System.IO.IOException">An I/O error occurs.</exception> /// <exception cref="System.NotSupportedException">The stream does not support reading.</exception> /// <exception cref="System.ObjectDisposedException">The stream is closed.</exception> public string ReadCString() { if (this._stream == null) { throw new System.ObjectDisposedException(this.GetType().FullName); } if (!this._stream.CanRead) { throw new System.NotSupportedException(); } System.Text.StringBuilder s = new System.Text.StringBuilder(); System.Text.Encoding encoding = this._cEncoding; System.Text.Decoder decoder = this._cDecoder; char[] buffer = new char[1]; do { if (this.IntReadChars(buffer, 0, 1, encoding, decoder) == 0) { throw new System.IO.EndOfStreamException(); } if (buffer[0] == '\0') { break; } s.Append(buffer[0]); } while (true); return(s.ToString()); }
void OnDataReceived(IAsyncResult asyn) { try { SocketPacket packet = (SocketPacket)asyn.AsyncState; int end = packet.TCPSocket.EndReceive(asyn); char[] chars = new char[end + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); d.GetChars(packet.DataBuffer, 0, end, chars, 0); System.String data = new System.String(chars); ReceiveData(data); WaitForData(); } catch (ObjectDisposedException) { Console.WriteLine("WARNING: Socket closed unexpectedly"); } catch (SocketException se) { if (!_TCPSocket.Connected) { if (OnDisconnected != null) { OnDisconnected(se); } } } }
public void SendMessage(string msg) { try { // New code to send strings NetworkStream networkStream = new NetworkStream(m_clientSocket); System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(networkStream); streamWriter.WriteLine(msg); streamWriter.Flush(); //------------------------------------------------------------------------------------------ byte[] data = new byte[500]; m_clientSocket.Receive(data); char[] chars = new char[data.Length + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(data, 0, data.Length, chars, 0); System.String szData = new System.String(chars); richTextRxMessage.Text = richTextRxMessage.Text + szData.ToString(); //------------------------------------------------------------------------------------------ /* Use the following code to send bytes * byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString ()); * if(m_clientSocket != null){ * m_clientSocket.Send (byData); * } */ } catch (SocketException se) { MessageBox.Show(se.Message); } }
public void OnDataReceived(IAsyncResult asyn) { try { CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState; //end receive... int iRx = 0; iRx = theSockId.thisSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); //txtDataRx.Text = txtDataRx.Text + szData; txtDataRx.Invoke(new MethodInvoker(delegate { txtDataRx.Text = txtDataRx.Text + szData; })); WaitForData(m_socWorker); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { MessageBox.Show(se.Message); } }
public void OnDataReceived(IAsyncResult asyn) { try { CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState; //end receive... int iRx = 0; iRx = theSockId.thisSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); txtDataRx.Text = szData; if (txtDataRx.Text == "r") { pictureBox1.Left += 12; } if (txtDataRx.Text == "l") { pictureBox1.Left -= 12; } WaitForData(); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { MessageBox.Show(se.Message); } }
public void OnDataReceived(IAsyncResult asyn) { try { SocketPacket theSockId = (SocketPacket)asyn.AsyncState; int iRx = theSockId.thisSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0); System.String szData = theSockId.string_RemoteEndPoint + ":" + (new System.String(chars)); textBox_MSG.Invoke(new UpdateText(updateText), szData); WaitForData(); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (System.Exception se) { //MessageBox.Show("服务器断开连接,请检查服务器然后重新连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.textBox_MSG.AppendText(se.Message + "\r\n"); button2.PerformClick(); } }
public void OnDataReceived(IAsyncResult asyn) { int ClientID = tempint; try { SocketPacket socketData = (SocketPacket)asyn.AsyncState; LenghtOfDataRecieved = socketData.RealmserverSocket.EndReceive(asyn); char[] chars = new char[LenghtOfDataRecieved + 1]; System.Text.Decoder decode = System.Text.Encoding.UTF8.GetDecoder(); int charLen = decode.GetChars(socketData.dataBuffer, 0, LenghtOfDataRecieved, chars, 0); System.String szData = new System.String(chars); if (LenghtOfDataRecieved != 0) { ProcessRecieved(socketData.dataBuffer, ClientID); } Thread.Sleep(50); WaitForData(socketData.RealmserverSocket, ClientID); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { ColoredConsole.ConsoleWriteErrorWithOut(se.Message); } }
public void OnReceive(IAsyncResult oAsyncResult) { try { SocketPacket oSocketID = (SocketPacket)oAsyncResult.AsyncState; //Stop Recieve int iRecieve = 0; iRecieve = oSocketID.oSocket.EndReceive(oAsyncResult); //Build the message char[] chars = new char[iRecieve + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int iCharLen = d.GetChars(oSocketID.bDataBuffer, 0, iRecieve, chars, 0); //string sData = new string(chars); Packet_Exchange.Packets.add_to_que(chars[0]); //Wait again WaitForData(oSocketWorker); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\n OnReceive: Socket has been closed\n"); } catch (SocketException ex) { System.Diagnostics.Debugger.Log(0, "1", ex.Message); } }
private string ReceiveData(int BytesReceive, int BufferSize, Socket SocketData) { string Message = string.Empty; if ((BufferSize - BytesReceive) != 0) { while (BytesReceive < BufferSize) { byte[] Buffer = new byte[(BufferSize - BytesReceive)]; int ByteRest = SocketData.Receive(Buffer, (BufferSize - BytesReceive), SocketFlags.None ); char[] charLenght = new char[ByteRest]; System.Text.Decoder decoder = System.Text.Encoding.UTF8.GetDecoder(); decoder.GetChars( Buffer, 0, ByteRest, charLenght, 0 ); BytesReceive += (BufferSize - BytesReceive); Message += new string(charLenght); } } return(Message); }
/// <summary> /// Decodes any byte array into a string /// </summary> /// <param name="byteArray">raw byte array to be decoded</param> /// <param name="encoding">byte array encoding type</param> /// <returns>decoded string</returns> public string DecodeBytesToString(byte[] byteArray) { char[] chars = new char[byteArray.Length + 1]; System.Text.Decoder d = this.encoding.GetDecoder(); int charLen = d.GetChars(byteArray, 0, byteArray.Length, chars, 0); return(new System.String(chars)); }
public static string GetNameFromByte(byte[] _name, int _iRx) { System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); char[] chars = new char[_iRx]; d.GetChars(_name, 0, _iRx, chars, 0); return(new string(chars)); }
public object GetRealObject(StreamingContext context) { if (this.realObject == null) { this.realObject = this.encoding.GetDecoder(); } return(this.realObject); }
public void ExportPurchaseInvoice(string encrift) { List <Purchase> purchase = new List <Purchase>(); byte[] b = Convert.FromBase64String(encrift); System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decoder = encoder.GetDecoder(); int charCount = utf8Decoder.GetCharCount(b, 0, b.Length); char[] decodedChar = new char[charCount]; utf8Decoder.GetChars(b, 0, b.Length, decodedChar, 0); string result = new string(decodedChar); JavaScriptSerializer js = new JavaScriptSerializer(); Purchase[] PurchaseList = js.Deserialize <Purchase[]>(result); foreach (var a in PurchaseList) { Purchase aPurchase = new Purchase(); aPurchase.PurchaseNo = a.PurchaseNo; aPurchase.PurchaseDate = a.PurchaseDate; aPurchase.PurchaseSupplierInvoiceNo = a.PurchaseSupplierInvoiceNo; aPurchase.ProductCode = db.productDetails.First(p => p.ProductDetailsID == a.PurchaseProductID).Code; aPurchase.ProductName = db.productDetails.First(p => p.ProductDetailsID == a.PurchaseProductID).ProductName; aPurchase.PurchaseProductPrice = a.PurchaseProductPrice; aPurchase.PurchaseQuantity = a.PurchaseQuantity; aPurchase.PurchaseTotal = a.PurchaseTotal; aPurchase.TotalAmount = a.TotalAmount; purchase.Add(aPurchase); } ReportDataSource reportDataSource = new ReportDataSource(); reportDataSource.Name = "PurchaseDataSet"; reportDataSource.Value = purchase; string mimeType = string.Empty; string encodeing = string.Empty; string fileNameExtension = "pdf"; Warning[] warnings; string[] streams; LocalReport localReport = new LocalReport(); localReport.ReportPath = Server.MapPath("~/Report/Purchase/PurchaseReport.rdlc"); localReport.DataSources.Add(reportDataSource); byte[] bytes = localReport.Render("PDF", null, out mimeType, out encodeing, out fileNameExtension, out streams, out warnings); Response.Buffer = true; Response.Clear(); Response.ContentType = mimeType; Response.AddHeader("content-disposition", "attachment;filename=file." + fileNameExtension); Response.BinaryWrite(bytes); Response.Flush(); }
private string ConvertBytesToString(byte[] bytes, int iRx) { char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); d.GetChars(bytes, 0, iRx, chars, 0); string szData = new string(chars); return(szData); }
public void SavePaneSettings(string outputFilePath) { byte[] currentRegPaneSettings = (byte[])Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\HolodeckEE").GetValue("PaneSettings"); System.IO.StreamWriter outputFile = new System.IO.StreamWriter(outputFilePath); System.Text.Decoder decoder = System.Text.Encoding.Unicode.GetDecoder(); char[] decodedPaneSettings = new char[currentRegPaneSettings.Length]; decoder.GetChars(currentRegPaneSettings, 0, currentRegPaneSettings.Length, decodedPaneSettings, 0); outputFile.Write(decodedPaneSettings); outputFile.Close(); }
/// <summary> /// Encodes the given bytes as <see cref="char"/>'s using the specified options using <see cref="System.Text.Encoding.GetChars"/>. /// </summary> /// <param name="encoding">The optional encoding to use, if none is specified the Default will be used.</param> /// <param name="toEncode">The data to encode, if null an <see cref="ArgumentNullException"/> will be thrown.</param> /// <param name="offset">The offset to start at</param> /// <param name="count">The amount of bytes to use in the encoding</param> /// <returns>The encoded data</returns> public static char[] GetChars(this System.Text.Decoder decoder, byte[] toEncode, int offset, int count) { //Use default.. if (decoder == null) { decoder = System.Text.Encoding.Default.GetDecoder(); } return(decoder.GetChars(toEncode, offset, count)); }
public static string BytesToString(byte[] bytes) { System.Text.Decoder decode = System.Text.Encoding.UTF8.GetDecoder(); long length = decode.GetCharCount(bytes, 0, bytes.Length); char[] chars = new char[length]; decode.GetChars(bytes, 0, bytes.Length, chars, 0); string result = new String(chars); return(result); }
public static string Decrypt(this string str) { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(str); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); return(new string(decoded_char)); }
public void OnDataReceived(IAsyncResult asyn) { try { Communications.SocketPacket socketData = (Communications.SocketPacket)asyn.AsyncState; int iRx = 0; // Complete the BeginReceive() asynchronous call by EndReceive() method // which will return the number of characters written to the stream // by the client iRx = socketData.m_currentSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); EndPoint remoteEndPoint = socketData.m_currentSocket.RemoteEndPoint; if (LastEndPointStarted == null) { LastEndPointStarted = remoteEndPoint; } if (LastEndPointStarted == remoteEndPoint) { // My attempts to defeat concurrent thread write collisions. I was seeing 2 end points trying to write // into the socket and that concatenated the bits at the bit level, so no byte received was even remotely // correct. I put in this equality test to force the last end point we started working with to be the // winner. The loser's message is ignored. ReceivedMsg.AppendText(szData); //when we are sure we received the entire message //pass the Object received into parameter //after removing the flag indicating the end of message String EOMDelimiter = m_Globals.m_communications.EOMDelimiter; if (ReceivedMsg.GetText().Contains(EOMDelimiter)) { LastEndPointStarted = null; String SanitizedMessage = Regex.Replace(ReceivedMsg.GetText(), EOMDelimiter, ""); ProcessCommMessage(SanitizedMessage, socketData.m_currentSocket.RemoteEndPoint); } } // Continue the waiting for data on the Socket WaitForData(socketData.m_currentSocket); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { MessageBox.Show(se.Message); } }
protected string GetDataAsString(byte[] data) { System.Text.Decoder utf8Decoder = System.Text.Encoding.UTF8.GetDecoder(); int charCount = utf8Decoder.GetCharCount(data, 0, (data.Length)); char[] recievedChars = new char[charCount]; utf8Decoder.GetChars(data, 0, data.Length, recievedChars, 0); string recievedString = new String(recievedChars); return(recievedString); }
public string getCharacterComplement() { char [] charBuf = new char[8]; System.Text.ASCIIEncoding ae = new System.Text.ASCIIEncoding(); System.Text.Decoder d = ae.GetDecoder(); d.GetChars(m_CharacterComplement, 0, 8, charBuf, 0); return(new string( charBuf )); }
public string getFileName() { char [] charBuf = new char[6]; System.Text.ASCIIEncoding ae = new System.Text.ASCIIEncoding(); System.Text.Decoder d = ae.GetDecoder(); d.GetChars(m_FileName, 0, 6, charBuf, 0); return(new string( charBuf )); }
public string GetTypeface() { char[] charBuf = new char[16]; System.Text.ASCIIEncoding ae = new System.Text.ASCIIEncoding(); System.Text.Decoder d = ae.GetDecoder(); d.GetChars(Typeface, 0, 16, charBuf, 0); return(new string(charBuf)); }
// This the call back function which will be invoked when the socket // detects any client writing of data on the stream public void OnDataReceived(IAsyncResult asyn) { SocketPacket socketData = (SocketPacket)asyn.AsyncState; try { // Complete the BeginReceive() asynchronous call by EndReceive() method // which will return the number of characters written to the stream // by the client int iRx = socketData.m_currentSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; // Extract the characters as a buffer System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); string msg = "" + socketData.m_clientNumber + ":"; AppendToRichEditControl(msg + szData); // Send back the reply to the client string replyMsg = "Server Reply:" + szData.ToUpper(); // Convert the reply to byte array byte[] byData = System.Text.Encoding.ASCII.GetBytes(replyMsg); Socket workerSocket = (Socket)socketData.m_currentSocket; workerSocket.Send(byData); // Continue the waiting for data on the Socket WaitForData(socketData.m_currentSocket, socketData.m_clientNumber); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { if (se.ErrorCode == 10054) // Error code for Connection reset by peer { string msg = "Client " + socketData.m_clientNumber + " Disconnected" + "\n"; AppendToRichEditControl(msg); // Remove the reference to the worker socket of the closed client // so that this object will get garbage collected m_workerSocketList[socketData.m_clientNumber - 1] = null; UpdateClientListControl(); } else { MessageBox.Show(se.Message); } } }
// Instance constructor public StringDecoderInstance(Context context, ObjectInstance thisPrototype, string encoding) : base(context, thisPrototype) { Encoding = Context.GetEncoding(encoding); if (Encoding == null) throw new JavaScriptException(Engine, "TypeError", "Unknown encoding: " + encoding); Decoder = Encoding.GetDecoder(); }