forked from solutionexchange/AutoFileName
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RqlConnector.js
119 lines (105 loc) · 2.83 KB
/
RqlConnector.js
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
111
112
113
114
115
116
117
118
119
function RqlConnector(LoginGuid, SessionKey) {
this.LoginGuid = LoginGuid;
this.SessionKey = SessionKey;
this.DCOM = 'DCOM';
this.DCOMUrl = 'rqlaction.asp';
this.WebService11 = 'WebService11';
this.WebService11Url = '/CMS/WebService/RqlWebService.svc';
this.RqlConnectionType = '';
this.InitializeConnectionType();
}
RqlConnector.prototype.SetConnectionType =function (ConnectionType)
{
this.RqlConnectionType = ConnectionType;
}
RqlConnector.prototype.GetConnectionType =function ()
{
return this.RqlConnectionType;
}
RqlConnector.prototype.InitializeConnectionType =function ()
{
if(this.GetConnectionType() == '')
{
if(this.TestConnection(this.WebService11Url))
{
this.SetConnectionType(this.WebService11);
}else{
this.SetConnectionType(this.DCOM);
}
}
}
RqlConnector.prototype.SendRql = function(InnerRQL, IsText, CallbackFunc)
{
switch(this.GetConnectionType())
{
case this.DCOM:
this.SendRqlCOM(InnerRQL, IsText, CallbackFunc);
break;
case this.WebService11:
this.SendRqlWebService(InnerRQL, IsText, CallbackFunc);
break;
}
}
RqlConnector.prototype.SendRqlWebService = function(InnerRQL, IsText, CallbackFunc)
{
var SOAPMessage = '';
SOAPMessage += '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">';
SOAPMessage += '<s:Body><q1:Execute xmlns:q1="http://tempuri.org/RDCMSXMLServer/message/"><sParamA>' + this.padRQLXML(InnerRQL, IsText) + '</sParamA><sErrorA></sErrorA><sResultInfoA></sResultInfoA></q1:Execute></s:Body>';
SOAPMessage += '</s:Envelope>';
$.ajax({
type: 'POST',
url: this.WebService11Url,
data: SOAPMessage,
contentType: 'text/xml; charset=utf-8',
dataType: 'xml',
beforeSend: function(xhr) {
xhr.setRequestHeader('SOAPAction', 'http://tempuri.org/RDCMSXMLServer/action/XmlServer.Execute');
},
success: function (data) {
var RetRql = $(data).find('Result').text();
if(IsText)
{
data = RetRql;
}
else
{
data = $.parseXML( $.trim(RetRql) );
}
CallbackFunc(data);
},
error: function (message) {
//alert(message);
CallbackFunc(message);
}
});
}
RqlConnector.prototype.SendRqlCOM = function(InnerRQL, IsText, CallbackFunc)
{
var Rql = this.padRQLXML(InnerRQL, IsText);
$.post(this.DCOMUrl, { rqlxml: Rql },
function(data){
data = $('<div/>').append(data);
CallbackFunc(data);
});
}
RqlConnector.prototype.padRQLXML =function (InnerRQL, IsText)
{
var Rql = '<IODATA loginguid="' + this.LoginGuid + '" sessionkey="' + this.SessionKey + '"';
if(IsText)
{
Rql += ' format="1"';
}
Rql += '>' + InnerRQL + '</IODATA>';
if(this.GetConnectionType(this.WebService11) == this.WebService11)
{
Rql = '<![CDATA[' + Rql + ']]>';
}
return Rql;
}
RqlConnector.prototype.TestConnection =function (Url)
{
var http = new XMLHttpRequest();
http.open('HEAD', Url, false);
http.send();
return http.status!=404;
}