Exemple #1
0
 public void OnGet()
 {
     using (var db = new GoContext())
     {
         Links = db.Links.ToList();
     }
 }
Exemple #2
0
        public IActionResult OnPost(string code, string address)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(Redirect("/"));
            }

            if (code.Equals("links", StringComparison.OrdinalIgnoreCase))
            {
                SetErrorMessage("Short address can't be 'links'. It is reserved!");
                return(Page());
            }

            code = code.ToLower();

            Initialize(code);

            if (string.IsNullOrEmpty(address))
            {
                SetErrorMessage("You need to enter an address!");
                return(Page());
            }

            if (!UrlChecker.CheckUrl(address))
            {
                SetErrorMessage("You need to enter a full valid address!");

                return(Page());
            }

            using (var db = new GoContext())
            {
                var link = db.Links.FirstOrDefault(f => f.Code.Equals(code));
                if (link == null)
                {
                    link      = new Link();
                    link.Code = code;

                    db.Links.Add(link);
                }

                link.Url       = address;
                link.UpdatedAt = DateTime.UtcNow;

                db.SaveChanges();

                Address = address;

                SetSuccessMessage("Your short link was saved.");
            }

            return(Page());
        }
Exemple #3
0
 private void Initialize(string code)
 {
     Code = code;
     using (var db = new GoContext())
     {
         var link = db.Links.FirstOrDefault(f => f.Code.Equals(code));
         if (link != null)
         {
             Address = link.Url;
         }
     }
 }
Exemple #4
0
        public async Task RequestAsync(GoContext context)
        {
            var httpRequest = CreateHttpRequestMessage(context.Request);

            var options = context.Request.Options;

            HttpResponseMessage httpResponse;

            using (var tokenSource = new CancellationTokenSource(options.Timeout))
                httpResponse = await _httpClient.SendAsync(httpRequest, tokenSource.Token);

            await InitializeResponseAsync(context.Response, httpResponse);
        }
        public IMethodInvoker CreateInvoker(MethodDescriptor methodDescriptor)
        {
            var entry = _methodInvokerCache.Get(methodDescriptor);

            var requestServices = _services.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider;

            var goContext = new GoContext
            {
                RequestServices = requestServices
            };

            return(new DefaultMethodInvoker(new RequestContext(goContext, methodDescriptor), entry));
        }
Exemple #6
0
        private IActionResult GoToUrl(string code, GoContext db)
        {
            var link = db.Links.FirstOrDefault(f => f.Code.Equals(code));

            if (link == null)
            {
                return(GoToEditPage(code));
            }

            link.VisitCount++;
            db.SaveChanges();

            return(Redirect(link.Url));
        }
Exemple #7
0
        public IActionResult OnGet(string code)
        {
            using (var db = new GoContext())
            {
                if (string.IsNullOrEmpty(code))
                {
                    return(NoCode(db));
                }

                code = code.ToLower();

                return(GoToUrl(code, db));
            }
        }
Exemple #8
0
        private IActionResult NoCode(GoContext db)
        {
            string code = null;

            while (code == null)
            {
                var newCode = RandomGenerator.RandomString();
                if (!db.Links.Any(a => a.Code.Equals(newCode)))
                {
                    code = newCode;
                }
            }

            return(GoToEditPage(code));
        }
        public GoContext go(string val)
        {
            GoContext _localctx = new GoContext(_ctx, State, val);

            EnterRule(_localctx, 0, RULE_go);
            try {
                int _alt;
                EnterOuterAlt(_localctx, 1);
                {
                    ruta  = val;
                    State = 25; inicio();
                    State = 29;
                    _errHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(_input, 0, _ctx);
                    while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber)
                    {
                        if (_alt == 1)
                        {
                            {
                                {
                                    State = 26; expr();
                                }
                            }
                        }
                        State = 31;
                        _errHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(_input, 0, _ctx);
                    }
                    State = 32; fin();
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                _errHandler.ReportError(this, re);
                _errHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
Exemple #10
0
 public RequestContext(GoContext goContext, MethodDescriptor methodDescriptor)
 {
     GoContext        = goContext;
     MethodDescriptor = methodDescriptor;
 }