I'm using this code while trying to insert data using Big Query.
Everything is running without any exceptions, but my table is empty.
What is the problem with my code?
string SERVICE_ACCOUNT_EMAIL = "MyAccount";
var certificate = new X509Certificate2(#"XXX.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL)
{
Scopes = new[] { BigqueryService.Scope.BigqueryInsertdata, BigqueryService.Scope.Bigquery }
}.FromCertificate(certificate));
// Create the service.
var service = new BigqueryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "test"
});
Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest tabreq = new Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest();
List<Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest.RowsData> tabrows = new List<Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest.RowsData>();
Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest.RowsData rd = new Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest.RowsData();
IDictionary<string, object> r = new Dictionary<string, object>();
r.Add("Key", "Value");
rd.Json = r;
tabrows.Add(rd);
tabreq.Rows = tabrows;
tabreq.Kind = "bigquery#tableDataInsertAllRequest";
service.Tabledata.InsertAll(tabreq, "xxx", "xxx", "xxx");
Your codes looks good, but the only one problem is that you need to send data, actually you are not sending any data, test this code and let me know (I created a table with two fields P1 and P2)
var logs = new List<TableDataInsertAllRequest.RowsData>();
var theLog = new TableDataInsertAllRequest.RowsData();
theLog.Json = new Dictionary<string, object>();
theLog.Json.Add("P1", "Hola");
theLog.Json.Add("P2", "Mundo");
logs.Add(theLog);
var service = GetBigQueryService();
var content = new TableDataInsertAllRequest();
content.Rows = logs;
content.Kind = "bigquery#tableDataInsertAllRequest";
content.IgnoreUnknownValues = true;
content.SkipInvalidRows = true;
var insertTask = service.Tabledata.InsertAll(content, "Your_Project_Id", "Your_DataSet", "Your_Table");
TableDataInsertAllResponse response = insertTask.Execute();
Related
So, I am trying to send some money over using NBitcoin, there is a step where i am failing and that is creating de bitcoin secret to sign the transaction, I have the address, and the ExtPrivKey but i haven't gotten any luck signing it, any recommendation, this is my code below.
var priv = mbwallet.SelectedWallet.PrivateKeys[0].ToWif();
//var ool = new BitcoinSecret(base58, App.Network);
var privkey = mbwallet.SelectedWallet.PrivateKeys[0].PrivateKey.GetBitcoinSecret(App.Network).ToWif();
var key = Key.Parse(privkey, App.Network);
var keysT = key.GetWif(App.Network);
//var myaddress = mbwallet.SelectedWallet.PrivateKeys[0].PrivateKey.PubKey.GetAddress(App.Network);
var myaddress = mbwallet.SelectedWallet.CurrentAddress;
string address = Address.Text;
var destination = BitcoinAddress.Create(address, App.Network);
decimal value = Convert.ToDecimal(Value.Text);
var coins2 = GetCoins(value);
TransactionBuilder txBuilder = new TransactionBuilder();
var tx = txBuilder.AddCoins(coins2)
.AddKeys(keysT)
.SetChange(myaddress)
.Send(destination, new Money(value, MoneyUnit.BTC))
.SendFees("0.0002");
//.BuildTransaction(true);
var tx2 = txBuilder.BuildTransaction(true);
//Console.WriteLine(txBuilder.Verify(tx));
var hello = tx2.ToHex();
var txRepo = new NoSqlTransactionRepository();
//txRepo.Put(tx.GetHash(), tx);
//Assert(txBuilder.Verify(tx)); //check fully signed
List<ICoin> GetCoins(decimal sendAmount)
{
//var mbwallet = (root.DataContext as MainWindowViewModel);
var amountMoney = new Money(sendAmount, MoneyUnit.BTC);
var client = new QBitNinjaClient(App.Network);
var txInAmount = Money.Zero;
var coins1 = new List<ICoin>();
foreach (var balance in client.GetBalance(mbwallet.SelectedWallet.CurrentAddress,//MBWallet.Wallet.Address,
true).Result.Operations)
{
var transactionId = balance.TransactionId;
var transactionResponse =
client.GetTransaction(transactionId).Result;
var receivedCoins = transactionResponse.ReceivedCoins;
foreach (Coin coin in receivedCoins)
{
if (coin.TxOut.ScriptPubKey ==
mbwallet.SelectedWallet.CurrentAddress.ScriptPubKey)//MBWallet.Wallet.BitcoinPrivateKey.ScriptPubKey) // this may not be necessary
{
coins1.Add(coin);
txInAmount += (coin.Amount as Money);
}
}
}
return coins1;
}
For what I see in the code you already add the private key to the builder so basically you only need to sign , something like this
Transaction signed = txBuilder.SignTransaction(tx2);
Error : Password Special Character issue in mongoDB
Code:
connstr="mongodb://test:test#123#67.186.193.192:27017/testdb"
Here i changed password "test#123" to "test%4123" . Because # ASCII code is %4
Now it is working fine.
MongoClient client = new MongoClient(connstr); //vss
var server = client.GetServer();
//server.Ping();
var db = client.GetDatabase(dbname);
List<KeyValuePair<string, string>> collections = new List<KeyValuePair<string, string>>();
var tableviewset = JArray.Parse(db.ListCollectionsAsync().Result.ToListAsync<BsonDocument>().Result.ToJson());
But my users will use different passwords like $,^,*,( ... etc. So in this situation what i do ?
You can do somthing like this , you can user MongoClientSettings for password and all other parameter.
private MongoClientSettings GetSecuritySettingForConnection()
{
MongoClientSettings settings = new MongoClientSettings();
settings.Server = new MongoServerAddress(host, port);
MongoIdentity identity = new MongoInternalIdentity(authenticationDatabase, userName);
MongoIdentityEvidence evidence = new PasswordEvidence(password);
settings.Credentials = new List<MongoCredential>()
{
new MongoCredential("SCRAM-SHA-1", identity, evidence)
};
settings.MaxConnectionIdleTime = new TimeSpan(0, 2, 0);
return settings;
}
After that You can this function over here:
var client = new MongoClient(GetSecuritySettingForConnection());
Let me know if any confusion.
var ec2Client = new AmazonEC2Client();
string amiID = "ami;
string keyPairName = "aaaa";
// List<string> groups = new List<string>() ;
var launchRequest = new RunInstancesRequest()
{
ImageId = amiID,
InstanceType = "tttt",
MinCount = 1,
MaxCount = 1,
KeyName = kkkk,
SubnetId = "bbbb",
};
How do I hard-code my access key and secret access key ?
var awsCreds = new BasicAWSCredentials("ACCESS_KEY", "SECRET_KEY");
var ec2Config = new AmazonEC2Config() {
// add configurations here,
// such as ServiceURL and RegionEndpoint
}
var ec2Client = new AmazonEC2Client(awsCreds, ec2Config);
Learn more:
AmazonEC2Client Class
AmazonEC2Config Class
Anyway, hard-coding access key and secret key is not recommended. Please be really cautious, especially when you are going to share your code to a public repository.
I am using paypal API for .NET to create payments.
My exact code in Console Application:
// Get a reference to the config
var config = ConfigManager.Instance.GetProperties();
// Use OAuthTokenCredential to request an access token from PayPal
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
var apiContext = new APIContext(accessToken);
var p = new Payment();
p.intent = "sale";
p.payer = new Payer();
p.payer.payment_method = "credit_card"; //paypal or credit_card
var t = new Transaction();
t.amount = new Amount();
t.amount.currency = "GBP";
t.amount.total = "10.00";
t.amount.details = new Details();
t.amount.details.subtotal = "6.00";
t.amount.details.tax = "2.00";
t.amount.details.shipping = "2.00";
t.item_list = new ItemList();
t.item_list.items = new List<Item>();
var i1 = new Item();
i1.quantity = "1";
i1.name = "OBJETO TESTE";
i1.price = "6.00";
i1.currency = "GBP";
i1.sku = "TESTE";
t.item_list.items.Add(i1);
var a = new ShippingAddress();
a.recipient_name = "ADDRESS";
a.line1 = "LINE1";
a.line2 = "LINE2";
a.city = "LONDOM";
a.country_code = "GB";
a.postal_code = "NW19EA";
t.item_list.shipping_address = a;
p.transactions = new List<Transaction>();
p.transactions.Add(t);
p.redirect_urls = new RedirectUrls();
p.redirect_urls.cancel_url = string.Format("{0}{1}", "http://localhost:3161/", "Order/CancelPayment");
p.redirect_urls.return_url = string.Format("{0}{1}", "http://localhost:3161/", "Order/CompletePayment");
var payment = Payment.Create(apiContext, p);
If I change payment method to paypal, its working. if I send credit_card I get error 500.
debug_id: 30e0f1bb08d3f
configuration: live
Merchants from UK cannot make Direct(Credit Card) Payments using REST API.
You will need to upgrade your account to PRO to make use of Direct Card Payments.
Only US merchants can make direct card payments in REST API without a PRO account.
i am trying to use google QPX Express API for ASP.NET in order to read flights with cheap price but stuck on the below code.please share me any idea .
// Passengers
PassengerCounts passengers = new PassengerCounts();
passengers.AdultCount = 2;
// Slice
List<SliceInput> slices = new List<SliceInput>();
SliceInput slice = new SliceInput();
slice.Origin = "ADD";
slice.Destination = "NBO";
slice.Date = "2015-10-29";
slices.Add(slice);
// Options request
TripOptionsRequest tripOptions = new TripOptionsRequest();
tripOptions.Passengers = passengers;
tripOptions.Solutions = 10;
tripOptions.Slice = slices;
Regards,
You need to send your request against the authenticated service and call execute.
QPXExpressService service = new QPXExpressService(new BaseClientService.Initializer()
{
ApiKey = "xxxx",
ApplicationName = "Daimto QPX Express Sample",
});
TripsSearchRequest x = new TripsSearchRequest();
x.Request = new TripOptionsRequest();
x.Request.Passengers = new PassengerCounts { AdultCount = 2 };
x.Request.Slice = new List<SliceInput>();
x.Request.Slice.Add(new SliceInput() { Origin = "ADD", Destination = "NBO", Date = "2015-10-29" });
x.Request.Solutions = 10;
var result = service.Trips.Search(x).Execute();