Ejemplo n.º 1
0
        public async Task <string> WriteFile(CmsFile file, CmsType cmsType, Guid id, string fieldName, string?lang, string?currentUser)
        {
            using (Stream stream = new MemoryStream(file.Bytes))
            {
                var response = await _client.UploadFileAsync($"{fieldName}.{file.ContentType}", stream);

                return(response.Skylink);
            }
        }
Ejemplo n.º 2
0
        public async Task UploadFileAsync()
        {
            string fileName = "test.txt";

            using (var fileStream = File.OpenRead(fileName))
            {
                var response = await _client.UploadFileAsync(fileName, fileStream);

                Assert.IsTrue(!string.IsNullOrEmpty(response.Skylink));
            }
        }
Ejemplo n.º 3
0
        private async Task <string?> SaveDocumentImage(byte[] img)
        {
            string?imgLink = null;

            if (img != null)
            {
                using (Stream stream = new MemoryStream(img))
                {
                    //Save preview image to Skynet file
                    var response = await client.UploadFileAsync("document.jpg", stream);

                    imgLink = response.Skylink;
                    Console.WriteLine("Image saved");
                }
            }

            return(imgLink);
        }
Ejemplo n.º 4
0
        public async Task <string> StoreMessage([FromBody] AddMessageRequest req)
        {
            string address = req.Address.ToLowerInvariant();

            string seed = $"{secretConfig.SkynetSeed}-{address}";
            var    key  = SiaSkynetClient.GenerateKeys(seed);

            var encrypted = Utils.Encrypt(System.Text.Encoding.UTF8.GetBytes(req.Message), key.privateKey);

            using (Stream stream = new MemoryStream(encrypted))
            {
                //Save data to Skynet file
                var response = await client.UploadFileAsync("secret.dat", stream);

                var link = response.Skylink;

                return(link);
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Upload(IFormFile file)
        {
            try
            {
                var result = await client.UploadFileAsync(file.FileName, file.OpenReadStream());

                return(Ok(new { Url = "https://siasky.net/" + result.Skylink }));

                //using (var stream = new MemoryStream())
                //{
                //    // Save the file
                //    file.CopyTo(stream);

                //    client.UploadFileAsync(file.FileName, file.OpenReadStream());

                //    return Ok(new { Url = url });
                //}
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Save current document
        /// </summary>
        /// <param name="fallbackTitle"></param>
        /// <returns></returns>
        public async Task SaveCurrentDocument(string fallbackTitle, byte[] img)
        {
            Error = null;
            if (CurrentDocument != null)
            {
                var existing = DocumentList.Where(x => x.Id == CurrentDocument.Id).FirstOrDefault();
                if (existing != null)
                {
                    DocumentList.Remove(existing);
                }

                var created = existing?.CreatedDate ?? DateTimeOffset.UtcNow;

                //Fix title if there is no title
                var title = CurrentDocument.Title;
                if (string.IsNullOrWhiteSpace(title))
                {
                    title = fallbackTitle;
                }
                if (string.IsNullOrWhiteSpace(title))
                {
                    title = "Untitled document " + created;
                }

                CurrentDocument.Title = title;

                DocumentSummary sum = new DocumentSummary()
                {
                    Id           = CurrentDocument.Id,
                    Title        = CurrentDocument.Title,
                    CreatedDate  = created,
                    ModifiedDate = DateTimeOffset.UtcNow
                };
                DocumentList.Add(sum);

                string?imgLink = null;
                if (img != null)
                {
                    using (Stream stream = new MemoryStream(img))
                    {
                        //Save preview image to Skynet file
                        var response = await client.UploadFileAsync("document.jpg", stream);

                        imgLink = response.Skylink;
                    }
                }
                sum.PreviewImage = imgLink;

                bool success = await SaveDocument(CurrentDocument);

                if (success)
                {
                    CurrentDocument = null;
                }
                else
                {
                    Error = "Unable to save document to Skynet. Please try again.";
                }

                //Save updated document list
                await SaveDocumentList(DocumentList);
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PayWith([FromBody] PayRequestVM model)
        {
            Guid uid;

            if (Guid.TryParse(model.Id, out uid))
            {
            }
            else
            {
                return(NotFound("Invalid uid"));
            }
            var order = await _unitOfWork.OrdersRepository.GetByIdAsync(uid);

            if (order == null)
            {
                return(NotFound());
            }

            if (order.Status == OrderStatuses.Initialized)
            {
                var merchant = await _unitOfWork.MerchantDetailssRepository.GetSingleAsync(ww => ww.MerchantId == order.MerchantId);

                var amountToChargeInUserSelectedCurrency = _assetManager.Convert(model.AssetId, order.PriceAssetId, order.PriceAmount);
                var txFee         = Math.Max(0.1M, 0.01M * amountToChargeInUserSelectedCurrency);
                var totalToCharge = amountToChargeInUserSelectedCurrency + txFee;
                order.UpdatedDate                = DateTime.UtcNow;
                order.CustomerAssetId            = model.AssetId;
                order.TxFeeInUsersCurrency       = txFee;
                order.TotalAmountInUsersCurrency = totalToCharge;
                order.Status       = OrderStatuses.Pending;
                order.WalletPaidTo = _orderService.PaymentWallets.First();
                order.Memo         = DateTime.UtcNow.ToString("MMyyyyddHHmmssff");
                order.WalletQrLink = _stellarSEP007GeneratorService.GenerateLink(new PaymentParameters
                {
                    Destination = order.WalletPaidTo,
                    Memo        = order.Memo,
                    AssetCode   = "", //asset.code
                    AssetIssuer = ""  //asset.Issuer
                });



                var _client = new SiaSkynetClient();

                string fileName = $"{order.MerchantId}_{order.MerchantOrderId}.html";
                string html     = @"<!doctype html>
<html>
	<head>
		<meta charset=utf-8>
		<title>Zarpay Receipt</title>
	<style>
	  h1 {
		font-size: 48px;
		font-weight: 500;
		margin-top: 40px;
		margin-bottom: 10px;
	  }
	  .bg-info {
		background-color: #bfbcbce8;
	}
	
	.text-white{
		color: white;
	}
	
	.px-4{
		padding-left : 1rem;
		padding-right: 1rem;
	}
	.px-4{
		padding-top : 1rem;
		padding-bottom: 1rem;
	}
	</style>
  </head>
	<body>
	    <center>
			<h1>Payment receipt!</h1>
			
			<table class=""table table-responsive "">
                    <tbody>
                        <tr>
                            <td class=""bg-info text-white px-4 text-right"">Date</td>
                            <td class=""px-4"">
                                {{date}}

                            </td>
                        </tr>
                        <tr>
                            <td class=""bg-info text-white px-4 text-right"">Processing Fee</td>
                            <td class=""px-4""> {{txfee}} XLM </td>
                        </tr>
                        <tr>
                            <td class=""bg-info text-white px-4 text-right"">Total Amount</td>
                            <td class=""px-4""> {{total}} XLM </td>
                        </tr>

                       
                    </tbody>
                </table>
			
		</center>
	
    </ body >
</ html > ";

                html = html.Replace("{{date}}", order.UpdatedDate.Value.ToShortDateString() + " " + order.UpdatedDate.Value.ToShortTimeString());
                html = html.Replace("{{txfee}}", txFee.ToString());
                html = html.Replace("{{total}}", totalToCharge.ToString());

                //using (var fileStream = System.IO.File.OpenRead(fileName))
                //{
                //    var response = await _client.UploadFileAsync(fileName, fileStream);

                //    var skylink = response.Skylink;
                //}

                using (var stream = GenerateStreamFromString(html))
                {
                    try
                    {
                        var response = await _client.UploadFileAsync(fileName, stream);

                        var skylink = response.Skylink;
                        order.ReceiptUrl = $"https://siasky.net/{skylink}";
                    }
                    catch (Exception ee)
                    {
                        _logger.LogError(ee, "Error in Genertin SkyLink");
                    }
                    //}
                }

                // probably adjust xpiry date
                await _unitOfWork.SaveChangesAsync();

                return(Ok(new
                {
                    Success = true,
                    Data = new
                    {
                        walletPaidTo = order.WalletPaidTo,
                        txFee,
                        totalAmountInUsersCurrency = Math.Floor(totalToCharge),
                        txFeeInUsersCurrency = txFee,
                        customerAssetAssetCode = order.CustomerAsset.AssetCode,
                        memo = order.Memo,
                        walletQrLink = order.WalletQrLink
                    }
                }));
            }
            else
            {
                return(View("InvalidOrder", order));
            }
            return(BadRequest(new
            {
                Success = false,
                Error = "Order already treated"
            }));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> test()
        {
            var _client = new SiaSkynetClient();

            var order = await _unitOfWork.Context.Order.FirstOrDefaultAsync();

            var amountToChargeInUserSelectedCurrency = 1400;
            var txFee         = Math.Max(0.1M, 0.01M * amountToChargeInUserSelectedCurrency);
            var totalToCharge = amountToChargeInUserSelectedCurrency + txFee;

            order.UpdatedDate = DateTime.UtcNow;

            order.TxFeeInUsersCurrency       = txFee;
            order.TotalAmountInUsersCurrency = totalToCharge;


            string fileName = $"{order.MerchantId}_{order.MerchantOrderId}.html";
            string html     = @"<!doctype html>
<html>
	<head>
		<meta charset=utf-8>
		<title>Zarpay Receipt</title>
	<style>
	  h1 {
		font-size: 48px;
		font-weight: 500;
		margin-top: 40px;
		margin-bottom: 10px;
	  }
	  .bg-info {
		background-color: #bfbcbce8;
	}
	
	.text-white{
		color: white;
	}
	
	.px-4{
		padding-left : 1rem;
		padding-right: 1rem;
	}
	.px-4{
		padding-top : 1rem;
		padding-bottom: 1rem;
	}
	</style>
  </head>
	<body>
	    <center>
			<h1>Payment receipt!</h1>
			
			<table class=""table table-responsive "">
                    <tbody>
                        <tr>
                            <td class=""bg-info text-white px-4 text-right"">Date</td>
                            <td class=""px-4"">
                                {{date}}

                            </td>
                        </tr>
                        <tr>
                            <td class=""bg-info text-white px-4 text-right"">Processing Fee</td>
                            <td class=""px-4""> {{txfee}} XLM </td>
                        </tr>
                        <tr>
                            <td class=""bg-info text-white px-4 text-right"">Total Amount</td>
                            <td class=""px-4""> {{total}} XLM </td>
                        </tr>

                       
                    </tbody>
                </table>
			
		</center>
	
    </ body >
</ html > ";

            html = html.Replace("{{date}}", order.UpdatedDate.Value.ToShortDateString() + " " + order.UpdatedDate.Value.ToShortTimeString());
            html = html.Replace("{{txfee}}", txFee.ToString());
            html = html.Replace("{{total}}", totalToCharge.ToString());


            using (var stream = GenerateStreamFromString(html)) {
                //using (var fileStream = System.IO.File.OpenRead(fileName))
                //{
                try
                {
                    var response = await _client.UploadFileAsync(fileName, stream);

                    var skylink = response.Skylink;
                    return(Ok(new { skylink }));
                }catch (Exception ee)
                {
                    _logger.LogError(ee, "Error in Test");
                }
                //}
            }

            return(Ok(new { Success = false }));
        }