public static void SendSetDefinesToConsulo(string uuid) { UnityUtil.RunInMainThread(() => { if (!ConsuloIntegration.UseConsulo()) { return; } string projectPath = Path.GetDirectoryName(Application.dataPath); projectPath = projectPath.Replace('\\', '/'); JSONClass result = new JSONClass(); result.Add("projectPath", projectPath); if (uuid != null) { result.Add("uuid", uuid); } JSONArray array = new JSONArray(); foreach (string define in EditorUserBuildSettings.activeScriptCompilationDefines) { array.Add(define); } result.Add("defines", array); ConsuloIntegration.SendToConsulo("unitySetDefines", result); }); }
public void TestOutput(NUnit.Framework.Interfaces.TestOutput output) { JSONClass jsonClass = new JSONClass(); jsonClass.Add("name", "Info"); jsonClass.Add("uuid", myUUID); jsonClass.Add("type", "TestOutput"); jsonClass.Add("message", output.Text); ConsuloIntegration.SendToConsulo("unityTestState", jsonClass); }
public void TestStarted(NUnit.Framework.Interfaces.ITest test) { Debug.Log(test.Name); WebApiServer.ourCurrentTestName = test.Name; JSONClass jsonClass = new JSONClass(); jsonClass.Add("name", test.Name); jsonClass.Add("uuid", myUUID); jsonClass.Add("type", "TestStarted"); ConsuloIntegration.SendToConsulo("unityTestState", jsonClass); }
public void TestFinished(NUnit.Framework.Interfaces.ITestResult result) { JSONClass jsonClass = new JSONClass(); jsonClass.Add("name", result.Name); jsonClass.Add("uuid", myUUID); string typeText; if (result.ResultState == ResultState.Ignored) { typeText = "TestIgnored"; } else if (result.ResultState == ResultState.Success) { typeText = "TestFinished"; } else { typeText = "TestFailed"; } jsonClass.Add("type", typeText); string message = result.Message; if (message != null) { jsonClass.Add("message", message); } string trace = result.StackTrace; if (trace != null) { jsonClass.Add("stackTrace", trace); } jsonClass.Add("time", result.Duration.ToString()); ConsuloIntegration.SendToConsulo("unityTestState", jsonClass); }
private void Process(HttpListenerContext context) { var requestHttpMethod = context.Request.HttpMethod; if ("POST".Equals(requestHttpMethod)) { string pathAndQuery = context.Request.Url.PathAndQuery; context.Response.ContentType = "application/json"; bool resultValue = false; HttpStatusCode code = HttpStatusCode.InternalServerError; JSONClass jsonClass = null; string uuid = null; switch (pathAndQuery) { case "/unityRefresh": jsonClass = ReadJSONClass(context); uuid = jsonClass == null ? null : jsonClass["uuid"].Value; resultValue = uuid != null; if (uuid != null) { UnityUtil.RunInMainThread(() => { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); JSONClass result = new JSONClass(); result.Add("uuid", uuid); ConsuloIntegration.SendToConsulo("unityRefreshResponse", result); }); } code = HttpStatusCode.OK; break; case "/unityRequestDefines": { jsonClass = ReadJSONClass(context); if (jsonClass != null) { resultValue = true; uuid = jsonClass["uuid"].Value; SendSetDefinesToConsulo(uuid); } code = HttpStatusCode.OK; break; } case "/unityOpenScene": jsonClass = ReadJSONClass(context); string fileValue = jsonClass == null ? null : jsonClass["file"].Value; if (fileValue != null) { resultValue = true; UnityUtil.RunInMainThread(() => { EditorApplication.OpenScene(fileValue); EditorUtility.FocusProjectWindow(); }); } code = HttpStatusCode.OK; break; #if NUNIT case "/unityRunTest": jsonClass = ReadJSONClass(context); if (jsonClass != null) { resultValue = true; string type = jsonClass["type"].Value; uuid = jsonClass["uuid"].Value; UnityUtil.RunInMainThread(() => { int undo = Undo.GetCurrentGroup(); RunNUnitTests(type, uuid); Undo.RevertAllDownToGroup(undo); JSONClass result = new JSONClass(); result.Add("uuid", uuid); result.Add("type", "RunFinished"); ConsuloIntegration.SendToConsulo("unityTestState", result); }); } code = HttpStatusCode.OK; break; #endif default: UnityUtil.RunInMainThread(() => { EditorUtility.DisplayDialog(PluginConstants.ourDialogTitle, $"Unknown how handle API url {pathAndQuery}, please update UnityEditor plugin for Consulo", "OK"); }); code = HttpStatusCode.InternalServerError; break; } string text = "{ \"success\":" + resultValue + " }"; context.Response.ContentLength64 = text.Length; context.Response.StatusCode = (int)code; byte[] encodingUTFGetBytes = Encoding.UTF8.GetBytes(text); context.Response.OutputStream.Write(encodingUTFGetBytes, 0, encodingUTFGetBytes.Length); context.Response.OutputStream.Flush(); } else { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; } context.Response.OutputStream.Close(); }
static WebApiServer() { Process currentProcess = Process.GetCurrentProcess(); int unityConsuloPluginPort = 56000 + currentProcess.Id % 1000 + 2000; // 56000 + 2000 HTTPServer httpServer = new HTTPServer(unityConsuloPluginPort); #if ACTION_DEBUG UnityEngine.Debug.Log("Binding port: " + unityConsuloPluginPort); #endif Action action = () => HTTPServer.SendSetDefinesToConsulo(null); UnityUtil.RunInMainThread(() => { AppDomain.CurrentDomain.DomainUnload += (sender, e) => { EditorUserBuildSettings.activeBuildTargetChanged -= action; httpServer.Stop(); }; }); EditorUserBuildSettings.activeBuildTargetChanged += action; Application.RegisterLogCallback((condition, stackTrace, type) => { string testUUID = ourCurrentTestUUID; if (testUUID != null) { JSONClass jsonClass = new JSONClass(); jsonClass.Add("name", ourCurrentTestName); jsonClass.Add("uuid", testUUID); jsonClass.Add("type", "TestOutput"); jsonClass.Add("message", condition); jsonClass.Add("stackTrace", stackTrace); jsonClass.Add("messageType", Enum.GetName(typeof(LogType), type)); ConsuloIntegration.SendToConsulo("unityTestState", jsonClass); } else { JSONClass jsonClass = new JSONClass(); jsonClass.Add("condition", condition); jsonClass.Add("stackTrace", stackTrace); jsonClass.Add("projectPath", Path.GetDirectoryName(Application.dataPath)); jsonClass.Add("type", Enum.GetName(typeof(LogType), type)); ConsuloIntegration.SendToConsulo("unityLog", jsonClass); } }); EditorApplication.playmodeStateChanged += delegate { JSONClass jsonClass = new JSONClass(); jsonClass.Add("isPlaying", new JSONData(EditorApplication.isPlaying)); jsonClass.Add("projectPath", Path.GetDirectoryName(Application.dataPath)); ConsuloIntegration.SendToConsulo("unityPlayState", jsonClass); }; }