Skip to content

Commit 0386c32

Browse files
committed
add restDoaService
1 parent 134fba4 commit 0386c32

8 files changed

Lines changed: 793 additions & 1 deletion

File tree

componentStatic/ErrorManager.as

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ package componentStatic
3535
messageTitle[telId] = 'شماره تلفن وارد شده صحیح نمی باشد';
3636
messageTitle[priceId] = 'مبلغ وارد شده صحیح نمی باشد';
3737
messageTitle[dateId] = 'تاریخ وارد شده صحیح نمی باشد';
38-
messageTitle[filedEmptyId]='لطفا تمام موارد خاسته شده را تکمیل نمایید';
38+
messageTitle[filedEmptyId]='لطفا موارد خواسته شده را تکمیل نمایید';
3939

4040
}
4141
public function setup():void

restDoaService/ErrorEnum.as

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package restDoaService
2+
{
3+
public class ErrorEnum
4+
{
5+
public static const noError:int = 0 ;
6+
7+
public static const SignInFailed:int = 1 ;
8+
public static const MemberIsDisabled:int = 2 ;
9+
public static const UserIsNotAuthorized:int = 3 ;
10+
public static const UserIsNotAuthenticated:int = 4 ;
11+
public static const PasswordIsNotConfirmedCorrectly:int = 5 ;
12+
public static const CurrentPasswordIsWrong:int = 6 ;
13+
public static const RequiredFieldsIsEmpty:int = 7 ;
14+
public static const UsernameIsDuplicated:int = 8 ;
15+
public static const DeviceIsNotAuthenticated:int = 9 ;
16+
public static const EmailIsNotValid:int = 10 ;
17+
public static const MobileIsNotValid:int = 11 ;
18+
19+
public static const ConnectionError:int = -1 ;
20+
21+
public static const JsonParsProblem:int = -2 ;
22+
23+
public static const BinaryError:int = -3 ;
24+
25+
public function ErrorEnum()
26+
{
27+
super();
28+
}
29+
}
30+
}

