/// <summary> /// Get application routing information. /// </summary> /// <returns>RbAppRouterCache</returns> private RbAppRouterCache GetAppRoutingInfo(RbHeader rbh) { AppRouter ar = null; bool ar_action = true; string cachekey = rbh.AppId + "_" + rbh.AppProcessingId; RbAppRouterCache rbapprc = null; if (rbAppRouterCacheDic.ContainsKey(cachekey)) { rbapprc = (RbAppRouterCache)rbAppRouterCacheDic[cachekey]; if (rbapprc.CacheExpiredDatetime >= DateTime.Now) { ar_action = false; } } if (ar_action) { ar = new AppRouter(rbh.AppId, rbh.AppProcessingId, sqlConnectionString, rbCacheExpiredTimeSec); rbapprc = ar.GetAppRouting(); if (rbapprc != null) { lock (thisLock) { rbAppRouterCacheDic[cachekey] = rbapprc; } } else { throw new ApplicationException("Error ** GetAppRouting() returns Null Object"); } } return(rbapprc); }
public async Task ChineseAppWithDomain() { string appId = "BMYV4RKSTwo8WSqt8q9ezcWF-gzGzoHsz"; string server = "https://bmyv4rks.lc-cn-n1-shared.com"; AppRouterController appRouterController = new AppRouterController(appId, server); AppRouter appRouterState = await appRouterController.Get(); Assert.AreEqual(appRouterState.ApiServer, server); Assert.AreEqual(appRouterState.EngineServer, server); Assert.AreEqual(appRouterState.PushServer, server); Assert.AreEqual(appRouterState.RTMServer, server); Assert.AreEqual(appRouterState.StatsServer, server); Assert.AreEqual(appRouterState.PlayServer, server); }
async Task <LobbyInfo> AuthorizeFromServer() { AppRouter appRouter = await appRouterController.Get(); HttpRequestMessage request = null; HttpResponseMessage response = null; try { Dictionary <string, object> data = new Dictionary <string, object>(); string dataContent = JsonConvert.SerializeObject(data); string url = $"{appRouter.PlayServer}/1/multiplayer/router/authorize"; if (!Uri.IsWellFormedUriString(appRouter.PlayServer, UriKind.Absolute)) { url = $"https://{appRouter.PlayServer}/1/multiplayer/router/authorize"; } request = new HttpRequestMessage { RequestUri = new Uri(url), Method = HttpMethod.Post, Content = new StringContent(dataContent) }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpUtils.PrintRequest(httpClient, request, dataContent); response = await httpClient.SendAsync(request); string content = await response.Content.ReadAsStringAsync(); HttpUtils.PrintResponse(response, content); if (response.StatusCode >= HttpStatusCode.OK && response.StatusCode < HttpStatusCode.Ambiguous) { lobbyInfo = await JsonUtils.DeserializeObjectAsync <LobbyInfo>(content); return(lobbyInfo); } PlayException exception = await JsonUtils.DeserializeObjectAsync <PlayException>(content); throw exception; } finally { if (request != null) { request.Dispose(); } if (response != null) { response.Dispose(); } } }
private void callAppButton_Click(object sender, EventArgs e) { if (textBoxDllFilePath.Text == string.Empty) { MessageBox.Show("** Error ** DLL File Local Path must be set !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (textBoxDeviceId.Text == string.Empty) { MessageBox.Show("** Error ** Device ID must be set !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (checkBoxSkipAppRouter.Checked && textBoxClassName.Text == string.Empty) { MessageBox.Show("** Error ** Class Name must be set !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Save the TextBox content saveTextBoxContent(); JObject jo_message = JsonConvert.DeserializeObject <JObject>(textBoxInput.Text); // Check RbHeader in detail RbHeaderBuilder hdBuilder = new RbHeaderBuilder(jo_message, textBoxDeviceId.Text); RbHeader rbh = hdBuilder.ValidateJsonSchema(); // RbBody JObject jo_temp = (JObject)jo_message[RbFormatType.RbBody]; string rbBodyString = JsonConvert.SerializeObject(jo_temp); // App Master Cache (RBFX.AppMaster) AppMaster am = new AppMaster(rbh.AppId, activeEncPassPhrase, activeSqlConnectionString, constTimeOutSec); RbAppMasterCache rbappmc = am.GetAppMaster(); // App Router Cache (RBFX.AppRouting) RbAppRouterCache rbapprc; if (checkBoxSkipAppRouter.Checked) { rbapprc = new RbAppRouterCache(); rbapprc.AppId = rbh.AppId; rbapprc.AppProcessingId = rbh.AppProcessingId; rbapprc.ClassName = textBoxClassName.Text; rbapprc.FileName = textBoxDllFilePath.Text; } else { AppRouter ar = new AppRouter(rbh.AppId, rbh.AppProcessingId, activeSqlConnectionString, constTimeOutSec); rbapprc = ar.GetAppRouting(); } // Load DLL //Assembly assembly = null; AppDomain appDomain = null; IAppRouterDll routedAppDll = null; try { //assembly = System.Reflection.Assembly.LoadFrom(textBoxDllFilePath.Text); //routedAppDll = assembly.CreateInstance(rbapprc.ClassName) as IAppRouterDll; string pid = Thread.CurrentThread.ManagedThreadId.ToString(); string appDomainName = "AppDomain_P" + pid; string cachedDirectory = Path.GetDirectoryName(textBoxDllFilePath.Text); string cachedFileName = Path.GetFileName(textBoxDllFilePath.Text); string cachedFileNameWithoutExt = Path.GetFileNameWithoutExtension(textBoxDllFilePath.Text); appDomain = createAppDomain(appDomainName, cachedDirectory); routedAppDll = appDomain.CreateInstanceAndUnwrap(cachedFileNameWithoutExt, rbapprc.ClassName) as IAppRouterDll; } catch (Exception ex) { MessageBox.Show("** Application (DLL) Load Error ** Check File Path or Class Name \n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Process Message try { rbh.ProcessingStack = activeFileName; JArrayString ja_messagesString = routedAppDll.ProcessMessage(rbappmc, rbapprc, rbh, rbBodyString); JArray ja_messages = ja_messagesString.ConvertToJArray(); textBoxOutput.Text = JsonConvert.SerializeObject(ja_messages); AppDomain.Unload(appDomain); } catch (Exception ex) { MessageBox.Show("** Error occured in Application (DLL) **\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); AppDomain.Unload(appDomain); return; } }