Exemple #1
0
        /// <summary>
        /// When the method completes, the queue message is deleted. If the method fails before completing, the queue message
        /// is not deleted; after a 10-minute lease expires, the message is released to be picked up again and processed. This
        /// sequence won't be repeated indefinitely if a message always causes an exception. After 5 unsuccessful attempts to
        /// process a message, the message is moved to a queue named {queuename}-poison. The maximum number of attempts is
        /// configurable.
        ///
        /// https://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-webjobs-sdk-get-started/#configure-storage
        /// </summary>
        /// <param name="auditInfo"></param>
        /// <param name="logger"></param>
        public static void AddRetrievalAuditLogRecord([QueueTrigger("%queueName%")] AuditDataModel auditInfo, TextWriter logger)
        {
            using (var io = new Wutnu.Data.WutNuContext())
            {
                try
                {
                    var ipInfo = IpLookup.Get(auditInfo.HostIp);
                    io.usp_AddHistory(
                        auditInfo.ShortUrl,
                        auditInfo.CallDate,
                        auditInfo.UserId,
                        auditInfo.HostIp,
                        ipInfo.Latitude,
                        ipInfo.Longitude,
                        ipInfo.City,
                        ipInfo.Region,
                        ipInfo.Country,
                        ipInfo.Continent,
                        ipInfo.Isp);
                    io.SaveChanges();
                }
                catch (Exception ex)
                {
                    Logging.WriteDebugInfoToErrorLog("Error dequeing", ex, io);
                    var x = ex.GetBaseException();
                    //logger.WriteLine("Error dequeuing: {0}, {1}", x.Message, x.StackTrace);

                    throw ex;
                }
            }
        }
Exemple #2
0
        public void Run(APIGatewayProxyRequest request, APIGatewayProxyResponse response, FinanceUser user)
        {
            var model = JsonConvert.DeserializeObject <SignupModel>(request.Body);

            if (!model.AgreedToLicense)
            {
                throw new Exception("agreedToLicense must be true");
            }
            var provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);
            var userPool = new CognitoUserPool(Configuration.FINANCE_API_COGNITO_USER_POOL_ID, Configuration.FINANCE_API_COGNITO_CLIENT_ID, provider);
            var result   = userPool.SignUpAsync(
                model.Email.ToLower(),
                model.Password,
                new Dictionary <string, string>(),
                new Dictionary <string, string>());

            result.Wait();
            var userService = new UserService();

            userService.CreateUser(model.Email, model.AgreedToLicense, IpLookup.GetIp(request));
            var json = new JObject
            {
                { "status", "Your user has successfully been created. " +
                  $"Your user name is {model.Email}. " +
                  "A confirmation link has been sent to your email from [email protected]. " +
                  "You need to click the verification link in the email before you can login." }
            };

            response.Body = json.ToString();
        }
Exemple #3
0
        public static void Start()
        {
            var account = new CloudStorageAccount(new StorageCredentials(
                                                      "",       // Azure Storage Account Name
                                                      ""),      // Azure Storage Account Key
                                                  true);        // Use Https
            var importer = new AzureStorageImporter(account,
                                                    "",         // Container
                                                    "");        // Blob Name

            IpLookup.Initialize(importer, "DefaultConnection"); // Optional Database Connection String Name
        }
    protected void CheckIpButton_Clicked(object sender, EventArgs e)
    {
        IpLookup ipl = IpLookup.LookupIp(Utils.TruncateString(IpNumberTextBox.Text, 15));

        if (ipl == null)
        {
            IpLookupResultLabel.Text = "Invalid ip number";
        }
        else
        {
            IpLookupResultLabel.Text = ipl.Country;
        }
    }
Exemple #5
0
    protected void LookupIpButton_Clicked(object sender, EventArgs e)
    {
        IpLookup ipl = IpLookup.LookupIp(LookupIpTextBox.Text);

        if (ipl == null)
        {
            IpLookupResultLabel.Text = "Invalid ip number";
        }
        else
        {
            IpLookupResultLabel.Text = ipl.Country;
        }
    }
