コード例 #1
0
ファイル: Program.cs プロジェクト: pekulini/P-app-as
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            HttpClient httpClient = new HttpClient()
            {
                BaseAddress = new Uri("https://www.reddit.com")
            };

            Console.OutputEncoding = Encoding.UTF8;
            int  limit = 1;
            bool shouldRun;

            do
            {
                bool parsed = false;
                while (!parsed)
                {
                    Console.WriteLine("Kol'ko ces komentara?");
                    parsed = int.TryParse(EasterEgg(), out limit);
                    if (!parsed)
                    {
                        Console.WriteLine("Lepo unesi bre, 1,2,3... Ajde opet.");
                    }
                }

                Console.WriteLine("'Oces da ti grupisem po threadu? y/n");

                var grupisanje = EasterEgg().Equals("y", StringComparison.OrdinalIgnoreCase);

                var json = await httpClient.GetStringAsync($"r/serbia/comments.json?limit={limit}");

                var comments = JsonSerializer.Deserialize <Example>(json);

                System.Collections.Generic.IList <Child> children = comments.data.children;

                if (grupisanje)
                {
                    children = children.OrderBy(c => c.data.link_title).ToList();
                }

                foreach (var item in children)
                {
                    Console.WriteLine(Environment.NewLine);
                    Console.WriteLine(item.data.author);
                    Console.WriteLine(item.data.link_title);
                    Console.WriteLine(item.data.body + Environment.NewLine);
                }

                Console.WriteLine("'Oces jos? y/n");
                shouldRun = EasterEgg().Equals("y", StringComparison.OrdinalIgnoreCase);
            } while (shouldRun);

            Console.WriteLine("Hvala sto ste koristili! Komentare, pohvale, pretnje, slike stopala i sl. saljite na u/pekulini.");
            Console.ReadLine();
        }
コード例 #2
0
ファイル: CakeRepository.cs プロジェクト: mkeeton/Projects
        public virtual Task <IList <Cake> > GetCakesAsync(System.Collections.Generic.IList <IcedMemories.Domain.Models.SearchCategoryOption> _categoryOptions)
        {
            IEnumerable <IcedMemories.Domain.Models.SearchCategoryOption> _sortedEnum = _categoryOptions.OrderBy(f => f.CategoryId);
            IList <IcedMemories.Domain.Models.SearchCategoryOption>       _sortedList = _sortedEnum.ToList();
            StringBuilder _sql        = new StringBuilder("app_Cakes C");
            string        _sqlSection = "";
            Guid          _catId      = new Guid();
            int           _catIndex   = 0;

            foreach (IcedMemories.Domain.Models.SearchCategoryOption _option in _categoryOptions)
            {
                if (_option.CategoryId != _catId)
                {
                    _catId     = _option.CategoryId;
                    _catIndex += 1;
                    if (_sqlSection != "")
                    {
                        _sqlSection += "))";
                        _sql.Insert(0, "(");
                        _sql.Append(_sqlSection);
                    }
                    _sqlSection = String.Format(" INNER JOIN app_SearchCategorySelections SCS{0} ON SCS{0}.CakeId=C.Id AND SCS{0}.CategoryOptionId IN ('{1}'", _catIndex, _option.Id);
                }
                else
                {
                    _sqlSection += String.Format(",'{0}'", _option.Id);
                }
            }
            if (_sqlSection != "")
            {
                _sqlSection += "))";
                _sql.Insert(0, "(");
                _sql.Append(_sqlSection);
            }
            _sql.Insert(0, "select DISTINCT C.* FROM ");
            _sql.Append(" ORDER BY C.DateAdded DESC");
            return(Task.Factory.StartNew(() =>
            {
                using (IDbConnection connection = CurrentContext.OpenConnection())
                    return (IList <Cake>)connection.Query <Cake>(_sql.ToString(), new { }).ToList();
            }));
        }