コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: ximalaya-snow/-hh
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            AirCatApi airCatApi = new AirCatApi();

            airCatApi.AirWebApiIP    = AirWebApiIP;
            airCatApi.AirWebApiPort  = AirWebApiPort;
            airCatApi.ServicePort    = LocalManagerPort;
            airCatApi.AirWebApiToken = ShareToken;


            Type type = airCatApi.GetType();

            MethodInfo[] methods = type.GetMethods();

            List <String> CommandList = new List <string>();

            foreach (MethodInfo method in methods)
            {
                if (method.IsStatic == false)
                {
                    continue;
                }
                if (method.ReturnParameter.ParameterType.Name != "String")
                {
                    continue;
                }
                CommandList.Add(method.Name);
            }
            CommandList.Sort();
            this.CobmoxCommands.ItemsSource = CommandList;


            airCatApi.OnDebug += AirCatApi_OnDebug;
            airCatApi.ServiceStart();

            ServerIP.Text         = AirWebApiIP;
            ServerPort.Text       = AirWebApiPort.ToString();
            ManagerIP.Text        = "127.0.0.1";
            ManagerPort.Text      = LocalManagerPort.ToString();
            Token.Text            = ShareToken;
            TestRobotWxid.Text    = DefaultRobotWxid;
            TestRoomWxid.Text     = DefaultRoomWxid;
            TestContractWxid.Text = DefaultContractWxid;


            new Thread(() =>
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    CobmoxCommands.SelectedIndex = CobmoxCommands.Items.IndexOf("GetRobotList");
                }));
            }).Start();
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: ximalaya-snow/-hh
        private void CommandRun(Boolean ClassData)
        {
            serverMessage.Text = "";

            AirCatApi airCatApi = new AirCatApi();
            Type      type      = airCatApi.GetType();

            MethodInfo[] methods = type.GetMethods();

            String CommnadRun = CobmoxCommands.SelectedValue.ToString();

            if (ClassData == true)
            {
                CommnadRun += "Data";
            }

            List <String> CommandList = new List <string>();

            foreach (MethodInfo method in methods)
            {
                if (method.IsStatic == false)
                {
                    continue;
                }
                //if (method.ReturnParameter.ParameterType.Name != "String") continue;

                if (method.Name == CommnadRun)
                {
                    ParameterInfo[] parameterInfos = method.GetParameters();
                    object[]        obj            = new object[parameterInfos.Length];
                    for (int j = 0; j < parameterInfos.Length; j++)
                    {
                        TextBox textBox = this.FindName(parameterInfos[j].Name) as TextBox;
                        if (textBox != null)
                        {
                            obj[j] = textBox.Text;
                        }
                        else
                        {
                            ComboBox comboBox = this.FindName(parameterInfos[j].Name) as ComboBox;
                            if (comboBox != null)
                            {
                                foreach (ComboBoxItem item in comboBox.Items)
                                {
                                    if (item.IsSelected == true)
                                    {
                                        obj[j] = item.Content.ToString();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    object message = "";
                    try
                    {
                        message = method.Invoke(airCatApi, obj);
                        String json = message.ToString();
                        if (json == "")
                        {
                            return;
                        }
                        if (json.Substring(0, 1) == "[")
                        {
                            serverMessage.Text = JArray.Parse(message.ToString()).ToString(Newtonsoft.Json.Formatting.Indented);
                        }
                        else
                        {
                            serverMessage.Text = JObject.Parse(message.ToString()).ToString(Newtonsoft.Json.Formatting.Indented);
                        }

                        //获取登陆微信列表
                        if (CommnadRun == "GetRobotList")
                        {
                            robotWxidList.Clear();
                            JObject jObject = JObject.Parse(message.ToString());
                            JArray  jArray  = JArray.Parse(jObject["Robots"].ToString());
                            foreach (var item in jArray)
                            {
                                JObject j = JObject.Parse(item.ToString());
                                robotWxidList.Add(j["RobotWxid"].ToString());
                            }
                        }

                        //获取群列表
                        if (CommnadRun == "GetRoomList")
                        {
                            JObject jObject   = JObject.Parse(message.ToString());
                            string  robotWxid = jObject["RobotWxid"].ToString();

                            //查找群列表中的数据
                            List <String> rooms = new List <string>();
                            foreach (var item in roomList)
                            {
                                if (item.Key == robotWxid)
                                {
                                    rooms = item.Value;
                                    break;
                                }
                            }

                            JArray jArray = JArray.Parse(jObject["Rooms"].ToString());
                            foreach (var item in jArray)
                            {
                                JObject j        = JObject.Parse(item.ToString());
                                string  roomWxid = j["RoomWxid"].ToString();

                                Boolean roomExist = false;
                                foreach (var room in rooms)
                                {
                                    if (room == roomWxid)
                                    {
                                        roomExist = true;
                                        break;
                                    }
                                }
                                if (roomExist == false)
                                {
                                    rooms.Add(roomWxid);
                                }
                            }
                            roomList[robotWxid] = rooms;
                        }
                    }
                    catch (Exception ex)
                    {
                        serverMessage.Text = message.ToString();
                        MessageBox.Show(ex.Message + ex.StackTrace);
                    }
                    return;
                }
            }
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: ximalaya-snow/-hh
        private void CobmoxCommands_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CommandParams.Children.Clear();
            CommandParams.Orientation = Orientation.Vertical;
            ComboBox comboBox = (ComboBox)sender;

            //检查参数
            AirCatApi airCatApi = new AirCatApi();
            Type      type      = airCatApi.GetType();

            MethodInfo[] methods = type.GetMethods();

            foreach (MethodInfo method in methods)
            {
                if (method.IsStatic == false)
                {
                    continue;
                }
                if (method.ReturnParameter.ParameterType.Name != "String")
                {
                    continue;
                }


                //if (method.ReturnParameter.) continue;
                if (method.Name == comboBox.SelectedValue.ToString())
                {
                    Grid grid = new Grid();
                    // grid.ShowGridLines = true;
                    ColumnDefinition columnDefinition1 = new ColumnDefinition();
                    columnDefinition1.Width = GridLength.Auto;
                    ColumnDefinition columnDefinition2 = new ColumnDefinition();
                    grid.ColumnDefinitions.Add(columnDefinition1);
                    grid.ColumnDefinitions.Add(columnDefinition2);

                    TextBlock_ApiComments.Text       = ("名称:" + method.Name + ((ApiCommentAttribute)method.GetCustomAttribute(typeof(ApiCommentAttribute))).ApiComment).Trim();
                    TextBlock_ApiComments.Visibility = Visibility.Visible;

                    ParameterInfo[] parameterInfos = method.GetParameters();
                    for (int i = 0; i < parameterInfos.Length; i++)
                    {
                        RowDefinition rowDefinition = new RowDefinition();
                        grid.RowDefinitions.Add(rowDefinition);
                    }

                    for (int i = 0; i < parameterInfos.Length; i++)
                    {
                        TextBlock textBlock = new TextBlock();
                        textBlock.Text    = parameterInfos[i].Name;
                        textBlock.Padding = new Thickness(3);
                        textBlock.Margin  = new Thickness(3);
                        grid.Children.Add(textBlock);
                        Grid.SetRow(textBlock, i);
                        Grid.SetColumn(textBlock, 0);


                        ComboBox comboBox2 = this.FindName(parameterInfos[i].Name) as ComboBox;
                        if (comboBox2 != null)
                        {
                            CommandParams.UnregisterName(parameterInfos[i].Name);
                        }

                        TextBox textBox2 = this.FindName(parameterInfos[i].Name) as TextBox;
                        if (textBox2 != null)
                        {
                            CommandParams.UnregisterName(parameterInfos[i].Name);
                        }

                        if (parameterInfos[i].Name == "FileName")
                        {
                            StackPanel stackPanel = new StackPanel();
                            TextBox    textBox    = new TextBox();
                            textBox.Name       = parameterInfos[i].Name;
                            textBox.Padding    = new Thickness(3);
                            textBox.Margin     = new Thickness(3);
                            textBox.IsReadOnly = true;
                            CommandParams.RegisterName(parameterInfos[i].Name, textBox);
                            stackPanel.Children.Add(textBox);

                            Button button = new Button();
                            button.Content = "浏览";
                            button.Click  += Button_Click1;
                            button.Tag     = parameterInfos[i].Name;
                            stackPanel.Children.Add(button);

                            grid.Children.Add(stackPanel);
                            Grid.SetRow(stackPanel, i);
                            Grid.SetColumn(stackPanel, 1);
                        }
                        else
                        {
                            if (parameterInfos[i].Name == "RobotWxid")
                            {
                                //登陆的用户列表
                                ComboBox comboBox1 = new ComboBox();
                                comboBox1.Name              = parameterInfos[i].Name;
                                comboBox1.Padding           = new Thickness(3);
                                comboBox1.Margin            = new Thickness(3);
                                comboBox1.SelectionChanged += ComboBox1_SelectionChanged;
                                comboBox1.SelectedIndex     = 0;

                                foreach (String item in robotWxidList)
                                {
                                    ComboBoxItem comboBoxItem = new ComboBoxItem();
                                    comboBoxItem.Content = item;

                                    if (selectedRobotWxid == item)
                                    {
                                        comboBoxItem.IsSelected = true;
                                    }

                                    comboBox1.Items.Add(comboBoxItem);
                                }

                                grid.Children.Add(comboBox1);
                                Grid.SetRow(comboBox1, i);
                                Grid.SetColumn(comboBox1, 1);
                                CommandParams.RegisterName(parameterInfos[i].Name, comboBox1);
                            }
                            //else if (parameterInfos[i].Name == "GetRoomList")
                            //{

                            //}
                            else
                            {
                                TextBox textBox = new TextBox();
                                textBox.Name    = parameterInfos[i].Name;
                                textBox.Padding = new Thickness(3);
                                textBox.Margin  = new Thickness(3);

                                if (parameterInfos[i].Name == "RoomWxid")
                                {
                                    textBox.Text = DefaultRoomWxid;
                                }
                                else if (parameterInfos[i].Name == "Wxid")
                                {
                                    textBox.Text = DefaultContractWxid;
                                }
                                else if (parameterInfos[i].Name == "AtWxid")
                                {
                                    textBox.Text = DefaultContractWxid;
                                }
                                grid.Children.Add(textBox);
                                Grid.SetRow(textBox, i);
                                Grid.SetColumn(textBox, 1);
                                CommandParams.RegisterName(parameterInfos[i].Name, textBox);
                            }
                        }
                    }
                    CommandParams.Children.Add(grid);
                }
            }
        }