Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ixc-software/snow
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksiivinogradov committed Mar 5, 2012
2 parents ab2d23c + fc6987b commit e3f8e41
Show file tree
Hide file tree
Showing 5 changed files with 459 additions and 110 deletions.
133 changes: 70 additions & 63 deletions ClassesForAllPlatforms/ClientController.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ - (id)initWithPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordin

mainServer = [[NSURL alloc] initWithString:@"https://mac.ixcglobal.com:8081"];
#else
mainServer = [[NSURL alloc] initWithString:@"http://127.0.0.1:8081"];
// mainServer = [[NSURL alloc] initWithString:@"http://192.168.0.58:8081"];
// mainServer = [[NSURL alloc] initWithString:@"http://127.0.0.1:8081"];
mainServer = [[NSURL alloc] initWithString:@"http://192.168.0.58:8081"];
#endif

//
Expand Down Expand Up @@ -420,42 +420,45 @@ -(void) createCountrySpecificCodesInCoreDataForMainSystem:(MainSystem *)mainSyst
NSMutableArray *codesFromFile = [parser parseFile];
[parser release], parser = nil;
path = nil;
NSMutableArray *countrySpecificCodesList = [NSMutableArray array];
NSMutableArray *countrySpecificCodesList = [[NSMutableArray alloc] init];
NSUInteger countForCodes = codesFromFile.count;