restDoaService/RestDoaEvent.as

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package restDoaService
2+
{
3+
import flash.events.Event;
4+
5+
6+
public class RestDoaEvent extends Event
7+
{
8+
/**Server connection error*/
9+
public static const CONNECTION_ERROR:String = "CONNECTION_ERROR" ;
10+
11+
/**Server error dispatches*/
12+
public static const SERVER_ERROR:String = "SERVER_ERROR" ;
13+
14+
/**Server connection error*/
15+
public static const SERVER_RESULT:String = "SERVER_RESULT" ;
16+
17+
/**Server connection error*/
18+
public static const SERVER_RESULT_UPDATE:String = "SERVER_RESULT_UPDATE" ;
19+
20+
/**Look for error codes on ErrorEnum class.
21+
<br>
22+
noError:int = 0 ;
23+
<br>
24+
SignInFailed:int = 1 ;
25+
<br>
26+
MemberIsDisabled:int = 2 ;
27+
<br>
28+
UserIsNotAuthorized:int = 3 ;
29+
<br>
30+
UserIsNotAuthenticated:int = 4 ;
31+
<br>
32+
PasswordIsNotConfirmedCorrectly:int = 5 ;
33+
<br>
34+
CurrentPasswordIsWrong:int = 6 ;
35+
<br>
36+
RequiredFieldsIsEmpty:int = 7 ;
37+
<br>
38+
UsernameIsDuplicated:int = 8 ;
39+
<br>
40+
DeviceIsNotAuthenticated:int = 9 ;
41+
<br>
42+
EmailIsNotValid:int = 10 ;
43+
<br>
44+
MobileIsNotValid:int = 11 ;*/
45+
public var errorCode:int ;
46+
public static var SERVER_RESULT_puInquiry_fun:String;
47+
48+
public function RestDoaEvent(type:String,ErrorCode:int=ErrorEnum.noError)
49+
{
50+
errorCode = ErrorCode ;
51+
super(type,false);
52+
}
53+
54+
override public function clone():Event
55+
{
56+
return new RestDoaEvent(type,errorCode);
57+
}
58+
}
59+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package restDoaService
2+
{
3+
import flash.events.EventDispatcher;
4+
import flash.events.IEventDispatcher;
5+
6+
[Event(name="CONNECTION_ERROR", type="restService.RestEvent")]
7+
/**Server returns error, use Error code or msg list*/
8+
[Event(name="SERVER_ERROR", type="restService.RestEvent")]
9+
public class RestDoaEventDispatcher extends EventDispatcher
10+
{
11+
public function RestDoaEventDispatcher(target:IEventDispatcher=null)
12+
{
13+
super(target);
14+
}
15+
}
16+
}

restDoaService/RestDoaService.as

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package restDoaService
2+
{
3+
import flash.net.SharedObject;
4+
5+
public class RestDoaService
6+
{
7+
internal static const debug_show_results:Boolean = false ;
8+
9+
10+
/**This will take all errors on it*/
11+
public static var eventDispatcher:RestDoaEventDispatcher = new RestDoaEventDispatcher();
12+
13+
/**located server domain*/
14+
internal static var serverDomain:String = null ;
15+
16+
//private static var id_UId:String = "UId",
17+
// id_UIdAuth:String = "UIdAuth";
18+
19+
//private static var _UId:String = '';//"226e4187-4135-4733-bfe2-8fc526d6971c";
20+
21+
//private static var _UIdAuth:String = '';//"29d46f85-1fb5-4ff2-8c36-6d70744eaf45" ;
22+
23+
private static var sharedObject:SharedObject;
24+
25+
private static function setUpStorage():void
26+
{
27+
if(sharedObject == null)
28+
{
29+
//trace("♠ Set up shared Object");
30+
sharedObject = SharedObject.getLocal('restMelkFullCash','/');
31+
}
32+
}
33+
34+
private static function get(id:String):String
35+
{
36+
setUpStorage();
37+
var cash:String = sharedObject.data[id];
38+
//trace("♠ Load "+id+" from tht shared object");
39+
if(cash == null)
40+
{
41+
return '';
42+
}
43+
//trace("♠ Loaded id is : "+cash);
44+
return cash ;
45+
}
46+
47+
private static function set(id:String,value:String):void
48+
{
49+
setUpStorage();
50+
//trace("♠ set the "+id+" to "+value);
51+
sharedObject.data[id] = value ;
52+
sharedObject.flush();
53+
}
54+
55+
56+
/*internal static function get UIdAuth():String
57+
{
58+
if(_UIdAuth=='')
59+
{
60+
_UIdAuth = get(id_UIdAuth);
61+
}
62+
return _UIdAuth;
63+
}*/
64+
65+
/*internal static function get UId():String
66+
{
67+
if(_UId=='')
68+
{
69+
_UId = get(id_UId);
70+
}
71+
//trace("♠ Get _UId : "+_UId);
72+
return _UId;
73+
}*/
74+
75+
76+
77+
/*private static function setUIdAuth(value:String):void
78+
{
79+
//trace("♠ set id_UIdAuth from "+_UIdAuth+" To "+value);
80+
if(_UIdAuth!=value)
81+
{
82+
set(id_UIdAuth,value);
83+
_UIdAuth = value;
84+
//trace("♠ done");
85+
}
86+
}*/
87+
88+
/*private static function setUId(value:String):void
89+
{
90+
//trace("♠ set _UId from "+_UId+" To "+value);
91+
if(_UId!=value)
92+
{
93+
set(id_UId,value);
94+
_UId = value;
95+
//trace("♠ done");
96+
}
97+
}*/
98+
99+
internal static function get domain():String
100+
{
101+
if(serverDomain==null)
102+
{
103+
throw "You Should setUp RestService first!\nUse RestService.setUp() function.";
104+
}
105+
return serverDomain;
106+
}
107+
108+
109+
public static function setUp(ServerDomain:String):void
110+
{
111+
if(ServerDomain.charAt(ServerDomain.length-1)!='/')
112+
{
113+
ServerDomain+='/';
114+
}
115+
serverDomain = ServerDomain ;
116+
//UId;
117+
//UIdAuth;
118+
trace("Rest service is starts on : "+serverDomain);
119+
}
120+
121+
/**Feal these values from signInViewModel to make user knownAsLoged in
122+
public static function setUid(uId:String,uIdAuth:String):void
123+
{
124+
setUId(uId) ;
125+
setUIdAuth(uIdAuth) ;
126+
trace("User is logged in");
127+
}*/
128+
129+
/*public static function logOut():void
130+
{
131+
setUId('');
132+
setUIdAuth('');
133+
trace("User is logged out");
134+
}*/
135+
136+
/**Returns true if user is logged in.
137+
public static function get isLogedIn():Boolean
138+
{
139+
if(UId=='' || UIdAuth=='')
140+
{
141+
return false ;
142+
}
143+
else
144+
{
145+
return true ;
146+
}
147+
}*/
148+
}
149+
}

0 commit comments

Comments
 (0)