The name 'FileSystem' does not exist in the current context.

  • Автор темы Автор темы zenfreak
  • Дата начала Дата начала

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Реакции
12
Баллы
18
Even if using System.IO;

I get this error: The name 'FileSystem' does not exist in the current context.

While trying:
Код:
Развернуть Свернуть Копировать
FileSystem.FileAppendString(path, htmlCode, appendNewLine);

inside a custom function in ActionGroup2.cs

bMwQAU3.png
 
Class FileSystem belongs to ZennoLab.Macros namespace. In CC, by default "ZennoLab.Macros.dll" is absent:
2017-06-12_14-14-37.png

So you need to add to References this dll from ZennoPoster directory, and add "using ZennoLab.Macros;" to your .cs file.
 
  • Спасибо
Реакции: zenfreak
Thank you @LaGir! You are right, I should have looked for "FileSystem" into the webframe docs. Now I know what to look for.

I am trying to move all my code to CC so I can do a better debugging but even if my code worked "out of the box" in OwnCode, I run into some basic problems. I'm still having trouble understanding how the CC works.

What I have understood so far is that I have one main Program.cs that executes functions created in ActionGroup1,2,3 ... like this:

Код:
Развернуть Свернуть Копировать
executionResult = ActionGroup1.Execute(instance, project);

And inside the ActionGroupX.cs files I have to create my functions using the instance and project as arguments:

Код:
Развернуть Свернуть Копировать
using System;
using System.Data;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Resources;
using System.ComponentModel;
using System.Collections.Generic;
using ZennoLab.CommandCenter;
using ZennoLab.InterfacesLibrary.ProjectModel;
using ZennoLab.InterfacesLibrary.ProjectModel.Enums;
using ZennoLab.Emulation;

namespace myProject
{
    internal class ActionGroup1
    {
       
        public static int myCustomFunction(int myCustomVar, Instance instance, IZennoPosterProjectModel project)
        {
           

            Tab tab = instance.MainTab;
            Document doc = tab.MainDocument;
           
            HtmlElementCollection heCol = doc.FindElementsByAttribute("div", "class", "myClass", "text");

            int count = heCol.Count;
            return 0;
        }
       
    }
}

And run them like this
Код:
Развернуть Свернуть Копировать
executionResult = ActionGroup1.myCustomFunction(10, instance, project);

The problem is that I cannot retrieve the html elements correctly, meaning that the count variable returns 0 even if that div class element exists and previously returned the correct value. I also checked the doc variable and has the right value (the current document html)

Код:
Развернуть Свернуть Копировать
HtmlElement he = tab.FindElementByAttribute("div", "class", "myClass", "text", 0)
doesn't return anything also even if when I check the tab I can see the correct html inside.

I think it has something to do with instance and project but don't know what should I do next.
 
Not sure if my approach described above is the correct but it works now. The problem was that the previous ActionGroup was loading a page that did not finish loading so adding:
Tab tab = instance.ActiveTab;
if ((tab.IsVoid) || (tab.IsNull)) return -1;
if (tab.IsBusy) tab.WaitDownloading();

before searching for the elements solved the problem.

Still not sure why and when to use the Instance instance, IZennoPosterProjectModel project arguments but the code works, for now ...
 
  1. int count = heCol.Count;
  2. return 0;

  1. should be

  1. return count;
 
Still not sure why and when to use the Instance instance, IZennoPosterProjectModel project arguments but the code works, for now ...
If you need to use properties or methods of instance or project in your function/method - use them as arguments, otherwise - don't use. I think that's enough.
If your template is complicated, it makes sense to create separate class with instance and project properties, and initialize them at the beginning of this template. In this case you can write like:
Код:
Развернуть Свернуть Копировать
MyClass.Project.SendInfoToLog("text");
...and you will not need to use instance and project as arguments in any methods.
 

Вложения

  • Спасибо
Реакции: zenfreak
@LaGir I've been using your suggestions but I'm having trouble using Thread.Sleep and getting this error:

3TZyUjM.jpg

Not sure how can I get my script to pause for a few seconds, any ideas?
 
I've been using your suggestions but I'm having trouble using Thread.Sleep and getting this error:
Thread.Sleep belongs to the namespace System.Threading, maybe you don't have this "using" in ActionGroup2.cs (by default it is absent in CC).
Or you can just write like this: System.Threading.Thread.Sleep(beforeRnd);
 
  • Спасибо
Реакции: LightWood и zenfreak
Before using the CurrentTheard.cs method you described above I was able to use Thread.Sleep(beforeRnd) just like that but you are right, using System.Threading.Thread.Sleep(beforeRnd); works out of the box :)

Thanks again LaGir :az:
 
  • Спасибо
Реакции: LaGir

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