[codesFromFile enumerateObjectsWithOptions:NSSortStable usingBlock:^(id code, NSUInteger idx, BOOL *stop) {
NSNumber *percentDone = [NSNumber numberWithDouble:[[NSNumber numberWithUnsignedInteger:idx] doubleValue] / [[NSNumber numberWithUnsignedInteger:countForCodes] doubleValue]];
[self updateUIwithMessage:@"Parse codes list.." andProgressPercent:percentDone withObjectID:nil];

NSMutableDictionary *codesFromFileListNew = [NSMutableDictionary dictionary];
[codesFromFileListNew setValue:[code objectAtIndex:0] forKey:@"country"];
[codesFromFileListNew setValue:[code objectAtIndex:1] forKey:@"specific"];
NSMutableArray *filteredResult = [NSMutableArray arrayWithArray:countrySpecificCodesList];
[filteredResult filterUsingPredicate:[NSPredicate predicateWithFormat:@"(country == %@) and (specific == %@)",[code objectAtIndex:0],[code objectAtIndex:1]]];
if ([filteredResult count] != 0)
{
// NSLog (@"We find a simular country: %@ specific %@ and code %@ Total destinations:%ld",[code objectAtIndex:0],[code objectAtIndex:1], [code objectAtIndex:2], [[ProjectArrays sharedProjectArrays].myCountrySpecificCodeList count]);
NSMutableDictionary *lastObject = [[NSArray arrayWithArray:countrySpecificCodesList] lastObject];
NSMutableArray *codes = [lastObject valueForKey:@"code"];
[codes addObject:[code objectAtIndex:2]];
[lastObject setValue:codes forKey:@"code"];
[countrySpecificCodesList removeLastObject];
[countrySpecificCodesList addObject:lastObject];
lastObject = nil;
codes = nil;
} else {
NSMutableDictionary *codesFromFileList = [NSMutableDictionary dictionary];
NSString *countryBefore = [code objectAtIndex:0];
NSString *specificBefore = [code objectAtIndex:1];
NSString *country = [countryBefore stringByReplacingOccurrencesOfString:@"'" withString:@"~"];
NSString *specific = [specificBefore stringByReplacingOccurrencesOfString:@"'" withString:@"~"];
@autoreleasepool {

[codesFromFileList setValue:country forKey:@"country"];
[codesFromFileList setValue:specific forKey:@"specific"];
[codesFromFileList setValue:[NSMutableArray arrayWithObject:[code objectAtIndex:2]] forKey:@"code"];
[countrySpecificCodesList addObject:codesFromFileList];
NSNumber *percentDone = [NSNumber numberWithDouble:[[NSNumber numberWithUnsignedInteger:idx] doubleValue] / [[NSNumber numberWithUnsignedInteger:countForCodes] doubleValue]];
[self updateUIwithMessage:@"Parse codes list.." andProgressPercent:percentDone withObjectID:nil];

NSMutableDictionary *codesFromFileListNew = [NSMutableDictionary dictionary];
[codesFromFileListNew setValue:[code objectAtIndex:0] forKey:@"country"];
[codesFromFileListNew setValue:[code objectAtIndex:1] forKey:@"specific"];
NSMutableArray *filteredResult = [NSMutableArray arrayWithArray:countrySpecificCodesList];
[filteredResult filterUsingPredicate:[NSPredicate predicateWithFormat:@"(country == %@) and (specific == %@)",[code objectAtIndex:0],[code objectAtIndex:1]]];
if ([filteredResult count] != 0)
{
// NSLog (@"We find a simular country: %@ specific %@ and code %@ Total destinations:%ld",[code objectAtIndex:0],[code objectAtIndex:1], [code objectAtIndex:2], [[ProjectArrays sharedProjectArrays].myCountrySpecificCodeList count]);
NSMutableDictionary *lastObject = [[NSArray arrayWithArray:countrySpecificCodesList] lastObject];
NSMutableArray *codes = [lastObject valueForKey:@"code"];
[codes addObject:[code objectAtIndex:2]];
[lastObject setValue:codes forKey:@"code"];
[countrySpecificCodesList removeLastObject];
[countrySpecificCodesList addObject:lastObject];
lastObject = nil;
codes = nil;
} else {
NSMutableDictionary *codesFromFileList = [NSMutableDictionary dictionary];
NSString *countryBefore = [code objectAtIndex:0];
NSString *specificBefore = [code objectAtIndex:1];
NSString *country = [countryBefore stringByReplacingOccurrencesOfString:@"'" withString:@"~"];
NSString *specific = [specificBefore stringByReplacingOccurrencesOfString:@"'" withString:@"~"];

[codesFromFileList setValue:country forKey:@"country"];
[codesFromFileList setValue:specific forKey:@"specific"];
[codesFromFileList setValue:[NSMutableArray arrayWithObject:[code objectAtIndex:2]] forKey:@"code"];
[countrySpecificCodesList addObject:codesFromFileList];
}
}
}];

Expand All @@ -475,38 +478,41 @@ -(void) createCountrySpecificCodesInCoreDataForMainSystem:(MainSystem *)mainSyst
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSUInteger idx = 0;
for (NSDictionary *countrySpecific in countrySpecificCodesList) {
NSNumber *percentDone = [NSNumber numberWithDouble:([[NSNumber numberWithUnsignedInteger:idx] doubleValue] / [[NSNumber numberWithUnsignedInteger:[countrySpecificCodesList count]] doubleValue])];
// if (sender && [sender respondsToSelector:@selector(updateProgessInfoWithPercent:)]) [sender performSelector:@selector(updateProgessInfoWithPercent:) withObject:percentDone];
[self updateUIwithMessage:@"Update codes database..." andProgressPercent:percentDone withObjectID:nil];

CountrySpecificCodeList *newTest = (CountrySpecificCodeList *)[NSEntityDescription insertNewObjectForEntityForName:@"CountrySpecificCodeList" inManagedObjectContext:self.moc];
newTest.country = [countrySpecific valueForKey:@"country"];
newTest.specific = [countrySpecific valueForKey:@"specific"];
//NSLog(@"CLIENT CONTROLLER: createCountrySpecificCodesInCoreDataForMainSystem start for %@ specific:%@",newTest.country,newTest.specific);

newTest.mainSystem = (MainSystem *)[self.moc objectWithID:mainSystemID];
NSMutableString *codes = [NSMutableString string];
NSArray *codesListLocal = [countrySpecific valueForKey:@"code"];
NSUInteger idxCodes = 0;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];

for (NSString *codeString in codesListLocal) {
CodesList *newList = (CodesList *)[NSEntityDescription insertNewObjectForEntityForName:@"CodesList" inManagedObjectContext:self.moc];
NSNumber *codeNumber = [formatter numberFromString:codeString];
newList.code = codeNumber;
newList.countrySpecificCodesList = newTest;
@autoreleasepool {

NSNumber *percentDone = [NSNumber numberWithDouble:([[NSNumber numberWithUnsignedInteger:idx] doubleValue] / [[NSNumber numberWithUnsignedInteger:[countrySpecificCodesList count]] doubleValue])];
// if (sender && [sender respondsToSelector:@selector(updateProgessInfoWithPercent:)]) [sender performSelector:@selector(updateProgessInfoWithPercent:) withObject:percentDone];
[self updateUIwithMessage:@"Update codes database..." andProgressPercent:percentDone withObjectID:nil];

CountrySpecificCodeList *newTest = (CountrySpecificCodeList *)[NSEntityDescription insertNewObjectForEntityForName:@"CountrySpecificCodeList" inManagedObjectContext:self.moc];
newTest.country = [countrySpecific valueForKey:@"country"];
newTest.specific = [countrySpecific valueForKey:@"specific"];
//NSLog(@"CLIENT CONTROLLER: createCountrySpecificCodesInCoreDataForMainSystem start for %@ specific:%@",newTest.country,newTest.specific);

newTest.mainSystem = (MainSystem *)[self.moc objectWithID:mainSystemID];
NSMutableString *codes = [NSMutableString string];
NSArray *codesListLocal = [countrySpecific valueForKey:@"code"];
NSUInteger idxCodes = 0;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];

if (idxCodes != [codesListLocal count] - 1) [codes appendFormat:@"%@, ",codeString];
else [codes appendFormat:@"%@",codeString];
idxCodes++;
for (NSString *codeString in codesListLocal) {
CodesList *newList = (CodesList *)[NSEntityDescription insertNewObjectForEntityForName:@"CodesList" inManagedObjectContext:self.moc];
NSNumber *codeNumber = [formatter numberFromString:codeString];
newList.code = codeNumber;
newList.countrySpecificCodesList = newTest;

if (idxCodes != [codesListLocal count] - 1) [codes appendFormat:@"%@, ",codeString];
else [codes appendFormat:@"%@",codeString];
idxCodes++;
}
[formatter release],formatter = nil;

newTest.codes = [NSString stringWithString:codes];
//NSLog(@"New Object = %@/%@",newTest.country,newTest.specific);
//[pool drain],pool = nil;
//pool = [[NSAutoreleasePool alloc] init];
idx++;
}
[formatter release],formatter = nil;

newTest.codes = [NSString stringWithString:codes];
//NSLog(@"New Object = %@/%@",newTest.country,newTest.specific);
//[pool drain],pool = nil;
//pool = [[NSAutoreleasePool alloc] init];
idx++;
}
//[pool drain],pool = nil;
[countrySpecificCodesList release];
Expand Down Expand Up @@ -2124,6 +2130,7 @@ -(NSDictionary *) getJSONAnswerForFunctionVersionTwo:(NSString *)function
if (error) {
NSLog(@"CLIENT CONTROLLER: getJSON answer error download:%@",[error localizedDescription]);
[self updateUIwithMessage:[error localizedDescription] withObjectID:nil withLatestMessage:YES error:NO];
[finalResultAlloc release];
return nil;
}
NSString *answer = [[NSString alloc] initWithData:receivedResult encoding:NSUTF8StringEncoding];
Expand Down Expand Up @@ -2208,7 +2215,7 @@ -(NSArray *)getAllObjectsListWithGUIDs:(NSArray *)guids
NSPropertyListFormat format;
NSArray *decodedObjects = [NSPropertyListSerialization propertyListFromData:allObjectsData mutabilityOption:0 format:&format errorDescription:&error];
[finalListObjectsMutable addObjectsFromArray:decodedObjects];
if (error) NSLog(@"SERVER CONTRORLER: allObjectsSerializationFailed:%@ format:%luu",error,format);
if (error) NSLog(@"SERVER CONTRORLER: allObjectsSerializationFailed:%@ format:%uu",error,format);
//NSLog(@"CLIENT CONTROLLER: guids:%@",guids);

