示例#1
0
 public override Task Execute(MessageData data)
 {
     ReferalService.Instance.WasReferedBy(data.User, data.GetAs <string>());
     return(data.Ok());
 }
        public override Task Execute(MessageData data)
        {
            string productId;

            try
            {
                productId = data.GetAs <string>();
            }
            catch (Exception)
            {
                throw new CoflnetException("invaild_data", "Data should contain a product id as string");
            }
            var product = GetProduct(productId);
            var price   = GetPrice(productId);

            var domain  = "https://sky.coflnet.com";
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = new SessionLineItemPriceDataOptions
                        {
                            UnitAmount = price.UnitAmount,

                            Currency = "eur",
                            Product  = productId
                        },

                        // Description = "Unlocks premium features: Subscribe to 100 Thrings, Search with multiple filters and you support the project :)",
                        Quantity = 1,
                    },
                },
                Metadata          = product.Metadata,
                Mode              = "payment",
                SuccessUrl        = domain + "/success",
                CancelUrl         = domain + "/cancel",
                ClientReferenceId = data.UserId.ToString()
            };
            var     service = new SessionService();
            Session session;

            try
            {
                session = service.Create(options);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new CoflnetException("internal_error", "service not working");
            }
            using (var context = new HypixelContext())
            {
                var user = data.User;
                context.Update(user);
                context.SaveChanges();
            }

            return(data.SendBack(data.Create("checkoutSession", session.Id), false));
            //return Json(new { id = session.Id });
        }
 public override Task Execute(MessageData data)
 {
     return(data.SendBack(new MessageData("bazaarResponse", JsonConvert.SerializeObject(BazaarController.Instance.GetInfo(data.Data)))));
 }
        public override Task Execute(MessageData data)
        {
            var refInfo = ReferalService.Instance.GetReferalInfo(data.User);

            return(data.SendBack(data.Create("refInfo", refInfo)));
        }
示例#5
0
 public void SendBack(MessageData data)
 {
     Send(MessagePackSerializer.ToJson(data));
 }
示例#6
0
 public override Task Execute(MessageData data)
 {
     SubscribeEngine.Instance.Subscribe(data.GetAs <string>(), data.UserId);
     return(data.SendBack(data.Create("subscribeResponse", "success")));
 }
示例#7
0
        public static MessageData Copy(MessageData original)
        {
            var d = new MessageData(original.Type, original.Data, original.MaxAge);

            return(d);
        }
示例#8
0
            private static ReducedCommandData CreateItem(MessageData m)
            {
                var compressed = Zip(m.Data);

                return(new ReducedCommandData(m.Type, compressed));
            }
示例#9
0
 public virtual Task SendBack(MessageData data, bool cache = true)
 {
     throw new Exception("Can't send back with default connection");
 }
示例#10
0
        public virtual MessageData Create <T>(string type, T data, int maxAge = 0)
        {
            var d = new MessageData(type, MessagePackSerializer.ToJson(data), maxAge);

            return(d);
        }
        public override Task Execute(MessageData data)
        {
            var devices = data.User.Devices;

            return(data.SendBack(data.Create("devices", devices)));
        }
示例#12
0
 public abstract Task Execute(MessageData data);
示例#13
0
        public override Task Execute(MessageData data)
        {
            var watch             = Stopwatch.StartNew();
            var search            = ItemSearchCommand.RemoveInvalidChars(data.Data);
            var cancelationSource = new CancellationTokenSource();
            var results           = SearchService.Instance.Search(search, cancelationSource.Token);

            var result   = new ConcurrentBag <SearchService.SearchResultItem>();
            var pullTask = Task.Run(async() =>
            {
                Console.WriteLine($"Started task " + watch.Elapsed);
                while (results.Result.TryDequeue(out SearchService.SearchResultItem r))
                {
                    result.Add(r);
                    if (result.Count > 15)
                    {
                        return; // return early
                    }
                    Task.Run(() => LoadPreview(watch, r), cancelationSource.Token).ConfigureAwait(false);
                }
            }, cancelationSource.Token);

            Console.WriteLine($"Waiting half a second " + watch.Elapsed);
            pullTask.Wait(320);
            while (results.Result.TryDequeue(out SearchService.SearchResultItem r))
            {
                result.Add(r);
            }
            Console.WriteLine($"Waited half a second " + watch.Elapsed);

            var maxAge = A_DAY / 2;

            cancelationSource.Cancel();
            Console.WriteLine($"Started sorting {search} " + watch.Elapsed);
            var orderedResult = result
                                .Select(r =>
            {
                var lower = r.Name.ToLower();
                return(new
                {
                    rating = String.IsNullOrEmpty(r.Name) ? 0 :
                             lower.Length / 2
                             - r.HitCount * 2
                             - (lower == search ? 10000000 : 0)                                                    // is exact match
                             - (lower.Length > search.Length && lower.Truncate(search.Length) == search ? 100 : 0) // matches search
                             - (Fastenshtein.Levenshtein.Distance(lower, search) <= 1 ? 40 : 0)                    // just one mutation off maybe a typo
                             + Fastenshtein.Levenshtein.Distance(lower.PadRight(search.Length), search) / 2        // distance to search
                             + Fastenshtein.Levenshtein.Distance(lower.Truncate(search.Length), search),
                    r
                });
            }
                                        )
                                .OrderBy(r => r.rating)
                                .Where(r => { Console.WriteLine($"Ranked {r.r.Name} {r.rating} {Fastenshtein.Levenshtein.Distance(r.r.Name.PadRight(search.Length), search) / 10} {Fastenshtein.Levenshtein.Distance(r.r.Name.Truncate(search.Length), search)}"); return(true); })
                                .Where(r => r.rating < 10)
                                .ToList()
                                .Select(r => r.r)
                                .Distinct(new SearchService.SearchResultComparer())
                                .Take(5)
                                .ToList();

            Console.WriteLine($"making response " + watch.Elapsed);
            if (orderedResult.Count() == 0)
            {
                maxAge = A_MINUTE;
            }

            return(data.SendBack(data.Create(Type, orderedResult, maxAge)));

            return(Task.Run(() =>
            {
                if (!(data is Server.ProxyMessageData <string, object>))
                {
                    TrackingService.Instance.TrackSearch(data, data.Data, orderedResult.Count, watch.Elapsed);
                }
            }));
        }
示例#14
0
 public bool TryFromCache(MessageData request)
 {
     return(TryFromCacheAsync(request).GetAwaiter().GetResult().HasFlag(CacheStatus.VALID));
 }
 public override Task Execute(MessageData data)
 {
     return(data.SendBack(new MessageData("itemNamesResponse", JsonConvert.SerializeObject(ItemDetails.Instance.AllItemNames()), A_WEEK)));
 }
示例#16
0
 public void Add(MessageData data)
 {
     Reduced.Add(CreateItem(data));
 }
示例#17
0
        public override Task Execute(MessageData data)
        {
            var respone = CreateResponse(data, data.GetAs <string>());

            return(data.SendBack(respone));
        }
示例#18
0
 public override Task SendBack(MessageData data, bool cache = true)
 {
     CacheService.Instance.Save(this, data);
     return(Task.CompletedTask);
 }
示例#19
0
 public override Task Execute(MessageData data)
 {
     return(data.SendBack(CreateResponse(data)));
 }