Announcing Microsoft ASP.NET WebHooks V1

WebHooks provide a simple pub/sub model for wiring together Web APIs and services with your code. A WebHook can be used to get notified when a file has changed in Dropbox, a code change has been committed to GitHub, a payment has been initiated in PayPal, a card has been created in Trello, and much more — the possibilities are endless! When subscribing, you provide a callback URI where you want to be notified. When an event occurs, an HTTP POST request is sent to your callback URI with information about what happened so that your Web app can act accordingly. WebHooks happen without polling and with no need to hold open a network connection while waiting for notifications.

Receiving WebHooks

Dealing with WebHooks depends on who the sender is. Sometimes there are additional steps registering a WebHook verifying that the subscriber is really listening. Often the security model varies quite a bit. Some WebHooks provide a push-to-pull model where the HTTP POST request only contains a reference to the event information which is then to be retrieved independently.

The purpose of Microsoft ASP.NET WebHooks is to make it both simpler and more consistent to wire up your API without spending a lot of time figuring out how to handle any WebHook variant:

WebHoks-Receiving

A WebHook handler is where you process the incoming WebHook. Here is a sample handler illustrating the basic model. No registration is necessary – it will automatically get picked up and called:

public class MyHandler : WebHookHandler
{
    // The ExecuteAsync method is where to process the WebHook data regardless of receiver
    public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
    {
        // Get the event type          
        string action = context.Actions.First();
 
        // Extract the WebHook data as JSON or any other type as you wish
        JObject data = context.GetDataOrDefault();
 
        return Task.FromResult(true);
    }
}

Finally, we want to ensure that we only receive HTTP requests from the intended party. Most WebHook providers use a shared secret which is created as part of subscribing for events. The receiver uses this shared secret to validate that the request comes from the intended party. It can be provided by setting an application setting in the Web.config file, or better yet, configured through the Azure portal or even retrieved from Azure Key Vault.

For more information about receiving WebHooks and lots of samples, please see these resources:

More detail on Microsoft Blog.

How do I extract text that lies between two strings?

My initial prolem was to extract from a SQL string generated by MySql, all fields. I had a string like

INSERT INTO `inventoryapp`.`inventory_keys`
(`Id`,
`PropertyId`,
`AppointmentId`,
`SectionType`,
`KeysDescription`,
`FobsWorking`,
`EntryCodes`,
`AlarmCodes`,
`Notes`,
`Version`,
`CreatedDate`,
`CreatedBy`,
`UpdatedDate`,
`UpdatedBy`,
`IsDeleted`)
VALUES
(<{Id: }>,
<{PropertyId: }>,
<{AppointmentId: }>,
<{SectionType: }>,
<{KeysDescription: }>,
<{FobsWorking: }>,
<{EntryCodes: }>,
<{AlarmCodes: }>,
<{Notes: }>,
<{Version: }>,
<{CreatedDate: }>,
<{CreatedBy: }>,
<{UpdatedDate: }>,
<{UpdatedBy: }>,
<{IsDeleted: }>);


With a bit of RegEx I can extract all fields with the following function:

public IEnumerable<string> GetSubStrings(string input, string start, 
                                         string end) {
    Regex r = new Regex(Regex.Escape(start) + "(.*?)" + Regex.Escape(end));
    MatchCollection matches = r.Matches(input);
    foreach (Match match in matches)
        yield return match.Groups[1].Value;
}


Then if you want to have in a single line this query and generate the list of fields to have a list of parameters for a MySqlCommand for example, you can use the following function:

string strSQL = yoursql.Replace(Environment.NewLine, "")
                       .Replace("\r", " ");
string strParameters = "";

List<string> prm = GetSubStrings(strSQL, "<{", ": }>").ToList();
foreach(string s in prm) {
    string tmp = s.Replace("?", "");
    strParameters += Environment.NewLine + 
        $"cmd.Parameters.Add(\"?{tmp}\", MySqlDbType.VarChar)" +
        $".Value = record.{tmp}"; ;
}
this.textBoxParams.Text = strParameters;

strSQL = strSQL.Replace("`inventoryapp`.", "");
strSQL = strSQL.Replace("<{", "?").Replace(": }>", "");

Happy coding!

It’s a Good Day to Be a C# Developer

great_time_csharp_header

Recently at Connect(), Microsoft made a slew of new announcements. First, the public availability of Visual Studio 2017 Release Candidate. This just isn't a new version of the signature developer tool, it also includes the latest bits for C# 7.0. Second, Google announced they were joining the .NET Foundation. This means that Google, technically a competitor of Microsoft, wants to be actively involved in the evolution of .NET (and indirectly C#). Third, the first public release of Visual Studio for Mac. As a native environment, Visual Studio for Mac will provide the same world class tooling support for Xamarin applications, using C# and F#.

We could go on, but there is a common thread that runs between many of these announcements. As a developer, choosing C# as a part of your technology stack is an excellent decision! But what if you are not a C# developer already? How does C# compare to other popular languages such as JavaScript, Java, Python, etc?

Migrate SQLite to MySQL

I’m developing a huge app made with Xamarin Forms in my company. A problem was to create all tables in the device with SQLite to the main database MySql.

SQLLite-To-MySql-1

I found a way to create all tables quickly with a tool called SQLite to MySQL.

SQLite-to-MySQL is a powerful and reliable tool to convert SQLite databases to MySQL, MariaDB or Percona format. The program has high performance due to direct connection to source and destination databases (it does not use ODBC or any other middleware software). Command line support allows to script, automate and schedule the conversion process.

SQLLite-To-MySql-2

SQLLite-To-MySql-3

Features

  • All versions of Linux/Unix and Windows MySQL servers are supported
  • Option to customize resulting table structure
  • Convert indexes and relationships between tables
  • Stores conversion settings into profile
  • Option to filter data using SELECT-queries
  • Option to merge SQLite data into an existing MySQL database
  • Option to synchronize MySQL database with SQLite data
  • Support for multibyte character sets
  • Option to export SQLite database into MySQL script file
  • Verified compatibility with MariaDB and Percona
  • Option to customize MySQL storage engine and MySQL charset
  • Special approach for Virtual Server users
  • Command line support
  • Easy-to-use wizard-style interface
  • Full install/uninstall support
  • Unlimited 24/7 support service
  • 1-year subscription for updates
    SQLLite-To-MySql-7

Click here to download and try it.

Advertsing

125X125_06

TagCloud

MonthList

CommentList