C# Archives - Falafel Software Blog

PressReleaseCustomContentType

Retrieving Simple Custom Properties from Sitefinity Content Items

By | .NET, C#, Sitefinity | No Comments

Sitefinity offers many extension points to its core content types, as well as letting you create completely customized content types of your own via the Module Builder. You can add custom fields to existing types like News and Events, or add as many fields as you like to custom content types. Working with these custom properties in code can seem a little daunting at first: How do you do it? What data types do you work with? Which methods do you call on your objects? There are several ways of accessing certain kinds of properties, while others you have to…

Read More

What to love and hate about Azure’s DocumentDB

By | Azure, C#, Data & Storage, JavaScript, Microsoft, News | 7 Comments

This is post 4 of 31 in the series “A Cloudy 29 Days of Microsoft Azure” Azure DocumentDB is Microsoft’s fully-managed document-oriented NoSQL database service that is built to work within the Azure Cloud ecosystem much like SQL Azure, SQL Storage, Azure search, etc. DocumentDB is relatively a new player in the NoSQL world (it was released for general availability in April 2015). It comes with an impressive list of features and has gone through several version updates. It also has its limits (the list hasn’t been updated for a while so make sure you read the comments section). In this post we are…

Read More
kendo-ui

Extending Kendo UI Editor Functionality in Sitefinity

By | C#, JavaScript, Kendo UI, Sitefinity | One Comment

In my previous post I detailed a feature where users can upload files to the Sitefinity Document Library asynchronously. However, the interface for doing so was a bit basic. There was an HTML file input that automatically uploaded the selected file immediately. It worked, but the user wasn’t left with much to do with the link that was returned. Extending Kendo UI Editor functionality, however, can be used to make the return value more useful and make the whole user experience much better. This post will show you how to take the feature and add it to the set of…

Read More
document-library

How to Upload Files to your Sitefinity Document Library Asynchronously

By | .NET, ASP.NET, C#, JavaScript, Sitefinity, Web API | 2 Comments

Sometimes, it is necessary for users of your site to be able to upload files to Document Libraries in an asynchronous manner. They could be creating user-generated content and require a space to upload a file to reference in their content, for instance. Using some JavaScript and an ASP.NET WebAPI controller, we can accomplish this fairly simply. The HTML The first thing we’ll need is an input that allows users to select a file. This’ll be a simple HTML input the “file” type. You can put this HTML (along with the associated JavaScript) anywhere on the page, either via Content…

Read More
WP_20151125_00_21_37_Cinemagraph_export

Heart Rate Display with a Photon and a Microsoft Band

By | .NET, Blogs, C#, Fun, IoT, Microsoft Band, Mobile, Multi-Device, News, Photon, Visual Studio, Windows Phone | 4 Comments

Those who know me, know I love sensors, and doing things with sensors. I’ve published many posts on accessing the various sensors on the Microsoft Band: Accelerometer & Gyroscope, Ultraviolet, Skin Temperature, and Galvanic Skin Response. One subject that I haven’t gotten to is the heart rate sensor. I’ve also started to publish a few IoT posts. For this post, I thought it would be fun to integrate the Band’s heart rate sensor with a Particle Photon so you can visualize your heart rate with an RGB LED. The LED pulses at the same rate as your heart and will shift…

Read More
WP_20151113_002

PIR Sensor with a Photon, Particle Cloud, and a UWA

By | .NET, Blogs, C#, Fun, IoT, Microsoft, Multi-Device, News, Photon, Visual Studio, Windows, Windows Universal Apps | One Comment

My latest sensor experiment involved the PIR Motion Sensor (HC-SR501) that comes with the Photon Maker Kit. The motion sensor didn’t have the best English documentation; however, there were enough translations and fragments out on the Internet to get the job done. I decided to interface the motion sensor with a Photon, and then feed the sensor output to a UWA through the Particle Cloud by using a Particle Event Stream. The sensor has two potentiometers on its PCB. One controls the sensitivity of the sensor and the other controls the output latch delay. Turning the sensitivity down essentially limits the…

