示例#1
0
    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();
    }