Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

testing

  • Loading branch information...
commit 1adff8e9983e518fb905d4fe7e236d37601c71d4 1 parent f64ac09
@bricel authored
View
285 Class/Services.cs
@@ -33,8 +33,10 @@ public struct DrupalCon
public interface IServiceSystem : IXmlRpcProxy
{
[XmlRpcMethod("system.connect")]
- Drupal Connect();
-
+ Drupal Connect();
+
+ [XmlRpcMethod("user.login")]
+ DrupalCon Login(ref string hash, string domain_name, ref string timestamp, string nonce, string sessid, string username, string password);
[XmlRpcMethod("user.login")]
DrupalCon Login(string sessid, string username, string password);
[XmlRpcMethod("user.login")]
@@ -45,11 +47,14 @@ public interface IServiceSystem : IXmlRpcProxy
[XmlRpcMethod("user.logout")]
bool Logout();
+
[XmlRpcMethod("user.get")]
XmlRpcStruct UserGet(string sessid, int uid);
[XmlRpcMethod("user.get")]
- XmlRpcStruct UserGet( int uid);
-
+ XmlRpcStruct UserGet( int uid);
+
+ [XmlRpcMethod("node.get")]
+ XmlRpcStruct NodeGet(ref string hash,string domain_name,ref string timestamp,string nonce, string sessid, int nid, object fields);
[XmlRpcMethod("node.get")]
XmlRpcStruct NodeGet(string sessid, int nid, object fields);
[XmlRpcMethod("node.get")]
@@ -108,8 +113,30 @@ public bool UseSessionID
{
get { return _useSessionID; }
set { _useSessionID = value; }
+ }
+
+ bool _useKeys = false;
+ public bool UseKeys
+ {
+ get { return _useKeys; }
+ set { _useKeys = value; }
+ }
+
+ string _key = "";
+ public string Key
+ {
+ get { return _key; }
+ set { _key = value; }
+ }
+ string _domainName = "";
+ public string DomainName
+ {
+ get { return _domainName; }
+ set { _domainName = value; }
}
+
+
}
//----------------------------------------------------------------------------------------------------------
/// <summary>
@@ -139,6 +166,15 @@ public Services(ServicesSettings settings)
private void errorMessage(string msg)
{
sendLogEvent(msg, "Services", Enums.MessageType.Error);
+ }
+ private XmlRpcStruct handleExeption(Exception ex)
+ {
+ if (ex is XmlRpcFaultException)
+ {
+ _errorCode = (ex as XmlRpcFaultException).FaultCode;
+ }
+ errorMessage(ex.Message);
+ return null;
}
//<summary>
@@ -150,25 +186,23 @@ public string UserID
}
public XmlRpcStruct OGgetVocab(int ogID)
- {
- try
- {
- object vocabs;
- if (_settings.UseSessionID)
- vocabs = drupalServiceSystem.OGgetVocab(_sessionID, ogID);
- else
- vocabs = drupalServiceSystem.OGgetVocab(ogID);
-
- if (vocabs is XmlRpcStruct)
- return (vocabs as XmlRpcStruct);
- else
- return null;
- }
- catch (XmlRpcFaultException ex)
- {
- _errorCode = ex.FaultCode;
- errorMessage(ex.Message);
- return null;
+ {
+ try
+ {
+ object vocabs;
+ if (_settings.UseSessionID)
+ vocabs = drupalServiceSystem.OGgetVocab(_sessionID, ogID);
+ else
+ vocabs = drupalServiceSystem.OGgetVocab(ogID);
+
+ if (vocabs is XmlRpcStruct)
+ return (vocabs as XmlRpcStruct);
+ else
+ return null;
+ }
+ catch (Exception ex)
+ {
+ return handleExeption(ex);
}
}
public XmlRpcStruct[] TaxonomyGetTree(int vid)
@@ -180,29 +214,40 @@ public XmlRpcStruct[] TaxonomyGetTree(int vid)
return drupalServiceSystem.TaxonomyGetTree(_sessionID, vid);
else
return drupalServiceSystem.TaxonomyGetTree(vid);
- }
- catch (XmlRpcFaultException ex)
- {
- _errorCode = ex.FaultCode;
- errorMessage(ex.Message);
- return null;
+ }
+ catch (Exception ex)
+ {
+ handleExeption(ex);
+ return null;
}
}
public XmlRpcStruct NodeGet(int nid)
{
try
- {
- object ob = new object();//dummy object to send
- if (_settings.UseSessionID)
- return drupalServiceSystem.NodeGet(_sessionID, nid, ob);
- else
+ {
+ // Dummy object to send.
+ object ob = new object();
+ if (_settings.UseSessionID)
+ {
+ // Use of key together with SID.
+ if (_settings.UseKeys)
+ {
+ string hash = GetHMAC("",_settings.Key);
+ string timestamp = GetUnixTimestamp();
+ string nonce = GetNonce(10);
+ return drupalServiceSystem.NodeGet(ref hash, _settings.DomainName, ref timestamp, nonce, _sessionID, nid,ob);
+
+ }
+ else
+ return drupalServiceSystem.NodeGet(_sessionID, nid, ob);
+
+ }
+ else
return drupalServiceSystem.NodeGet(nid, ob);
- }
- catch (XmlRpcFaultException ex)
- {
- _errorCode = ex.FaultCode;
- errorMessage(ex.Message);
- return null;
+ }
+ catch (Exception ex)
+ {
+ return handleExeption(ex);
}
}
public XmlRpcStruct NodeGet(int nid, string[] fields)
@@ -214,14 +259,13 @@ public XmlRpcStruct NodeGet(int nid, string[] fields)
else
return drupalServiceSystem.NodeGet(nid, fields);
+ }
+ catch (Exception ex)
+ {
+ return handleExeption(ex);
}
- catch (XmlRpcFaultException ex)
- {
- _errorCode = ex.FaultCode;
- errorMessage(ex.Message);
- return null;
- }
- }
+ }
+
public XmlRpcStruct UserGet(int nid)
{
@@ -233,12 +277,10 @@ public XmlRpcStruct UserGet(int nid)
else
return drupalServiceSystem.UserGet( nid);
- }
- catch (XmlRpcFaultException ex)
- {
- errorMessage(ex.Message);
- _errorCode = ex.FaultCode;
- return null;
+ }
+ catch (Exception ex)
+ {
+ return handleExeption(ex);
}
}
/// <summary>
@@ -257,49 +299,46 @@ public XmlRpcStruct UserGet()
return drupalServiceSystem.UserGet( userID);
- }
- catch (XmlRpcFaultException ex)
- {
- errorMessage(ex.Message);
- _errorCode = ex.FaultCode;
- return null;
+ }
+ catch (Exception ex)
+ {
+ return handleExeption(ex);
}
}
public int NodeSave(XmlRpcStruct node)
- {
- try
- {
- //string filePath = DrupalServices.SERVERURL + ((taskNode["field_dispatch_zip_file"] as object[])[0] as XmlRpcStruct)["filepath"];
- //drupServ.DownloadFile(filePath, @"c:\test\1234\" + nextTaskNid.ToString() + ".zip");//save zip file locally
- //Now activaing mtm or other task
-
- //update task node
- //System.Windows.Forms.MessageBox.Show(((taskNode["field_dispatch_state"] as object[])[0] as XmlRpcStruct)["value"].ToString());
- // ((taskNode["field_dispatch_state"] as object[])[0] as XmlRpcStruct)["value"] = "Completed";//Change status to completed
- // ((taskNode["field_dispatch_log"] as object[])[0] as XmlRpcStruct)["value"] = "what ever";
-
- // (taskNode["title"]) = "brice_eee";
- //example of log update
- //((taskNode["field_dispatch_log"] as object[])[0] as XmlRpcStruct)["value"] += "yalla beitar" ;//update log
- //int newnodeID = drupServ.NodeSave(taskNode);
-
- // XmlRpcStruct fref=drupServ.FileSave(@"c:\test\1234\rani.pds", "cad_file");
-
- //(node["title"]) =DateTime.Now.ToString();//update log
- //((node["field_file_upload"] as object[])[0] as XmlRpcStruct)["filepath"] = @"c:\test.PDS";
- string res ;
- if (_settings.UseSessionID)
- res = drupalServiceSystem.NodeSave(_sessionID, node);
- else
- res = drupalServiceSystem.NodeSave(node);
-
- return Convert.ToInt32(res);
- }
- catch (XmlRpcFaultException ex)
- {
- errorMessage(ex.Message);
- _errorCode = ex.FaultCode;
- return 0;
+ {
+ try
+ {
+ //string filePath = DrupalServices.SERVERURL + ((taskNode["field_dispatch_zip_file"] as object[])[0] as XmlRpcStruct)["filepath"];
+ //drupServ.DownloadFile(filePath, @"c:\test\1234\" + nextTaskNid.ToString() + ".zip");//save zip file locally
+ //Now activaing mtm or other task
+
+ //update task node
+ //System.Windows.Forms.MessageBox.Show(((taskNode["field_dispatch_state"] as object[])[0] as XmlRpcStruct)["value"].ToString());
+ // ((taskNode["field_dispatch_state"] as object[])[0] as XmlRpcStruct)["value"] = "Completed";//Change status to completed
+ // ((taskNode["field_dispatch_log"] as object[])[0] as XmlRpcStruct)["value"] = "what ever";
+
+ // (taskNode["title"]) = "brice_eee";
+ //example of log update
+ //((taskNode["field_dispatch_log"] as object[])[0] as XmlRpcStruct)["value"] += "yalla beitar" ;//update log
+ //int newnodeID = drupServ.NodeSave(taskNode);
+
+ // XmlRpcStruct fref=drupServ.FileSave(@"c:\test\1234\rani.pds", "cad_file");
+
+ //(node["title"]) =DateTime.Now.ToString();//update log
+ //((node["field_file_upload"] as object[])[0] as XmlRpcStruct)["filepath"] = @"c:\test.PDS";
+ string res;
+ if (_settings.UseSessionID)
+ res = drupalServiceSystem.NodeSave(_sessionID, node);
+ else
+ res = drupalServiceSystem.NodeSave(node);
+
+ return Convert.ToInt32(res);
+ }
+ catch (Exception ex)
+ {
+ handleExeption(ex);
+ return 0;
}
}
public XmlRpcStruct[] ViewsGet(string viewName, string[] args)
@@ -313,23 +352,20 @@ public XmlRpcStruct[] ViewsGet(string viewName, int limit)
return this.ViewsGet(viewName, limit, arrayArgs);
}
public XmlRpcStruct[] ViewsGet(string viewName, int limit, object args)
- {
- try
- {
- XmlRpcStruct o1 = new XmlRpcStruct();
- if (_settings.UseSessionID)
-
- return drupalServiceSystem.ViewsGet(_sessionID, viewName, "default", o1, args, 0, limit);
- else
- return drupalServiceSystem.ViewsGet(viewName, "default", o1, args, 0, limit);
- }
- catch (Exception ex)
- {
- errorMessage(ex.Message);
- _errorCode = 0;
- if (ex is XmlRpcFaultException)
- _errorCode = (ex as XmlRpcFaultException).FaultCode;
- return null;
+ {
+ try
+ {
+ XmlRpcStruct o1 = new XmlRpcStruct();
+ if (_settings.UseSessionID)
+ return drupalServiceSystem.ViewsGet(_sessionID, viewName, "default", o1, args, 0, limit);
+ else
+ return drupalServiceSystem.ViewsGet(viewName, "default", o1, args, 0, limit);
+ }
+ catch (Exception ex)
+ {
+ _errorCode = 0;
+ handleExeption(ex);
+ return null;
}
}
//--------------------------------------------------------------------------------------
@@ -502,18 +538,29 @@ public bool Login(string user, string password)
// Clean URL pref
if (!_settings.CleanURL)
xmlrpcServer = "?q=services/xmlrpc";
- else
- xmlrpcServer = "services/xmlrpc";
+ else
+ xmlrpcServer = "services/xmlrpc";
- drupalServiceSystem.Url = _settings.DrupalURL + xmlrpcServer;
+ drupalServiceSystem.Url = _settings.DrupalURL + xmlrpcServer +"?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=126589808359313";
Drupal cnct = drupalServiceSystem.Connect();
DrupalCon lgn ;
- // SesionID pref
-
- if (_settings.UseSessionID)
- lgn = drupalServiceSystem.Login(cnct.sessid, user, password);
- else
- lgn = drupalServiceSystem.Login( user, password);
+ // SesionID pref
+
+ if (_settings.UseSessionID)
+ {
+ if (_settings.UseKeys)
+ {
+ string hash = "";// GetHMAC("", _settings.Key);
+ string timestamp="";// = GetUnixTimestamp();
+ string nonce = GetNonce(10);
+ lgn = drupalServiceSystem.Login(ref hash, _settings.DomainName, ref timestamp, nonce, cnct.sessid, user, password);
+ }
+ else
+ lgn = drupalServiceSystem.Login(cnct.sessid, user, password);
+
+ }
+ else
+ lgn = drupalServiceSystem.Login(user, password);
_sessionID = lgn.sessid;
_uID = lgn.user.uid; //returned from login
_isLoggedIn = true;
View
BIN  DrutNET.suo
Binary file not shown
View
35 DrutNETSample/Form1.cs
@@ -22,14 +22,17 @@ public Form1()
// Create a settings object to define connection settings.
ServicesSettings settings = new ServicesSettings();
- settings.DrupalURL = "http://localhost/drupal-sqlite/";
- settings.CleanURL = false;
- settings.UseSessionID = true;
+ settings.DrupalURL = "http://localhost/DrutNet/drupal-sqlite/";
+ settings.CleanURL = true;
+ settings.UseSessionID = true;
+ settings.UseKeys = true;
+ settings.Key = "03cfd62180a67dcbcb1be9a7f78dc726";
+ settings.DomainName = "localhost";
// Create a connection object
_serviceCon = new Services(settings);
// Login to drupal
- _serviceCon.Login("admin", "1234");
+ _serviceCon.Login("demo", "1234");
}
void DrutNETBase_OnUpdateLog(string str, string mSender, Enums.MessageType mType, bool verbose)
{
@@ -147,20 +150,24 @@ void listViewTags_ItemChecked(object sender, ItemCheckedEventArgs e)
(e.Item.Tag as TaxonomyTerm).IsSelected = false;
}
}
- }
-
- private void button_load_Click(object sender, EventArgs e)
- {
- // Node to load
- _node = _serviceCon.NodeGet(Convert.ToInt32(textBox_nodeID.Text));
- if (_node!=null)
- richTextBox1.Text = _node["body"].ToString();
+ }
+
+ private void button_load_Click(object sender, EventArgs e)
+ {
+ textBox_message.Text = "";
+ // Node to load
+ _node = _serviceCon.NodeGet(Convert.ToInt32(textBox_nodeID.Text));
+ if (_node != null)
+ richTextBox1.Text = _node["body"].ToString();
}
private void button_save_Click(object sender, EventArgs e)
- {
+ {
+ textBox_message.Text = "";
if (_node != null)
- {
+ {
+ // Reload node to prevent access restriction, by other user
+ _node = _serviceCon.NodeGet(Convert.ToInt32(textBox_nodeID.Text));
//update node
_node["body"] = richTextBox1.Text;
_serviceCon.NodeSave(_node);
View
10 drupal-sqlite/.buildpath
@@ -1,5 +1,5 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<buildpath>
- <buildpathentry kind="src" path=""/>
- <buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
-</buildpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<buildpath>
+ <buildpathentry excluding=".svn/" kind="src" path=""/>
+ <buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
+</buildpath>
View
50 drupal-sqlite/.project
@@ -1,22 +1,28 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>drupal-sqlite</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.dltk.core.scriptbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.php.core.PHPNature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>drutnet</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.dltk.core.scriptbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.php.core.PHPNature</nature>
+ <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+ </natures>
+</projectDescription>
View
12 drupal-sqlite/.settings/.jsdtscope
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path=""/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
+ <attributes>
+ <attribute name="hide" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
View
3  drupal-sqlite/.settings/org.eclipse.php.core.prefs
@@ -0,0 +1,3 @@
+#Thu Feb 11 14:30:34 IST 2010
+eclipse.preferences.version=1
+include_path=
View
1  drupal-sqlite/.settings/org.eclipse.wst.jsdt.ui.superType.container
@@ -0,0 +1 @@
+org.eclipse.wst.jsdt.launching.baseBrowserLibrary
View
1  drupal-sqlite/.settings/org.eclipse.wst.jsdt.ui.superType.name
@@ -0,0 +1 @@
+Window
View
BIN  drupal-sqlite/sites/default/db/db.s3db 100644 → 100755
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.