Read More

Azure Mobile Apps: Writing a Fast Custom DomainManager, Part 3

By | Azure, C#, JavaScript, SQL Server | 4 Comments

This is post 8 of 11 in the series “Azure for Developers” Picking Up From Last Time Last time, I finished the overview of the helpers afforded by the MappedEntityDomainManager and how they could be used to easily implement a custom DomainManager that maps an ITableData DTO class to a database table with an integral primary key, and I profiled the SQL that was generated by performing an ID lookup as well as the SQL that was generated by querying the OData endpoint of a TableController that uses this custom DomainManager. I explained why the SQL generated by this custom…

Read More
PhotonColor

Controlling an RGB LED on a Photon with a UWA Color Picker

By | .NET, Blogs, C#, Fun, IoT, Microsoft, Mobile, Multi-Device, News, Photon, Visual Studio, Windows Universal Apps | 3 Comments

The Particle Photon makes it easy to control the color of an RGB LED. There are a number of color picker controls you can use in Windows apps. I wanted to see how easy it was to hook a Photon RGB LED up to a Windows app color picker. It ended up being a snap by using the Particle cloud functions. In this project I wrote a simple UWA that calls a Particle cloud function called “setRGB” on my targeted Photon whenever I change the selected value on the color picker. Then I implemented an event handler on that Photon’s…

Read More

Azure Mobile Apps: Writing a Fast Custom DomainManager, Part 2

By | Azure, C#, SQL Server | 3 Comments

This is post 7 of 11 in the series “Azure for Developers” Picking Up Where We Left Off Last time, I wrote about how to develop a custom DomainManager to plug into an Azure Mobile Apps TableController. The goal is to implement a DomainManager that works seamlessly with the Azure Mobile App client SDKs, enables CRUD against database tables with non-string keys, and generates good SQL that can be supported with ordinary general-purpose indexes. I covered which class to inherit from, the methods you’ll need to implement, and some of the helpful utilities that the parent class affords you. In this…

Read More
TwoPhotonsUselessMachine

Exploring Multi-Photon and Particle Cloud Functionality with a Useless Machine

By | .NET, Blogs, C#, Fun, Hardware, IoT, Microsoft, Mobile, Multi-Device, News, Photon, Visual Studio, Web, Windows, Windows Universal Apps | 2 Comments

There are many ways for Particle Photons to interact with each other. Even more ways for other devices and apps to interact with Photons through the Particle Cloud. To explore these capabilities, I created a useless machine. My useless machine is made up of two Photons. Photon 1 “falafel_1” has a photo resistor and a green LED. Photon 2 “falafel_2” also has a photo resistor and a green LED. However, Photon 2 also has a servo motor and a second red LED. The servo motor is mounted so that when it is rotated to 90 degrees, it covers both photo…

Read More

Azure Mobile Apps: Writing a Fast Custom DomainManager, Part 1

By | Azure, C#, SQL Server | 2 Comments

This is post 6 of 11 in the series “Azure for Developers” My last post took you on a journey with me as I analyzed the Azure Mobile App default base entity class and talked about some of the things I saw there. To summarize, I was most disturbed to note that the default choice of primary key was a Unicode string, which as a database and query guy immediately raised all sorts of alarms, flags, flashing lights, klaxons, sirens… well, you get the idea. Strings make inefficient keys to begin with, and Unicode keys literally doubly so. I found a…

Read More

Await in Catch and Finally blocks – Day 13 – VS2015 Series

By | ASP.NET, Visual Studio | 2 Comments

This is post 13 of 31 in the series “31 Days of VS2015 Tricks and Treats” Await in Catch and Finally blocks Of all the language additions in C# 6 the added ability to use await in catch and finally blocks is likely my favorite. Previous to C# 6 one couldn’t. This inability could be particularly irksome as it created a conflict between two common good practices: Posting event to logs asynchronously so move the overhead of log I/O out of band from the application Logging errors as they occur. Since exceptions are handled by catch blocks with detection only being…

