using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.XPath;
public partial class _Default : System.Web.UI.Page
{
protected String cascadeLocation;
protected String cascadeUser;
protected String cascadePassword;
protected String authType;
protected bool enableUsers;
protected String xmlFeedPath;
protected void Page_Load(object sender, EventArgs e)
{
String configurationPageName = "users-group-xml-import-config.xml"; // Name of the configuration page
String basePath = System.AppDomain.CurrentDomain.BaseDirectory; // The base directory that this script runs from
XPathDocument configDoc = new XPathDocument(basePath + configurationPageName);
XPathNavigator configNav = configDoc.CreateNavigator();
XPathNavigator systemDataStructure = configNav.SelectSingleNode("/system-data-structure");
cascadeLocation = systemDataStructure.SelectSingleNode("cms-login-info/server").Value;
cascadeUser = systemDataStructure.SelectSingleNode("cms-login-info/username").Value;
cascadePassword = systemDataStructure.SelectSingleNode("cms-login-info/password").Value;
authType = systemDataStructure.SelectSingleNode("authentication-type").Value;
enableUsers = systemDataStructure.SelectSingleNode("enable-users").Value == "Yes";
xmlFeedPath = systemDataStructure.SelectSingleNode("xml-feed").Value;
Label1.Text = "";
// Construct a web service for Cascade Server
wsdl.AssetOperationHandlerService service = new wsdl.AssetOperationHandlerService();
service.Url = cascadeLocation + "/ws/services/AssetOperationService?wsdl";
// Construct an authentication object for web service call
wsdl.authentication auth = new wsdl.authentication();
auth.username = cascadeUser;
auth.password = cascadePassword;
// Load the xml-feed document into an XPathDocument object and create its XPathNavigator
XPathDocument xmlFeedDoc = new XPathDocument(basePath + xmlFeedPath);
XPathNavigator xmlFeedNav = xmlFeedDoc.CreateNavigator();
// Create all the groups listed in the xml-feed file
XPathNodeIterator groups = xmlFeedNav.Select("/xml/group");
wsdl.createResult r;
while (groups.MoveNext())
{
wsdl.asset asset = new wsdl.asset();
wsdl.group group = new wsdl.group();
// Add the child-nodes "groupName" and "role" to the wsdl.group object
group.groupName = groups.Current.SelectSingleNode("groupName").Value;
group.role = new wsdl.roles();
{
switch (groups.Current.SelectSingleNode("role").Value)
{
case "administrator":
group.role = wsdl.roles.administrator;
break;
case "approver":
group.role = wsdl.roles.approver;
break;
case "contributor":
group.role = wsdl.roles.contributor;
break;
case "manager":
group.role = wsdl.roles.manager;
break;
case "publisher":
group.role = wsdl.roles.publisher;
break;
}
}
asset.group = group;
try
{
r = service.create(auth, asset); // Create user-group in CMS
}
catch (Exception ex)
{
Label1.Text += "WSDL call failed: Unable to add groups: ERROR: " + ex.Message;
return;
}
if (r.success != "true")
{
Label1.Text += "Failed to add groups: ERROR: " + r.message;
}
else
{
Label1.Text += "Added group: " + group.groupName + "
";
}
}
Label1.Text += "
";
// Create all the users from the xml-feed file
XPathNodeIterator users = xmlFeedNav.Select("/xml/user");
while (users.MoveNext())
{
wsdl.asset asset = new wsdl.asset();
wsdl.user user = new wsdl.user();
user.username = users.Current.SelectSingleNode("username").Value;
user.fullName = users.Current.SelectSingleNode("fullName").Value;
user.email = users.Current.SelectSingleNode("email").Value;
switch (authType)
{
case "normal":
user.authType = wsdl.userauthtypes.normal;
break;
case "ldap":
user.authType = wsdl.userauthtypes.ldap;
break;
case "custom":
user.authType = wsdl.userauthtypes.custom;
break;
}
user.enabled = enableUsers;
if (enableUsers) { Label1.Text += "enableUsers = true
"; }
user.password = users.Current.SelectSingleNode("password").Value;
user.groups = users.Current.SelectSingleNode("groups").Value;
user.defaultGroup = (users.Current.SelectSingleNode("defaultGroup") != null) ? users.Current.SelectSingleNode("defaultGroup").Value : "";
{
switch (users.Current.SelectSingleNode("role").Value)
{
case "administrator":
user.role = wsdl.roles.administrator;
break;
case "approver":
user.role = wsdl.roles.approver;
break;
case "contributor":
user.role = wsdl.roles.contributor;
break;
case "manager":
user.role = wsdl.roles.manager;
break;
case "publisher":
user.role = wsdl.roles.publisher;
break;
}
}
asset.user = user;
try
{
r = service.create(auth, asset); // Create user in CMS
}
catch (Exception ex){
Label1.Text += "WSDL call failed: Unable to add users: ERROR: " + ex.Message;
return;
}
if (r.success != "true")
{
Label1.Text += "Failed to add users: ERROR: " + r.message;
}
else
{
Label1.Text += "Added user: " + user.username + "
";
}
}
}
}