Over the last year we’ve shown you various features that were being considered for C# 7. With the preview of Visual Studio 15, Microsoft has decided to demonstrate the features to make it into the final release of C# 7. Tuple Value Types .NET has a tuple type, but in the context of C# there are a lot of problems. Being a reference type, you probably want to avoid using it in performance sensitive code as you have to pay for GC costs. And as they are immutable, while making…
Author: Enrico
DistinctBy in Linq (Find Distinct object by Property)
public class Size { public string Name { get; set; } public int Height { get; set; } public int Width { get; set; } } Consider that we have Size Class for advertisement which is having Heigth, Width and Name as property in it. Now Requirement is I have to find out the all product with distinct Name values. Size[] adv = { new Size { Name = “Leaderboard”, Height = 90, Width = 728 }, new Size { Name = “Large Rectangle”, Height = 280, Width = 336…
Data and data access technologies
In my previous post I spoke about key layers of distributed applications. Now we will go through the most crucial layer of any distributed application, the data layer. In this part, you will be introduced to various database technologies, along with .NET-related technologies. Data can be stored in a wide range of data sources such as relational databases, files on the local filesystems, on the distributed filesystems, in a caching system, in storage located on the cloud, and in memory. Relational databases (SQL server): This is the traditional data source…
Key layers of distributed applications
Every application that is going to be used by end users should be designed appropriately as users are expecting to process information from various data sources that might be geographically distributed. They are also expecting this information to be up-to-date and capable of being inflected very fast. Designing such applications is not an easy task and involves integration among different groups of components. Let’s review the layers that form a typical distributed application. The responsibilities in a distributed system can be divided into four layers: The data layer The business…
C# and HTML5: drag and Drop elements
HTML5 API includes Drag and Drop (DnD) native functionality. The event listener methods for all the drag and drop events accept Event object which has a readonly attribute called dataTransfer. The event.dataTransfer returns DataTransfer object associated with the event This is the list of events fired during the different stages: Event Description dragstart Fires when the user starts dragging of the object. dragenter Fired when the mouse is first moved over the target element while a drag is occuring. A listener for this event should indicate whether a drop is…
Microsoft’s multipronged strategy for bringing speech to IoT devices
Microsoft has been stepping up its game around connecting its Azure cloud services to Internet of Things (IoT) devices. But few may realize the company also is simultaneously working to bring its various speech capabilities to IoT devices, too. Microsoft provides IoT developers with various tools for integrating speech with their devices. There are built-in Windows 10 speech application programming interfaces (APIs) for tasks like dictating a simple message and Web search. There are natural-language services — known as Language Understanding Intelligent Service (LUIS) — that are part of Microsoft…
World’s First Autonomous Drone, The DJI Phantom 4, Revealed
Recently, the Irish Internet of Things chip maker Movidius, has won a multi-million dollar deal with Google, and it has been revealed as the brain behind the breakthrough autonomous drone, the DJI Phantom 4. This autonomous drone, which went on sale in Apple Stores across the US last week, features a new visual guidance facet, which sticks to and follows a subject, and can stay in a fixed position without the need of a GPS signal. Described as the first in the industry, the addition of Movidius chips technology and…
Microsoft, others join forces to work on encrypted email protocols
In the world of the Internet, technology is constantly changing. The SMTP technology behind email, however, has not changed much since it was first released a very long time ago. Despite the invention of SMTP SMARTTM to solve this problem, most emails are still unencrypted, and thus open to a man in the middle hack. Luckily though, a team of engineers from Microsoft, Google, Yahoo, Comcast, and other leading companies have been working on a proposal which would cut out the middle man hacker The proposal which has been submitted…
275 million Android phones imperiled by new code-execution exploit
Almost 300 million phones running Google’s Android operating system are vulnerable to a newly developed drive-by attack that can install malware and take control of key operations, a security firm has warned. A proof-of-concept exploit dubbed Metaphor works against Android versions 2.2 through 4.0 and 5.0 and 5.1, which together are estimated to run 275 million phones, researchers from Israeli security firm NorthBit said. It attacks the same Stagefright media library that made an estimated 950 million Android phones susceptible to similar code-execution attacks last year. The following video demonstrates…
Microsoft adds ‘non-security updates’ to security patches
MS16-023, billed as a “Security update for Internet Explorer” and issued on March 8, includes six “General distribution release (GDR) fixes”. Five are innocuous as they address glitches like “Empty textarea loses its closing tag in Internet Explorer 11 after conversion from XML to HTML.” But the last item on the list item 3146449, has the rather more interesting title “Updated Internet Explorer 11 capabilities to upgrade Windows 8.1 and Windows 7.” A great many users just accept all Windows updates, so will never see item 3146449. Even if you…
Microsoft has released a Debian Linux switch OS
Put down your coffee gently. Microsoft has today released a homegrown open-source operating system, based on Debian GNU/Linux, that runs on network switches. The software is dubbed SONiC, aka Software for Open Networking in the Cloud. It’s a toolkit of code and kernel patches to bend switch hardware to your will, so you can dictate how it works and what it can do, rather than relying on proprietary firmware from a traditional networking vendor. It also pits Redmond against white-box network operating systems from the likes of HP, Dell, and…
Announcing SQL Server on Linux
It’s been an incredible year for the data business at Microsoft and an incredible year for data across the industry. This Thursday at our Data Driven event in New York, we will kick off a wave of launch activities for SQL Server 2016 with general availability later this year. This is the most significant release of SQL Server that we have ever done, and brings with it some fantastic new capabilities. SQL Server 2016 delivers: Groundbreaking security encryption capabilities that enable data to always be encrypted at rest, in motion…
Integration with C# and ReactJS
The goal for this project is to show a list of books with ReactJS from a WebAPI written in C#. You can download this project from Github. New project Start by creating a new ASP.NET MVC 4 project: 1. File → New → Project 2. Select ".NET Framework 4" and Templates → Visual C# → Web → ASP.NET MVC 4 Web Application. Call it "CSReact" 3. In the "New ASP.NET MVC 5 (or 4) Project" dialog, select the MVC (or empty) template. Install ReactJS.NET We need to install ReactJS.NET to…
ReactJS: component Lifecycle and Rendering
These are the functions that will be, or can be, included in your specification object when you’re creating a component. Part of these specification functions are lifecycle functions, which when encountered, will show the details as to when they execute during the life of a component. Function invocation order during the initial render of a React component Component lifecycle that happens when the state changes on a component Lifecycle of a component when it has altered props render Every React component must have a render function. This render function will…
Microsoft now plans March Windows 10 Mobile rollout
February has come and gone without the highly anticipated Windows 10 Mobile upgrade for legacy Lumia handsets. In an email to partners, seen by VentureBeat, Microsoft is now targeting a release this month, to occur after the regular monthly service updates for the two Windows 10-powered handsets already on the market, the Lumia 950 and 950 XL. Unlike the previous schedule this one separates the upgrade from the service update. In other words, whereas the February rollout would have seen the update bundled into the upgrade, in March they are…
C# MVC: HttpContextBase from HttpContext.Current
It’s easy by using the HttpContextWrapper HttpContextBase basecontext = (new HttpContextWrapper(HttpContext.Current)); Happy coding!
How to check if IsNumeric?
If you need to check if something is a number, in C# doesn’t exist a function for that. That I’ve created the following code. public bool IsNumeric(object Expression) { if (Expression == null || Expression is DateTime) return false; if (Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean) return true; try { if (Expression is string) Double.Parse(Expression as string); else Double.Parse(Expression.ToString()); return true; } catch { } // just dismiss errors…
Remove line numbers from code
Often you copy from a site some code but it has line numbers and you have to spend some times to remove them. With my simple tool on line, you can remove them quickly. Try it!
Customize Json result in Web API
If you work with Visual Studio 2015 and WebAPI, this short post is for you! We have to make our Web API project easy to debug so, I’m going to remove the XML formatter. I’m doing that because I’m in a test project and I’d like to see the response in the browser. The easily way to force the response to Json for all Web API requests is to remove the XML. Obviously you shouldn’t do it in production. Global.asax var formatters = GlobalConfiguration.Configuration.Formatters; formatters.Remove(formatters.XmlFormatter); Now we can start change…
Creating a URL shortener using ASP.NET WepAPI and MVC: error handling
In the two previous post I discussed about the first step to creare this application and the implementation of the business logic. Now we can implement the error handling. We have two custom exception classes: ShorturlConflictException (when a segment already exists) and ShorturlNotFoundException (when a segment isn’t found in the database). There is also a third type: an unexpected exception, for example when there is no database connection. Normally, the user will see these errors. We have to build a mechanism where these exceptions are caught and a nice error…
Creating a URL shortener using ASP.NET WepAPI and MVC: implementing the business layer
In my previsious post I discussed the first implementation of this application. In this post I’m explained how to implement the business layer. First of all you make sure the Business project references the Data, Entities and Exceptions projects. In the Exceptions project you add two new classes: ShorturlConflictException using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PSC.Shorturl.Web.Exceptions { public class ShorturlConflictException : Exception { } } ShorturlNotFoundException using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PSC.Shorturl.Web.Exceptions { public class ShorturlNotFoundException : Exception {…
Agile approaches
There are a number of specific Agile approaches, as well as a generic agile style of working. Extreme Programming is a software development methodology, containing mainly programming practices such as Test Driven Development, Pair programming and Continuous Integration, but little management. Lean, which came from the manufacturing environment, is all about efficient processes. The focus is on eliminating waste from the production line and thereby reducing cost. Scrum is a very simple agile process, designed for delivering software in small chunks, taken from a backlog of work to be done.…
Davos: Smart machines set to transform society
Artificial intelligence will spur economic growth and create new wealth. Machines that “think” like humans will help solve huge problems, from curing cancer to climate change. Yet millions of human workers will need to retrain, as robots make their existing jobs redundant. These are the contrasting messages provided by the world’s leading technologists during the World Economic Forum in Davos this week, as political and business leaders ponder how best to respond to the rise of smart machines. Sebastian Thrun, the inventor of Google’s self-driving cars and an honorary professor…
Creating a URL shortener using ASP.NET WepAPI and MVC
In this tutorial, I use several techniques and tools. I use Microsoft Visual Studio 2015 and the latest version of all components. ASP.NET MVC: Microsoft’s modern web application framework. As the name says, it pushes you to use the MVC (model view controller) software design principle. ASP.NET Web API: Web API and MVC are used together in many applications. With MVC, the HTML of the web pages are rendered on the server, and with Web API you can, like the name says, create an API. Web API also uses the…
Throw vs Throw e
Some people asked me the different between those two following code: Code 1 try { … } catch (Exception ex) { throw ex; } Code 2 try { … } catch (Exception ex) { throw; } I don’t think there is ever a good reason to write catch (Exception e) { throw e; }. This loses the original stacktrace. When you use throw; the original stacktrace is preserved. This is good because it means that the cause of the error is easier to find.