Get Screen Size on C#

The process is running under DPI virtualization. So we should apply the DPI aware manifest option to stop DPI virtualization

[DllImport("user32.dll", SetLastError=true)]
static extern bool SetProcessDPIAware();

Then

public enum SystemMetric
{
    VirtualScreenWidth = 78, // CXVIRTUALSCREEN 0x0000004E 
    VirtualScreenHeight = 79, // CYVIRTUALSCREEN 0x0000004F 
}

[DllImport("user32.dll")]
public static extern int GetSystemMetrics(SystemMetric metric);

public static Size GetVirtualDisplaySize()
{
    var width = GetSystemMetrics(SystemMetric.VirtualScreenWidth);
    var height = GetSystemMetrics(SystemMetric.VirtualScreenHeight);

    return new Size(width, height);
}

References
https://stackoverflow.com/questions/28339257/getsystemmetrics-and-tscreen-returns-wrong-value
https://www.pinvoke.net/default.aspx/user32/SetProcessDPIAware.html
https://stackoverflow.com/questions/1317235/c-get-complete-desktop-size
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiaware

Deploy .NET Core app on Ubuntu

check if it runs

dotnet run

Deploy in a build directory

dotnet publish --output “ /var/www/build” --configuration release

Go to the build directory and run the application

dotnet ForExample.dll

Create the service file

sudo nano /etc/systemd/system/kestrel-ForExample-test.service
[Unit]
Description=Example .NET Web API App running on Ubuntu
[Service]
WorkingDirectory=/var/www/ForExample/ForExample
ExecStart=/usr/bin/dotnet /var/www/build/ForExample.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.t

Register the service

sudo systemctl enable kestrel-ForExample-test.service

Start the service and verify that it’s running.

sudo systemctl start kestrel-mebgispanel-test.service
sudo systemctl status kestrel-mebgispanel-test.service

Check the server logs

sudo journalctl -fu kestrel-helloapp.service

References
https://medium.com/faun/ubuntu-servers-and-asp-net-core-project-deployment-using-nginx-d9a3a1f6ac82

Install .NET on Manjaro

.NET Core
If you only want to run .NET Core managed applications, install the dotnet-runtime package.
To build apps with .NET Core, install dotnet-sdk as well.
Microsoft recommends using Visual Studio Code , their Electron-based FOSS IDE, to build & debug .NET Core apps.

Tip: Add ~/.dotnet/tools to PATH, otherwise dotnet tools with not work from shell.
Mono
Install the mono package.

References
https://wiki.archlinux.org/index.php/.NET_Core
https://wiki.archlinux.org/index.php/Mono

Download image from url in C#

Simply You can use following methods.

using (WebClient client = new WebClient()) 
  {
    client.DownloadFile(new Uri(url), @"c:\temp\image35.png");

     //OR 

    client.DownloadFileAsync(new Uri(url), @"c:\temp\image35.png");
   }

If You don’t know the Format(.png, .jpeg etc) of Image

public void SaveImage(string filename, ImageFormat format) {

    WebClient client = new WebClient();
    Stream stream = client.OpenRead(imageUrl);
    Bitmap bitmap;  bitmap = new Bitmap(stream);

    if (bitmap != null) 
      bitmap.Save(filename, format);

    stream.Flush();
    stream.Close();
    client.Dispose();
}

References
https://stackoverflow.com/questions/24797485/how-to-download-image-from-url

Install .NET Core on Ubuntu 16.04

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-get update
sudo apt-get install dotnet-sdk-2.0.0

References
https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.0-download.md

How to add JavaScript library in MVC project

JavaScript :

BundleConfig.RegisterBundles(BundleTable.Bundles);
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
            "~/Scripts/jquery-ui-{version}.js"));
@Scripts.Render("~/bundles/jqueryui")

CSS :

bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
              "~/Content/themes/base/jquery.ui.core.css",
              "~/Content/themes/base/jquery.ui.resizable.css",
              "~/Content/themes/base/jquery.ui.selectable.css",
              "~/Content/themes/base/jquery.ui.accordion.css",
              "~/Content/themes/base/jquery.ui.autocomplete.css",
              "~/Content/themes/base/jquery.ui.button.css",
              "~/Content/themes/base/jquery.ui.dialog.css",
              "~/Content/themes/base/jquery.ui.slider.css",
              "~/Content/themes/base/jquery.ui.tabs.css",
              "~/Content/themes/base/jquery.ui.datepicker.css",
              "~/Content/themes/base/jquery.ui.progressbar.css",
              "~/Content/themes/base/jquery.ui.theme.css"));
@Styles.Render("~/Content/themes/base/css")

References :
http://stackoverflow.com/questions/20081328/how-to-add-jqueryui-library-in-mvc-5-project

Keywords : 

References ,  Script , Bundle