Crash in BOXKeychainItemWrapper.m - box-api

App crashes suddenly once in a while in method
resetKeychainItem
at line 210:
NSAssert( junk == noErr || junk == errSecItemNotFound, #"Problem deleting current dictionary." );
Is there any way to avoid this crash/Any update on this issue?
Method:
- (void)resetKeychainItem
{
#synchronized(self) {
OSStatus junk = noErr;
if (self.keychainItemData != nil)
{
NSMutableDictionary *tempDictionary = [self dictionaryToSecItemFormat:self.keychainItemData];
junk = SecItemDelete((CFDictionaryRef)tempDictionary);
NSAssert( junk == noErr || junk == errSecItemNotFound, #"Problem deleting current dictionary." );
// Default data for keychain item.
self.keychainItemData = [self defaultKeychainItemDataDictionaryWithIdentifier:self.identifier
accessGroup:self.accessGroup];
}
}
}

We'll respond through the issue you submitted in GitHub:
https://github.com/box/box-ios-sdk/issues/117

Related

Can I use duplicate IDs on multiple <template> fragments?

Why does HTML5 validation fail when having duplicate element IDs but on different <template>. I'm planning to use only one template at a time so the actual DOM ID won't be duplicated.
something like:
<template id="companyAccount">
<li><label>Company: <input type="text" id="account_name"></label></li>
<li><label>Street: <input id="account_street" ...
...
</template>
<template id="residentialAccount">
<li><label>Name: <input type="text" id="account_name"></label></li>
<li><label>Street: <input id="account_street" ...
...
</template>
<script>
...
let template = $(isResidential ? '#residentialAccount' : '#companyAccount').get(0).content;
$('#account_info').empty().append(template.cloneNode(true));
</script>
As TJBlackman mentioned each value for id attributes must be unique. However when working with code it's up to you to determine if the code being imported contains a duplicate id. Additionally I've pretty much stopped using validators for the most part as they aren't well maintained (and the W3C's CSS validator is atrocious) and the consoles, proper error handling and using the XML parser for HTML5 will tell you pretty much everything you need to know.
You have a couple of options. You can use data-account="residential" (don't make the mistake of using camelCasing as that will eventually put you in direct conflict with the standards bodies) and detect the attribute via document.querySelectorAll:
function $(o)
{
var a = true;
try {document.querySelectorAll(o);}
catch(err) {a = false; console.log('Error: "'+o+'" is not a valid CSS selector.'); sound.notice();}
return (a && document.querySelectorAll && document.querySelectorAll(o)) ? document.querySelectorAll(o) : false;
}
Usage: $('[data-account="residential"]')[0].length and $('[data-account="residential"]')[0].value.
Alternatively you can do what I do with my platform which has things tightly integrated though this is the function I use that you might decide to slim down for your specific purposes. You can use document.createTreeWalker and literally go through every single element to scan for walker.currentNode.hasAttribute('id') to test against document.getElementById. This code is used before importing XML in to the DOM on my platform:
/******** part of larger ajax() function ********/
if (xhr.readyState == 4 && xhr.status != 204)
{}
//This code occurs within the above condition.
var r = jax_id_duplication_prevention(xhr.responseXML,param_id_container_pos,id_container);
if (r)
{
if (param_id_container_pos=='after') {id_container.parentNode.insertBefore(xml.getElementsByTagName('*')[0],id_container.nextSibling);}
else if (param_id_container_pos=='before') {id_container.parentNode.insertBefore(document.importNode(xml.getElementsByTagName('*')[0],true),id_container);}
else if (param_id_container_pos=='first')
{
if (id_container.childNodes.length > 0) {id_container.insertBefore(document.importNode(xml.getElementsByTagName('*')[0],true),id_container.firstChild);}
else {id_container.appendChild(document.importNode(xml.getElementsByTagName('*')[0],true));}
}
else if (param_id_container_pos=='inside') {id_container.appendChild(document.importNode(xml.getElementsByTagName('*')[0],true));}
else if (param_id_container_pos=='replace') {id_container.parentNode.replaceChild(document.importNode(xml.getElementsByTagName('*')[0],true),id_container);}
else if (param_id_container_pos=='fragment')
{
if (option.fragment) {delete option.fragment;}
option.fragment = document.importNode(new DOMParser().parseFromString(xhr.responseText,'application/xml').childNodes[0],true);
if (id_container && typeof id_container == 'function') {id_container();}
}
else {alert('Error: unknown position to import data to: '+id_container_pos);}
}
/******** part of larger ajax() function ********/
function ajax_id_duplication_prevention(xml,param_id_container_pos,id_container)
{
var re = true;
if (typeof id_container == 'string' && id_container.length > 0 && id_(id_container)) {id_container = id_(id_container);}
if (typeof option.id_fade == 'string' && option.id_fade.length > 0 && id_(option.id_fade)) {element_del(option.id_fade); option.id_fade = '';}
if (typeof xml.firstChild.hasAttribute == 'function')
{
if (xml.firstChild.hasAttribute('id') && xml.firstChild.getAttribute('id').length > 0 && id_(xml.firstChild.getAttribute('id')) && id_(xml.firstChild.id).parentNode.id=='liquid') {change(xml.firstChild.id,'fade');}
if (xml.firstChild.hasAttribute('id') && xml.firstChild.getAttribute('id').length > 0 && id_(xml.firstChild.id) && !id_(xml.firstChild.id).parentNode.id=='liquid') {re = false;}
else if (typeof document.createTreeWalker=='function')
{
var idz = [];
try
{
var walker = document.createTreeWalker(xml,NodeFilter.SHOW_ELEMENT,null,false);
while (walker.nextNode())
{
if (walker.currentNode.hasAttribute('id') && walker.currentNode.getAttribute('id').length > 0)
{
if (walker.currentNode.id==undefined && walker.currentNode.nodeName.toLowerCase()=='parsererror') {console.log('Error: a parser error was detected.');}
else if (walker.currentNode.id==undefined) {alert('walker.currentNode.nodeName = '+walker.currentNode.nodeName+'\n\n'+document.serializeToString(xml));}
else
{
for (var i = 0; i<id_('liquid').childNodes.length; i++)
{
if (id_('liquid').childNodes[i].nodeType==1 && id_(walker.currentNode.id) && is_node_parent(walker.currentNode.id,id_('liquid').childNodes[i]) && (param_id_container_pos!='replace' || walker.currentNode.id!=id_container.id))
{
if (param_id_container_pos != 'replace' && id_container != walker.currentNode.id) {element_del(id_('liquid').childNodes[i]);}//If changing operator test: ajax('get','?ajax=1&web3_url=/'+url_section()+'/'+url_page(),'replace',push_current_id());
}
}
var n = id_(walker.currentNode.id);
if (in_array(walker.currentNode.id,idz))
{
var fd = new FormData();
fd.append('ajax','error_xml');
fd.append('post_error','Duplicate id <code>'+walker.currentNode.id+'</code>.');
fd.append('post_url',url_window().split(url_base())[1].split('?')[0]);
fd.append('post_xml',new XMLSerializer().serializeToString(xml));
if (fd) {ajax('post',path+'/themes/',fd);}
modal.alert('Error: can not import XML, the id \''+walker.currentNode.id+'\' was detected twice in the layer being imported. Duplicated ID\'s break expected functionality and are illegal. While the XML content was not imported it is still possible that the related request was successful. It is possible to override this problem by simply doing a full request (press the Go button in your browser\'s graphic user interface) however if the id is referenced programmatically the website may exhibit unusual behavior.');
break;
setTimeout(function()
{
history.back();
push_reload();
console.log('Developer: duplicate id '+walker.currentNode.id+' was encounterted.');
if (status >= 9) {modal.xml('Duplicate ID Error', '%3Cp%3EError%3A%20the%20id%20%3Ccode%3E'+walker.currentNode.id+'%3C%2Fcode%3E%20occurred%20twice%20and%20therefore%20the%20page%20can%20not%20be%20viewed.%3C%2Fp%3E%3Cp%3EFor%20debugging%20and%20fixing%20purposes%20you%20should%20consider%20opening%20the%20URL%20in%20a%20new%20tab.%3C%2Fp%3E%3Cdiv%20class%3D%22center%20margin%22%3E%3Cinput%20onclick%3D%22modal.close()%3B%22%20tabindex%3D%223%22%20type%3D%22button%22%20value%3D%22Close%22%20%2F%3E%3C%2Fdiv%3E');}
else {modal.xml('Duplicate ID Error', '%3Cp%3EError%3A%20the%20id%20%3Ccode%3E'+walker.currentNode.id+'%3C%2Fcode%3E%20occurred%20twice%20and%20therefore%20the%20page%20can%20not%20be%20viewed.%3C%2Fp%3E%3Cdiv%20class%3D%22center%20margin%22%3E%3Cinput%20onclick%3D%22modal.close()%3B%22%20tabindex%3D%223%22%20type%3D%22button%22%20value%3D%22Close%22%20%2F%3E%3C%2Fdiv%3E');}
re = false;
},4000);
}
else {idz.push(walker.currentNode.id);}
}
if (id_(walker.currentNode.id) && (param_id_container_pos!='replace' && walker.currentNode.id!=id_container.id && !is_node_parent(walker.currentNode.id,id_container)))
{//ajax replace (carousel loader) complications if changed.
re = false;
modal.alert('Error: unable to import page, the id \''+walker.currentNode.id+'\' already exists in the DOM.');
break;
}
}
}
}
catch (err) {}//IE9
}
}
return re;
}
Regardless of how you approach addressing the issue it is not one addressed by the standards bodies and must be explicitly handled by developers. Failure to handle duplicate id attribute/values will result in the wrong element being chosen at some point which may quietly accrue compromised/malformed data over time that no one might notice for years and thus could easily hinder if not outright destroy any business relations effected by it. Good luck!

Multiple APIs are called with (change) in angular

On selecting any date and hitting enter an API call should be made. And there's a x icon in the input on clicking it, it should call the API with date 01/01/12 Also this has feature like if you type 2/3 and hit enter it will automatically make it 02/03/20. The problem is if the input is empty and if I hit Enter same API calls are made thrice.
But the feature should be like if you select a date then without hitting Enter an API call should be made. I can't just use change function because if 2/3 is typed and Tab is pressed then it will not adjust the date automatically and also multiple API calls on hitting Enter. Is there a way to stop multiple API calls?
(change)="startDate($event)" (keydown.enter)="CallAPI($event)"
startDate(event) {
if (event.target.value == '' || event.target.value == null)
this.cutoverFilterApi(event)
}
CallAPI(event) {
let data = event.target.value;
if (data != '' && data != null && data != "NaN/NaN/NaN") {
data = data;
} else {
data = "01/01/12";
}
this.httpService.getData('PATH' + data).subscribe((response: any) => {
this.dateChangeData = response.results;
this.rowData = response.results;
this.gridApi.setRowData(this.rowData);
});
}
You could keep the last valid value and avoid request if it is the same.
Something like this,
lastDate = null; // <- variable to keep last value
CallAPI(event) {
let data = event.target.value;
if (data != '' && data != null && data != "NaN/NaN/NaN") {
data = data;
} else {
data = "01/01/12";
}
// check if data is not the same as last request
if (this.lastDate === data) {
return;
}
this.lastDate = data; // <- update new request date
this.httpService.getData('PATH' + data).subscribe((response: any) => {
this.dateChangeData = response.results;
this.rowData = response.results;
this.gridApi.setRowData(this.rowData);
});
}
You can use this
(dateInput)="addEvent('input', $event)" (dateChange)="addEvent('change', $event)"
instead of
(change)="startDate($event)" (keydown.enter)="CallAPI($event)"
I have an example of angular material datepicker, which will make your code easier.
Reference link
I hope it is helpful for you. :)

