Exemple #1
0
        /// <summary>
        /// get buttons of all services
        /// </summary>
        /// <returns></returns>
        private List <List <BotButtonInfo> > GetListOfServicesButtons(TelegramClientInfo clientInfo)
        {
            List <BotButtonInfo> columns = new List <BotButtonInfo>();

            List <List <BotButtonInfo> > rows = new List <List <BotButtonInfo> >();

            int columnIndex             = 0;
            List <System.Type> services = _serverBase.GetListOfRegistredTypes().ToList();

            for (int i = 0; i < services.Count; i++)
            {
                System.Type item = services[i];
                ServiceContractAttribute attribute = item.GetCustomAttribute <ServiceContractAttribute>();
                if (attribute.ServiceType != ServiceType.HttpService)
                {
                    continue;
                }
                string serviceName = "";
                if (CurrentBotStructureInfo.InitializeServicesFromAttributes)
                {
                    BotDisplayNameAttribute nameAttribute = item.GetCustomAttribute <BotDisplayNameAttribute>();
                    if (nameAttribute == null)
                    {
                        continue;
                    }
                    //serviceName = nameAttribute.Content;
                }

                serviceName = attribute.Name;
                if (!CurrentBotStructureInfo.OnServiceGenerating(serviceName, clientInfo))
                {
                    continue;
                }
                if (!Services.ContainsKey(attribute.Name))
                {
                    Services.Add(serviceName, item);
                }
                if (columnIndex == 3)
                {
                    columnIndex = 0;
                    rows.Add(columns.ToList());
                    columns.Clear();
                }
                columns.Add(GetServiceCaption(item));
                columnIndex++;
            }
            if (rows.Count == 0)
            {
                rows.Add(columns);
            }
            return(rows);
        }