Read More

Expression Bodied Methods and Properties – Day 11 – VS 2015 Series

By | .NET, C#, C# 6, News | 2 Comments

This is post 11 of 31 in the series “31 Days of VS2015 Tricks and Treats” More Syntactical Sugar Syntactical Sugar comes in a wide range of flavors, nonetheless their goal is to decrease the level of noise in our code resulting in code where its intent is clear, easy to read, and distracting elements are minimized. Often they are tightly focused changes affecting a single code item.

This is a typical example. The left hand side type reference is redundant. Replacing it with var doesn’t make the code any less clear and makes it much easier to scan. Expression Bodied Methods…

Read More

String Interpolation – Day 10 – Visual Studio 2015

By | .NET, C# 6, Visual Studio | 3 Comments

This is post 10 of 31 in the series “31 Days of VS2015 Tricks and Treats” Even in the early days of C# there were ways to construct strings that use values from variables using either concatenation or string.Format. After many years with no change in how this is done, C# 6 brings a new feature called String Interpolation that will make it easier to build strings containing variable data. First, let’s look at what our options were before string interpolation, with either string.Format or concatenation:

While both of these work fine, they each have their downsides: concatenation lets you see your variables…

Read More

Using Static Directive – Day 9 – VS 2015 Series

By | .NET, C#, C# 6, News, Visual Studio | 6 Comments

This is post 9 of 31 in the series “31 Days of VS2015 Tricks and Treats” Using Static Directive? Admittedly, the title of this article reads somewhat awkwardly. For the sake of improving clarity it could instead be, Using Statics in a Using Directive. However, I find the oddly compressed wording of the title fitting as its spartan use of terms bear similarity to the subject of the article; adding using directives to static classes in order to streamline code references to static members. The Using Directive In C# the using keyword has two forms: using Statement – a convenience Statement used to assure proper use of…

Read More

nameof – Day 3 – VS 2015 Series

By | .NET, C#, C# 6, News, Visual Studio | 3 Comments

This is post 3 of 31 in the series “31 Days of VS2015 Tricks and Treats” When magic isn’t Discernng why certain code is considered good and other code -well- isn’t is often readily apparent by examing a handful of the code’s characteristics. One important characteristic which is always considered is the code’s level of coupling. Various parts of a system are “coupled” if they interact therefore depend on each other. If the interdependencies are limited to what is strictly -and practically- necessary the system is considered loosely coupled, this is good practice. The opposite extreme is considered tightly coupled,…

Read More
PhotonOscope2

Particle Photon Oscilloscope

By | .NET, Blogs, C#, Fun, Hardware, IoT, Microsoft, Mobile, Multi-Device, News, Photon, Visual Studio, Windows | One Comment

I previously turned my Windows IoT Core-based Raspberry Pi 2 into an oscilloscope, but I didn’t stop there. The next gadget in my target is the Particle Photon. This is an amazing little device. However ,unlike the Raspberry Pi 2, it doesn’t have an HDMI output (it’s only about the size of an HDMI connector). I wasn’t sure how best to display the signal data. I took inspiration from a post from Hackster.io – Sending sound over the Internet. They used the TCP capabilities of the Photon to stream audio data to a client. That’s all I needed to bring…

Read More

Null-Conditional Operators – Day 2 – Visual Studio 2015

By | .NET, C# 6, Visual Studio | 8 Comments

This is post 2 of 31 in the series “31 Days of VS2015 Tricks and Treats” One of my favorite new features of C# 6 is the null-conditional operator. While it is certainly possible to go without this feature, it will greatly simplify the code you write to avoid NullReferenceExceptions. To give you an idea of what this will do for you, imagine getting rid of most of the “if (x != null)” statements in your code!  There are three uses of the null-conditional operator: member access, index access, and delegate invocation. Member Access Member Access will probably be one of…

Read More
vs15-banner.jpg

Index Initializers – Day 1 – VS 2015 Series