//NSLog(@"CLIENT CONTROLLER: decodedObjects:%@",decodedObjects);
Expand Down
2 changes: 1 addition & 1 deletion snowMobile/ViewControllers/AuthorizationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ -(void)finalizeRegisterIssuesForLogin:(BOOL)isLogin;
admin.isRegistrationDone = [NSNumber numberWithBool:YES];
// [clientController getAllObjectsForEntity:@"CurrentCompany" immediatelyStart:YES isUserAuthorized:YES];
[clientController putObjectWithTimeoutWithIDs:[NSArray arrayWithObject:[admin objectID]] mustBeApproved:NO];
[clientController updateLocalGraphFromSnowEnterpriseServerWithDateFrom:nil withDateTo:nil];
[clientController updateLocalGraphFromSnowEnterpriseServerWithDateFrom:nil withDateTo:nil withIncludeCarrierSubentities:NO];
} else {
[self showErrorMessage:@"login failed"];
loginActivity.hidden = YES;
Expand Down
2 changes: 2 additions & 0 deletions snowMobile/ViewControllers/DestinationsListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@
@property (readwrite) BOOL isRoutesForSaleListUpdated;
@property (readwrite) BOOL isRoutesPushlistListUpdated;
@property (retain, nonatomic) IBOutlet UIButton *cancelAllUpdatesButton;
@property (retain, nonatomic) IBOutlet UIView *toolBarView;
@property (retain, nonatomic) IBOutlet UISegmentedControl *routesChangeFilterWithOrWithoutTraffic;

@end
Loading

0 comments on commit e3f8e41

Please sign in to comment.