Last active
April 17, 2022 18:52
-
-
Save countnazgul/0069a00b8dc275445692e9284de337bc to your computer and use it in GitHub Desktop.
[Create reload task] Create new reload task with QlikView management API #qlik #qlikview #csharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void CreateTask(string user) | |
{ | |
QMSClient Client; | |
string QMS = "http://localhost:4799/QMS/Service"; | |
Client = new QMSClient("BasicHttpBinding_IQMS", QMS); | |
string key = Client.GetTimeLimitedServiceKey(); | |
ServiceKeyClientMessageInspector.ServiceKey = key; | |
Client.ClearQVSCache(QVSCacheObjects.UserDocumentList); | |
ServiceKeyClientMessageInspector.ServiceKey = Client.GetTimeLimitedServiceKey(); | |
ServiceInfo[] ServiceList = Client.GetServices(ServiceTypes.All); | |
Guid QvsGuid = ServiceList[1].ID; | |
DocumentFolder[] DocFolders = Client.GetUserDocumentFolders(QvsGuid, DocumentFolderScope.All); | |
DocumentFolder Folder = DocFolders[0]; | |
DocumentNode[] Documents = Client.GetUserDocumentNodes(QvsGuid, Folder.ID, user + @"\1_applications\2_etl"); | |
Guid m = new Guid("00000000-0000-0000-0000-000000000000"); | |
DocumentTask ta = CreateTaskDetails(Documents[0], QvsGuid, m); | |
ta.Scope = DocumentTaskScope.General | DocumentTaskScope.Triggering | DocumentTaskScope.DocumentInfo; | |
Client.SaveDocumentTask(ta); | |
DocumentNode[] Documents1 = Client.GetUserDocumentNodes(QvsGuid, Folder.ID, user + @"\1_applications\1_qvw"); | |
DocumentTask ta1 = CreateTaskDetails(Documents1[0], QvsGuid, ta.ID); | |
ta1.Scope = DocumentTaskScope.General | DocumentTaskScope.Triggering | DocumentTaskScope.DocumentInfo; | |
Client.SaveDocumentTask(ta1); | |
TaskInfo ti = Client.GetTask(ta.ID); | |
Client.Close(); | |
sendTaskDetails(user, ti.ID.ToString(), ta.General.TaskName); | |
} | |
private DocumentTask CreateTaskDetails(DocumentNode dn, Guid qvsGuid, Guid masterTask) { | |
DocumentTask ta = new DocumentTask(); | |
ta.Document = dn; | |
ta.QDSID = qvsGuid; | |
ta.ID = Guid.NewGuid(); | |
DocumentTask.TaskReload reload = new DocumentTask.TaskReload(); | |
reload.Mode = TaskReloadMode.Full; | |
ta.Reload = reload; | |
DocumentTask.TaskGeneral general = new DocumentTask.TaskGeneral(); | |
general.TaskName = "Reload " + dn.Name; | |
general.Enabled = true; | |
ta.General = general; | |
//ta.Scope = DocumentTaskScope.General; | |
ta.DocumentInfo = new DocumentTask.TaskDocumentInfo(); | |
ta.DocumentInfo.Description = "Task created using QMS API"; | |
DocumentAttribute[] da = new DocumentAttribute[0]; | |
ta.DocumentInfo.Attributes = da; | |
if (masterTask.ToString() != "00000000-0000-0000-0000-000000000000") | |
{ | |
TaskInfo[] ti = new TaskInfo[1]; | |
TaskInfo ti1 = new TaskInfo(); | |
ti1.Enabled = true; | |
ti1.ID = masterTask; | |
ti1.Type = TaskType.DocumentTask; | |
ti[0] = ti1; | |
ta.Triggering = new DocumentTask.TaskTriggering(); | |
ta.Triggering.TaskDependencies = ti; | |
ta.Triggering.ExecutionAttempts = 1; | |
ta.Triggering.ExecutionTimeout = 1440; | |
Trigger[] t = new Trigger[1]; | |
TaskEventTrigger t1 = new TaskEventTrigger(); | |
t1.Type = TaskTriggerType.TaskFinishedTrigger; | |
t1.TaskID = masterTask; | |
t1.Enabled = true; | |
t1.ID = new Guid(); | |
t[0] = t1; | |
ta.Triggering.Triggers = t; | |
} | |
else | |
{ | |
TaskInfo[] ti = new TaskInfo[1]; | |
TaskInfo ti1 = new TaskInfo(); | |
ti1.Enabled = true; | |
ti1.ID = ta.ID; | |
ti1.Type = TaskType.DocumentTask; | |
ti[0] = ti1; | |
ta.Triggering = new DocumentTask.TaskTriggering(); | |
ta.Triggering.TaskDependencies = new TaskInfo[0]; | |
ta.Triggering.ExecutionAttempts = 1; | |
ta.Triggering.ExecutionTimeout = 1440; | |
var t1 = new ScheduleTrigger(); | |
Trigger[] t = new Trigger[1]; | |
t1.Type = TaskTriggerType.OnceTrigger; | |
t1.ID = new Guid(); | |
t1.Enabled = true; | |
//t1.ID = new Guid(); | |
t[0] = t1; | |
ta.Triggering.Triggers = t; | |
} | |
return ta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment