Esempio n. 1
0
        public static async Task <FancyContext> Connect()
        {
            var context = new FancyContext();
            await context.Database.Connection.OpenAsync();

            return(context);
        }
        public async Task <User> GetCurrentUser()
        {
            using (var context = new FancyContext())
            {
                var query = context.Users
                            .Include(a => a.CertCredentials)
                            .Include(a => a.Membership)
                            .Where(a => a.CertCredentials.Fingerprint.ToUpper() == UserFingerprint);
                var user = await query.SingleAsync();

                return(user);
            }
        }
Esempio n. 3
0
        public async Task <HttpResponse> GetMyAvatar()
        {
            using (var context = new FancyContext())
            {
                var texture = (await GetCurrentUser()).Membership.Texture;

                if (texture == null || texture.Length == 0)
                {
                    return(NoImageAvailable);
                }

                return(Data(texture, HttpStatus.Ok, ContentType.Custom).SetHeader("Content-Type", "image/png"));
            }
        }
Esempio n. 4
0
        public async Task <HttpResponse> GetByName(string name)
        {
            using (var context = new FancyContext())
            {
                var texture = await context.Users.Where(a => a.Name == name).Select(a => a.Membership.Texture).SingleOrDefaultAsync();

                if (texture == null || texture.Length == 0)
                {
                    return(NoImageAvailable);
                }

                return(Data(texture, HttpStatus.Ok, ContentType.Custom).SetHeader("Content-Type", "image/png"));
            }
        }
Esempio n. 5
0
        public async Task <HttpResponse> GetMessages(string day)
        {
            DateTime Start = DateTime.ParseExact(day, "yyyy-MM-dd", CultureInfo.InvariantCulture).Date;

            DateTime End = Start.AddDays(1);


            using (var context = new FancyContext())
            {
                var logs = await context.Logs.Include(a => a.Who).Where(a => a.When > Start && a.When < End).OrderByDescending(a => a.When).ToArrayAsync();


                var res = GroupMessages(logs);

                return(Json(res));
            }
        }
Esempio n. 6
0
        public static void Main(string[] args)
        {
            IPAddress bindIp;
            ushort    port;

            if (args.Length != 2)
            {
                Console.WriteLine("MumbleLogViewer.exe <bindIp> <port>");
                return;
            }

            if (!IPAddress.TryParse(args[0], out bindIp))
            {
                Console.WriteLine("Cannot parse IP");
                return;
            }

            if (!ushort.TryParse(args[1], out port))
            {
                Console.WriteLine("Cannot parse port");
                return;
            }

            Console.WriteLine("Initializing Model...");
            using (var context = new FancyContext())
                Console.WriteLine("Number of Users: {0}", context.Users.Count());
            Console.WriteLine("Finished!");

            Newtonsoft.Json.JsonConvert.DefaultSettings = () => new JsonSerializerSettings {
                Converters = new List <JsonConverter> {
                    new LongStringJsonConverter()
                }
            };


            var server = new HttpServer(new IPEndPoint(bindIp, port), Assembly.GetAssembly(typeof(MainClass)));

            server.Run().Wait();
        }
Esempio n. 7
0
        public async Task <HttpResponse> Search(string query)
        {
            var queries = query.Split(' ').Where(a => a.Trim().Length > 2).Select(a => a.ToLowerInvariant()).ToArray();

            using (var context = new FancyContext())
            {
                var messages = context.Logs.Include(a => a.Who).OfType <LogEntry.ChatMessage>();

                foreach (var q in queries)
                {
                    messages = messages.Where(
                        a => a.Who.Name.ToLower().Contains(q) || a.Message.ToLower().Contains(q)
                        );
                }

                messages = messages.OrderByDescending(a => a.When).Take(30);

                var logs = await messages.ToArrayAsync();

                var res = GroupMessages(logs);

                return(Json(res));
            }
        }