<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blazor &#8211; achraf ben alaya</title>
	<atom:link href="https://achrafbenalaya.com/tag/blazor/feed/" rel="self" type="application/rss+xml" />
	<link>https://achrafbenalaya.com</link>
	<description>Tech Blog By Achraf Ben Alaya</description>
	<lastBuildDate>Sun, 10 Jan 2021 13:44:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.11</generator>

<image>
	<url>/wp-content/uploads/2022/02/cropped-me-scaled-1-32x32.jpeg</url>
	<title>blazor &#8211; achraf ben alaya</title>
	<link>https://achrafbenalaya.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">189072172</site>	<item>
		<title>The Differences Between Blazor Server And Blazor  WebAssembly</title>
		<link>https://achrafbenalaya.com/2021/01/10/the-differences-between-blazor-server-and-blazor-webassembly/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-differences-between-blazor-server-and-blazor-webassembly</link>
					<comments>https://achrafbenalaya.com/2021/01/10/the-differences-between-blazor-server-and-blazor-webassembly/#respond</comments>
		
		<dc:creator><![CDATA[achraf]]></dc:creator>
		<pubDate>Sun, 10 Jan 2021 13:42:29 +0000</pubDate>
				<category><![CDATA[blazor]]></category>
		<category><![CDATA[Blog]]></category>
		<guid isPermaLink="false">https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/?p=965</guid>

					<description><![CDATA[If you didn’t hear about it yet ,Blazor is a revolutionary client-end User Interface framework developed by Microsoft’s mighty ASP.NET Expert team. Since its launch, it has become a big talking point among the tech organizations and Developer community. Blazor offers an amazing ability to code enriched web User Interfaces/User Experiences by using CSS, C#, and [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you didn’t hear about it yet ,Blazor is a revolutionary client-end User Interface framework developed by Microsoft’s mighty ASP.NET Expert team. Since its launch, it has become a big talking point among the tech organizations and Developer community. Blazor offers an amazing ability to code enriched web User Interfaces/User Experiences by using CSS, C#, and HTML instead of using JavaScript, a proposition most of the Developers have been dreaming of for long .</p>
<h1><strong>What is Blazor?</strong></h1>
<p>Blazor is an open-source and freely available framework, which allows developers to develop highly interactive web applications by using C# programming language. It allows a single programming language C#, HTML or Razor to write both the Client-side and Server-side code. Blazor achieves this by using .NET runtime which is compiled into WebAssembly bytecode. The .NET runtime functions into the browser and can allow any .NET DLL to execute, including the code we have written in C# programming language.</p>
<p>Blazor is composed of two hosting Models and we are going to see them one by one</p>
<p><strong>1-Blazor server side</strong></p>
<p><strong>2-Blazor WebAssembly</strong></p>
<ul>
<li>
<h1>Blazor server side</h1>
</li>
</ul>
<p>With the Blazor Server hosting model, the app is executed on the server from within an ASP.NET Core app. UI updates, event handling, and JavaScript calls are handled over a SignalR connection.</p>
<p>A Blazor application can easily run on an ASP.NET core backend and could be accessed easily by a browser. The ASP.NET Core applications can either be running on IIS or could be hosted as self-contained applications. Blazor application or website could be accessed by any browser at client-side. Blazor Server utilizes a JavaScript file to function and use CSS and HTML to render its user interface (UI). Here it is important to note that Blazor Server does not use WebAssembly.</p>
<ul>
<li>
<h1> Blazor WebAssembly</h1>
</li>
</ul>
<p>The second Blazor hosting model is running client-side in the browser on WebAssembly. The Blazor app, its dependencies, and the .NET runtime are downloaded to the browser. The app is executed directly on the browser UI thread. UI updates and event handling occur within the same process. The app&#8217;s assets are deployed as static files to a web server or service capable of serving static content to clients.</p>
<p>Blazor WebAssembly is supported by all the renowned modern web browsers available in the market for both mobile and desktop. Its execution is quite like JavaScript, where it allows the WebAssembly applications to execute securely on the end-users device, that too within the browser’s security sandbox. It offers an ability to the applications so that they could be deployed as a true standalone static site, without any .NET server component. The applications can be amalgamated with ASP.NET Core, which ensures a full stack web development with the help of .NET ecosystem, that is where the application code can be effortlessly shared with the server and the client.</p>
<p>&nbsp;</p>
<ul>
<li>
<h1>Difference : (what should I use ?)</h1>
</li>
</ul>
<p>If you are going to develop a standard application that will be used even with a very bad internet connection than the WebAssembly is the ideal one because it can run without server connection,</p>
<p>More than that ,the  WebAssembly application offer offline mode ,the application can continue to run even without internet connection while the server application become useless in this case.</p>
<p>The Web assembly application will be download by the end user and will run on the browser ,so here we don’t need to scale anything ,while on the server side , Microsoft says that a server with a single CPU and 3.5 Ram can handle 5K concurrent connections .</p>
<ul>
<li>
<h1>In Summary</h1>
</li>
</ul>
<p>Keep it simple and build something small, with a couple of screens, just to see how each of the hosting models work and than you can go and start building your own project .</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://achrafbenalaya.com/2021/01/10/the-differences-between-blazor-server-and-blazor-webassembly/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">965</post-id>	</item>
		<item>
		<title>Xamarin.forms,Blazor and Web API</title>
		<link>https://achrafbenalaya.com/2020/04/26/xamarin-formsblazor-and-web-api/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=xamarin-formsblazor-and-web-api</link>
					<comments>https://achrafbenalaya.com/2020/04/26/xamarin-formsblazor-and-web-api/#respond</comments>
		
		<dc:creator><![CDATA[achraf]]></dc:creator>
		<pubDate>Sun, 26 Apr 2020 16:38:29 +0000</pubDate>
				<category><![CDATA[xamarin]]></category>
		<category><![CDATA[blazor]]></category>
		<guid isPermaLink="false">https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/?p=443</guid>

					<description><![CDATA[After the success of past video and blog post of Blazor Write C# instead of JavaScript to Build a Client-Side Single-Page App I decided to create a cross platform application using xamarin.forms Even though i was sick ,and after few of tries , I managed to create a video to demonstrate how we can consume [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>After the success of past video and blog post of Blazor Write C# instead of JavaScript to Build a Client-Side Single-Page App I decided to create a cross platform application using xamarin.forms</p>
<p>Even though i was sick ,and after few of tries , I managed to create a video to demonstrate how we can consume the service that we have created and how I created the mobile application .</p>
<p>First , If you want to see what are we building , you can watch the video below .</p>
<p><iframe title="Building an ASP.NET Core/Blazor/Xamarin Application" width="500" height="281" src="https://www.youtube.com/embed/Vg1SHXQC6tw?feature=oembed&#038;enablejsapi=1" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p>Now , We are going to see step by step how we can :</p>
<p>How we can use conveyor to Access and test your web application from other devices, such as phones, tablets and computers, locally or over the web. Consume to Web Service Using Postman. Create the xamarin forms project. Create the Dataservice &amp; use Mvvm . Next Steps. Conveyor Usually , when I create a web service , I deploy it to my azure account but this time and for some reasons , I wanted to test it on my localhost , but as you know you can’t just simply access that localhost from another computer or smartphone .</p>
<p>So when I was looking around for some solutions , which one of them was changing the configuration inside the applicationhost.config by changing :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">&lt;bindings&gt;
               &lt;binding protocol="http" bindingInformation="*:51889:localhost" /&gt;
               &lt;binding protocol="https" bindingInformation="*:44351:localhost" /&gt;
       &lt;/bindings&gt;
       &lt;bindings&gt;
           &lt;binding protocol="http" bindingInformation="*:51889:localhost" /&gt;
           &lt;binding protocol="http" bindingInformation="*:44351:pc-hostname" /&gt;
           &lt;binding protocol="http" bindingInformation="*:44351:10.0.1.10" /&gt;
       &lt;/bindings&gt;</pre>
<p>Well this worked once , but after a while for some reasons It did stop and that’s when I found <a href="https://conveyor.cloud/">conveyor</a>.</p>
<p>&nbsp;</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post13/01.png" width="743" height="579" /></p>
<p>You can download the template from visual studio marketplace from this Link. Now after installing the template you have to restart visual studio (Make sure you run it as Administrator). next , you need to run the solution and clique on :</p>
<p><img decoding="async" class="aligncenter size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post13/02.png" width="482" height="257" /></p>
<p>You can have more details by visiting Conveyor website or by watching their full demo .</p>
<div></div>
<div>
<h3 id="testing-our-web-api" class="post-content-header">Testing our Web Api :</h3>
<p>So last time we have created our Web Api and before going to consume the web-service , I always prefer to test it using postman .</p>
<p>The Postman is the most popular and the most powerful HTTP client for testing the restful web services. Postman makes it easy to test the Restful Web APIs, as well as it develops and documents Restful APIs by allowing the users to quickly put together both simple and complex HTTP requests. The Postman is available as both a Google Chrome in-browser app and Google Chrome Packaged App.</p>
</div>
<p><img decoding="async" class="aligncenter size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post13/03.png" width="1024" height="585" /></p>
<p>After checking that everything working fine and our calls to the Web-Api respond as we want now we can go and create our mobile application .</p>
<p>Xamarin Forms Project So first what is Xamarin forms ? Xamarin.Forms is an open source cross-platform framework from Microsoft for building iOS, Android, &amp; Windows apps with .NET from a single shared codebase. You can read more about xamarin forms from this documentation. now Let’s create our project :</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post13/04.png" width="992" height="668" /></p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post13/05.png" width="1012" height="697" /></p>
<p>Since we need a menu , cause we have a list of doctors ,gender ,patient ,and to move around between those menus we should use the Master-Detail template . now , after choosing the right template , we will have a solution that contain 3 project ,the main project where we are going to create most of our code , an android project and and ios project as in picture below .</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post13/06.png" width="706" height="337" /></p>
<p>Now , before doing anything , we need to update all the packages installed in our solution by going to manage nuget packages for solution and updating all the nuget packages there and building the project . If we have a successful build , now we can start coding .</p>
<p>As I said ,we are going to use Mvvm . now what is Mvvm ? MVVM is a design pattern used to decouple user-interface (view), data (model), and application logic (view model). Xamarin has built-in support for the MVVM pattern including data binding, making it easy to follow this design pattern so that you can create application code that’s better tested and easier to extend without requiring radical changes . You can read more about it here .</p>
<p>So , now we are going to create four folder , Models ,Views and ViewModels and one for the dataservices. In our Modules folder ,we are going to create our modules , and for demo sample , we are going to use the gender class.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">public class Genders
{
    public int GendersId { get; set; }
    public string Name { get; set; }
    public bool IsVisible { get; set; }
    public string Urd { get; set; }

}
</pre>
<p>Next , Inside our ViewModels folder we are going to create three classes , GendersViewModel , EditGenderViewModel and AddGenderViewModel .</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">public class GendersViewModel :BaseViewModel
{
     private List&lt;Genders&gt; _genders1;
    private  DataServices _dataServices = new DataServices();
    private bool _isRefresh;


    public List&lt;Genders&gt; _genders
    {
        get { return _genders1;}
        set  {

        _genders1 = value;
        OnPropertyChanged();

            }
        }

    public GendersViewModel()
    {
        GetGenders();
        
    }

    public bool isRefresh
    {
        get {return _isRefresh; }
        set
        {
            _isRefresh = value;
            OnPropertyChanged();
        } 
    }

    public ICommand GetGendersCOmmand =&gt; new Command(async () =&gt;

    {
        isRefresh = true;
        await GetGenders();
        isRefresh = false;
    });

    private async Task GetGenders()

    {
        _genders = await _dataServices.GetGenders();

    }

}
    public  class EditGenderViewModel
{
    public Genders TheSelectedGender { get; set; }
    private DataServices _dataServices = new DataServices();

    public ICommand EditGendersCOmmand =&gt; new Command(async () =&gt;

    {
        TheSelectedGender.Urd = System.DateTime.Now.ToShortDateString();
        await _dataServices.PutGenders(TheSelectedGender.GendersId, TheSelectedGender);

    });


    public ICommand DeleteGendersCOmmand =&gt; new Command(async () =&gt;

    {
       
        await _dataServices.DeleteGenders(TheSelectedGender.GendersId);


    });

}
public class AddGenderViewModel
{
    public Genders TheSelectedGender { get; set; }
    private DataServices _dataServices = new DataServices();

    public AddGenderViewModel()
    {
        TheSelectedGender = new Genders();
    }

    public ICommand sendGendersCOmmand =&gt; new Command(async () =&gt;

    {
        TheSelectedGender.Urd = System.DateTime.Now.ToShortDateString();
        await _dataServices.PostGenders(TheSelectedGender);
    });


}


     public class DataServices

     {

   private string GenderUrl = Constants.GenderLink;

  #region Genders


    public async Task&lt;List&lt;Genders&gt;&gt; GetGenders()
    {

        var HttpClient = new HttpClient();
        var Json= await HttpClient.GetStringAsync(GenderUrl);
        var Genders = JsonConvert.DeserializeObject&lt;List&lt;Genders&gt;&gt;(Json);

        return Genders;
    }

    public async Task PostGenders(Genders genders)

    {

        var httpClient = new HttpClient();
        var jsonObject = JsonConvert.SerializeObject(genders);
        StringContent content =new StringContent(jsonObject);
        content.Headers.ContentType= new MediaTypeHeaderValue("application/json");
        var result=  await httpClient.PostAsync(GenderUrl, content);

    }

    public async Task PutGenders(int id,Genders genders)

    {

        var httpClient = new HttpClient();
        var jsonObject = JsonConvert.SerializeObject(genders);
        StringContent content = new StringContent(jsonObject);
        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
        var result = await httpClient.PutAsync(GenderUrl+id, content);

    }

    public async Task DeleteGenders(int id)
    {

        var HttpClient = new HttpClient();
        var responsen = await HttpClient.DeleteAsync(GenderUrl+id);

       // return Genders;
    }

    #endregion</pre>
<p>Now our moduels and viewModules are ready , we need to create our views , by that I mean our pages For our blog , we are going only to create the GenderPage which will contain the list genders .</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">&lt;ContentPage.BindingContext&gt;

    &lt;viewModels:GendersViewModel&gt;&lt;/viewModels:GendersViewModel&gt;

&lt;/ContentPage.BindingContext&gt;


&lt;ContentPage.ToolbarItems&gt;
    &lt;ToolbarItem Text="Add" Clicked="GoToAddGender" /&gt;
&lt;/ContentPage.ToolbarItems&gt;


&lt;ListView
x:Name="GenderListView"
HasUnevenRows="True"
ItemsSource="{Binding _genders}"
ItemTapped="GenderListView_OnItemTapped"
IsPullToRefreshEnabled="True"
RefreshCommand="{Binding GetGendersCOmmand}"
IsRefreshing="{Binding isRefresh}"&gt;
&lt;ListView.Header&gt;
    &lt;Grid &gt;
        &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition Width="*" /&gt;
            &lt;ColumnDefinition Width="*"/&gt;
            &lt;ColumnDefinition Width="*"/&gt;
            &lt;ColumnDefinition Width="*"/&gt;
            &lt;/Grid.ColumnDefinitions&gt;
        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition Height="Auto" /&gt;
        &lt;/Grid.RowDefinitions&gt;
            &lt;Label Text="ID"  TextColor="Red" FontSize="Small" Grid.Column="0" Grid.Row="0"  HorizontalOptions="Center"/&gt;
            &lt;Label Text="Name" TextColor="Red" Grid.Column="1" Grid.Row="0" HorizontalOptions="Center" VerticalOptions="Center"/&gt;
            &lt;Label Text="Urd" TextColor="Red" Grid.Column="2" Grid.Row="0" HorizontalOptions="Center" VerticalOptions="Center"/&gt;
            &lt;Label Text="Visible" TextColor="Red" Grid.Column="3" Grid.Row="0" HorizontalOptions="Center" VerticalOptions="Center"&gt;&lt;/Label&gt;
        &lt;/Grid&gt;
&lt;/ListView.Header&gt;
&lt;ListView.ItemTemplate&gt;
    &lt;DataTemplate&gt;
    &lt;ViewCell&gt;


&lt;Grid Padding="10"&gt;
    &lt;Grid.ColumnDefinitions&gt;
        &lt;ColumnDefinition /&gt;
        &lt;ColumnDefinition /&gt;
        &lt;ColumnDefinition /&gt;
        &lt;ColumnDefinition /&gt;

    &lt;/Grid.ColumnDefinitions&gt;
                    &lt;Label Text="{Binding GendersId}" Grid.Column="0" HorizontalOptions="CenterAndExpand" VerticalOptions="Center"&gt;&lt;/Label&gt;
                    &lt;Label Text="{Binding Name}"  Grid.Column="1"  HorizontalOptions="CenterAndExpand"  VerticalOptions="Center"&gt;&lt;/Label&gt;
                    &lt;Label Text="{Binding Urd}"  Grid.Column="2"  HorizontalOptions="CenterAndExpand" VerticalOptions="Center"&gt;&lt;/Label&gt;
                    &lt;CheckBox IsChecked="{Binding IsVisible}" IsEnabled="False"  Grid.Column="3"  HorizontalOptions="CenterAndExpand" VerticalOptions="Center"&gt;&lt;/CheckBox&gt;

                &lt;/Grid&gt;

    &lt;/ViewCell&gt;


&lt;/DataTemplate&gt;

&lt;/ListView.ItemTemplate&gt;
&lt;/ListView&gt;</pre>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">private async void GoToAddGender(object sender, EventArgs e) { await Navigation.PushAsync(new AddGender()); }

    private void GenderListView_OnItemTapped(object sender, ItemTappedEventArgs e)
    {
      var _Genders=  e.Item as Models.Genders;
      Navigation.PushAsync(new EditGenders(_Genders));
    }</pre>
<p>Now , as you can see , we are binding to GendersViewModel were can all our commands. And like that we will have this page .</p>
<p>Now, for the next steps , I decided to enhance the ui for the web app and the mobile app too ,hide elements when isvisibe is set to false and use DataGrid for both projects .</p>
<p>I hope this was helpful , you can find the full code inside my github <a href="http://bit.ly/2PzkrXD">repo </a>.</p>
<p><img loading="lazy" decoding="async" class="alignleft " src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post13/07.jpg" width="301" height="602" /></p>
<p><img loading="lazy" decoding="async" class="alignleft" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post13/08.jpg" width="303" height="606" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://achrafbenalaya.com/2020/04/26/xamarin-formsblazor-and-web-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">443</post-id>	</item>
	</channel>
</rss>
