public void Extract(IFile file, string outputDirectoryPath) { if (string.IsNullOrEmpty(outputDirectoryPath)) { outputDirectoryPath = _outputDirectory.Path; } var outputPath = Path.Combine(outputDirectoryPath, file.Name); try { AssertExistenceOfDirectory(outputDirectoryPath); using (var s = file.Read()) using (var f = _fileSystem.File.Create(outputPath)) { s.CopyTo(f); } } catch (Exception e) { _messages.Add($"Extraction failed: {file.Path} --> {outputPath}"); _messages.Add(e.Message); _messages.Add(e.StackTrace); } _messages.Add($"Extracted: {file.Path} --> {outputPath}"); }
public int RefreshFromMissed() { int i = 0; while (_missed.Count > 0) { _queue.Add(_missed.Dequeue()); i++; } return(i); }
public int RefreshFromMissed() { int i = 0; while (_missed.TryTake(out T val)) { _queue.Add(val); i++; } return(i); }
public int RefreshFromMissed() { int i = 0; T val = default(T); while (fMissed.TryTake(out val)) { fQueue.Add(val); i++; } return(i); }
private void Profile(Action action, string what) { var sw = Stopwatch.StartNew(); action(); _messages.Add($"DataForge: {what} took {sw.ElapsedMilliseconds} ms."); }
public IFileViewer Create(IFile file) { var errorMessage = ""; if (_dataForgeFileCache[file] == null) { // HACK(PJ): load only once for now. Caching for open p4k most likely. try { using (var s = file.Read()) using (var r = new BinaryReader(s)) { _dataForgeFileCache[file] = new DataForgeFile(r, _messages); } } catch (Exception e) { errorMessage = $"There was an error opening {file.Name}.\r\n\r\n{e.Message}\r\n\r\n{e.StackTrace}"; _messages.Add(errorMessage); } } return(new DataForgeFileViewer(_dataForgeFileCache[file], errorMessage)); }
public override void SendMessage(int msgId, byte[] msgObj) { #if LOG_SEND_BYTES var sb = new System.Text.StringBuilder(); for (int i = 0; i < msgObj.Length; i++) { sb.AppendFormat("{0}\t", msgObj[i]); } Logger.Log("HjTcpNetwork send bytes : " + sb.ToString()); #endif byte[] packObj = new byte[12 + msgObj.Length]; // 包头4个字节:包识别符(1字节)+noaes标志(1字节)+包长度(2字节,Big Endian) packObj[0] = PACKAGE_IDENTIFY; packObj[1] = 0x01; packObj[2] = (byte)((packObj.Length >> 8) & 0xFF); packObj[3] = (byte)(packObj.Length & 0xFF); // 消息头8个字节:消息识别符(1字节)+消息来源(1字节)+消息类型(2字节)+套接字索引(2字节)+ 消息体长度(2字节) packObj[4] = MESSAGE_VERSION; packObj[6] = (byte)(msgId & 0xFF); packObj[7] = (byte)((msgId >> 8) & 0xFF); // 消息体长度2个字节改为 packObj[10] = (byte)(msgObj.Length & 0xFF); packObj[11] = (byte)((msgObj.Length >> 8) & 0xFF); // 消息体 Array.Copy(msgObj, 0, packObj, 12, msgObj.Length); mSendMsgQueue.Add(packObj); mSendSemaphore.ProduceResrouce(); }
public void Log(ILogMessage message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } queue.Add(message); }
public void LockingCastingTest() { QueueFactory <string> factory = new QueueFactory <string> { Style = QueueFactory <string> .QueueStyle.Locking }; IMessageQueue <string> locking = factory.GetQueue(); Assert.IsNotNull(locking); Assert.IsTrue(locking is LockQueue <string>); locking.Add("Test1"); locking.Add("Test2"); Assert.AreEqual(2, locking.Count()); bool result = locking.TryTake(out string s); Assert.IsTrue(result); Assert.AreEqual("Test1", s); }
/// <summary> /// Publishes data /// </summary> /// <param name="data"></param> public void Publish(T data) { _messageQueue.Add(new PublicationData <T> { Id = Guid.NewGuid(), PublishDateTime = DateTime.Now, Data = data }); }
public void RingQueueCastingTest() { var factory = new QueueFactory <string> { Style = QueueStyle.Ring }; IMessageQueue <string> messageQueue = factory.GetQueue(); Assert.IsNotNull(messageQueue); Assert.IsTrue(messageQueue is RingQueue <string>); messageQueue.Add("Test1"); messageQueue.Add("Test2"); Assert.AreEqual(2, messageQueue.Count()); var result = messageQueue.TryTake(out string s); Assert.IsTrue(result); Assert.AreEqual("Test1", s); }
public async Task <object> Receive(Func <object, bool> aPattern, int timeOutMS) { CheckArg.Pattern(aPattern); var lTCS = new Behavior(aPattern, new TaskCompletionSource <object>()); Interlocked.Increment(ref fShared.fReceive); fCompletions.Add(lTCS); AddMissedMessages(); Interlocked.Exchange(ref fShared.fInTask, 0); TrySetInTask(TaskCreationOptions.LongRunning); if (timeOutMS != Timeout.Infinite) { var noTimeOut = lTCS.Completion.Task.Wait(timeOutMS); if (noTimeOut) { return(await lTCS.Completion.Task); } else { // remove this lTCS Queue <IBehavior> lQueue = new Queue <IBehavior>(); IBehavior bhv; while (fCompletions.TryTake(out bhv)) { if (bhv != lTCS) { lQueue.Enqueue(bhv); } } while (lQueue.Count > 0) { fCompletions.Add(lQueue.Dequeue()); } Interlocked.Decrement(ref fShared.fReceive); return(null); } } else { return(await lTCS.Completion.Task); } }
public override void SendMessage(byte[] msgObj) { #if LOG_SEND_BYTES var sb = new System.Text.StringBuilder(); for (int i = 0; i < msgObj.Length; i++) { sb.AppendFormat("{0}\t", msgObj[i]); } Logger.Log("HjTcpNetwork send bytes : " + sb.ToString()); #endif mSendMsgQueue.Add(msgObj); mSendSemaphore.ProduceResrouce(); }
private async Task OpenP4kFile() { CanExecuteChanged.Raise(this); _command.Execution.PropertyChanged += UpdateCanExecuteWhenTaskIsComplete; var openFileDialog = new OpenFileDialog { DefaultExt = ".p4k", Filter = "Game archive (.p4k)|*.p4k" }; if (!openFileDialog.ShowDialog() .Value) { return; } var file = _fileSystem.FileInfo.FromFileName(openFileDialog.FileName); _messages.Add($"Loading {openFileDialog.FileName}..."); _progress.SetIndetermined(); await _currentP4K.ChangeAsync(file); }
protected void DoConnect() { if (mClientSocket != null) { return; } try { String newServer = string.Format("ws://{0}:{1}/websocket", mIp, mPort); mClientSocket = new WebSocket(newServer); mClientSocket.OnMessage += (sender, e) => { if (e.IsBinary) { mReceiveMsgQueue.Add(e.RawData); } else { UnityEngine.Debug.Log("收到非二进制数据"); } }; mClientSocket.OnOpen += (sender, e) => { UnityEngine.Debug.Log("连接成功"); OnConnected(); }; mClientSocket.OnError += (sender, e) => { mStatus = SOCKSTAT.CLOSED; UnityEngine.Debug.Log("发生错误:" + e.Message); }; mClientSocket.OnClose += (sender, e) => { mStatus = SOCKSTAT.CLOSED; UnityEngine.Debug.Log("连接关闭"); }; mStatus = SOCKSTAT.CONNECTING; mClientSocket.Connect(); } catch (Exception e) { UnityEngine.Debug.Log(e); } }
public override void SendMessage(byte[] msgObj) { #if LOG_SEND_BYTES var sb = new System.Text.StringBuilder(); for (int i = 0; i < msgObj.Length; i++) { sb.AppendFormat("{0}\t", msgObj[i]); } Logger.Log("HjTcpNetwork send bytes : " + sb.ToString()); #endif ByteBuffer buffer = new ByteBuffer(); //包头4字节,转成大端格式 byte[] lenBytes = BitConverter.GetBytes(msgObj.Length); Array.Reverse(lenBytes); buffer.WriteBytes(lenBytes); buffer.WriteBytes(msgObj); mSendMsgQueue.Add(buffer.ToBytes()); mSendSemaphore.ProduceResrouce(); }
//发送消息格式: //[前两个字节为消息长度,后接加密消息 ] public override void SendMessage(byte[] msgObj) { #if LOG_SEND_BYTES var sb = new System.Text.StringBuilder(); for (int i = 0; i < msgObj.Length; i++) { sb.AppendFormat("{0}\t", msgObj[i]); } Logger.Log("HjTcpNetwork send bytes : " + sb.ToString()); #endif //int msgId = -1; //if (msgObj.Length != 0) { // msgId = Tea.Tea.byteToInt(msgObj, 5); //} if (!IsConnect()) { Logger.LogError("HjTcpNetwork SendMessage 连接已经断开不能发送协议!"); return; } //Logger.Log("C# send msgId : " + msgId); byte[] encryptData = Tea.Tea.encryptMy2(msgObj, netSecretKey); mSendMsgQueue.Add(encryptData); mSendSemaphore.ProduceResrouce(); }
public void AddMiss(T aMessage) { fMissed.Add(aMessage); }
public void AddMiss(T aMessage) => _missed.Add(aMessage);
public void Log(LogType logType, string message) => queue.Add(new NormalMessage(logType, message));
public void Add(ref TMessage message) { _queue2.Add(ref message); }
public override void SendMessage(byte[] msgObj) { mSendMsgQueue.Add(msgObj); mSendSemaphore.ProduceResrouce(); }