By | .NET, C#, C# 6, News, Visual Studio | 5 Comments

This is post 1 of 31 in the series “31 Days of VS2015 Tricks and Treats” Syntactical Sugar   Many of the new features in C# 6 come under the heading of Syntactical Sugar. Syntactical sugar refers to a simplification of existing syntax making it easier to read and write. In practice it’s mostly about lowering the noise level. An unsweetened and contrived example:

Applying some Syntactical Sugar by using the var keyword, LINQ, and method chaining AKA fluent syntax our example becomes:

Our “sweetening” results in less overall code, in other words less code to manually compose. And while there’s…

Read More
IoTWifi

Windows IoT Core Remote Wifi Scanner

By | .NET, C#, Fun, IoT, Microsoft, Mobile, Multi-Device, News, Visual Studio, Windows, Windows Universal Apps | 3 Comments

Windows IoT Core has a nice web-based device management interface. This app can configure many aspects of the device, such as connecting the device to a WiFi network. Because the web-based device management was just a web app, I thought it shouldn’t be difficult to write a remote app to do the same. I ended up with a remote app that could query WiFi networks visible to a Windows IoT Core device and connect or disconnect that device to those networks. To get started, I connected my browser to the web-based device management app for one of my Windows IoT Core…

Read More
Office Lens_20150902_104950_processed

Windows IoT Core Oscilloscope

By | .NET, Blogs, C#, Fun, Hardware, IoT, Microsoft, Mobile, Multi-Device, News, Telerik, Tools, Visual Studio, Windows Universal Apps | 2 Comments

In my continuing quest to see what the Windows IoT Core is capable of and my desire to push my gadgets to their limits, I came up with an interesting oscilloscope project using a Windows IoT Core-based Raspberry Pi 2 and a simple ADC. Now, I’m not claiming that you can just quickly build an oscilloscope using a Raspberry Pi 2 and an ADC and never need to spend the money on an oscilloscope ever again. The one shown in this project is limited in its temporal resolution to the millisecond range. For an oscilloscope, that’s slow, but it may…

Read More
UniversalBluetoothTest

Bluetooth Rfcomm Communication with a Windows IoT Core Device

By | .NET, C#, IoT, Mobile, News | 2 Comments

Being a gadget guy, I can’t express enough the excitement I have for the Windows 10 IoT Core. The fact that I can now run most any UWA on a Raspberry Pi 2 is cool. I looked at the many ways you could wirelessly communicate with the Raspberry Pi 2. Carey has done a great post on using ZigBee modules. Then there is also Wifi and Bluetooth. This post will look at using Bluetooth to link a Raspberry Pi 2 with my Surface Pro 3. If you’ve not installed the Windows IoT Core onto your Raspberry Pi 2 you can…

Read More
Windows-10-App-Visual-Studio-Template

Hello, Windows 10: Getting Started Developing

By | Windows | 8 Comments

This is post 1 of 14 in the series “Developing for Windows 10” Today is a big day in the history of Microsoft; the long-awaited Windows 10 release is finally here, bringing a whole new level of interactivity, security, productivity and entertainment. And with it comes a whole a whole new App Development model designed to unify and enhance the developer (and ultimately the user) experience. As an avid fan of everything Microsoft, I’m excited to start this new journey, and in addition to sharing my enthusiasm for the platform, I thought I would go a step further and share…

Read More
Watermark image demo windows phone 81

Crop, Blend (Watermark) Photos on Windows Phone 8.1 with the Lumia Imaging SDK

By | Windows Phone | 5 Comments

I recently needed the ability to combine two images on Windows Phone 8.1 (WinRT not Silverlight) so that one overlays the other, like a watermark. Because the watermark image was a fixed size and dimension, we also needed to make sure that the photo being merged shared the same aspect ratio (in this case a square). Although I found many examples for cropping and blending in Silverlight, Windows 8.1, and Win32 (GDI+), none of them apply to Windows Phone 8.1 as it omits many of the required libraries and references. One solution often suggested is to use XAML to layer…

Read More