Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / Javascript
Tip/Trick

Lavoro - Web-based Approach for Operating System Development

Rate me:
Please Sign up or sign in to vote.
1.26/5 (5 votes)
24 May 2023CPOL 5.5K   1  
Description of the Lavoro web operating system
We propose the solution for web-based operating systems like Lavoro project which utilizes the COM interoperability for better handling of the URL-based file 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:

C#
[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:

C#
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:

JavaScript
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:

C#
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
-- There are no messages in this forum --