Update
Description
Update the SurveySchema
See the rules in the documentation for Filters to understand what changes are legal changed depending on Filter used |
Signature
void Update(string key, string projectId, SurveySchema schema)
Parameters
Name | Data Type | Description |
---|---|---|
key |
string required |
The authentication key |
projectId |
string required |
ID of the project |
schema |
SurveySchema required |
TranslationXML document |
Example
var authoring = new AuthoringSoapClient();
//***************************************************
//
// Retrieve, change and update ProjectInfo
//
//***************************************************
// Add a normal project (false = not a panel)
// projectID will be set to the new projectnumber
string projectID = authoring.AddProject(key,false);
// Get the project information (only projectnumber, build and
// default language is set
SurveySchema def = authoring.GetProjectInfo(key,projectID);
// Get ProjectInfo
ProjectInfo projectInfo = (ProjectInfo)def.Root.Nodes.GetValue(0);
// Check that we got it
if (projectInfo==null)
throwError();
// Change ProjectInfo
projectInfo.Description = "The first project made by use of the API";
// Suppose that default language is English (9), make a title
LanguageString newTitle = AuthoringUtil.NewLanguageString("My new Title",9);
// Add the title to projectInfo
ArrayList titles = new ArrayList((Array)projectInfo.Titles);
titles.Add(newTitle);
projectInfo.Titles = (LanguageString[])titles.ToArray(typeof(LanguageString));
// Set name of the project
projectInfo.Name = "API-made project";
// Update
authoring.Update(key,projectID,def);
//***************************************************
//
// Retrieve, change and update Quota
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Get Quota named quota1, projectspecific to enable update
SurveySchema def = authoring.GetQuota(key,projectID,"quota1",true);
// Get the quota
Quota quota = (Quota)def.Root.Nodes.GetValue(0);
// Check that the quota exists
if (quota==null)
throwError();
// Change quota name
quota.Name = "NewQuotaName";
// Change quota emailaddress
quota.EmailAddress = "dummy@dummy.dummy";
// Create a new reference to an existing SingleQuestion called s1
FormReference formReference = AuthoringUtil.NewFormReference("s1");
// Add the reference to the quota
ArrayList forms = new ArrayList((Array)quota.Forms);
forms.Add(formReference);
quota.Forms = (FormReference[])forms.ToArray(typeof(FormReference));
// Update the quota
authoring.Update(key,projectID,def);
//***************************************************
//
// Get all quotas, delete one and update
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Get all Quotas, projectspecific to enable update
SurveySchema def = authoring.GetQuotas(key,projectID,true);
// Remove the last quota if it exists
ArrayList quotas = new ArrayList((Array)def.Root.Nodes);
if (quotas.Count > 0)
{
quotas.RemoveAt(quotas.Count-1);
def.Root.Nodes = (Quota[])quotas.ToArray(typeof(Quota));
}
// Update the quota
authoring.Update(key,projectID,def);
//***************************************************
//
// Retrieve, change and update PredefinedList
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Create a ReadFilterSimple
// Retrieve all languages
// Set references to other PredefinedLists as reference and not expanded
// Enable update
ReadFilterSimple readFilterSimple =
AuthoringUtil.NewReadFilterSimple(true,false,true);
// Get the predefined list named "a-g"
SurveySchema def =
authoring.GetPredefinedList(key,projectID,"a-g",readFilterSimple);
// Check that we got a reply
if (def.Root.Nodes.Length == 0)
throwError();
// Get the predefined list
PredefinedList predefinedList =
(PredefinedList)def.Root.Nodes.GetValue(0);
// Make changes
// Add a new Answer
Answer newAnswer = AuthoringUtil.NewAnswer("BMW");
// Give values to the new answer
AnswerText answerText =
AuthoringUtil.NewAnswerText("BMW",9);
ArrayList texts = new ArrayList();
texts.Add(answerText);
newAnswer.Texts = (AnswerText[])texts.ToArray(typeof(AnswerText));
// Add new answer to answerlist
ArrayList answers = new ArrayList((Array)predefinedList.Answers);
answers.Add(newAnswer);
predefinedList.Answers = (AnswerBase[])answers.ToArray(typeof(AnswerBase));
// Update
authoring.Update(key,projectID,def);
//***************************************************
//
// Get all predefined lists, Add predefined list, Update
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Create ReadFilter
ReadFilterSimple readFilterSimple =
AuthoringUtil.NewReadFilterSimple(false,false,true);
// Get all PredefinedLists, projectspecific to enable update
SurveySchema def =
authoring.GetPredefinedLists(key,projectID,readFilterSimple);
// Create new PredefinedList
PredefinedList newPredefinedList = AuthoringUtil.NewPredefinedList("Gender");
// Create new answers
Answer answer1 = AuthoringUtil.NewAnswer("M");
Answer answer2 = AuthoringUtil.NewAnswer("F");
// Create new answertexts
AnswerText answerText1 =
AuthoringUtil.NewAnswerText("Male",9);
AnswerText answerText2 =
AuthoringUtil.NewAnswerText("Female",9);
// Add answertexts to answers
ArrayList texts1 = new ArrayList();
texts1.Add(answerText1);
answer1.Texts = (AnswerText[])texts1.ToArray(typeof(AnswerText));
ArrayList texts2 = new ArrayList();
texts2.Add(answerText2);
answer2.Texts = (AnswerText[])texts2.ToArray(typeof(AnswerText));
// Add new answers to PredefinedList
ArrayList answers = new ArrayList();
answers.Add(answer1);
answers.Add(answer2);
newPredefinedList.Answers = (Answer[])answers.ToArray(typeof(Answer));
// Add PredefinedList to PredefinedList-collection
ArrayList predefinedLists = new ArrayList((Array)def.Root.Nodes);
predefinedLists.Add(newPredefinedList);
def.Root.Nodes = (PredefinedList[])predefinedLists.ToArray(typeof(PredefinedList));
// Update
authoring.Update(key,projectID,def);
//***************************************************
//
// Get the loopstructure, pick one loop,
// get all subforms and change their name, finally update
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Get loopstructure
SurveySchema def = authoring.GetLoopStructure(key,projectID,SchemaSourceType.Design);
// Check that we got at least one loop
if (def.Root.Nodes.Length == 0)
throwError();
// Get the first Loop
Loop loop = (Loop)def.Root.Nodes.GetValue(0);
// Configure ReadFilter
ReadFilter readFilter =
AuthoringUtil.NewReadFilter(false,false,true,true);
// Get all forms under the loop
// (not including subloops and forms under subloops
def = authoring.GetFormsInLoop(key,projectID,loop,readFilter,SchemaSourceType.Design);
// Make iterator for the forms
IEnumerator e = def.Root.Nodes.GetEnumerator();
// Iterate through all forms and change their name
while (e.MoveNext())
((FormBase)e.Current).Name += "_iterated";
// Update
authoring.Update(key,projectID,def);
//***************************************************
//
// Get Questionnaire, change and update
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Get the questionnaire
SurveySchema def = authoring.GetQuestionnaire(key,projectID,true);
// Get the questionnaire object
Questionnaire questionnaire = (Questionnaire)def.Root.Nodes.GetValue(0);
// Perform some changes
// Set new description of the project
((ProjectInfo)questionnaire.ProjectInfo).Description = "my new description";
// Change name of second quota if exists
if (questionnaire.Quotas.Length >=2)
((Quota)questionnaire.Quotas.GetValue(1)).Name = "new quota name";
// Change the precode of the first answer of the third predefined list if exists
// Check that the third predefined list exists
if (questionnaire.PredefinedLists.Length >=3)
// Check that the third predefined list has at least one answer
if (((PredefinedList)questionnaire.PredefinedLists.GetValue(2)).Answers.Length > 1)
// Check that the first answer is not a reference to a predefined list
if (((PredefinedList)questionnaire.PredefinedLists.GetValue(2)).Answers.GetValue(0).GetType() == typeof(Answer))
// Make the change
((Answer)((PredefinedList)questionnaire.PredefinedLists.GetValue(2)).Answers.GetValue(0)).Precode = "newPrecode";
// Add a new folder to Routing
// Create Folder
Folder folder = AuthoringUtil.NewFolder("new Folder");
// Place folder after 3rd element in the routing
ArrayList routing = new ArrayList((Array)questionnaire.Routing);
routing.Insert(3,folder);
questionnaire.Routing = (QuestionnaireNode[])routing.ToArray(typeof(QuestionnaireNode));
// Update
authoring.Update(key,projectID,def);
//***************************************************
//
// Get Routing, Change, Update
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Get the questionnaire
SurveySchema def = authoring.GetRouting(key,projectID,true);
// Add a new Directive to Routing
// Create Directive
Directive directive = AuthoringUtil.NewDirective(DirectiveDataType.Single);
ArrayList nodes = new ArrayList((Array)def.Root.Nodes);
// Insert as item #3
nodes.Insert(3,directive);
def.Root.Nodes = (Node[])nodes.ToArray(typeof(Node));
// Update
authoring.Update(key,projectID,def);
//***************************************************
//
// Get Nodes
// Get ConditionBranch
// Update
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Make a new poetReadFilter
PoetReadFilter poetReadFilter =
AuthoringUtil.NewPoetReadFilter(false,false,true,true,false);
// Only conditions
ArrayList nodeTypes = new ArrayList();
nodeTypes.Add(NodeType.Condition);
poetReadFilter.NodeTypes = (NodeType[])nodeTypes.ToArray(typeof(NodeType));
// Get all conditions in the project
SurveySchema def = authoring.GetNodes(key,projectID,null,poetReadFilter);
// Pick the first condition
Condition condition = (Condition)def.Root.Nodes.GetValue(0);
// Set the readfilter to include all nodetypes
poetReadFilter.IncludeAllNodeTypes = true;
// Get All Truenodes (nodes under the 'IF THEN'-part) of the condition
def = authoring.GetConditionBranch(key,projectID,condition,poetReadFilter,true);
// Add new node to place under the THEN-part
SingleForm single = AuthoringUtil.NewSingleForm("newSingle");
ArrayList nodes = new ArrayList((Array)def.Root.Nodes);
nodes.Add(single);
def.Root.Nodes = (Node[])nodes.ToArray(typeof(Node));
// Update
authoring.Update(key,projectID,def);
//***************************************************
//
// Get Form from name
// Get Node
// Get Forms in Loop
// Update
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Get loop by use of name (heavy task in design, light in runtime)
SurveySchema def = authoring.GetFormByName(
key,
projectID,
"l1",
AuthoringUtil.NewReadFilterSimple(false,false,true),
SchemaSourceType.Design);
// Point to the loop
Loop loop = (Loop)def.Root.Nodes.GetValue(0);
// If a node is retrieved in lightweight-version it can be used to get its heavyweight-version
PoetReadFilter poetReadFilter =
AuthoringUtil.NewPoetReadFilter(true,false,true,true,true);
poetReadFilter.IncludeAllForms = true;
poetReadFilter.IncludeAllNodeTypes = true;
poetReadFilter.IncludeAllLanguages = true;
def = authoring.GetNode(key,projectID,loop,poetReadFilter);
// Point to the same node, but now including languages
loop = (Loop)def.Root.Nodes.GetValue(0);
// Create new readfilter
ReadFilter readFilter =
AuthoringUtil.NewReadFilter(false,false,true,true);
// Get the forms under the loop
def = authoring.GetFormsInLoop(key,projectID,loop,readFilter,SchemaSourceType.Design);
// Change the name of the first hit
FormBase form = (FormBase)def.Root.Nodes.GetValue(0);
// Add to the existing name of the form
form.Name += "_new";
// Update
authoring.Update(key,projectID,def);
//***************************************************
//
// Get PredefinedLists from project #1
// Copy into project #2
//
//***************************************************
// Create instance of the webservice
Authoring authoring = new Authoring();
// Make a readfilter that is complete and not projectspecific
ReadFilterSimple readFilterSimple =
AuthoringUtil.NewReadFilterSimple(true,false,false);
// Get all predefined lists from sourceproject
SurveySchema defSource = authoring.GetPredefinedLists(key,projectIDSource,readFilterSimple);
// We want the destination to be projectspecific
readFilterSimple.ProjectSpecific = true;
// Get all predefine lists from destinationproject
SurveySchema defDestination = authoring.GetPredefinedLists(key,projectIDDestination,readFilterSimple);
// Transfer predefined lists
ArrayList nodes = new ArrayList((Array)defDestination.Root.Nodes);
foreach (Node node in defSource.Root.Nodes)
nodes.Add(node);
defDestination.Root.Nodes = (Node[])nodes.ToArray(typeof(Node));
// Update destination
authoring.Update(key,projectIDDestination,defDestination);
//***************************************************
//
// FullDeployment
//
//***************************************************
// Example of how to automatically deploy a project based
// on a survey XML of an old format without WI-deployment
// information. (Note that in XMLs from ConfirmIt8.1 WI-deployment
// information is already part of the XML and the following scheme
// is only necessary if WI-deployment information is to be changed.
// Make a survey import from a file.
Authoring authoring = new Authoring();
XmlDocument xml = new XmlDocument();
xml.Load(filename);
string newProjectId = authoring.ImportSurvey(key,xml.InnerXml);
// Retrieve the project information
SurveySchema schema = authoring.GetProjectInfo(key,newProjectId);
ProjectInfo pi = (ProjectInfo)schema.Root.Nodes.GetValue(0);
// Make the first of the legal languages the default language
// Note that setting the default language is necessary to be able to
// use URLs to the survey without language specified. Setting the
// default language also prevents confirmit from using default WI-properties
// if the survey is compiled through the ConfirmIt userinterface later.
pi.DefaultLanguage = pi.Languages[0];
// Setting a few standard properties
pi.ProgressBar = true;
pi.AllowModify = false;
pi.AllowModifyComplete = false;
// Putting some values into the help and endlink fields
ArrayList urls = new ArrayList();
ArrayList texts = new ArrayList();
foreach (int language in pi.Languages)
{
LanguageString text = new LanguageString();
text.Language = language;
text.Value = "Please click here...";
texts.Add(text);
LanguageString url = new LanguageString();
url.Language = language;
url.Value = "http://www.yahoo.com";
urls.Add(url);
}
pi.EndLinkTexts = (LanguageString[])texts.ToArray(typeof(LanguageString));
pi.HelpLinkTexts = pi.EndLinkTexts;
pi.EndLinkUrls = (LanguageString[])urls.ToArray(typeof(LanguageString));
pi.HelpLinkUrls = pi.EndLinkUrls;
// Update projectInfo
authoring.Update(key,newProjectId,schema);
// Generate database and generate Web Interview
// Note that a alias for SurveyDeployer namespace was used to prevent ambigous
// names. Normally this would have been prevented by splitting the deployer
// part into a separate class
dep.SurveyDeployer deployer = new dep.SurveyDeployer();
deployer.DeployProject(key,newProjectId,dep.DatabaseType.Production);