private void OnEnable() { // Reference the selected client client = (SimpleClient)target; // Get a reference to the serialized connection property connection = serializedObject.FindProperty("Connection"); // Load configuration data AmqpConfigurationEditor.LoadConfiguration(); // Restore the connection index var connectionNames = AmqpConfigurationEditor.GetConnectionNames(); for (var i = 0; i < connectionNames.Length; i++) { var cName = connectionNames[i]; if (connection.stringValue == cName) { index = i; break; } } lightGreen = CustomGUIUtils.GetColorBackgroundStyle(XKCDColors.LightGreen); lightRed = CustomGUIUtils.GetColorBackgroundStyle(XKCDColors.LightRed); lightYellow = CustomGUIUtils.GetColorBackgroundStyle(XKCDColors.LightYellow); }
private static void RestoreConfigurationIndex() { string[] connectionNames = AmqpConfigurationEditor.GetConnectionNames(); if (client != null) { for (int i = 0; i < connectionNames.Length; i++) { string cName = connectionNames[i]; if (client.Connection == cName) { selectedConfigurationIndex = i; break; } } } }
public override void OnInspectorGUI() { // Update client serializedObject.Update(); this.client.ServerMode = EditorGUILayout.Toggle("Act as Server", this.client.ServerMode); // Generate the connection dropdown options/content #region Dropdown connections var connectionNames = AmqpConfigurationEditor.GetConnectionNames(); var options = new List <GUIContent>(); for (var i = 0; i < connectionNames.Length; i++) { var cName = connectionNames[i]; if (string.IsNullOrEmpty(client.Connection) || client.Connection == cName) { index = i; } options.Add(new GUIContent(cName)); } // Connections drop down string tooltip = "Select the AMQP connection to use. Connections can be configured in the AMQP/Configuration menu."; index = EditorGUILayout.Popup(new GUIContent("Connection", tooltip), index, options.ToArray()); // If the index has changed, record the change if (index != lastIndex) { Undo.RecordObject(target, "Undo Connection change"); } // Set the connection name based on dropdown value client.Connection = connection.stringValue = options[index].text; #endregion // Dropdown connections // Draw the rest of the inspector's default layout //DrawDefaultInspector(); if (GUILayout.Button("Awake")) { this.client.Awake(); this.Repaint(); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("EnableUpdate")) { this.client.EnableUpdate(); this.Repaint(); } if (GUILayout.Button("DisableUpdate")) { this.client.DisableUpdate(); this.Repaint(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Toggle("IsConnecting?", this.client.isConnecting); EditorGUILayout.Toggle("IsConnected?", this.client.IsConnected); EditorGUILayout.Toggle("hasConnected?", this.client.hasConnected); EditorGUILayout.Toggle("isDisconnecting?", this.client.isDisconnecting); EditorGUILayout.Toggle("hasDisconnected?", this.client.hasDisconnected); EditorGUILayout.Toggle("isReconnecting?", this.client.isReconnecting); EditorGUILayout.Toggle("wasBlocked?", this.client.wasBlocked); EditorGUILayout.Toggle("hasAborted?", this.client.hasAborted); EditorGUILayout.Toggle("canSubscribe?", this.client.canSubscribe); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Connect")) { this.client.Connect(); this.Repaint(); } if (GUILayout.Button("Disconnect")) { this.client.Disconnect(); this.Repaint(); } EditorGUILayout.EndHorizontal(); #region Available Queues //if (showAvailableQueues = EditorGUILayout.Foldout(showAvailableQueues, "Available Queues:")) //{ EditorGUILayout.BeginVertical("box"); foreach (var queue in this.client.GetQueues()) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Name:", queue.Name); if (GUILayout.Button("Subscribe", GUILayout.Width(30))) { this.client.SubscribeToQueue(queue.Name); } if (GUILayout.Button("X", GUILayout.Width(30))) { this.client.DeleteQueue(queue.Name); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); //} #endregion Available Queues #region Create Queue EditorGUILayout.BeginHorizontal("box"); this.queueName = EditorGUILayout.TextField("Queue Name", this.queueName); if (GUILayout.Button("Create")) { this.client.DeclareQueue(this.queueName); } EditorGUILayout.EndHorizontal(); #endregion // Create Queue #region Subscribe Queue AmqpQueue[] queues = this.client.GetQueues(); string[] names = new string[queues.Length]; for (int i = 0; i < queues.Length; i++) { names[i] = queues[i].Name; } selectedQueue = EditorGUILayout.Popup("Queue", selectedQueue, names); if (queues.Length != 0) { if (GUILayout.Button("Subscribe to " + names[this.selectedQueue] + " Queue")) { this.client.SubscribeToQueue(names[this.selectedQueue]); } } #endregion // Subscribe Queue if (this.client.ServerMode) { #region JobQueue string[] jobQueueNames = new string[this.client.GetQueues().Length]; for (int i = 0; i < this.client.GetQueues().Length; i++) { jobQueueNames[i] = this.client.GetQueues()[i].Name; } this.jobQueueIndex = EditorGUILayout.Popup("JobQueue", this.jobQueueIndex, jobQueueNames); for (int i = 0; i < jobQueueNames.Length; i++) { if (jobQueueNames[i] == "jobs") { this.jobQueueIndex = i; break; } } string jobQueueName = this.client.GetQueues().Length == 0 ? "not set" : jobQueueNames[this.jobQueueIndex]; //EditorGUILayout.LabelField("JobQueue", jobQueueName); #endregion // JobQueue #region ReplyQueue string[] replyToQueueNames = new string[this.client.GetQueues().Length]; for (int i = 0; i < this.client.GetQueues().Length; i++) { replyToQueueNames[i] = this.client.GetQueues()[i].Name; } this.replyQueueIndex = EditorGUILayout.Popup("ReplyToQueue", this.replyQueueIndex, replyToQueueNames); for (int i = 0; i < replyToQueueNames.Length; i++) { if (replyToQueueNames[i] == "reply") { this.replyQueueIndex = i; break; } } string replyQueueName = this.client.GetQueues().Length == 0 ? "not set" : replyToQueueNames[this.replyQueueIndex]; //EditorGUILayout.LabelField("ReplyToQueue", replyQueueName); #endregion // JobQueue #region JobQueue string[] statusUpdateQueueNames = new string[this.client.GetQueues().Length]; for (int i = 0; i < this.client.GetQueues().Length; i++) { statusUpdateQueueNames[i] = this.client.GetQueues()[i].Name; } this.statusUpdateQueueIndex = EditorGUILayout.Popup("ReplyToQueue", this.statusUpdateQueueIndex, statusUpdateQueueNames); for (int i = 0; i < statusUpdateQueueNames.Length; i++) { if (statusUpdateQueueNames[i] == "statusUpdates") { this.statusUpdateQueueIndex = i; break; } } string statusUpdateQueueName = this.client.GetQueues().Length == 0 ? "not set" : statusUpdateQueueNames[this.statusUpdateQueueIndex]; //EditorGUILayout.LabelField("ReplyToQueue", replyQueueName); #endregion // JobQueue EditorGUILayout.BeginVertical("box"); TileManager.TileWidth = (double)EditorGUILayout.FloatField("TileWidth", (float)TileManager.TileWidth); TileManager.tileRadius = EditorGUILayout.IntField("TileRadius", TileManager.tileRadius); TileManager.LOD = EditorGUILayout.IntField("LOD", TileManager.LOD); TileManager.OriginLatitude = (double)EditorGUILayout.FloatField("OriginLatitude", (float)TileManager.OriginLatitude); TileManager.OriginLongitude = (double)EditorGUILayout.FloatField("OriginLongitude", (float)TileManager.OriginLongitude); EditorGUILayout.EndVertical(); this.client.method = (SerializationMethod)EditorGUILayout.EnumPopup("SerializationMethod", this.client.method); if (GUILayout.Button("Send OSM-Job-Messages")) { this.client.SendOSMJobMessages( jobQueueName, replyQueueName, statusUpdateQueueName, TileManager.tileRadius, TileManager.TileWidth, TileManager.OriginLongitude, TileManager.OriginLatitude, this.client.method); } if (GUILayout.Button("Generate locally")) { mainScene = EditorSceneManager.GetActiveScene(); swComplete.Start(); tiles = new List <Tile>(); for (int i = -TileManager.tileRadius; i <= TileManager.tileRadius; i++) { for (int j = -TileManager.tileRadius; j <= TileManager.tileRadius; j++) { jobs++; Stopwatch sw = new Stopwatch(); sw.Reset(); sw.Start(); Tile newTile = Tile.CreateTileGO(i, j, 5); tiles.Add(newTile); tileJobsLocal.Add(i + "/" + j, newTile); tileJobsStopwatchLocal.Add(i + "/" + j, sw); //newTile.ProceduralDone += GenerationDone; //newTile.StartQuery(); //EditorSceneManager.SaveScenes //SceneManager.SetActiveScene(mainScene); } } tiles[0].ProceduralDone += GenerationDone; tiles[0].StartQuery(); } } else // Client-Mode { #region JobQueue string[] jobQueueNames = new string[this.client.GetQueues().Length]; for (int i = 0; i < this.client.GetQueues().Length; i++) { jobQueueNames[i] = this.client.GetQueues()[i].Name; } this.jobQueueIndex = EditorGUILayout.Popup("JobQueue", this.jobQueueIndex, jobQueueNames); string jobQueueName = this.client.GetQueues().Length == 0 ? "not set" : jobQueueNames[this.jobQueueIndex]; EditorGUILayout.LabelField("JobQueue", jobQueueName); if (jobQueueNames.Length != 0) { if (GUILayout.Button("Subscribe to " + jobQueueNames[this.jobQueueIndex] + " Queue")) { //this.client.BasicQos(1, 1, true); this.client.SubscribeToQueue(jobQueueNames[this.jobQueueIndex]); } } #endregion // JobQueue } GUI.backgroundColor = Color.white; EditorGUILayout.BeginVertical("box"); { foreach (StatusUpdateMessage item in SimpleClient.jobStatus.Values) { CustomGUIUtils.BeginGroup(); { switch (item.status) { case Status.PENDING: statusStyle = lightRed; break; case Status.IN_PROGRESS: statusStyle = lightYellow; break; case Status.DONE: statusStyle = lightGreen; break; default: statusStyle = GUIStyle.none; break; } EditorGUILayout.BeginHorizontal(statusStyle); EditorGUILayout.LabelField("" + item.jobID, GUILayout.Width(20f)); EditorGUILayout.LabelField("" + item.name, GUILayout.Width(80f)); EditorGUILayout.EndHorizontal(); foreach (string todo in item.childTodos) { CustomGUIUtils.BeginGroup(); TodoItem todoItem = item.childDict[todo]; switch (todoItem.status) { case Status.PENDING: statusStyle = lightRed; break; case Status.IN_PROGRESS: statusStyle = lightYellow; break; case Status.DONE: statusStyle = lightGreen; break; default: statusStyle = GUIStyle.none; break; } EditorGUILayout.BeginHorizontal(statusStyle); EditorGUILayout.LabelField(todoItem.name); EditorGUILayout.EndHorizontal(); DrawTodoItem(todoItem); CustomGUIUtils.EndGroup(); } } CustomGUIUtils.EndGroup(); } } EditorGUILayout.EndVertical(); // Save/serialized modified connection serializedObject.ApplyModifiedProperties(); // Update the last connection index lastIndex = index; }
private void ClientSettingsGUI() { GUILayout.BeginArea(new Rect(0, buttonHeight + 20, 300, 400)); client.ServerMode = EditorGUILayout.Toggle("Act as Server", client.ServerMode); #region Dropdown connections // Generate the connection dropdown options/content List <GUIContent> options = new List <GUIContent>(); string[] connectionNames = AmqpConfigurationEditor.GetConnectionNames(); //if (Event.current.type == EventType.Layout) //{ for (var i = 0; i < connectionNames.Length; i++) { var cName = connectionNames[i]; if (string.IsNullOrEmpty(client.Connection) || client.Connection == cName) { selectedConfigurationIndex = i; } options.Add(new GUIContent(cName)); } if (options.Count == 0) { Init(); } //} // Connections drop down string tooltip = "Select the AMQP connection to use. Connections can be configured in the AMQP/Configuration menu."; selectedConfigurationIndex = EditorGUILayout.Popup(new GUIContent("Connection", tooltip), selectedConfigurationIndex, options.ToArray()); // Set the connection name based on dropdown value try { GUIContent con = options[selectedConfigurationIndex]; client.Connection = options[selectedConfigurationIndex].text; } catch (ArgumentException) { Repaint(); return; } #endregion // Dropdown connections string connectionString = options[selectedConfigurationIndex].text; #region REST-Versuche AmqpConnection connection = SimpleClient.GetConnection(connectionString); //if (connection != null) //{ // //string consumers = "http://*****:*****@" + connection.Host + ":" + connection.AmqpPort + "/api/consumers"; // //Debug.Log("http://*****:*****@" + connection.Host + ":" + connection.AmqpPort + "/api/consumers"); // if (managementAPI == null && client.IsConnected) // { // managementAPI = new RabbitmqManagementAPI(connection); // } // if (overview == null) // { // if (client.IsConnected) // { // overview = managementAPI.Overview(); // //overview.Start(); // } // } // else // { // Debug.Log("OverviewResult: " + overview.GetResult()); // //Debug.Log("overViewRequest != null"); // if (client.IsConnected) // { // if (overview.RequestFinished) // { // if (!overview.RequestErrorOccurred) // { // Debug.Log("not finished: " + overview.ResponseCode.ToString()); // } // else // { // Debug.Log("OverviewResult: " + overview.GetResult()); // } // } // else // { // //Debug.Log("not finished: " + overview.ResponseCode.ToString()); // } // } // } //} //if (connection != null) //{ // //http://10.211.55.2:15672/api/queues // string ourPostData = ""; // Dictionary<string, string> headers = new Dictionary<string, string>(); // headers.Add("Content-Type", "application/json"); // byte[] pData = new byte[0]; // string consumers = "http://" + connection.Host + ":" + connection.AmqpPort + "/api/queues"; // WWW api = new WWW(consumers, pData, headers); // while (!api.isDone) // { // if (api.error != null) // { // Debug.Log("Error"); // break; // } // } // string jsonStr = Encoding.UTF8.GetString(api.bytes); // Debug.Log(consumers + " : " + api.text); //} //WWW api = new WWW(consumers); //while (!api.isDone) //{ // // wait //} //Debug.Log("result: " + api.text); //UnityWebRequest //UnityWebRequest request = UnityWebRequest.Get(consumers); //while (!request.isDone || request.isError) //{ // // wait // if (request.isError) // { // Debug.Log("Error"); // } //} //Debug.Log("result UnityWebRequest: " + request.downloadHandler.text); #endregion // REST-Versuche if (GUILayout.Button("Awake")) { client.Awake(); Repaint(); return; } EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("EnableUpdate")) { client.EnableUpdate(); return; } if (GUILayout.Button("DisableUpdate")) { client.DisableUpdate(); return; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Toggle("IsConnecting?", client.isConnecting); EditorGUILayout.Toggle("IsConnected?", client.IsConnected); EditorGUILayout.Toggle("hasConnected?", client.hasConnected); EditorGUILayout.Toggle("isDisconnecting?", client.isDisconnecting); EditorGUILayout.Toggle("hasDisconnected?", client.hasDisconnected); EditorGUILayout.Toggle("isReconnecting?", client.isReconnecting); EditorGUILayout.Toggle("wasBlocked?", client.wasBlocked); EditorGUILayout.Toggle("hasAborted?", client.hasAborted); EditorGUILayout.Toggle("canSubscribe?", client.canSubscribe); EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Connect")) { client.Connect(); return; } if (GUILayout.Button("Disconnect")) { client.Disconnect(); return; } } EditorGUILayout.EndHorizontal(); #region Available Queues EditorGUILayout.BeginVertical("box"); foreach (var queue in client.GetQueues()) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Name:", queue.Name); if (GUILayout.Button("Subscribe", GUILayout.Width(30))) { client.SubscribeToQueue(queue.Name); } if (GUILayout.Button("X", GUILayout.Width(30))) { client.DeleteQueue(queue.Name); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); #endregion Available Queues #region Create Queue EditorGUILayout.BeginHorizontal("box"); this.createQueueName = EditorGUILayout.TextField("Queue Name", this.createQueueName); if (GUILayout.Button("Create")) { client.DeclareQueue(this.createQueueName); } EditorGUILayout.EndHorizontal(); #endregion // Create Queue #region Subscribe Queue AmqpQueue[] queues = client.GetQueues(); string[] names = new string[queues.Length]; for (int i = 0; i < queues.Length; i++) { names[i] = queues[i].Name; } selectedQueue = EditorGUILayout.Popup("Queue", selectedQueue, names); if (queues.Length != 0) { if (GUILayout.Button("Subscribe to " + names[this.selectedQueue] + " Queue")) { client.SubscribeToQueue(names[this.selectedQueue]); } } #endregion // Subscribe Queue #region JobQueue string[] jobQueueNames = new string[client.GetQueues().Length]; for (int i = 0; i < client.GetQueues().Length; i++) { jobQueueNames[i] = client.GetQueues()[i].Name; } this.jobQueueIndex = EditorGUILayout.Popup("JobQueue", this.jobQueueIndex, jobQueueNames); for (int i = 0; i < jobQueueNames.Length; i++) { if (jobQueueNames[i] == "jobs") { this.jobQueueIndex = i; break; } } jobQueueName = client.GetQueues().Length == 0 ? "not set" : jobQueueNames[this.jobQueueIndex]; //EditorGUILayout.LabelField("JobQueue", jobQueueName); #endregion // JobQueue #region ReplyQueue string[] replyToQueueNames = new string[client.GetQueues().Length]; for (int i = 0; i < client.GetQueues().Length; i++) { replyToQueueNames[i] = client.GetQueues()[i].Name; } this.replyQueueIndex = EditorGUILayout.Popup("ReplyToQueue", this.replyQueueIndex, replyToQueueNames); for (int i = 0; i < replyToQueueNames.Length; i++) { if (replyToQueueNames[i] == "reply") { this.replyQueueIndex = i; break; } } replyQueueName = client.GetQueues().Length == 0 ? "not set" : replyToQueueNames[this.replyQueueIndex]; //EditorGUILayout.LabelField("ReplyToQueue", replyQueueName); #endregion // JobQueue #region StatusUpdateQueue string[] statusUpdateQueueNames = new string[client.GetQueues().Length]; for (int i = 0; i < client.GetQueues().Length; i++) { statusUpdateQueueNames[i] = client.GetQueues()[i].Name; } this.statusUpdateQueueIndex = EditorGUILayout.Popup("ReplyToQueue", this.statusUpdateQueueIndex, statusUpdateQueueNames); for (int i = 0; i < statusUpdateQueueNames.Length; i++) { if (statusUpdateQueueNames[i] == "statusUpdates") { this.statusUpdateQueueIndex = i; break; } } statusUpdateQueueName = client.GetQueues().Length == 0 ? "not set" : statusUpdateQueueNames[this.statusUpdateQueueIndex]; #endregion // StatusUpdateQueue GUILayout.EndArea(); }