DocumentCollection

Assembly: ZennoLab.CommandCenter
Full name: ZennoLab.CommandCenter.DocumentCollection
Kind: class


Represents a strongly typed list of documents that can be accessed by index.

If the DocumentCollection object does not indicate to the real html element of dom model when this property is true. Also objects of this class contains IsNull property for identification of document collection’s existence. Almost all classes of ZennoLab.CommandCenter contains such properties. Use it for the correct execution of the code.

Properties

IsVoid

Property

bool IsVoid { get; }

Gets the specified collection is void collection or not.

Example

public static int Execute(Instance instance, IZennoPosterProjectModel project)
            {
                // clear cookie
                instance.ClearCookie();
                
                // go to zennolab.com
                Tab tab = instance.MainTab;
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents
                DocumentCollection docCol = tab.AllDocuments;
                
                // if collection is void
                if (docCol.IsVoid) return -1;
                
                return 0;
            }

Example2

public static function Execute($instance, $project)
            {
                // clear cookie
                $instance->ClearCookie();
                
                // go to zennolab.com
                $tab = $instance->MainTab;
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents
                $docCol = $tab->AllDocuments;
                
                // if collection is void
                if ($docCol->IsVoid) return -1;
                
                return 0;
            }

ErrorDetected

Property

bool ErrorDetected { get; }

Gets information about the error detected in the performance last command

If the DocumentCollection object does not indicate to the real document collection then this property is true. Also objects of this class contains IsVoid property for identification of document collection’s existence. Almost all classes of ZennoLab.CommandCenter contains such properties. Use it for the correct execution of the code.

Example