Yii2 update data by excel file long load time

I'm using Yii2 to create a tool to manage work load of my team. So everyday i need to import large amount of data (larger than 5k) to db using Excel and the loadtime usually take about 20-30 mins. Is there any way to improve the load time?
Please help me with this.
Here's the code I used:
public function actionImportExcel()
{
$inputFile = 'uploads/importexcel/import.csv';
try{
$inputFileType = \PHPExcel_IOFactory::identify($inputFile);
$objReader = \PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFile);
}catch(Exception $e)
{
die('Error');
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for( $row = 1; $row <= $highestRow; $row++)
{
$rowData = $sheet->rangeToArray('A'.$row.':'.$highestColumn.$row,NULL,TRUE,FALSE);
if($row == 1)
{
continue;
}
$test = $rowData[0][0];
$ext = Sku3d::find()->where(['sku' => $test])->exists();
if($ext){
$one = Sku3d::find()->where(['sku' => $test])->one();
$one->status = $rowData[0][14];
$one->round = $rowData[0][19];
$one->source = $rowData[0][29];
$one->modeler = $rowData[0][30];
if($one->datesubmit == NULL || $one->datesubmit == ""){
$one->save();
}else{
$day = DateTime::createFromFormat('Y-m-d', $one->datesubmit);
$one->monthsubmit=date("Y-m-t", strtotime($one->datesubmit));
$one->save();
}
if($rowData[0][14] == "Approved"){
$one->approvedate = $rowData[0][16];
if($one->approvedate == NULL || $one->approvedate == ""){
$one->save();
}else{
$one->approvemonth=date("Y-m-t", strtotime($one->approvedate));
$one->save();
}
}else{
$one->approvedate = Null;
$one->approvemonth = Null;
}
$one->save();
// print_r($one->getErrors());
// die;
}
else{
}
}
}
Thank you!
You're executing very similar queries when you check if the row already exist and when you are loading it from DB.
If you are expecting more new records then existing one, you can load all skus to the array before the cycle, then check if the sku is among existing.
Before the for cycle:
$existingSkus = Sku3d::find()
->select(['sku'])
->indexBy('sku')
->column();
Then inside your for cycle:
if (array_key_exists($test, $existingsSkus)) {
$one = Sku3d::find()->where(['sku' => $test])->one();
// ...
}
If you are expecting that most of rows in import already exist in DB and you are going to update them, then you can skip the exists() query and load the data directly.
$one = Sku3d::find()->where(['sku' => $test])->one();
if(!empty($one)) {
// ... update existing row loaded in $one
} else {
// ... create new row
}
Another problem in your code is that you call the save multiple times for each updated row.
if($one->datesubmit == NULL || $one->datesubmit == ""){
$one->save(); //first save
} else {
// ...
$one->save(); //first save - else branch
}
// ...
if ($rowData[0][14] == "Approved"){
$one->approvedate = $rowData[0][16];
if ($one->approvedate == NULL || $one->approvedate == ""){
$one->save(); // second save
} else {
$one->approvemonth=date("Y-m-t", strtotime($one->approvedate));
$one->save(); //second save - else branch
}
}else{
$one->approvemonth = Null;
}
$one->save(); //third save when the previous condition is true, second save otherwise
Do you really need to call the save before you are done with all changes? Doing one save at the end will be faster then doing 2 or 3 saves for each row.
Also if there are many new rows in each import, you might want to use batch insert instead of creating and saving new model for each row.

