예제 #1
0
        // Method we use to list a discord user's subscriptions
        public async Task <List <string> > GetSubscriptions(ulong discordId)
        {
            // Twitter IDs are always longs -- while they're stored as UNSIGNED BIGINTS I could get them as ulongs
            // but I'll keep them as longs for consistency's sake

            // This is a list of Ids, which aren't necessarily human-readable. We will parse to usernames later.
            List <long> IdResults = new List <long>();

            try {
                if (Connection.State == ConnectionState.Closed)
                {
                    await Connection.OpenAsync();
                }

                MySqlCommand Command = new MySqlCommand("SELECT TwitterId FROM DiscordTwitterUsers WHERE DiscordId=@D_ID", Connection);
                Command.Prepare();
                Command.Parameters.AddWithValue("@D_ID", discordId);
                Reader = await Command.ExecuteReaderAsync();

                while (await Reader.ReadAsync())
                {
                    // Read all the twitter ids that match and add them to list
                    IdResults.Add(Reader.GetInt64(0));
                }
            } catch (MySqlException e) {
                Utils.MainLog(
                    $"MySqlException occured while getting subscriptions for a Discord user: {e.ToString()}",
                    "Error",
                    "GetSubscriptions"
                    );
            } finally {
                if (Reader != null)
                {
                    Reader.Close();
                }
                if (Connection != null)
                {
                    await Connection.CloseAsync();
                }
            }

            // Internal function to convert enumerable as LINQ doesn't accept async predicates
            async Task <List <string> > IdsToUsernames(List <long> IdList)
            {
                IEnumerable <Task <string> > TaskList = IdList.Select(id => Program.TwitterBotInstance.GetUsername(id));
                var Usernames = await Task.WhenAll(TaskList);

                return(Usernames.ToList());
            }

            // Convert all entries to usernames using Twitter bot's lookup
            List <string> UsernameResults = await IdsToUsernames(IdResults);

            return(UsernameResults);
        }
예제 #2
0
        protected override void CreateChildControls()
        {
            var provider = GetProvider();

            using (CmsContext.Editing)
            {
                var item = CmsService.Instance.GetItem<Entity>(new Id(Request.QueryString["itemId"]));
                var fieldName = Request.QueryString["fieldName"];
                var value = new IdList(item[fieldName]);
                var destinationNodes = value.Select(id => provider.GetNode(id.ToString())).Where(node => node != null).ToArray();

                var treeview = new LinqItTreeView();
                treeview.Provider = Request.QueryString["provider"];
                treeview.ProviderReferenceId = Request.QueryString["itemId"];

                var placeholder = new PlaceHolder();
                placeholder.Controls.Add(new LiteralControl("<div class=\"srcList \">"));
                placeholder.Controls.Add(treeview);
                placeholder.Controls.Add(new LiteralControl("</div>"));

                multiListControl.Initialize(placeholder, destinationNodes);
            }
            base.CreateChildControls();
        }