Google Drive sync with Grive2 on Ubuntu

Install Grive2

Detailed instructions here.

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update 
sudo apt-get install grive

The first run to establish a connection and authenticate

mkdir GoogleDrive
cd GoogleDrive

grive -a 

Grive -a will give you url to enable access to google drive, returned private key must be copied back to the terminal.

To sync manually you execute “grive” command in the GoogleDrive folder:

 grive

Enable Grive2 auto syncbetter use without it

By default, this sync process take too much processor strength and make too much network traffic almost all the time or every 3 seconds, even when there are no changes on the google drive and the timer is set to 15 minutes.

Maybe default configuration just isn’t configured optimally or something. Take this into consideration before continue.

GoogleDrive in the systemctl commands is folder in your $HOME.

systemctl --user enable grive-timer@$(systemd-escape GoogleDrive).timer 
 systemctl --user start grive-timer@$(systemd-escape GoogleDrive).timer 
 systemctl --user enable grive-changes@$(systemd-escape GoogleDrive).service 
 systemctl --user start grive-changes@$(systemd-escape GoogleDrive).service

Systemctl commands results:

Created symlink /home/igorb/.config/systemd/user/timers.target.wants/grive-timer@GoogleDrive.timer → /usr/lib/systemd/user/grive-timer@.timer

Change timer to only fire once in 15 minutes:

First stop the timer & service:

systemctl --user stop grive-timer@$(systemd-escape GoogleDrive).timer

systemctl --user stop grive-changes@$(systemd-escape GoogleDrive).service

Edit the timer file:

sudo gedit ~/.config/systemd/user/timers.target.wants/grive-timer@GoogleDrive.timer 

Change the content of the timer setup:

[Unit]
 Description=Google drive sync (fixed intervals)
 [Timer]
 OnCalendar=*:0/15
 OnBootSec=3min
 OnUnitActiveSec=15min
 Unit=grive-timer@%i.service
 [Install]
 WantedBy=timers.target

Run the command to reload timers and then start the timer and service again.

systemctl --user daemon-reload

Set permission for GoogleDrive files

Ifyou have google drive folder on second drive, not exactly on “home” folder, then you need to change permissions for folders and files :

sudo chmod -R a+rwx ./Storage

Setup VSCode for C# development

Ubuntu 18.04 , 19.04

Dotnet Sdk 3.0 release installation

Install it directly from the software repository.

Mono

Remove all versions of mono completely from the system, vscode & omnisharp comes with the mono included, the incorrect version on the system will interfere with the embedded runtime and will not work correctly .

 igorb@desktop:~$ mono --version
 Command 'mono' not found, but can be installed with:
 sudo apt install mono-runtime 

VSCode installation

Download VSCode and install it.

Open downloaded deb file with “Open with software install” and install it.

Hide some folders from file explorer

As explained here just set files to exclude.

Search for “files:exclude” and add bin and obj folder to the list of excluded entities.

**/bin
**/obj

Add to favorites on Ubuntu

This is maybe some odd advice but, when you add Code to favorite applications (to the launcher) you do that from the Show Applications menu !

If you start code from the terminal and mark newly showed icon as “Add to favorites” , the Code somehow doesn’t compile and debug correctly. There is some strange errors after succesfully builded solution…

C# project build errors

In case of errors on build , make sure you have only one dotnet sdk installed on your system (ubuntu).

igorb@desktop:~$ dotnet --list-sdks
3.0.100 [/usr/share/dotnet/sdk]

Omnisharp project build errors

In case of any errors on the project load (OmniSharp log in the output terminal), like :

OmniSharp.MSBuild.ProjectManager        Failed to load project file '/mnt/development/GitHub/Bisaga/About.Application/About.Application.csproj'.

Add build path to the /etc/profile file, do not forget to re-login:

export MSBuildSDKsPath="/usr/share/dotnet/sdk/$(dotnet --version)/Sdks"

Change number of notifying instances

echo fs.inotify.max_user_instances=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Create blazor library project in the Visual Studio 2019 preview

Correct way is to create ASP.NET Core Web Application and in the second step select “Razor Class Library” project template.

If you create Standard or AspNet.Core library directly then your project file will not contain correct setup for razor component source generation, but you can easily correct this manually:

The correct .csproj file structure of razor library project

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AddRazorSupportForMvc>true</AddRazorSupportForMvc>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

</Project>

 

_Imports.razor file

Imports razor file can contain any number of statements (usually centralized using statements). The file will be automatically included in all razor component files in the folder and all subfolders of imports file.

@using MatBlazor
@using Bisaga.Organization.Web.Pages;

Razor files and coresponding code behind file naming convension

If we want to have “code behind” files (with csharp code) hidden “under” the razor file (in Visual Studio) then you need to name components with the same name and additional suffix “.cs”.

Example:

The name of the component “BsgCompanyForm.razor” and the code behind with “functions” in csharp file named “BsgCompanyForm.razor.cs”. But don’t forget that the name of the class cannot be the same as the component name (in this case “BsgCompanyForm” but we usually add some additional suffix in the class name too.

Both files are then connected with the @inherits statement

BsgCompanyForm.razor file:

@inherits BsgCompanyFormBase

<h1>Company</h1>

BsgCompanyForm.razor.cs file:

using Bisaga.Framework.Web;
using System;
using System.Collections.Generic;
using System.Text;

namespace Bisaga.Organization.Web.Pages
{
    public class BsgCompanyFormBase : BsgPageBase
    {
    }
}

If you need to include additional resources (as javascript, CSS) to the project for the final web project deployment, use EmbeddedBlazorContent library: http://bisaga.com/blog/programming/embeddedblazorcontent-how-to-include-static-content-from-blazor-libraries/

EmbeddedBlazorContent – how to include static content from blazor libraries

If you want to include some static resources from the Blazor component library use “EmbeddedBlazorContent” tool.

Source: https://github.com/SamProf/EmbeddedBlazorContent

Create static content in Blazor component library

Create “content” folder in the root of the library project and add CSS and JS files in.

Add embeded resource build action on all the files

Open properties on each resource file and select “Embedded resource” build action on it.

Additional attributes for embedded resource in the project file

Open .CSPROJ project file and edit EmbeddedResource definition to have additional LogicalName definition.

For CSS files:

  <LogicalName>blazor:css:%(RecursiveDir)%(Filename)%(Extension)</LogicalName>

For JS files:

 <LogicalName>blazor:js:%(RecursiveDir)%(Filename)%(Extension)</LogicalName>

Sample:

  <ItemGroup>
    <EmbeddedResource Include="content\bisaga_core.css">
      <LogicalName>blazor:css:%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </EmbeddedResource>
    <EmbeddedResource Include="content\bisaga_core.js">
      <LogicalName>blazor:js:%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </EmbeddedResource>
  </ItemGroup>

Add EmbeddedBlazorContent library to blazor server side web project

Startup.cs

Add configuration for embeded content library to Configure metod in Startup.cs

# Startup.cs
app.UseEmbeddedBlazorContent(typeof(Bisaga.Core.Components.BsgComponentBase).Assembly);

_Host.cshtml

Add call to EmbeddedBlazorContent where you wish to include embedded files.

@using EmbeddedBlazorContent

<head>
  ...
    @Html.EmbeddedBlazorContent()
</head>