internal static void CompleteTask <T>(ref T enumerator, int _timeout = 0) where T : ISveltoTask { var quickIterations = 0; if (_timeout < 0) { while (enumerator.MoveNext()) { ; } } else if (_timeout == 0) { while (enumerator.MoveNext()) { ThreadUtility.Wait(ref quickIterations); } } else { var then = DateTime.Now.AddMilliseconds(_timeout); var valid = true; while (enumerator.MoveNext() && (valid = DateTime.Now < then)) { ThreadUtility.Wait(ref quickIterations); } if (valid == false) { throw new Exception("synchronous task timed out, increase time out or check if it got stuck"); } } }
void CompressTree() { int level = 0; using (LowPriority ? ThreadUtility.EnterBackgroundProcessingMode() : null) { while (level + 1 < LevelCount) { int leafIndex = 0; var internalLeafCount = (_leafCount / 2) + (_leafCount % 2); TTH[level + 1] = new byte[internalLeafCount][]; if (!LowPriority && _leafCount > 128) { Parallel.For(0, _leafCount / 2, ind => ProcessInternalLeaf(level + 1, ind, TTH[level][ind * 2], TTH[level][ind * 2 + 1])); leafIndex = _leafCount / 2; } else { for (var i = 1; i < _leafCount; i += 2) { ProcessInternalLeaf(level + 1, leafIndex++, TTH[level][i - 1], TTH[level][i]); } } if (leafIndex < internalLeafCount) { TTH[level + 1][leafIndex] = TTH[level][_leafCount - 1]; } level++; _leafCount = internalLeafCount; } } }
/// <summary> /// Initializes a new instance of the <see cref="TimeoutCommand"/> class. /// </summary> /// <param name="innerCommand">The inner command</param> /// <param name="timeout">Timeout value</param> public TimeoutCommand(TestCommand innerCommand, int timeout) : base(innerCommand) { Guard.ArgumentValid(innerCommand.Test is TestMethod, "TimeoutCommand may only apply to a TestMethod", nameof(innerCommand)); Guard.ArgumentValid(timeout > 0, "Timeout value must be greater than zero", nameof(timeout)); BeforeTest = (context) => { var testThread = Thread.CurrentThread; var nativeThreadId = ThreadUtility.GetCurrentThreadNativeId(); // Create a timer to cancel the current thread _commandTimer = new Timer( (o) => { _commandTimedOut = true; ThreadUtility.Abort(testThread, nativeThreadId); // No join here, since the thread doesn't really terminate }, null, timeout, Timeout.Infinite); }; AfterTest = (context) => { _commandTimer.Dispose(); // If the timer cancelled the current thread, change the result if (_commandTimedOut) { context.CurrentResult.SetResult(ResultState.Failure, string.Format("Test exceeded Timeout value of {0}ms", timeout)); } }; }
public TextEditor[] GetAllTextEditors() { if (ThreadUtility.IsOnUIThread()) { if (Sets.Items == null) { return(new TextEditor[0]); } var editors = new List <TextEditor>(); foreach (SetsViewItem item in Sets.Items) { if (item.Content is TextEditor textEditor) { editors.Add(textEditor); } } return(editors.ToArray()); } else { return(_allTextEditors); } }
public CommonApiTest() { if (_useRedis) { var redisConfiguration = "localhost:6379"; RedisManager.ConfigurationOption = redisConfiguration; CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisObjectCacheStrategy.Instance);//Redis } //全局只需注册一次 AccessTokenContainer.Register(_appId, _appSecret); ////注册小程序 //if (!string.IsNullOrEmpty(_wxOpenAppId)) //{ // AccessTokenContainer.Register(_wxOpenAppId, _wxOpenSecret); //} ThreadUtility.Register(); //v13.3.0之后,JsApiTicketContainer已经合并入AccessTokenContainer,已经不需要单独注册 ////全局只需注册一次 //JsApiTicketContainer.Register(_appId, _appSecret); }
void QuickLockingMechanism() { var quickIterations = 0; var frequency = 1024; while (ThreadUtility.VolatileRead(ref _interlock) != 1 && quickIterations < 4096) { ThreadUtility.Wait(ref quickIterations, frequency); if (ThreadUtility.VolatileRead(ref _flushingOperation.kill) == true) { return; } } if (_interlock == 0 && ThreadUtility.VolatileRead(ref _flushingOperation.kill) == false) { RelaxedLockingMechanism(); } else { _interlock = 0; } }
public void Signal() { ThreadUtility.VolatileWrite(ref _signal, true); }
/// <summary> /// 激活微信缓存 /// </summary> private void RegisterWeixinThreads() { ThreadUtility.Register(); }
internal void RunCoroutineFiber() { #if ENABLE_PLATFORM_PROFILER var platformProfiler = new Common.PlatformProfilerMT(); using (platformProfiler.Sample(name)) #endif { while (_breakThread == false) { ThreadUtility.MemoryBarrier(); if (newTaskRoutines.Count > 0 && false == waitForFlush) //don't start anything while flushing { newTaskRoutines.DequeueAllInto(_coroutines); } var coroutines = _coroutines.ToArrayFast(); for (var index = 0; index < _coroutines.Count && false == ThreadUtility.VolatileRead(ref _breakThread); ++index) { bool result; #if ENABLE_PLATFORM_PROFILER using (platformProfiler.Sample(coroutines[index].ToString())) #endif { if (waitForFlush) { coroutines[index].Stop(); } #if TASKS_PROFILER_ENABLED result = Profiler.TaskProfiler.MonitorUpdateDuration(coroutines[index], name); #else result = coroutines[index].MoveNext(); #endif if (result == false) { _coroutines.UnorderedRemoveAt(index--); } } } if (ThreadUtility.VolatileRead(ref _breakThread) == false) { if (_intervalInTicks > 0 && waitForFlush == false) { WaitForInterval(); } if (_coroutines.Count == 0) { waitForFlush = false; if (newTaskRoutines.Count == 0 || isPaused == true) { _lockingMechanism(); } ThreadUtility.MemoryBarrier(); } else { if (_isRunningTightTasks) { ThreadUtility.Wait(ref _yieldingCount, 16); } } } } if (_onThreadKilled != null) { _onThreadKilled(); } if (_mevent != null) { _mevent.Dispose(); _mevent = null; ThreadUtility.MemoryBarrier(); } } }
/// <summary> /// Abort Async thread. /// </summary> /// <param name="guid">Guid of async thread.</param> public static void AbortAsync(string guid) { ThreadUtility.AbortAsync(guid); }
public void Signal() { _signal = true; ThreadUtility.MemoryBarrier(); }
internal void RunCoroutineFiber() { using (var platformProfiler = new Svelto.Common.PlatformProfilerMT(_name)) { while (_breakThread == false) { ThreadUtility.MemoryBarrier(); if (_newTaskRoutines.Count > 0 && false == _waitForFlush) //don't start anything while flushing { _newTaskRoutines.DequeueAllInto(_coroutines); } for (var i = 0; i < _coroutines.Count && false == _breakThread; i++) { var enumerator = _coroutines[i]; #if TASKS_PROFILER_ENABLED bool result = Profiler.TaskProfiler.MonitorUpdateDuration(enumerator, _name); #else bool result; using (platformProfiler.Sample(enumerator.ToString())) { result = enumerator.MoveNext(); } #endif if (result == false) { var disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } _coroutines.UnorderedRemoveAt(i--); } } if (_breakThread == false) { if (_interval > 0 && _waitForFlush == false) { WaitForInterval(); } if (_coroutines.Count == 0) { _waitForFlush = false; if (_newTaskRoutines.Count == 0) { _isAlive = false; if (_relaxed) { RelaxedLockingMechanism(); } else { QuickLockingMechanism(); } } ThreadUtility.MemoryBarrier(); } else { if (_isRunningTightTasks) { ThreadUtility.Yield(); } } } } if (_onThreadKilled != null) { _onThreadKilled(); } if (_mevent != null) { _mevent.Dispose(); _mevent = null; ThreadUtility.MemoryBarrier(); } } }
bool BIT(byte bitmask) { return((ThreadUtility.VolatileRead(ref _value) & bitmask) == bitmask); }
void UNSETBIT(int bitmask) { ThreadUtility.VolatileWrite(ref _value, (byte)(_value & ~bitmask)); }
void SETBIT(byte bitmask) { ThreadUtility.VolatileWrite(ref _value, (byte)(_value | bitmask)); }
/// <summary> /// Migrate a scene /// </summary> /// <param name="scenePath">The scene file to migrate</param> public void MigrateScene(string scenePath = null, string rootPath = null) { try { if (scenePath == null) { ThreadUtility.RunWaitMainTask(() => { scenePath = EditorUtility.OpenFilePanel("Scene to import", constants.RootDirectory, "unity"); }); if (scenePath.Length == 0) { Debug.LogWarning("No path was selected"); return; } } if (rootPath == null) { rootPath = constants.RootDirectory; } Debug.Log("Started migration of scene: " + scenePath); if (BinaryUtility.IsBinaryFile(scenePath)) { Debug.LogError("Could not parse file, since it's a binary file. Scene file: " + scenePath); return; } string IDPath = ProjectPathUtility.getProjectPathFromFile(scenePath) + constants.RelativeExportPath; if (!File.Exists(IDPath)) { ThreadUtility.RunWaitMainTask(() => { EditorUtility.DisplayDialog("Could not find old ID's", "Could not find the ID's of the original project. File does not exist : \r\n" + IDPath, "Ok"); }); return; } List <ClassModel> oldIDs = Administration.Instance.oldIDsOverride ?? IDController.DeserializeIDs(IDPath); string newIDsPath = rootPath + constants.RelativeExportPath; List <ClassModel> newIDs; if (Administration.Instance.newIDsOverride == null) { newIDs = File.Exists(newIDsPath) ? IDController.DeserializeIDs(newIDsPath) : idController.ExportClassData(rootPath); } else { newIDs = Administration.Instance.newIDsOverride; } List <ScriptMapping> scriptMappings = new List <ScriptMapping>(); string scriptMappingsPath = rootPath + constants.RelativeScriptMappingPath; if (Administration.Instance.ScriptMappingsOverride != null) { scriptMappings = Administration.Instance.ScriptMappingsOverride; } else if (File.Exists(scriptMappingsPath)) { scriptMappings = MappingController.DeserializeMapping(scriptMappingsPath); } this.MigrateSceneIDs(rootPath, oldIDs, newIDs, scenePath, scriptMappings); Debug.Log("Migrated scene : " + scenePath); } catch (Exception e) { Debug.LogError("Could not migrate scene: " + scenePath + "\r\nException: " + e); } }
/// <summary> /// Parse the prefab. /// Change the guid's and fileID's on scripts and port the fields /// </summary> /// <param name="prefabFile"></param> /// <param name="originalAssetPath"></param> /// <param name="destinationAssetPath"></param> /// <param name="prefabs"></param> /// <param name="prefabGuid"></param> /// <exception cref="FormatException"></exception> /// <exception cref="NullReferenceException"></exception> public List <ScriptMapping> MigratePrefab(string prefabFile, string originalAssetPath, string destinationAssetPath, List <PrefabModel> prefabs, string prefabGuid, List <ScriptMapping> scriptMappings) { try { if (!prefabFile.EndsWith(".prefab")) { throw new FormatException("Could not parse prefab, not of type prefab, file : " + prefabFile); } Debug.Log("Started migration of prefab: " + prefabFile); if (BinaryUtility.IsBinaryFile(prefabFile)) { Debug.LogError("Could not parse file, since it's a binary file. Prefab file: " + prefabFile); return(scriptMappings); } PrefabModel currentPrefab = prefabs.FirstOrDefault(prefab => prefab.Guid == prefabGuid); if (currentPrefab == null) { Debug.LogError( "Could not find reference to the prefab with the guid. Might be a model file. Prefab: " + prefabFile); return(scriptMappings); } string originalProjectPath = ProjectPathUtility.getProjectPathFromFile(prefabFile); //Deserialize the old ID's List <ClassModel> oldIDs = Administration.Instance.oldIDsOverride ?? IDController.DeserializeIDs(originalProjectPath + constants.RelativeExportPath); if (oldIDs == null) { throw new NullReferenceException("Old IDs not set"); } //Deserialize the new ID's List <ClassModel> newIDs = Administration.Instance.newIDsOverride ?? IDController.DeserializeIDs(destinationAssetPath + constants.RelativeExportPath); if (newIDs == null) { throw new NullReferenceException("New IDs not set"); } string[] parsedPrefab = idController.TransformIDs(currentPrefab.Path, oldIDs, newIDs, ref scriptMappings); var unmappedScriptMappings = scriptMappings .Where(script => script.HasBeenMapped == ScriptMapping.MappedState.NotMapped).ToList(); if (unmappedScriptMappings.Count == 0) { parsedPrefab = fieldMappingController.MigrateFields(prefabFile, ref parsedPrefab, ref scriptMappings, originalAssetPath, destinationAssetPath); SavePrefabFile(parsedPrefab, currentPrefab, destinationAssetPath); } else { bool completed = false; ThreadUtility.RunMainTask(() => { MergeWizard wizard = MergeWizard.CreateWizard(unmappedScriptMappings); wizard.onComplete = mergedScriptMappings => { scriptMappings = scriptMappings.Merge(mergedScriptMappings); File.WriteAllText(destinationAssetPath + constants.RelativeScriptMappingPath, JsonConvert.SerializeObject(scriptMappings, constants.IndentJson)); ThreadUtility.RunTask(() => { parsedPrefab = fieldMappingController.MigrateFields(prefabFile, ref parsedPrefab, ref scriptMappings, originalAssetPath, destinationAssetPath); SavePrefabFile(parsedPrefab, currentPrefab, destinationAssetPath); }); completed = true; }; }); while (!completed) { Thread.Sleep(constants.THREAD_WAIT_TIME); } } } catch (Exception e) { Debug.LogError("Could not parse prefab: " + prefabFile + "\r\nException: " + e); } return(scriptMappings); }
public void Reset() { _completed = false; ThreadUtility.MemoryBarrier(); }
public void Reset() { _signal = false; _return = null; ThreadUtility.MemoryBarrier(); }
public bool MoveNext() { ThreadUtility.MemoryBarrier(); return(!_signal); }
public void Signal(object obj) { _signal = true; _return = obj; ThreadUtility.MemoryBarrier(); }
public NotepadsMainPage() { InitializeComponent(); _defaultNewFileName = _resourceLoader.GetString("TextEditor_DefaultNewFileName"); NotificationCenter.Instance.SetNotificationDelegate(this); // Setup theme ThemeSettingsService.SetRequestedTheme(RootGrid, Window.Current.Content, ApplicationView.GetForCurrentView().TitleBar, Application.Current.RequestedTheme); ThemeSettingsService.OnBackgroundChanged += ThemeSettingsService_OnBackgroundChanged; ThemeSettingsService.OnThemeChanged += ThemeSettingsService_OnThemeChanged; ThemeSettingsService.OnAccentColorChanged += ThemeSettingsService_OnAccentColorChanged; // Setup custom Title Bar Window.Current.SetTitleBar(AppTitleBar); // Setup status bar ShowHideStatusBar(EditorSettingsService.ShowStatusBar); EditorSettingsService.OnStatusBarVisibilityChanged += async(sender, visibility) => { await ThreadUtility.CallOnUIThreadAsync(Dispatcher, () => { if (ApplicationView.GetForCurrentView().ViewMode != ApplicationViewMode.CompactOverlay) { ShowHideStatusBar(visibility); } }); }; // Session backup and restore toggle EditorSettingsService.OnSessionBackupAndRestoreOptionChanged += async(sender, isSessionBackupAndRestoreEnabled) => { await ThreadUtility.CallOnUIThreadAsync(Dispatcher, async() => { if (isSessionBackupAndRestoreEnabled) { SessionManager.IsBackupEnabled = true; SessionManager.StartSessionBackup(startImmediately: true); } else { SessionManager.IsBackupEnabled = false; SessionManager.StopSessionBackup(); await SessionManager.ClearSessionDataAsync(); } }); }; // Sharing Windows.ApplicationModel.DataTransfer.DataTransferManager.GetForCurrentView().DataRequested += MainPage_DataRequested; Windows.UI.Core.Preview.SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += MainPage_CloseRequested; if (App.IsGameBarWidget) { TitleBarReservedArea.Width = .0f; } else { Window.Current.SizeChanged += WindowSizeChanged; Window.Current.VisibilityChanged += WindowVisibilityChangedEventHandler; } InitControls(); // Init shortcuts _keyboardCommandHandler = GetKeyboardCommandHandler(); //Register for printing if (!PrintManager.IsSupported()) { MenuPrintButton.Visibility = Visibility.Collapsed; MenuPrintAllButton.Visibility = Visibility.Collapsed; MenuPrintSeparator.Visibility = Visibility.Collapsed; } else { PrintArgs.RegisterForPrinting(this); } }
/// <summary> /// 注册 Threads 的方法(如果不注册此线程,则AccessToken、JsTicket等都无法使用SDK自动储存和管理) /// </summary> /// <param name="registerService">RegisterService</param> /// <returns></returns> public static IRegisterService RegisterThreads(this IRegisterService registerService) { ThreadUtility.Register();//如果不注册此线程,则AccessToken、JsTicket等都无法使用SDK自动储存和管理。 return(registerService); }
private async void ThemeSettingsService_OnAccentColorChanged(object sender, Color color) { await ThreadUtility.CallOnUIThreadAsync(Dispatcher, ThemeSettingsService.SetRequestedAccentColor); }
/// <summary> /// 出牌 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo) { if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID))) { session.Logger.Debug("ChuPai : 非法连接"); session.Close(); return; } var returnmsg = ReturnMsg.CreateBuilder(); var PGH = ReturnAll.CreateBuilder(); var chu = SendCP.ParseFrom(requestInfo.Body); mjuser thisuser = Gongyong.mulist.Find(u => u.RoomID == chu.Roomid && u.Openid == chu.Openid); if (thisuser == null) { return; } if (thisuser.ByteData == requestInfo.Key) { return; } else { thisuser.ByteData = requestInfo.Key; } model.ServerMaJiang mj = new model.ServerMaJiang(); Room r = Gongyong.roomlist.Find(u => u.RoomID == chu.Roomid); if (r.room_peo != 4) { if (Gongyong.mulist.Any(w => w.RoomID == chu.Roomid && w.QYM == 0)) { thisuser.ByteData = string.Empty; session.Logger.Debug("牌桌玩家没有全部定缺"); return; } } if (r.DQcz != "3001") { session.Logger.Debug("当前操作不是出牌 当前操作为:" + r.DQcz); thisuser.ByteData = string.Empty; return; } mj = thisuser.majiangs.Find(u => u.PaiHs == chu.Mj.PaiHS && u.PaiId == chu.Mj.PaiID); //mj.PaiHs = chu.Mj.PaiHS; //mj.PaiId = chu.Mj.PaiID; if (r.DQHY != thisuser.ZS_Fw) { thisuser.ByteData = string.Empty; session.Logger.Debug("不是活跃用户"); return; } if (mj == null) { thisuser.ByteData = string.Empty; session.Logger.Debug("用户不存在"); return; } if (thisuser.Is_baotin || thisuser.Is_tiant)//报听天听用户必须摸牌打牌。不能换牌 { if (r.LastMoMJ != null && (chu.Mj.PaiHS != r.LastMoMJ.PaiHs || chu.Mj.PaiID != r.LastMoMJ.PaiId)) { session.Logger.Debug("出牌不是摸到的"); thisuser.ByteData = string.Empty; return; } } ThreadUtility.RemoveManagedThread(thisuser.Openid);//当用户操作时 取消用户的倒计时 r.LastChuMJ = mj; thisuser.SendData.Clear(); thisuser.majiangs.Remove(mj); List <model.ServerMaJiang> listmjs = new List <model.ServerMaJiang>(); listmjs.AddRange(thisuser.majiangs.ToArray()); //StringBuilder paidui = new StringBuilder(); //foreach (var item in r.RoomPai) //{ // paidui.Append(item.PaiHs + ","); //} //session.Logger.Error("出牌堆" + paidui); string is_paixin = new Ting().GetTing(listmjs); thisuser.majiangs.Sort((a, b) => - b.PaiHs.CompareTo(a.PaiHs)); r.DQcz = ""; int hStart = 0;//胡牌的数量? int hzs_fw = 0; GetPaiXin(is_paixin, thisuser); int index = 0; List <mjuser> mjuserss = Gongyong.mulist.FindAll(u => u.RoomID == chu.Roomid); session.Logger.Debug("判断放炮"); List <HuInfo> huList = new List <HuInfo>();//处理一炮多响新增一个胡牌类型对象 ///判断各种放炮 foreach (var item in mjuserss) { HuInfo huInfo = new HuInfo(); int Qcount = 0; if (r.room_peo < 4) { switch (item.QYM) { case 1: if (chu.Mj.PaiHS < 10) { Qcount++; } break; case 2: if (chu.Mj.PaiHS > 10 && chu.Mj.PaiHS < 20) { Qcount++; } break; case 3: if (chu.Mj.PaiHS > 20) { Qcount++; } break; default: break; } } if (Qcount == 0) { if (item.ZS_Fw != thisuser.ZS_Fw) { List <model.ServerMaJiang> listgett = new List <model.ServerMaJiang>(); List <model.ServerMaJiang> listnew = new List <model.ServerMaJiang>(); listgett.AddRange(item.majiangs.ToArray()); listnew.AddRange(item.majiangs.ToArray()); string hxx = new Ting().GetTing(listnew); model.ServerMaJiang mjh = new model.ServerMaJiang() { PaiHs = chu.Mj.PaiHS, PaiId = chu.Mj.PaiID }; listgett.Add(mjh); GetPaiXin(hxx, item); if (thisuser.Mtype == 1) { if (new Ting().GetTing(listgett) == "H") { hStart++; index++; hzs_fw = item.ZS_Fw; r.DQHY = item.ZS_Fw; session.Logger.Debug("热炮"); huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 4; huInfo.MJ = mjh; huInfo.OpenID = item.Openid; huInfo.PaoIndex = thisuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); r.DQHY = item.ZS_Fw; r.DQcz = "30080"; #region 旧热炮 //var sendh = SendHu.CreateBuilder(); //sendh.SetFWZ(item.ZS_Fw); //sendh.SetFWB(thisuser.ZS_Fw); //sendh.SetType(4); //sendh.SetMJ(chu.Mj); //sendh.SetOpenid(thisuser.Openid); //sendh.SetRoomid(r.RoomID); //byte[] rbyte = sendh.Build().ToByteArray(); // r.DQHY = item.ZS_Fw; // Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5016, rbyte.Length, requestInfo.MessageNum, rbyte))); //int messageNum = (GameInformationBase.BASEAGREEMENTNUMBER + 5016); //热炮必胡,所以需要服务器自己返回胡牌的信息。 //new GetH().ExecuteCommand(Gongyong.userlist.Find(u => u.openid == item.Openid).session, // new ProtobufRequestInfo { Body = rbyte, Key = messageNum.ToString(), Messagelength = rbyte.Length, MessageNum = messageNum, MessageResNum = 0 }); // session.Logger.Debug("热炮"); //returnmsg.SetMj(chu.Mj); //returnmsg.SetFW(thisuser.ZS_Fw); //byte[] ball = returnmsg.Build().ToByteArray(); //foreach (var newitems in mjuserss) //{ // UserInfo user = Gongyong.userlist.Find(u => u.openid == newitems.Openid); // user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3009, ball.Length, requestInfo.MessageNum, ball))); //} //return; #endregion } } else if ((item.Is_baotin || item.Is_tiant) && !item.IsGuoHu) { if (new Ting().GetTing(listgett) == "H") { hStart++; index++; hzs_fw = item.ZS_Fw; huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 2; huInfo.MJ = mjh; huInfo.OpenID = item.Openid; huInfo.PaoIndex = thisuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); //var sendh = ReturnHByType.CreateBuilder(); //sendh.SetFWZ(item.ZS_Fw); //sendh.SetFWB(thisuser.ZS_Fw); //sendh.SetType(2); //sendh.SetMJ(chu.Mj); //byte[] rbyte = sendh.Build().ToByteArray(); //r.DQHY = item.ZS_Fw; //Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, rbyte.Length, requestInfo.MessageNum, rbyte))); r.DQHY = item.ZS_Fw; r.DQcz = "30080"; session.Logger.Debug("报听放炮"); } } #region 旧代码 //} //if (item.ZS_Fw != thisuser.ZS_Fw) //{ //if ((hxx == "QD" || hxx == "DD" || hxx == "DDDD" || hxx == "LQD")&& !item.IsGuoHu) //{ // if (item.ZS_Fw != thisuser.ZS_Fw) // { // if (new Ting().GetTing(listgett) == "H") // { // hStart++; // index++; // hzs_fw = item.ZS_Fw; // var sendh = ReturnHByType.CreateBuilder(); // //sendh.SetFWZ(item.ZS_Fw); // //sendh.SetFWB(thisuser.ZS_Fw); // //sendh.SetType(2); // //sendh.SetMJ(chu.Mj); // //r.DQHY = item.ZS_Fw; // //byte[] rbyte = sendh.Build().ToByteArray(); // //Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, rbyte.Length, requestInfo.MessageNum, rbyte))); // huInfo.HuIndex = item.ZS_Fw; // huInfo.HuType =2; // huInfo.MJ = mjh; // huInfo.OpenID = item.Openid; // huInfo.PaoIndex = thisuser.ZS_Fw; // huInfo.RoomID = r.RoomID; // huList.Add(huInfo); // session.Logger.Debug("大牌"+ hxx+"牌"+ chu.Mj.PaiHS); // } // } //} //} //if (item.ZS_Fw #endregion != thisuser.ZS_Fw) //{ else if ((!string.IsNullOrEmpty(item.Gong)) && !item.IsGuoHu) { if (new Ting().GetTing(listgett) == "H") { hStart++; index++; hzs_fw = item.ZS_Fw; var sendh = ReturnHByType.CreateBuilder(); //sendh.SetFWZ(item.ZS_Fw); //sendh.SetFWB(thisuser.ZS_Fw); //sendh.SetType(2); //sendh.SetMJ(chu.Mj); //r.DQHY = item.ZS_Fw; //byte[] rbyte = sendh.Build().ToByteArray(); //Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, rbyte.Length, requestInfo.MessageNum, rbyte))); huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 2; huInfo.MJ = mjh; huInfo.OpenID = item.Openid; huInfo.PaoIndex = thisuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); r.DQHY = item.ZS_Fw; r.DQcz = "30080"; session.Logger.Debug("有杠" + hxx + "牌" + chu.Mj.PaiHS); } } //} //if (item.ZS_Fw != thisuser.ZS_Fw) //{ else if ((item.paixinfs != 5 && item.paixinfs != 0) && !item.IsGuoHu) { var newlist = new List <model.ServerMaJiang>(); newlist.AddRange(listgett); Ting t = new Ting(); if (t.GetTing(listgett) == "H") { hxx = t.GetHPaiPaiXin(newlist, item.Peng.GroupBy(w => w.PaiHs).Count(), string.IsNullOrEmpty(item.Gong) ? 0 : item.Gong.Split(',').Length, chu.Mj.PaiHS); t.GetPaiXin(hxx, item); if (item.paixinfs != 5 && item.paixinfs != 0) { hStart++; index++; hzs_fw = item.ZS_Fw; huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 2; huInfo.MJ = mjh; huInfo.OpenID = item.Openid; huInfo.PaoIndex = thisuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); r.DQHY = item.ZS_Fw; r.DQcz = "30080"; session.Logger.Debug("胡牌" + hxx + "牌" + chu.Mj.PaiHS); } } } if (huList.Count == 0 || huList[0].HuType != 4)//热炮不能有碰 { //} //if (item.ZS_Fw != thisuser.ZS_Fw) //{ UserInfo userp = Gongyong.userlist.Find(u => u.openid == item.Openid); List <model.ServerMaJiang> UmjList = item.majiangs.FindAll(u => u.PaiHs == mj.PaiHs); if (item.Is_tiant || item.Is_baotin)//天听或者报听 不能有碰杠牌 { } else { if (UmjList.Count >= 2) { index++; PGH.SetPeng(1); PGH.SetFw(thisuser.ZS_Fw); PGH.SetMj(chu.Mj); byte[] xia = PGH.Build().ToByteArray(); if (huList.Count > 0 && hzs_fw != item.ZS_Fw) { RoomMsgWirte msgri = new RoomMsgWirte() { openid = item.Openid, xiaoxihao = 3008, ArrList = xia, roomid = r.RoomID, operating = "30081" + "," + thisuser.ZS_Fw }; Gongyong.roommsg.Add(msgri); } else { item.SendData.Add(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); r.DQHY = item.ZS_Fw; r.DQcz = "30081" + "," + thisuser.ZS_Fw; r.PaiHSCZ = mj; userp.session.TrySend(item.SendData); session.Logger.Debug("方位------" + item.ZS_Fw + "--碰--" + chu.Mj.PaiHS); } } if (UmjList.Count == 3) { index++; var returngang = GangMSG.CreateBuilder(); returngang.SetFw(thisuser.ZS_Fw); returngang.SetMj(chu.Mj); returngang.SetType(1); byte[] xia = ReturnGang.CreateBuilder().AddGang(returngang).Build().ToByteArray(); if (huList.Count > 0 && hzs_fw != item.ZS_Fw) { RoomMsgWirte msgri = new RoomMsgWirte() { ArrList = xia, xiaoxihao = 5022, openid = item.Openid, roomid = r.RoomID, operating = "30082,1" + "," + thisuser.ZS_Fw }; Gongyong.roommsg.Add(msgri); } else { item.SendData.Add(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5022, xia.Length, requestInfo.MessageNum, xia))); r.DQHY = item.ZS_Fw; r.DQcz = "30082,1" + "," + thisuser.ZS_Fw; r.PaiHSCZ = mj; userp.session.TrySend(item.SendData); session.Logger.Debug("方位------" + item.ZS_Fw + "--杠--" + chu.Mj.PaiHS); } } } } } } } if (huList.Count > 0) { r.Is_Hu = true; session.Logger.Debug(huList); if (huList.Count > 1 || huList[0].HuType == 4) { var sendh = SendHu.CreateBuilder(); foreach (var item in huList) { if (!sendh.HasFWZ) { sendh.SetFWZ(item.HuIndex); } if (!sendh.HasFWB) { sendh.SetFWB(item.PaoIndex); } sendh.SetType(item.HuType); sendh.SetMJ(chu.Mj); if (!sendh.HasOpenid) { sendh.SetOpenid(item.OpenID); } if (!sendh.HasRoomid) { sendh.SetRoomid(r.RoomID); } sendh.AddDXInfo(DuoXiangHu.CreateBuilder().SetDXFW(item.HuIndex).SetDXType(item.HuType)); } byte[] rbyte = sendh.Build().ToByteArray(); //Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5016, rbyte.Length, requestInfo.MessageNum, rbyte))); int messageNum = (GameInformationBase.BASEAGREEMENTNUMBER + 5016); //热炮必胡,所以需要服务器自己返回胡牌的信息。 new GetH().ExecuteCommand(Gongyong.userlist.Find(u => u.openid == huList[0].OpenID).session, new ProtobufRequestInfo { Body = rbyte, Key = messageNum.ToString(), Messagelength = rbyte.Length, MessageNum = messageNum, MessageResNum = 0 }); return; } else { var sendh = ReturnHByType.CreateBuilder(); sendh.SetFWZ(huList[0].HuIndex); sendh.SetFWB(huList[0].PaoIndex); sendh.SetType(huList[0].HuType); sendh.SetMJ(chu.Mj); r.DQHY = huList[0].HuIndex; byte[] rbyte = sendh.Build().ToByteArray(); var sendData = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, rbyte.Length, requestInfo.MessageNum, rbyte)); mjuserss.Find(w => w.Openid.Equals(huList[0].OpenID)).SendData.Add(sendData); Gongyong.userlist.Find(u => u.openid == huList[0].OpenID).session.TrySend(sendData); } } else { r.Is_Hu = false; } thisuser.chuda.Add(mj); thisuser.Mtype = 0;//不将自己的摸牌类型修改 会导致碰牌后的出牌也被判断成热炮 ///下发出的牌 if (index > 0) { returnmsg.SetMj(chu.Mj); returnmsg.SetFW(thisuser.ZS_Fw); byte[] ball = returnmsg.Build().ToByteArray(); foreach (var newitems in mjuserss) { UserInfo user = Gongyong.userlist.Find(u => u.openid == newitems.Openid); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3009, ball.Length, requestInfo.MessageNum, ball))); } //牌局回放 r.gameOperationProcess.AddGameOperationInfo( GameOperationInfo.CreateBuilder() .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(thisuser.ZS_Fw) .SetOperationType(2) .AddMJ(chu.Mj) ); } ///下发冲锋鸡消息 if (index == 0) { if (mj.PaiHs == 8 && r.is_wgj) { int wgjc = 0; foreach (var item in mjuserss) { int Pcount = item.Peng.FindAll(u => u.PaiHs == 8).Count; int Ccount = item.chuda.FindAll(u => u.PaiHs == 8).Count; if (item.ZS_Fw == thisuser.ZS_Fw) { Ccount = Ccount - 1; } if (!string.IsNullOrEmpty(item.Gong)) { item.Gong.Remove(item.Gong.Length - 1, 1); string[] G = item.Gong.Split(','); foreach (var items in G) { string[] GOne = items.Split('|'); if (GOne[0] == "8") { wgjc++; } } } if (Pcount > 0 || Ccount > 0) { wgjc++; } } if (wgjc == 0) { thisuser.is_cfwg = true; returnmsg.SetMsg("CFWG"); } else { returnmsg.SetMsg(""); } } if (mj.PaiHs == 11) { int cfjc = 0; foreach (var item in mjuserss) { int Pcount = item.Peng.FindAll(u => u.PaiHs == 11).Count; int Ccount = item.chuda.FindAll(u => u.PaiHs == 11).Count; if (item.ZS_Fw == thisuser.ZS_Fw) { Ccount = Ccount - 1; } if (!string.IsNullOrEmpty(item.Gong)) { item.Gong.Remove(item.Gong.Length - 1, 1); string[] G = item.Gong.Split(','); foreach (var items in G) { string[] GOne = items.Split('|'); if (GOne[0] == "11") { cfjc++; } } } if (Pcount > 0 || Ccount > 0) { cfjc++; } } if (cfjc == 0) { thisuser.Is_cfj = true; returnmsg.SetMsg("CFJ"); } else { returnmsg.SetMsg(""); } } returnmsg.SetMj(chu.Mj); returnmsg.SetFW(thisuser.ZS_Fw); byte[] ball = returnmsg.Build().ToByteArray(); var paiCount = ReturnPaiCount.CreateBuilder(); if (r.RoomPai.Count == 108) { switch (r.room_peo) { case 2: if (r.RoomPai.Count == 108) { paiCount.SetPaiCount(81); } break; case 3: if (r.RoomPai.Count == 108) { paiCount.SetPaiCount(68); } break; case 4: if (r.RoomPai.Count == 108) { paiCount.SetPaiCount(55); } break; default: break; } } else { paiCount.SetPaiCount(r.RoomPai.Count); } byte[] returnPaiCount = paiCount.Build().ToByteArray(); var sby = ReturnHyUser.CreateBuilder(); foreach (var items in mjuserss) { UserInfo user = Gongyong.userlist.Find(u => u.openid == items.Openid); bool is_send = user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3009, ball.Length, requestInfo.MessageNum, ball))); PGH.SetMo(1); // user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7006, returnPaiCount.Length, requestInfo.MessageNum, returnPaiCount))); //if (is_send) //{ // session.Logger.Debug("方位------" + items.ZS_Fw + "--发送成功-- 3009"); //} //else //{ // session.Logger.Debug("方位------" + items.ZS_Fw + "--发送失败-- 3009"); //} session.Logger.Debug("方位------" + items.ZS_Fw + "--发送-- 3009" + "牌" + chu.Mj.PaiHS); if (thisuser.ZS_Fw == r.room_peo) { if (items.ZS_Fw == 1) { PGH.SetFw(items.ZS_Fw); items.Mtype = 0; byte[] xia = PGH.Build().ToByteArray(); items.SendData.Add(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); user.session.TrySend(items.SendData); r.DQHY = items.ZS_Fw; r.DQcz = "30083"; session.Logger.Debug("方位------" + items.ZS_Fw + "--摸牌--"); } } else { if (items.ZS_Fw == thisuser.ZS_Fw + 1) { PGH.SetFw(items.ZS_Fw); items.Mtype = 0; byte[] xia = PGH.Build().ToByteArray(); items.SendData.Add(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); user.session.TrySend(items.SendData); r.DQHY = items.ZS_Fw; r.DQcz = "30083"; session.Logger.Debug("方位------" + items.ZS_Fw + "--摸牌-- "); } } #region 旧摸牌 /* if (thisuser.ZS_Fw == 4) * { * if (items.ZS_Fw == 1) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * } * } * else * { * if (hStart == 0) * { * if (r.room_peo == 2) * { * if (thisuser.ZS_Fw == 2 || items.ZS_Fw - 1 == thisuser.ZS_Fw) * { * * if (items.ZS_Fw != thisuser.ZS_Fw) * { * PGH.SetFw(items.ZS_Fw); * items.Mtype = 0; * byte[] xia = PGH.Build().ToByteArray(); * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * session.Logger.Debug("方位------" + thisuser.ZS_Fw + "--出--" + chu.Mj.PaiHS); * } * * } * } * else if (r.room_peo == 3) * { * if (thisuser.ZS_Fw == 3) * { * if (items.ZS_Fw == 1) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * items.Mtype = 0; * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * } * } * else * { * if (items.ZS_Fw - 1 == thisuser.ZS_Fw) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * items.Mtype = 0; * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * } * } * } * else * { * if (thisuser.ZS_Fw == 4) * { * if (items.ZS_Fw == 1) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * items.Mtype = 0; * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * } * } * else * { * if (items.ZS_Fw - 1 == thisuser.ZS_Fw) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * items.Mtype = 0; * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * } * } * } * } * } */ #endregion } //牌局回放 出牌 r.gameOperationProcess.AddGameOperationInfo( GameOperationInfo.CreateBuilder() .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(thisuser.ZS_Fw) .SetOperationType(2) .AddMJ(chu.Mj) .SetMJType(returnmsg.Msg) ); // Thread.Sleep(100); sby.SetFw(r.DQHY); sby.SetCz(r.DQcz); byte[] hybyte = sby.Build().ToByteArray(); foreach (var item in mjuserss) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.IsActive = true; user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7004, hybyte.Length, requestInfo.MessageNum, hybyte))); } } ThreadUtility.StartManagedThread(Gongyong.mulist.Find(w => w.ZS_Fw == r.DQHY && w.RoomID == r.RoomID).Openid, r.RoomID, r.DQcz); }
protected override void Because_Of() { _thread = ThreadUtility.CreateThread(new ThreadStart(_testedClass.Initialize), ""); }
/// <summary> /// 激活微信缓存 /// </summary> private void RegisterWeixinThreads() { ThreadUtility.Register();//如果不注册此线程,则AccessToken、JsTicket等都无法使用SDK自动储存和管理。 }
protected override void Because_Of() { _thread = ThreadUtility.CreateThread(_testedClass.Dispose); }
public void Signal(object obj) { _return = obj; ThreadUtility.VolatileWrite(ref _signal, true); }
protected override void Because_Of() { _thread = ThreadUtility.CreateThread(testedClass.Poll, "Poll Thread"); }