65.9K
CodeProject is changing. Read more.
Home

Lavoro - Web-based Approach for Operating System Development

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.26/5 (5 votes)

May 25, 2023

CPOL
viewsIcon

5892

Description of the Lavoro web operating system

Introduction

We give the usage of the interop-operations in .NET and implementation of the virtual file system based on the links to URL of the object around the web.

Background

The background is to be the way C# allows the programmable access to the public methods inside class through WebBrowser control element:

[System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public partial class MainForm : Form

    ...

This is far not last to mention that method is then defined with public modifier:

public void UpdateFiles(String s) {
    File.WriteAllText(FilesPath, "var files = [" + s + "];", Encoding.UTF8);
            
    this.webBrowserFile.Navigate(new Uri(BrowserPath));    

}

Using the code

The external keyword is reserved for calling .NET methods which are defined as public above:

function addFile(file) {
    files.push(file);
}
            
function updateFilesNET() {
    var r = "";
    
    for (var e in files) {
        if (r.length > 0) {
            r += ",";
        }

        r += "{ url: '" + files[e].url + "', cookie: '" + files[e].cookie + "'}";
    }
        
    window.external.UpdateFiles(r);
}

function previewFileNET(vurl, vcookie) {
    window.external.PreviewFile(vurl, vcookie);
}

function addFileNET(vurl, vcookie) {    
    addFile({ url: vurl, cookie: vcookie});
}
            
var index = -1;
            
function removeIndex(e, i, a) {
    return i != index;
}
            
function removeFile(i) {
    index = i;
                
    files = files.filter(removeIndex);
                
    updateFilesNET();
}

The script functions from above code snippet can be called via InvokeScript method inside WebBrowser .NET class:

public void AddFile(String url, String cookie) {
    this.webBrowserFile.Document.InvokeScript("addFileNET", new string[] { url, cookie });
            
    this.webBrowserFile.Document.InvokeScript("updateFilesNET");
            
    this.webBrowserFile.Navigate(new Uri(BrowserPath));

}

Points of Interest

Thus, we have learned the interoperability being on the guard for the crucial tasks like web operating system development. We have provided the quick and simple access to the resources the operating system is eligible to manage.

In our code more than COM Interop can be learned, like resizing of the web elements on the form.

History

25th of May 2023 - Initial release.