public static int Execute(Instance instance, IZennoPosterProjectModel project)
            {
                // clear cookie
                instance.ClearCookie();
                
                // go to zennolab.com
                Tab tab = instance.MainTab;
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents
                DocumentCollection docCol = tab.AllDocuments;
                
                // go to lessons.zennolab.com
                tab.Navigate("lessons.zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // add range to collection
                docCol.AddRange(tab.AllDocuments);
                
                // if any error
                if (docCol.ErrorDetected) return -1;
                
                return 0;
            }

Example2

public static function Execute($instance, $project)
            {
                // clear cookie
                $instance->ClearCookie();
                
                // go to zennolab.com
                $tab = $instance->MainTab;
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents
                $docCol = $tab->AllDocuments;
                
                // go to lessons.zennolab.com
                $tab->Navigate("lessons.zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // add range to collection
                $docCol->AddRange($tab->AllDocuments);
                
                // if any error
                if ($docCol->ErrorDetected) return -1;
                
                return 0;
            }

Count

Property

int Count { get; }

Gets the number of elements actually contained in the DocumentCollection.

Count is the number of elements that are actually in the DocumentCollection.

Example

// get all documents from page
            DocumentCollection docCol = tab.AllDocuments;
             
            // get count
            int count = docCol.Count;

Example2

// get all documents from page
            $docCol = $tab->AllDocuments;
             
            // get count
            $count = $docCol->Count;

Documents

Property

Document[] Documents { get; }

Gets copies the documents of the DocumentCollection to a new array.

Example

// clear cookie
            instance.ClearCookie();
             
            // go to zennolab.com
            Tab tab = instance.MainTab;
            if ((tab.IsVoid) || (tab.IsNull)) return -1;
            if (tab.IsBusy) tab.WaitDownloading();
            tab.Navigate("zennolab.com");
            if (tab.IsBusy) tab.WaitDownloading();
             
            // get an array of documents
            Document[] docs = docCol.Documents;

Example2

// clear cookie
            $instance->ClearCookie();
             
            // go to zennolab.com
            $tab = $instance->MainTab;
            if (($tab->IsVoid) || ($tab->IsNull)) return -1;
            if ($tab->IsBusy) $tab->WaitDownloading();
            $tab->Navigate("zennolab.com");
            if ($tab->IsBusy) $tab->WaitDownloading();
             
            // get an array of documents
            $docs = $docCol->Documents;

Methods

GetByNumber

Method

Document GetByNumber(int number)

Gets the document by specified number.

Parameters

TypeNameDescription
intnumberThe zero-based number of the document to get.

Returns: The document at the specified number.

Example

public static int Execute(Instance instance, IZennoPosterProjectModel project)
            {
                // clear cookie
                instance.ClearCookie();
                
                // go to zennolab.com
                Tab tab = instance.MainTab;
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents
                DocumentCollection docCol = tab.AllDocuments;
                
                if (docCol.Count <= 0) return -1;
                
                // get document by number
                Document doc = docCol.GetByNumber(docCol.Count-1);
                
                return 0;
            }

Example2

public static function Execute($instance, $project)
            {
                // clear cookie
                $instance->ClearCookie();
                
                // go to zennolab.com
                $tab = $instance->MainTab;
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents
                $docCol = $tab->AllDocuments;
                
                if ($docCol->Count <= 0) return -1;
                
                // get document by number
                $doc = $docCol->GetByNumber($docCol->Count-1);
                
                return 0;
            }

Add

Method

void Add(Document document)

Adds a document to the end of the DocumentCollection.

Parameters

TypeNameDescription
DocumentdocumentThe document to be added to the end of the DocumentCollection.

Example

public static int Execute(Instance instance, IZennoPosterProjectModel project)
            {
                // clear cookie
                instance.ClearCookie();
                
                // go to zennolab.com
                Tab tab = instance.MainTab;
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents from zennolab.com
                DocumentCollection docCol = tab.AllDocuments;
                
                // go to lessons.zennolab.com
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("lessons.zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents from lessons.zennolab.com
                DocumentCollection newDocCol = tab.AllDocuments;
                
                // add elements of second collection to first collection
                for (int i = 0; i < newDocCol.Count; i++) docCol.Add(newDocCol.Documents[i]);
                
                return 0;
            }

Example2

public static function Execute($instance, $project)
            {
                // clear cookie
                $instance->ClearCookie();
                
                // go to zennolab.com
                $tab = $instance->MainTab;
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents from zennolab.com
                $docCol = $tab->AllDocuments;
                
                // go to lessons.zennolab.com
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("lessons.zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents from lessons.zennolab.com
                $newDocCol = $tab->AllDocuments;
                
                // add elements of second collection to first collection
                for ($i = 0; $i < $newDocCol->Count; $i++) $docCol->Add($newDocCol->Documents[$i]);
                
                return 0;
            }

AddRange

Method

void AddRange(DocumentCollection documents)

Adds the documents of the specified collection to the end of the DocumentCollection.

The order of the elements in the collection is preserved in the DocumentCollection.

Parameters

TypeNameDescription
DocumentCollectiondocumentsThe collection whose documents should be added to the end of the DocumentCollection. The collection itself cannot be null.

Example

public static int Execute(Instance instance, IZennoPosterProjectModel project)
            {
                // clear cookie
                instance.ClearCookie();
                
                // go to zennolab.com
                Tab tab = instance.MainTab;
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents from zennolab.com
                DocumentCollection docCol = tab.AllDocuments;
                
                // go to lessons.zennolab.com
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("lessons.zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents from lessons.zennolab.com
                DocumentCollection newDocCol = tab.AllDocuments;
                
                // add elements from second collection to first collection
                docCol.AddRange(newDocCol);
                
                return 0;
            }

Example2

public static function Execute($instance, $project)
            {
                // clear cookie
                $instance->ClearCookie();
                
                // go to zennolab.com
                $tab = $instance->MainTab;
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents from zennolab.com
                $docCol = $tab->AllDocuments;
                
                // go to lessons.zennolab.com
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("lessons.zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents from lessons.zennolab.com
                $newDocCol = $tab->AllDocuments;
                
                // add elements from second collection to first collection
                $docCol->AddRange($newDocCol);
                
                return 0;
            }

AddRange

Method

void AddRange(Document[] documents)

Adds the documents of the specified array to the end of the DocumentCollection.

The order of the elements in the collection is preserved in the DocumentCollection.

Parameters

TypeNameDescription
Document[]documentsThe array whose documents should be added to the end of the DocumentCollection. The collection itself cannot be null.

Example

public static int Execute(Instance instance, IZennoPosterProjectModel project)
            {
                // clear cookie
                instance.ClearCookie();
                
                // go to zennolab.com
                Tab tab = instance.MainTab;
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents from zennolab.com
                DocumentCollection docCol = tab.AllDocuments;
                
                // go to lessons.zennolab.com
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("lessons.zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents from lessons.zennolab.com
                DocumentCollection newDocCol = tab.AllDocuments;
                
                // add elements from second collection to first collection
                docCol.AddRange(newDocCol.Documents);
                
                return 0;
            }

Example2

public static function Execute($instance, $project)
            {
                // clear cookie
                $instance->ClearCookie();
                
                // go to zennolab.com
                $tab = $instance->MainTab;
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents from zennolab.com
                $docCol = $tab->AllDocuments;
                
                // go to lessons.zennolab.com
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("lessons.zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents from lessons.zennolab.com
                $newDocCol = $tab->AllDocuments;
                
                // add elements from second collection to first collection
                $docCol->AddRange($newDocCol->Documents);
                
                return 0;
            }

Insert

Method

void Insert(Document document, int index)

Inserts a document into the DocumentCollection at the specified index.

If index is equal to Count, item is added to the end of DocumentCollection.

Parameters

TypeNameDescription
DocumentdocumentThe document to insert.
intindexThe zero-based index at which document should be inserted.

Example

// get all documents
            DocumentCollection docCol = tab.AllDocuments;
             
            // get main document
            Document doc = tab.MainDocument;
             
            if (docCol.Count <= 0) return -1
             
            int index = docCol.Count / 2;
             
            // insert main document to collection
            docCol.Insert(doc, index);

Example2

// get all documents
            $docCol = $tab->AllDocuments;
             
            // get main document
            $doc = $tab->MainDocument;
             
            if ($docCol->Count <= 0) return -1
             
            $index = $docCol=>Count / 2;
             
            // insert main document to collection
            $docCol->Insert($doc, $index);

InsertRange

Method

void InsertRange(DocumentCollection documents, int index)

Inserts the documents of a collection into the DocumentCollection at the specified index.

If index is equal to Count, the elements are added to the end of DocumentCollection. The order of the elements in the collection is preserved in the DocumentCollection.

Parameters

TypeNameDescription
DocumentCollectiondocumentsThe collection whose elements should be inserted into the DocumentCollection. The collection itself cannot be null.
intindexThe zero-based index at which the new documents should be inserted.

Example

public static int Execute(Instance instance, IZennoPosterProjectModel project)
            {
                // clear cookie
                instance.ClearCookie();
                
                // go to zennolab.com
                Tab tab = instance.MainTab;
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents from zennolab.com
                DocumentCollection docCol = tab.AllDocuments;
                
                // go to lessons.zennolab.com
                tab.Navigate("lessons.zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // go to lessons.zennolab.com
                DocumentCollection newDocCol = tab.AllDocuments;
                
                // insert second collection to first collection start with 0 index
                docCol.InsertRange(newDocCol, 0);
                
                return 0;
            }

Example2

public static function Execute($instance, $project)
            {
                // clear cookie
                $instance->ClearCookie();
                
                // go to zennolab.com
                $tab = $instance->MainTab;
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents from zennolab.com
                $docCol = $tab->AllDocuments;
                
                // go to lessons.zennolab.com
                $tab->Navigate("lessons.zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // go to lessons.zennolab.com
                $newDocCol = $tab->AllDocuments;
                
                // insert second collection to first collection start with 0 index
                $docCol->InsertRange($newDocCol, 0);
                
                return 0;
            }

InsertRange

Method

void InsertRange(Document[] documents, int index)

Inserts the documents of an array into the DocumentCollection at the specified index.

If index is equal to Count, the elements are added to the end of DocumentCollection. The order of the elements in the collection is preserved in the DocumentCollection.

Parameters

TypeNameDescription
Document[]documentsThe array whose elements should be inserted into the DocumentCollection. The array itself cannot be null.
intindexThe zero-based index at which the new documents should be inserted.

Example

public static int Execute(Instance instance, IZennoPosterProjectModel project)
            {
                // clear cookie
                instance.ClearCookie();
                
                // go to zennolab.com
                Tab tab = instance.MainTab;
                if ((tab.IsVoid) || (tab.IsNull)) return -1;
                if (tab.IsBusy) tab.WaitDownloading();
                tab.Navigate("zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // get all documents from zennolab.com
                DocumentCollection docCol = tab.AllDocuments;
                
                // go to lessons.zennolab.com
                tab.Navigate("lessons.zennolab.com");
                if (tab.IsBusy) tab.WaitDownloading();
                
                // go to lessons.zennolab.com
                DocumentCollection newDocCol = tab.AllDocuments;
                
                // insert second collection to first collection start with 0 index
                docCol.InsertRange(newDocCol.Documents, 0);
                
                return 0;
            }

Example2

public static function Execute($instance, $project)
            {
                // clear cookie
                $instance->ClearCookie();
                
                // go to zennolab.com
                $tab = $instance->MainTab;
                if (($tab->IsVoid) || ($tab->IsNull)) return -1;
                if ($tab->IsBusy) $tab->WaitDownloading();
                $tab->Navigate("zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // get all documents from zennolab.com
                $docCol = $tab->AllDocuments;
                
                // go to lessons.zennolab.com
                $tab->Navigate("lessons.zennolab.com");
                if ($tab->IsBusy) $tab->WaitDownloading();
                
                // go to lessons.zennolab.com
                $newDocCol = $tab->AllDocuments;
                
                // insert second collection to first collection start with 0 index
                $docCol->InsertRange($newDocCol->Documents, 0);
                
                return 0;
            }

Remove

Method

void Remove(int index)

Removes the element at the specified index of the DocumentCollection.

Parameters

TypeNameDescription
intindexThe zero-based index of the document to remove.

Example

// get all documents from page
            DocumentCollection docCol = tab.AllDocuments;
             
            // remove the last document
            docCol.Remove(docCol.Count-1);

Example2

// get all documents from page
            $docCol = $tab->AllDocuments;
             
            // remove the last document
            $docCol->Remove($docCol->Count-1);

IndexOf

Method

int IndexOf(Document document)

Searches for the specified object and returns the zero-based index of the first occurrence within the entire DocumentCollection.

The DocumentCollection is searched forward starting at index and ending at the last element.

Parameters

TypeNameDescription
DocumentdocumentThe document to locate in the DocumentCollection.

Returns: The zero-based index of the first occurrence of item within the entire DocumentCollection, if found; otherwise, –1.

Example

// get main document
            Document doc = tab.MainDocument;
             
            // get index of main document in document collection of current web page
            int index = docCol.IndexOf(doc);

Example2

// get main document
            $doc = $tab->MainDocument;
             
            // get index of main document in document collection of current web page
            $index = $docCol->IndexOf($doc);