Auto manage and protect Created\Updated fields with Entity Framework 5

I want so every added\changed record will have a time stamp of creation\change.
But - so it will be easy to embed and easy to manage - automatically.
Overwrite the 'DbContext' class or embed this in the '.tt' file (Codefirst \ DBFirst)
The code assume so you have the fields 'CreatedOn'\'ModifiedOn' inside the POCO.
If you don't have them, or you have only one - the code will work fine.
Be aware! If you use a extension (as this one) so allow you to do batch updates or changes from a stored procedure - this will not work
EDIT:
I found the source of my inspiration - thanks 'Nick' here
public override int SaveChanges()
{
var context = ((IObjectContextAdapter)this).ObjectContext;
var currentTime = DateTime.Now;
var objectStateEntries = from v in context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified)
where v.IsRelationship == false && v.Entity != null
select v;
foreach (var entry in objectStateEntries)
{
var createdOnProp = entry.Entity.GetType().GetProperty("CreatedOn");
if (createdOnProp != null)
{
if (entry.State == EntityState.Added)
{
if (createdOnProp != null)
{
createdOnProp.SetValue(entry.Entity, currentTime);
}
}
else
{
Entry(entry.Entity).Property("CreatedOn").IsModified = false;
}
}
var modifiedOnProp = entry.Entity.GetType().GetProperty("ModifiedOn");
if (modifiedOnProp != null)
{
modifiedOnProp.SetValue(entry.Entity, currentTime);
}
}
return base.SaveChanges();
}

Entity Framework SaveChanges function won't commit my changes

I have an initial selection which I place into list. I use the list to loop through each record and where it meets certain criteria I run trough a series of inserts, deletes and updates. Finally call the SaveChanges() method to commit changes.
The code runs through without raising an exception but no changes reflect in the database. I have been searching the web with no luck.
I'm using VS2008 with SQL2008 backend.
Please help?
using (SMSEntities db = new SMSEntities())
{
try
{
//Get SMS's to send from Inbox
List<Inbox> tmpInbox = (from c in db.Inboxes where c.Status != "NEW" && c.Status != "SUCCESS" select c).ToList();// new { Inbox.InboxID, Inbox.StatusTrackingID, Inbox.Status, Inbox.NoOfAttempts, Inbox.CellNo, Inbox.SourceCellNo, Inbox.Header, Inbox.Message, Inbox.MessageDate, Inbox.AccountID, Inbox.LastAttemptDate }).ToList();
foreach (Inbox tmpInboxIndex in tmpInbox)
{
bool success = false;
//Check status here
string SentStatus = CheckSMSSentToProvider(tmpInboxIndex.StatusTrackingID);
// Define a transaction scope for the operations.
using (TransactionScope transaction = new TransactionScope())
{
try
{
if ((SentStatus == "DELIVERED") || (SentStatus == "NOTFOUND") || (SentStatus == "DELETED") || (SentStatus == "REJECTED") || (SentStatus == "UNDELIVERED"))
{
//Insert the Log row
Log newLog = new Log();
newLog.InboxID = tmpInboxIndex.InboxID;
newLog.CellNo = tmpInboxIndex.CellNo;
newLog.SourceCellNo = tmpInboxIndex.SourceCellNo;
newLog.Message = tmpInboxIndex.Message;
newLog.Header = tmpInboxIndex.Header;
newLog.MessageDate = tmpInboxIndex.MessageDate;
newLog.AccountID = tmpInboxIndex.AccountID;
newLog.ProcessedDate = DateTime.Now;
newLog.Status = tmpInboxIndex.Status;
newLog.StatusTrackingID = tmpInboxIndex.StatusTrackingID;
newLog.NoOfAttempts = tmpInboxIndex.NoOfAttempts;
newLog.LastAttemptDate = tmpInboxIndex.LastAttemptDate;
db.Logs.AddObject(newLog);
//Delete the Inbox row
if (tmpInbox != null)
{
var deleteInbox = (from c in db.Inboxes where c.InboxID == tmpInboxIndex.InboxID select c).FirstOrDefault();
if (deleteInbox != null)
{
db.DeleteObject(deleteInbox);
//db.SaveChanges(SaveOptions.DetectChangesBeforeSave);
}
}
}
else
{
//Update inbox status
var tmpUpdateInbox = (from c in db.Inboxes where c.InboxID == tmpInboxIndex.InboxID select c).FirstOrDefault();
tmpUpdateInbox.Status = SentStatus;
tmpUpdateInbox.NoOfAttempts = tmpInboxIndex.NoOfAttempts + 1;
tmpUpdateInbox.LastAttemptDate = DateTime.Now;
//db.SaveChanges(SaveOptions.DetectChangesBeforeSave);
}
// Mark the transaction as complete.
transaction.Complete();
success = true;
//break;
}
catch (Exception ex)
{
// Handle errors and deadlocks here and retry if needed.
// Allow an UpdateException to pass through and
// retry, otherwise stop the execution.
if (ex.GetType() != typeof(UpdateException))
{
Console.WriteLine("An error occured. "
+ "The operation cannot be retried."
+ ex.Message);
break;
}
// If we get to this point, the operation will be retried.
}
}
if (success)
{
// Reset the context since the operation succeeded.
//db.AcceptAllChanges();
db.SaveChanges();
}
}
// Dispose the object context.
db.Dispose();
}
catch (Exception exp)
{
throw new Exception("ERROR - " + exp.Message.ToString(), exp);
}
}
return true;
Regards,
GPR.
Are you using a local database file? You may be looking for changes in the wrong place. By default, when the program starts, VS copies the database file into the debug or release folder. Then the program runs and changes are made, and saved, to the file in the debug or release folder. The program ends, and when you look at the database in your source folder it looks the same. You can change the connection string in the app.config to use an absolute path to avoid this.
See http://blogs.msdn.com/b/smartclientdata/archive/2005/08/26/456886.aspx for more info
The TransactionScope is useless if you do not put the call to SaveChanges into it.
Either move the call to SaveChanges into it or remove the TransactionScope completely.