I have recently come across an issue that I cannot open my Pkpass which is created using dotnet-passbook version 3.2.0.
The Pkpass created locally can be opened fine and the issue is with the Pkpass created in the server.
I have even tried to upload the Pkpass from the server to the validator but the validator just returns “Failed to process the Pkpass file.”
Below is my code snapshot for building the Pkpass:
public static FileContentResult GetPass(Shopper account)
{
try {
if (account == null)
{
return null;
}
PassGenerator generator = new PassGenerator();
PassGeneratorRequest request = new PassGeneratorRequest();
// "webServiceURL" : "https://example.com/passes/",
// "authenticationToken" : "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc",
// Product info
request.PassTypeIdentifier = "PassTypeIdentifier";
request.TeamIdentifier = "TeamIdentifier";
request.SerialNumber = "SerialNumber";
request.Description = "Description";
request.OrganizationName = "OrganizationName";
request.LogoText = "LogoText";
// Add the installed certificate and it's thumbprint
WebClient webClient = new WebClient();
try
{
X509KeyStorageFlags flags = X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable;
request.PassbookCertificate = new X509Certificate2(webClient.DownloadData(CertificatesBucket + "/Certificates.p12"), S3_AppleCertificatePassword, flags);
}
catch (Exception e)
{
throw new Exception("Error occurs when geting certificate: " + e.Message);
}
// Add Apple's WWDRCA certificates
try
{
request.AppleWWDRCACertificate = new X509Certificate2(webClient.DownloadData(CertificatesBucket + "/AppleWWDRCAG2.cer"));
}
catch (Exception e)
{
throw new Exception("Error occurs when geting AppleWWDRCCA: " + e.Message);
}
// override icon and icon retina
try
{
request.Images.Add(PassbookImage.Logo, webClient.DownloadData(AppleImageBucket + "/logo.png"));
request.Images.Add(PassbookImage.Icon, webClient.DownloadData(AppleImageBucket + "/icon.png"));
request.Images.Add(PassbookImage.Icon2X, webClient.DownloadData(AppleImageBucket + "/icon%402x.png"));
request.Images.Add(PassbookImage.Strip, webClient.DownloadData(AppleImageBucket + "/strip.png"));
request.Images.Add(PassbookImage.Strip2X, webClient.DownloadData(AppleImageBucket + "/strip%402x.png"));
}
catch (Exception e)
{
throw new Exception("Error occurs when geting images: " + e.Message);
}
// Add barcode
request.AddBarcode(BarcodeType.PKBarcodeFormatCode128, account.Id, "ISO-8859-1");
// Link the pass to an existing app using the app's Apple ID.
request.AssociatedStoreIdentifiers.Add(121212);
request.Style = PassStyle.StoreCard;
// Add fields
request.AddHeaderField(new StandardField("StandardField", "TEXT", account.Id));
request.AddSecondaryField(new StandardField("StandardField", "TEXT", account.Name));
request.AddSecondaryField(new StandardField("StandardField", "TEXT", "TEXT"));
request.TransitType = TransitType.PKTransitTypeAir;
byte[] generatedPass = generator.Generate(request);
//throw new Exception("apple generatedPass: " + JsonTransHelper.SerializeObject(generatedPass));
return new FileContentResult(generatedPass, "application/vnd.apple.pkpass");
}
catch (Exception ex)
{
throw new Exception("Error occurs when creating apple pass: " + ex.Message);
}
}
}
}
Any help greatly appreciated!
It is caused by AWS API Gateway. If you running this on a Lambda function try to invoke it directly.
Offset to Central Directory cannot be held in an Int64 .net core
I have several CMIS requests and need to do them in parallel. But when I try it (using CompletableFutire or stream().parallel(), I got:
java.util.concurrent.ExecutionException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
For that queries I do :
#Autowired
#Qualifier("searchService")
private org.alfresco.service.cmr.search.SearchService searchService;
....
searchService.query(searchParameters);
What am I doing wrong?
The following code is one of my attempt to perform CMIS in parallel:
List<CompletableFuture<Form14Row>> requests = Arrays.asList(setUpRow(1,beginnigString, endString, docType, NDBaseDocumentModel.DOC_KIND_GOST_R, searchParameters, "ГОСТ Р"),
setUpRow(2,beginnigString, endString, docType, NDBaseDocumentModel.DOC_KIND_GOST, searchParameters, "ГОСТ") );
CompletableFuture<Void> allRequests = CompletableFuture.allOf(
requests.toArray(new CompletableFuture[requests.size()])
);
CompletableFuture<List<Form14Row>> allPageContentsFuture = allRequests.thenApply(v -> {
return requests.stream()
.map(pageContentFuture -> pageContentFuture.join())
.collect(Collectors.toList());
});
//java.util.concurrent.ExecutionException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
try {
List<Form14Row> rowss = allPageContentsFuture.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
...
private CompletableFuture<Form14Row> setUpRow(Integer index, String beginnigString, String endString, String docType, String docKind, SearchParameters searchParameters, String groupPosition) {
return CompletableFuture.supplyAsync(() -> {
String cql = "SELECT p.cmis:objectId FROM ecmcnddoc:common_attr_aspect AS d JOIN ecmcnddoc:biblio_attr_aspect AS p ON d.cmis:objectId = p.cmis:objectId JOIN ecmcnddoc:reg_attr_aspect AS s ON s.cmis:objectId = p.cmis:objectId JOIN ecmcnddoc:spec_attr_aspect AS asp ON asp.cmis:objectId = p.cmis:objectId WHERE p.cmis:objectTypeId='D:" + docType + "' AND d.ecmcnddoc:doc_kind_cp_ecmcdict_value='" + docKind + "' AND p.ecmcnddoc:biblio_fond='" + NDBaseDocumentModel.BIBLIO_FUND + "' AND s.ecmcnddoc:doc_reg_date >= TIMESTAMP '" + beginnigString + "T00:00:00.000+00:00' AND s.ecmcnddoc:doc_reg_date <= TIMESTAMP '" + endString + "T00:00:00.000+00:00' AND (asp.ecmcnddoc:doc_status='draft' OR asp.ecmcnddoc:doc_status='actual')";
searchParameters.setQuery(cql);
ResultSet rs = customSearchService.query(searchParameters); // Exception here
Form14Row isoRow = new Form14Row();
isoRow.setCount(rs.length());
isoRow.setIndex(index);
isoRow.setKindName(groupPosition);
return isoRow;
});
}
Everything works fine in serial execution
Security context is binded to main thread and is not propagated to children threads, you would need to set one.
Maybe you could try to adapt this snippet:
CompletableFuture.runAsync(() -> {
try {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(userName);
// Do your stuff...
} finally {
AuthenticationUtil.popAuthentication();
}
});
I want to create a simple news feed, I use web API to get the news updates, users can use combox select category (world news & sports news),and the news will be auto updated every 5 seconds, if I only select once, the news feed can auto updated and repeat, But if I change the selection, it start to show me both categories. here is my code
public async void NewsRepeat()
{
RootObject2 myNews = await NewsProxy.GetNews();
RootObject3 mySportNews = await sportsNewsProxy.GetSportNews();
if (newsTpye.SelectedIndex==0)
{
for ( k = 0; k <= 8; k++)
{
newsImage.Source = new BitmapImage(new Uri(myNews.articles[k].urlToImage, UriKind.Absolute));
showTime.Text = myNews.articles[k].publishedAt.ToString();
showDescription.Text = "(" + myNews.source + "): " + myNews.articles[k].description;
await Task.Delay(5000);
}
}
else if (newsTpye.SelectedIndex==1)
{
for (k = 0; k <= 8; k++)
{
newsImage.Source = new BitmapImage(new Uri(mySportNews.articles[k].urlToImage, UriKind.Absolute));
showTime.Text = mySportNews.articles[k].publishedAt;
showDescription.Text = "(" + mySportNews.source + "): " + mySportNews.articles[k].description;
await Task.Delay(5000);
}
}
NewsRepeat();
}
private void newsType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NewsRepeat();
}
Your code runs continuously / infinite loops. NewsRepeat never finishes - so when you change selection your now running two instances of NewsRepeat side by side. Change it again and you're running three, and so on.
On SelectionChanged you want to somehow stop the previous instance of NewsRepeat from running.
(Also, creating BitmapImages in the ViewModel is a bad idea generally - bind the directly in XAML to the URL property - Windows will carry out some performance and memory enhancements for you)
One possible solution is to use a CancellationTokenSource, which is a very simple object you can use to manually throw OperationCanceledException's when you deem it necessary (
frequently used as a pattern to cancel async Tasks). Keep it mind it does not work automatically - it's something you have to handle.
CancellationTokenSource cts = null;
public async void NewsRepeat()
{
cts?.Cancel();
try
{
var localCts = cts = new CancellationTokenSource();
RootObject2 myNews = await NewsProxy.GetNews();
RootObject3 mySportNews = await sportsNewsProxy.GetSportNews();
localCts.Token.ThrowIfCancellationRequested();
if (newsTpye.SelectedIndex == 0)
{
for (k = 0; k <= 8; k++)
{
newsImage.Source = new BitmapImage(new Uri(myNews.articles[k].urlToImage, UriKind.Absolute));
showTime.Text = myNews.articles[k].publishedAt.ToString();
showDescription.Text = "(" + myNews.source + "): " + myNews.articles[k].description;
await Task.Delay(5000);
localCts.Token.ThrowIfCancellationRequested();
}
}
else if (newsTpye.SelectedIndex == 1)
{
for (k = 0; k <= 8; k++)
{
newsImage.Source = new BitmapImage(new Uri(mySportNews.articles[k].urlToImage, UriKind.Absolute));
showTime.Text = mySportNews.articles[k].publishedAt;
showDescription.Text = "(" + mySportNews.source + "): " + mySportNews.articles[k].description;
await Task.Delay(5000);
localCts.Token.ThrowIfCancellationRequested();
}
}
NewsRepeat();
}
catch (OperationCanceledException)
{
// Swallow this exception only - this is probably
// the one we've thrown ourselves
}
}
private void newsType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NewsRepeat();
}
I have developed a J2ME App which i tried in Blackberry device. Application launched successfully but when i am making a network call its throwing exception. Currently the Blackberry device which i own doesn't have BIS(Blackberry Internet Service) plan enabled. I am testing it in Blackberry OS version less than six.
Here is my Coding for HTTP Get Method
public static Vector httpGet(String uri, String param) {
Vector buf = new Vector();
try {
String parameter = param;
String url = uri + "?" + parameter;
System.out.println("Passed URL:" + uri + "?" + parameter);
HttpConnection hc = (HttpConnection) Connector.open(url);
hc.setRequestMethod(HttpConnection.GET);
Commons.print(hc.getResponseCode() + ":" + HttpConnection.HTTP_OK
+ ":" + hc.getResponseMessage());
if (hc.getResponseCode() >= 400) {
hc = null;
return null;
}
InputStream inn = hc.openInputStream();
if (inn == null)
return null;
DataInputStream in = new DataInputStream(inn);
String st = "";
while ((st = readLine(in)) != null) {
buf.addElement(st);
}
if (in != null) {
in.close();
}
if (hc != null) {
hc.close();
setStatus(DataMembers.okStatus);
}
} catch (Exception ex) {
System.out.println("Error:" + ex.toString());
setStatus(DataMembers.failStatus);
buf = null;
}
return buf;
}
Does Blackberry requires BIS connection for making a network call? I am not appending any manual connection String to my URL.
I am receiving an error
Incorrect syntax near ?
when trying to use a update query function. The code is from SagePay http://www.sagepay.co.uk/file/12136/download-document/DotNetkit%201.2.6.7%20-%202014-08-14.zip?token=BJFwtM7qNnnm5ZCc_l_dOhq4INB0cQTPCxCd5JOpeh4 and relates to their server InFrame implementation.
As far as I can see the order is being passed correctly, and the list of fields, match the database, just not understanding why I am seeing this error. The code was originally created for MySQL but have had to adapt to SQL Server.
I've tried debugging, but cannot actually see what is being committed to the SQL Server from cmd.ExecuteNonQuery(); any help would be much appreciated, here is the code:
private static readonly List<String> FieldNames = new List<String>
{
VendorTxCodeField, AddressResultField, AddressStatusField, AmountField, AvsCv2Field, BankAuthCodeField, BasketField,
BillingFirstnamesField, BillingSurnameField, BillingPhoneField, BillingAddress1Field, BillingAddress2Field, BillingCityField,
BillingPostCodeField, BillingStateField, BillingCountryField, DeclineCodeField, DeliveryFirstnamesField, DeliverySurnameField, DeliveryPhoneField,
DeliveryAddress1Field, DeliveryAddress2Field, DeliveryCityField, DeliveryPostCodeField, DeliveryStateField, DeliveryCountryField,
CapturedAmountField, CardTypeField, CavvField, CurrencyField, CustomerEmailField, Cv2ResultField, ExpiryDateField, FraudResponseField,
GiftAidField, Last4DigitsField, LastUpdatedField, PayerIdField, PayerStatusField, PostCodeResultField,
RelatedVendorTxCodeField, SecurityKeyField, StatusField, StatusMessageField, SurchargeField, ThreeDSecureStatusField,
TransactionTypeField, TxAuthNoField, TokenIdField, VpsTxIdField
};
public static bool UpdateOrder(Order order, string vendorTxCode)
{
var result = false;
SqlConnection conn = null;
try
{
conn = new SqlConnection(ConnectionString);
conn.Open();
var cmd = new SqlCommand
{
Connection = conn, CommandText = "UPDATE Orders SET " + string.Join(",", FieldNames.Select(field => field + "=?" + field).ToList()) + " WHERE " + VendorTxCodeField + " =?" + VendorTxCodeField
};
cmd.Prepare();
AddOrderParameters(cmd, order);
cmd.ExecuteNonQuery();
result = true;
}
catch (SqlException ex)
{
Console.WriteLine("Error: {0}", ex);
}
finally
{
if (conn != null)
{
conn.Close();
}
}
return result;
}
private static void AddOrderParameters(SqlCommand command, Order order)
{
command.Parameters.AddWithValue(VendorTxCodeField, order.VendorTxCode);
command.Parameters.AddWithValue(AddressResultField, order.AddressResult);
command.Parameters.AddWithValue(AddressStatusField, order.AddressStatus);
command.Parameters.AddWithValue(AmountField, order.Amount);
command.Parameters.AddWithValue(AvsCv2Field, order.AvsCv2);
command.Parameters.AddWithValue(BankAuthCodeField, order.BankAuthCode);
command.Parameters.AddWithValue(BasketField, order.Basket);
command.Parameters.AddWithValue(BillingAddress1Field, order.BillingAddress1);
command.Parameters.AddWithValue(BillingAddress2Field, order.BillingAddress2);
command.Parameters.AddWithValue(BillingCityField, order.BillingCity);
command.Parameters.AddWithValue(BillingCountryField, order.BillingCountry);
command.Parameters.AddWithValue(BillingFirstnamesField, order.BillingFirstnames);
command.Parameters.AddWithValue(BillingPhoneField, order.BillingPhone);
command.Parameters.AddWithValue(BillingPostCodeField, order.BillingPostCode);
command.Parameters.AddWithValue(BillingStateField, order.BillingState);
command.Parameters.AddWithValue(BillingSurnameField, order.BillingSurname);
command.Parameters.AddWithValue(CapturedAmountField, order.CapturedAmount);
command.Parameters.AddWithValue(CardTypeField, order.CardType);
command.Parameters.AddWithValue(CavvField, order.Cavv);
command.Parameters.AddWithValue(CurrencyField, order.Currency);
command.Parameters.AddWithValue(CustomerEmailField, order.CustomerEmail);
command.Parameters.AddWithValue(Cv2ResultField, order.Cv2Result);
command.Parameters.AddWithValue(DeclineCodeField, order.DeclineCode);
command.Parameters.AddWithValue(DeliveryAddress1Field, order.DeliveryAddress1);
command.Parameters.AddWithValue(DeliveryAddress2Field, order.DeliveryAddress2);
command.Parameters.AddWithValue(DeliveryCityField, order.DeliveryCity);
command.Parameters.AddWithValue(DeliveryCountryField, order.DeliveryCountry);
command.Parameters.AddWithValue(DeliveryFirstnamesField, order.DeliveryFirstnames);
command.Parameters.AddWithValue(DeliveryPhoneField, order.DeliveryPhone);
command.Parameters.AddWithValue(DeliveryPostCodeField, order.DeliveryPostCode);
command.Parameters.AddWithValue(DeliveryStateField, order.DeliveryState);
command.Parameters.AddWithValue(DeliverySurnameField, order.DeliverySurname);
command.Parameters.AddWithValue(ExpiryDateField, order.ExpiryDate);
command.Parameters.AddWithValue(FraudResponseField, order.FraudResponse);
command.Parameters.AddWithValue(GiftAidField, order.GiftAid);
command.Parameters.AddWithValue(Last4DigitsField, order.Last4Digits);
command.Parameters.AddWithValue(LastUpdatedField, order.LastUpdated);
command.Parameters.AddWithValue(PayerIdField, order.PayerId);
command.Parameters.AddWithValue(PayerStatusField, order.PayerStatus);
command.Parameters.AddWithValue(PostCodeResultField, order.PostCodeResult);
command.Parameters.AddWithValue(RelatedVendorTxCodeField, order.RelatedVendorTxCode);
command.Parameters.AddWithValue(SecurityKeyField, order.SecurityKey);
command.Parameters.AddWithValue(StatusField, order.Status);
command.Parameters.AddWithValue(StatusMessageField, order.StatusMessage);
command.Parameters.AddWithValue(SurchargeField, order.Surcharge);
command.Parameters.AddWithValue(ThreeDSecureStatusField, order.ThreeDSecureStatus);
command.Parameters.AddWithValue(TokenIdField, order.TokenId);
command.Parameters.AddWithValue(TransactionTypeField, order.TransactionType);
command.Parameters.AddWithValue(TxAuthNoField, order.TxAuthNo);
command.Parameters.AddWithValue(VpsTxIdField, order.VpsTxId);
}
You have to use # for sql-parameters. Maybe this fixes your issue although i must admit that i don't understand the query because the column-names are the same as the values. However ...
string sql = #"UPDATE Orders SET {0}
Where {1}=#{1};";
sql = string.Format(sql
, string.Join(",", FieldNames.Select(field => string.Format("{0}=#{0}", field)))
, VendorTxCodeField);
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
for (int i = 0; i < FieldNames.Count; i++)
{
cmd.Parameters.AddWithValue(FieldNames[i], FieldNames[i]);
}
// open connection and execute the command...
}