Skip to content

Commit

Permalink
Added the option during batch-write to skip or re-try when a write er…
Browse files Browse the repository at this point in the history
…ror is encountered
  • Loading branch information
kevinbrewster committed Feb 7, 2013
1 parent cb19fc9 commit 6e16405
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
1 change: 0 additions & 1 deletion Classes/AppDelegate/AppDelegate.m
Expand Up @@ -41,7 +41,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
} else{
[self ORSSerialPortWasDisconnected:nil];
}

}
- (void)setView:(NSString*)name
{
Expand Down
45 changes: 34 additions & 11 deletions Classes/Controllers/WriteViewController.m
Expand Up @@ -18,14 +18,7 @@ @implementation WriteViewController
- (void)awakeFromNib {
[super awakeFromNib];
self.actionButton.title = @"Write";

self.trackString = [NSMutableDictionary dictionary];

//MSRDevice = 2;

//[self writeFromURL:@"file://localhost/Users/kevinbrewster/Desktop/good%20codes.txt" withTrack:nil];
//[self writeFromURL:[NSURL URLWithString:@"file://localhost/Users/kevinbrewster/Desktop/good%20codes.txt"] withTrack:nil];
//[self writeFromURL:[NSURL URLWithString:@"file://localhost/Users/kevinbrewster/Desktop/GoodCodes.csv"] withTrack:nil];
}

- (void)doAction:(NSButton *)button
Expand Down Expand Up @@ -54,14 +47,30 @@ - (void)doAction:(NSButton *)button
if(data) trackData[key] = data;
}
}

[self.MSRDevice writeTrackData:[NSDictionary dictionaryWithDictionary:trackData] withFormat:self.dataFormat andCompletionBlock:^(MSRStatus status) {
[self endAction:self.actionButton withStatus:status];

if(self.writeQueue.count){
self.completedWrites++;
[self.writeQueue removeObjectAtIndex:0];
if(self.writeQueue.count){
[self actionButtonPressed:button];
if(status == MagReadWriteOK){
self.completedWrites++;
[self.writeQueue removeObjectAtIndex:0];
if(self.writeQueue.count){
[self actionButtonPressed:button];
}
} else{
// If we are batch-writing cards and one was not successful, give the option to re-try that card or move on
NSAlert *alert = [NSAlert alertWithMessageText:[self.MSRDevice statusDescription:status forAction:@"write"]
defaultButton:@"Re-Try Card"
alternateButton:@"Skip This Card"
otherButton:nil
informativeTextWithFormat:@""];

AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
[alert beginSheetModalForWindow:appDelegate.window
modalDelegate:self
didEndSelector:@selector(batchWriteAlertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
}
}];
Expand All @@ -86,6 +95,20 @@ - (void)cancelAction:(NSButton *)button
[super cancelAction:button];
}
}
- (void)batchWriteAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
if(returnCode == NSAlertFirstButtonReturn){
// skip card
self.completedWrites++;
[self.writeQueue removeObjectAtIndex:0];
if(self.writeQueue.count){
[self actionButtonPressed:self.actionButton];
}
} else{
// re-try card
[self actionButtonPressed:self.actionButton];
}
}
- (void)cancelAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
if(returnCode == NSAlertFirstButtonReturn){
Expand Down
3 changes: 1 addition & 2 deletions Classes/Models/MSR206Device.m
Expand Up @@ -321,8 +321,7 @@ - (void)writeTrackData:(NSDictionary *)trackData withFormat:(NSString *)format a
[dataBlock appendBytes:"\x1B\x73" length:2];
[dataBlock appendData:cardData];
[dataBlock appendBytes:"\x3F\x1C" length:2];



[self sendCommand:dataBlock withStopString:@"\x1B" andStopBytes:@1 andCompletionBlock:^(NSData *response){
const unsigned char *bytes = [response bytes];
MSRStatus status = bytes[response.length-1];
Expand Down
2 changes: 1 addition & 1 deletion Resources/MagStriper-Info.plist
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2</string>
<string>4</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit 6e16405

Please sign in to comment.