How to control tasks in ZP from Visual Studio C# application?

cheekybot

Client
Регистрация
19.09.2014
Сообщения
36
Благодарностей
3
Баллы
8
I'm creating an application in Visual Studio to read and write data to a database for ZP to work with and want to have quick view of running tasks.

I borrowed some code from another thread to test and added references to the DLLs that darkdiver mentioned in from this thread but AddTries() doesn't change any values in ZP and "var tasks = new List<string>(ZennoPoster.TasksList);" always returns null.

I'm still new to C#... can anyone point out what I'm missing for this to work?

ZennoLab.CommandCenter.dll
ZennoLab.Global.dll
ZennoLab.CommunicationInterfaces.dll
ZennoLab.InterfacesLibrary.dll
ZennoLab.LogLibrary.dll

Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZennoLab.CommandCenter;
using ZennoLab.InterfacesLibrary;
using ZennoLab.InterfacesLibrary.ProjectModel;
using ZennoLab.InterfacesLibrary.ProjectModel.Collections;
using ZennoLab.InterfacesLibrary.ProjectModel.Enums;
using Global.ZennoExtensions;

namespace ConsoleApplication1
{
  class Program
  {
  static void Main(string[] args)
  {
    var searchName = "Test";
    var searchResult = false;
    // get the task list from the ZennoPoster
    var tasks = new List<string>(ZennoPoster.TasksList);
    foreach (var tsk in tasks)
    {
    // loading Xml documnt with task content
    var doc = new System.Xml.XmlDocument();
    doc.LoadXml("<Task>" + tsk + "</Task>");
    // Search task by name
    var nameElement = doc.SelectSingleNode("Task/Name");
    if (nameElement == null) continue;
    var name = nameElement.InnerText;
    // if we found our task
    if (name == searchName)
    {
    // take task id
    var idElement = doc.SelectSingleNode("Task/Id");
    if (idElement == null) continue;
    var id = Guid.Parse(idElement.InnerText);
    // take execution settings element
    var esElement = doc.SelectSingleNode("Task/ExecutionSettings");
    if (esElement == null) continue;
    // take limit of threads of the task
    var threadsElement = doc.SelectSingleNode("Task/ExecutionSettings/LimitOfThreads");
    if (threadsElement == null) continue;
    // change the value
    threadsElement.InnerText = "10";
    // set new settings
    ZennoPoster.SetExecutionSettings(id, esElement.InnerXml);
    {
    // take execution settings element
    var esElement1 = doc.SelectSingleNode("Task/ExecutionSettings");
    if (esElement1 == null) continue;
    // take limit of threads of the task
    var threadsElement1 = doc.SelectSingleNode("Task/ExecutionSettings/NumberOfTries");
    if (threadsElement1 == null) continue;
    // change the value
    threadsElement1.InnerText = "1";
    // set new settings
    ZennoPoster.SetExecutionSettings(id, esElement1.InnerXml);
    }
    searchResult = true;
    break;
    }
    }
    if (!searchResult)
    throw new Exception("Task " + searchName + " not found!");
    }
  }
}
 
Последнее редактирование:

LexxWork

Client
Регистрация
31.10.2013
Сообщения
1 190
Благодарностей
786
Баллы
113
var tasks = ZennoPoster.TasksList.ToList();
 

cheekybot

Client
Регистрация
19.09.2014
Сообщения
36
Благодарностей
3
Баллы
8
Still running into the same problem



I changed to an easier task to test and show what I mean:

Here is Visual Studio



Here is Code Creator

 

LexxWork

Client
Регистрация
31.10.2013
Сообщения
1 190
Благодарностей
786
Баллы
113
I think it's restricted in nondeveloper license. You should run it only in template through zennoposter.
I've tried the same and got the same error message.
Instance instance = new Instance("127.0.0.1", 40505, "server") raise the same error;
And what will support say ?
 

cheekybot

