forked from karelia/MockServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKMSCommand.m
110 lines (83 loc) · 1.81 KB
/
KMSCommand.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// KMSCommand.m
// MockServer
//
// Created by Sam Deane on 25/01/2013.
// Copyright (c) 2013 Karelia Software. All rights reserved.
//
#import "KMSCommand.h"
#import "KMSConnection.h"
#import "KMSServer.h"
#import "KMSPauseCommand.h"
#import "KMSSendDataCommand.h"
#import "KMSSendStringCommand.h"
#import "KMSSendServerDataCommand.h"
#import "KMSCloseCommand.h"
@implementation KMSCommand
+ (NSArray*)commandArrayFromObjectArray:(NSArray*)array
{
NSMutableArray* result = [NSMutableArray arrayWithCapacity:[array count]];
for (id item in array)
{
KMSCommand* command = [item asKMSCommand];
if (command)
{
[result addObject:command];
}
}
return result;
}
- (KMSCommand*)asKMSCommand
{
return self;
}
- (NSTimeInterval)performOnConnection:(KMSConnection*)connection server:(KMSServer*)server
{
return 0;
}
- (KMSCommand*)substitutedWithValues:(NSDictionary *)values
{
return self;
}
@end
#pragma mark - NSObject
@implementation NSObject(KMSCommand)
- (KMSCommand*)asKMSCommand
{
return nil;
}
@end
#pragma mark - NSString
@implementation NSString(KMSCommand)
- (KMSCommand*)asKMSCommand
{
KMSCommand* result = nil;
if ([self isEqual:CloseCommandToken])
{
result = [KMSCloseCommand closeCommand];
}
else if ([self isEqual:DataCommandToken])
{
result = [KMSSendServerDataCommand sendServerData];
}
else
{
result = [KMSSendStringCommand sendString:self];
}
return result;
}
@end
#pragma mark - NSData
@implementation NSData(KMSCommand)
- (KMSCommand*)asKMSCommand
{
return [KMSSendDataCommand sendData:self];
}
@end
#pragma mark - NSNumber
@implementation NSNumber(KMSCommand)
- (KMSCommand*)asKMSCommand
{
return [KMSPauseCommand pauseFor:[self doubleValue]];
}
@end