Exemple #6
0
        public void Run(APIGatewayProxyRequest request, APIGatewayProxyResponse response, FinanceUser user)
        {
            var model = JsonConvert.DeserializeObject <PurchaseModel>(request.Body);

            if (!model.AgreedToBillingTerms)
            {
                throw new Exception("Must agree to billing terms");
            }
            Subscription subscription;

            try
            {
                subscription = Purchase(
                    user.Email,
                    model.CardCvc,
                    model.CardNumber,
                    model.CardExpirationMonth,
                    model.CardExpirationYear);
            }
            catch (StripeException stripeException)
            {
                response.Body = new JObject
                {
                    { "status", stripeException.Message }
                }.ToString();
                response.StatusCode = 400;
                return;
            }
            response.Body = JsonConvert.SerializeObject(subscription);
            var jsonPatch = new JObject
            {
                ["billingAgreement"] = JObject.FromObject(new BillingAgreement
                {
                    AgreedToBillingTerms = model.AgreedToBillingTerms,
                    Date      = DateTime.UtcNow.ToString("O"),
                    IpAddress = IpLookup.GetIp(request)
                })
            };

            new UserService().UpdateUser(user.Email, jsonPatch);
        }
Exemple #7
0
        public static IpLookup WhoIs(string IP)
        {
            try
            {
                string url = string.Format(@"http://ip-api.com/json/{0}", IP);
                //Uri uri = new Uri(url);
                WebRequest webRequest = WebRequest.Create(url);
                WebResponse response = webRequest.GetResponse();
                StreamReader streamReader = new StreamReader(response.GetResponseStream());
                var responseData = streamReader.ReadToEnd();
                IpLookup values = JsonConvert.DeserializeObject<IpLookup>(responseData);
                return values;
            }
            catch (Exception)
            {

                IpLookup values = new IpLookup();
                values.status = "";
                values.org = "";
                values.regionName = "";
                return values;
            }
        }
Exemple #8
0
        public void Run(APIGatewayProxyRequest request, APIGatewayProxyResponse response, FinanceUser user)
        {
            var receipt                 = JsonConvert.DeserializeObject <Receipt>(request.Body);
            var dbClient                = new AmazonDynamoDBClient();
            var logger                  = new ConsoleLogger();
            var receiptDbClient         = new DatabaseClient <ReceiptSaveResult>(dbClient, logger);
            var spotReservationDbClient = new DatabaseClient <SpotReservation>(dbClient, logger);
            var vendorDbClient          = new DatabaseClient <Vendor>(dbClient, logger);
            var qboClient               = new QuickBooksOnlineClient(PrivateAccounting.Constants.LakelandMiPuebloRealmId, new DatabaseClient <QuickBooksOnlineConnection>(dbClient, logger), logger);

            var allActiveCustomers = qboClient
                                     .QueryAll <Customer>("select * from customer")
                                     .ToDictionary(x => x.Id);
            var activeVendors = new ActiveVendorSearch()
                                .GetActiveVendors(allActiveCustomers, vendorDbClient)
                                .ToList();
            var spotClient           = new DatabaseClient <Spot>(dbClient, logger);
            var spotReservationCheck = new SpotReservationCheck(spotClient, spotReservationDbClient, activeVendors, allActiveCustomers);
            var validation           = new ReceiptValidation(spotReservationCheck).Validate(receipt).Result;

            if (validation.Any())
            {
                response.StatusCode = 400;
                response.Body       = new JObject {
                    { "error", JArray.FromObject(validation) }
                }.ToString();
                return;
            }
            var    taxRate        = new Tax().GetTaxRate(qboClient, PropertyRentalManagement.Constants.QUICKBOOKS_RENTAL_TAX_RATE);
            var    cardPayment    = new CardPayment(logger, Configuration.CLOVER_MI_PUEBLO_PRIVATE_TOKEN);
            var    receiptService = new ReceiptSave(receiptDbClient, qboClient, taxRate, spotReservationDbClient, logger, cardPayment);
            string customerId     = receipt.Customer.Id;

            if (string.IsNullOrWhiteSpace(customerId))
            {
                var customer = new Customer {
                    DisplayName = receipt.Customer.Name
                };
                customer   = qboClient.Create(customer);
                customerId = customer.Id.ToString();
            }
            var vendor = activeVendors.FirstOrDefault(x => x.QuickBooksOnlineId.GetValueOrDefault().ToString() == customerId)
                         ?? vendorDbClient.Create(VendorService.CreateModel(int.Parse(customerId), null, null, null));

            receipt.Id = string.IsNullOrWhiteSpace(receipt.Id) ? Guid.NewGuid().ToString() : receipt.Id; // Needed until UI is deployed.
            var receiptResult = receiptService.SaveReceipt(receipt, customerId, user.FirstName, user.LastName, user.Email, vendor, IpLookup.GetIp(request));

            response.Body = JsonConvert.SerializeObject(receiptResult);
        }