Client
Регистрация
19.09.2014
Сообщения
36
Благодарностей
3
Баллы
8
I opened a ticket with support, waiting to hear from them now..

Thanks for helping me check out the issue :-)
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
This method should work in ZennoPoster, when you run your project there. Not from VS.
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113

Ambassy

Client
Регистрация
10.10.2014
Сообщения
11
Благодарностей
0
Баллы
1
Would love to know too. In general, ZP would be worth 5x its value to me if I could get external VS applications and ZP to play together without using hackish methods.

Right now I'm stuck with the following tedious way of communication between VS and ZP:
1. Convert .NET 4.5 object to 4.0
2. Serialize object to json
3. Save json object in a textfile in the folder the ZP task manager watches
4. Read the textfile from ZP
5. Deserialize json object to .NET 4.0 object
6. After the work is done, serialize to json once again
7. Send object in a POST request to an end point which my VS application listens to


Would LOVE if ZP simply could be included as a library and controlled directly from other VS projects (as well as being upgraded to .NET 4.5).
 

LexxWork

Client
Регистрация
31.10.2013
Сообщения
1 190
Благодарностей
786
Баллы
113
May be if you buy develeper licence you could realize your intention. Anyway by now you can rewrite your application into libriary for zennoposter and run it in c# macros.
 

cheekybot

Client
Регистрация
19.09.2014
Сообщения
36
Благодарностей
3
Баллы
8
ZP can be laggy sometimes.. I want to control ZP when it's minimized and have tabs/windows for my own code outside of ZP.

If I have to click play on a ZP task just to access my application that controls ZP.. no point having an all-in-one application..

Shouldn't have to buy developer license to have external VS access. There's already a commission if you sell your project without dev license. ZP should already have security there if they want to make max profit..

Maybe @darkdiver can share some info to help? I saw in this thread he mentions using ZP classes in VS.. http://zennolab.com/discussion/threads/how-to-encapsulate-a-method-which-covers-the-zennoposter-method-into-my-dll-file.14921/#post-90388
 

Ambassy

Client
Регистрация
10.10.2014
Сообщения
11
Благодарностей
0
Баллы
1

cheekybot

Client
Регистрация
19.09.2014
Сообщения
36
Благодарностей
3
Баллы
8

Ambassy

Client
Регистрация
10.10.2014
Сообщения
11
Благодарностей
0
Баллы
1
It's located on the wiki here https://wiki.zennolab.com/doku.php?id=en:devlicense:general

Problem is, for $200 per 6 months is a lot to have a .exe if you don't want to sell it. Forces you to sell projects even if you just want for personal use..
Thanks for the link. Personally I will gladly pay $200 in order to be able to export to .exe files in ZP (even though I ain't gonna sell the bots - just the increased stability and time saved would make it worth it).

However I see that I'll have to upload projects etc. If I but the developer license, will I be able to run my projects in .exe format and pass arguments to the file at startup? (Question to the ZP staff)
 

cheekybot

Client
Регистрация
19.09.2014
Сообщения
36
Благодарностей
3
Баллы
8
I rather buy more pro licenses and have freedom to use VS too. It's my only problem.. but I like your work around so I will try that instead.

ZP almost perfect platform :(. Example: I just worry if the PC gets reset, no way to auto restart or remote restart the listener task. Same thing for all tasks... dead in water. Unless someone has an idea?
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
Thanks for the link. Personally I will gladly pay $200 in order to be able to export to .exe files in ZP (even though I ain't gonna sell the bots - just the increased stability and time saved would make it worth it).

However I see that I'll have to upload projects etc. If I but the developer license, will I be able to run my projects in .exe format and pass arguments to the file at startup? (Question to the ZP staff)
exe bots will be avialable later. It's in todo list for developer licenses.
 

Ambassy

Client
Регистрация
10.10.2014
Сообщения
11
Благодарностей
0
Баллы
1

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)