Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added debug info

  • Loading branch information...
commit beb9af5defea720bf01934881d83fcef7d3602ed 1 parent f590591
@georges georges authored
View
2  Framework/MCResource/MCAssociation.j
@@ -28,4 +28,4 @@
return "<" + class_getName(isa) + " 0x" + [CPString stringWithHash:[self UID]] + ": " + _associationName + " on " + [_parent className] + ">";
}
-@end
+@end
View
12 Framework/MCResource/MCBelongsToAssociation.j
@@ -9,22 +9,24 @@
{
_associatedObject = nil;
}
-
+
return self;
}
- (MCResource)associatedObject
{
+ CPLog.trace("MCBelongsToAssociation.associatedObject");
+
if(_associatedObject)
return _associatedObject;
-
+
var parentalAssociationId = [_parent valueForKey:_associationName + "Id"];
if(!parentalAssociationId)
return nil;
-
+
_associatedObject = [MCResource getResourceWithId:parentalAssociationId ofClass:_associatedObjectClass];
-
+
return _associatedObject;
}
@@ -33,4 +35,4 @@
_associatedObject = associatedObject;
}
-@end
+@end
View
58 Framework/MCResource/MCHTTPRequest.j
@@ -28,23 +28,23 @@
* },
* "id": 3
* } };
- *
+ *
* // Construct a request
* var saveRequest = [MCHTTPRequest requestTarget:[CPURL URLWithString:@"/orders/123"]
* withMethod:@"PUT"
* andDelegate:self];
- *
+ *
* // Convert our test values to a CPDictionary
* var testCPDict = [CPDictionary dictionaryWithJSObject:testDict recursively:YES];
- *
- * // Set data to be transmitted
+ *
+ * // Set data to be transmitted
* [saveRequest setData:testCPDict];
- *
+ *
* // And finally, start the request
* [saveRequest start];
*
*/
-
+
// File-scoped variables -- class variables
var MCHTTPRequestDelegate = nil;
var MCHTTPRequestDelegateRespondsToAuthorizationCredentials = NO;
@@ -77,7 +77,7 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
+ (void)setDelegate:(id)aDelegate
{
MCHTTPRequestDelegate = aDelegate;
-
+
if([aDelegate respondsToSelector:@selector(authorizationCredentials)])
{
MCHTTPRequestDelegateRespondsToAuthorizationCredentials = YES;
@@ -104,7 +104,7 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
[aRequest setDelegate:aDelegate];
[aRequest setURL:aTarget];
[aRequest setHTTPMethod:aMethod];
-
+
return aRequest;
}
@@ -116,7 +116,7 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
// Set default values
dataTransformer = MCHTTPRequestCachedDefaultTransformer;
HTTPMethod = @"GET";
-
+
// Set default headers
_HTTPHeaderFields = [CPDictionary dictionary];
@@ -130,8 +130,8 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
[_HTTPHeaderFields setValue:"no-cache" forKey:"Cache-Control"];
[_HTTPHeaderFields setValue:"XMLHttpRequest" forKey:"X-Requested-With"];
- // Add authorization credentials if
- // a) they were specified through setAuthorizationCredentials:
+ // Add authorization credentials if
+ // a) they were specified through setAuthorizationCredentials:
// b) none were specified but the class delegate can supply them.
if(authorizationCredentials)
{
@@ -139,10 +139,10 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
}
else if(MCHTTPRequestDelegateRespondsToAuthorizationCredentials)
{
- [_HTTPHeaderFields setValue:[[[self class] delegate] authorizationCredentials] forKey:@"Authorization"];
+ [_HTTPHeaderFields setValue:[[[self class] delegate] authorizationCredentials] forKey:@"Authorization"];
}
}
-
+
return self;
}
@@ -164,7 +164,7 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
{
// Conserve memory
delete _formData;
-
+
// Build new formData
_formData = [dataTransformer transformedData:someData];
}
@@ -174,7 +174,7 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
{
if(!_formData)
_formData = new FormData();
-
+
_formData.append(aKey, value);
}
@@ -198,13 +198,13 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
{
if(HTTPMethod === aMethod)
return;
-
+
// Make sure the given method is valid
if(!aMethod || !aMethod.match(/(put|get|delete|post)/i))
{
- throw [MCError errorWithDescription:@"Unknown HTTP request method: '" + aMethod + "'"];
+ throw [MCError errorWithDescription:@"Unknown HTTP request method: '" + aMethod + "'"];
}
-
+
HTTPMethod = aMethod;
}
@@ -231,15 +231,17 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
//
- (BOOL)start
{
+ CPLog.trace("MCHTTPRequest.start");
+
if(_connection)
{
CPLog.warn("Connection has already started");
return YES;
}
-
+
error = nil;
_connection = [[MCURLConnection alloc] initWithRequest:self delegate:self startImmediately:YES];
-
+
if(_connection)
return YES;
else
@@ -267,15 +269,15 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
#pragma mark NSURLConnection delegate methods
/*
- * CPURLConnection delegate methods (used by MCURLConnection as well)
+ * CPURLConnection delegate methods (used by MCURLConnection as well)
* For documentation of these methods, see Cappuccino docs
- */
+ */
- (void)connection:(CPURLConnection)aConnection didFailWithError:(id)anError
{
if(delegate)
{
error = anError;
- [delegate requestDidFail:self];
+ [delegate requestDidFail:self];
}
else
{
@@ -286,7 +288,7 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
- (void)connection:(CPURLConnection)aConnection didReceiveResponse:(CPHTTPURLResponse)aResponse
{
_response = aResponse;
-
+
if(![aResponse isKindOfClass:[CPHTTPURLResponse class]])
{
CPLog.warn("Expected a CPHTTPURLResponse, but got '" + [aResponse class] + "' instead. Status codes are probably not reliable.");
@@ -312,10 +314,10 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
else
responseData = _responseData;
}
-
+
[[CPNotificationCenter defaultCenter] postNotificationName:MCHTTPRequestDidFinishNotificationName
object:self];
-
+
if(delegate)
{
[delegate requestDidFinish:self];
@@ -340,7 +342,7 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
- (void)connection:(CPURLConnection)connection progressDidChange:(float)progress
{
[[CPNotificationCenter defaultCenter] postNotificationName:MCHTTPRequestDidChangeProgressNotificationName
- object:self
+ object:self
userInfo:[CPDictionary dictionaryWithObject:progress forKey:@"progress"]];
}
@@ -350,4 +352,4 @@ var MCHTTPRequestCachedDefaultTransformer = [MCJSONDataTransformer new];
throw [MCError errorWithDescription:@"Access denied to " + URL + " by server with 401 Forbidden"];
}
-@end
+@end
View
19 Framework/MCResource/MCQueuedRequest.j
@@ -6,7 +6,7 @@
CPSet childRequests @accessors;
BOOL blocking @accessors;
float progress @accessors(readonly);
-
+
CPSet finishedChildRequests;
id originalDelegate;
}
@@ -14,7 +14,7 @@
// Constructor method for clean code (TM)
+ (MCQueuedRequest)queuedRequestWithRequest:(MCHTTPRequest)aRequest
{
- var queuedRequest = [[MCQueuedRequest alloc] initWithRequest:aRequest];
+ var queuedRequest = [[MCQueuedRequest alloc] initWithRequest:aRequest];
return queuedRequest;
}
@@ -27,7 +27,7 @@
finishedChildRequests = [CPSet set];
[self setHTTPRequest:aRequest];
}
-
+
return self;
}
@@ -52,8 +52,8 @@
// completion of the original request
originalDelegate = [aRequest delegate];
[aRequest setDelegate:self];
-
- [[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(requestDidChangeProgress:) name:MCHTTPRequestDidChangeProgressNotificationName object:aRequest];
+
+ [[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(requestDidChangeProgress:) name:MCHTTPRequestDidChangeProgressNotificationName object:aRequest];
}
// Add a child request to be executed upon completion of this request.
@@ -94,7 +94,7 @@
{
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(childRequestDidFinish:) name:MCHTTPRequestDidFinishNotificationName object:[childRequest HTTPRequest]];
[[self queue] appendRequest:childRequest];
- }
+ }
}
}
@@ -119,6 +119,7 @@
- (void)requestDidFail:(MCHTTPRequest)aRequest
{
+ CPLog.trace("MCQueuedRequest.requestDidFail");
[originalDelegate requestDidFail:self];
}
@@ -129,13 +130,13 @@
{
var description = @"<MCQueuedRequest 0x" + [CPString stringWithHash:[self UID]] + ": " + [HTTPRequest HTTPMethod] + " to " + [HTTPRequest URL] + ">",
childRequestArray = [childRequests allObjects];
-
+
for(var i = 0; i < [childRequestArray count]; i++)
{
description += @"\n\tChild request: " + [[childRequestArray objectAtIndex:i] description];
}
-
+
return description;
}
-@end
+@end
View
17 Framework/MCResource/MCResource.j
@@ -318,16 +318,17 @@ var AllResourcesByTypeAndId = [CPDictionary dictionary];
return self;
}
+
// This is a standard override for development purposes - if log output gets too messy, remove it.
- (CPString)description
{
- var description = [self className] + ", ID " + [self identifier] + ": { \n",
+ var description = [self className] + ", ID " + [self identifier] + ": { ",
attributes = [[[self class] attributes] keyEnumerator],
attribute;
while(attribute = [attributes nextObject])
{
- description += "\t " + attribute + " = '" + [self valueForKey:attribute] + "'\n";
+ description += attribute + " " //+ " = '" + [self valueForKey:attribute] + "'\n";
}
description += "};";
@@ -335,6 +336,7 @@ var AllResourcesByTypeAndId = [CPDictionary dictionary];
return description;
}
+
#pragma mark -
#pragma mark Public methods
@@ -345,6 +347,8 @@ var AllResourcesByTypeAndId = [CPDictionary dictionary];
+ (MCResource)getResourceWithId:(int)anIdentifier ofClass:(Class)resourceClass
{
+ CPLog.trace("MCResource.getResourceWithId");
+
return [AllResourcesByTypeAndId valueForKeyPath:resourceClass + "." + anIdentifier];
}
@@ -629,7 +633,7 @@ var AllResourcesByTypeAndId = [CPDictionary dictionary];
}
else
{
- // CPLog.warn(@"Resource " + self + " loaded without identifier key! This will likely cause problems in the future.");
+ CPLog.warn(@"Resource " + self + " loaded without identifier key! This will likely cause problems in the future.");
}
// And normal treatment for the other resources
@@ -1300,6 +1304,8 @@ var AllResourcesByTypeAndId = [CPDictionary dictionary];
+ (void)requestDidFail:(MCQueuedRequest)aRequest
{
+ CPLog.trace("MCResource+requestDidFail");
+
var aDelegate = [classMethodDelegateDictionary objectForKey:aRequest],
aSelector = [classMethodSelectorDictionary objectForKey:aRequest];
@@ -1322,6 +1328,8 @@ var AllResourcesByTypeAndId = [CPDictionary dictionary];
// Let's hope this doesn't get called to often ;)
- (void)requestDidFail:(MCQueuedRequest)aRequest
{
+ CPLog.trace("MCResource.requestDidFail");
+
var aDelegate = [_instanceMethodDelegateDictionary objectForKey:aRequest],
aSelector = [_instanceMethodSelectorDictionary objectForKey:aRequest];
@@ -1355,7 +1363,8 @@ var AllResourcesByTypeAndId = [CPDictionary dictionary];
informativeTextWithFormat:MCResourceGeneralErrorDetailedMessage];
[alert setDelegate:self];
- [alert beginSheetModalForWindow:[CPApp mainWindow]];
+ if (CPApp)
+ [alert beginSheetModalForWindow:[CPApp mainWindow]];
_MCResourceErrorAlertIsShowing = YES;
}
Please sign in to comment.
Something went wrong with that request. Please try again.