Skip to content

Instantly share code, notes, and snippets.

View jfversluis's full-sized avatar

Gerald Versluis jfversluis

View GitHub Profile
@jfversluis
jfversluis / gist:9cef638839b29b09838abd7d10c73950
Created August 13, 2016 09:09
Detecting and receiving attachments with your Bot
if (activity.Attachments?.Count() > 0)
{
var imageCount = activity.Attachments.Count(a => a.ContentType.Contains("image"));
if (imageCount > 0)
{
// Notify user that we got something
var message = imageCount == 1 ? $"You've sent 1 image" : $"You've sent {imageCount} images";
var imageReply = activity.CreateReply(message);
await connector.Conversations.ReplyToActivityAsync(imageReply);
@jfversluis
jfversluis / gist:23e6bfef80e2b93af60be649dcc1bb91
Last active August 13, 2016 09:15
Bot Framework code to get bytes from Attachment on Skype
byte[] imageBytes = null;
// For Skype we need to get an OAuth token to access the content url
if (activity.ChannelId.ToLower() == "skype")
{
using (var httpClient = new HttpClient())
{
// Request OAuth token
var formValues = new KeyValuePair<string, string>[]
{
@jfversluis
jfversluis / gist:b1f9b804ddb8565741af35bcb49c1643
Created August 15, 2016 07:28
Code to receive an image file on the Bot Framework and send it to the Emotion API
var imageCount = activity.Attachments.Count(a => a.ContentType.Contains("image"));
if (imageCount > 0)
{
// Notify user that we got something
var message = imageCount == 1 ? $"You've sent 1 image" : $"You've sent {imageCount} images";
var imageReply = activity.CreateReply(message);
await connector.Conversations.ReplyToActivityAsync(imageReply);
}
@jfversluis
jfversluis / EmbedNativeAwesomenessPage.xaml
Last active November 11, 2016 04:07
Code for embedding native controls in Xamarin.Forms
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:EmbedNativeAwesomeness"
xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
x:Class="EmbedNativeAwesomeness.EmbedNativeAwesomenessPage">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="Isn't this awesome?!" VerticalOptions="Center" HorizontalOptions="Center" />
<ios:UIDatePicker />
<ios:UISlider />
@jfversluis
jfversluis / EmbedNativeAwesomenessPage.xaml
Created November 11, 2016 04:08
Code for embedding native controls in Xamarin.Forms
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:EmbedNativeAwesomeness"
xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
x:Class="EmbedNativeAwesomeness.EmbedNativeAwesomenessPage">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="Isn't this awesome?!" VerticalOptions="Center" HorizontalOptions="Center" />
<ios:UIDatePicker />
<ios:UISlider MaxValue="10" Value="{Binding SlideValue}" />
@jfversluis
jfversluis / UIRedTintSwitch.cs
Created November 11, 2016 04:09
Code for creating a native Red Tint UISwitch in Xamarin.iOS
public class UiRedTintSwitch : UISwitch
{
public UiRedTintSwitch ()
{
OnTintColor = UIColor.Red;
}
}
@jfversluis
jfversluis / EmbedNativeAwesomeness.xaml
Created November 11, 2016 04:10
Code for embedding native controls in Xamarin.Forms
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:EmbedNativeAwesomeness"
xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
xmlns:ioscustom="clr-namespace:EmbedNativeAwesomeness.iOS;assembly=EmbedNativeAwesomeness.iOS;targetPlatform=iOS"
x:Class="EmbedNativeAwesomeness.EmbedNativeAwesomenessPage">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="Isn't this awesome?!" VerticalOptions="Center" HorizontalOptions="Center" />
<ios:UIDatePicker />
@jfversluis
jfversluis / SwitchEffect.cs
Created January 16, 2017 17:08
iOS platform specific SwitchEffect
using EffectsSample.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ResolutionGroupName ("MyCompany")]
[assembly: ExportEffect (typeof (SwitchEffect), "SwitchEffect")]
namespace EffectsSample.iOS
{
public class SwitchEffect : PlatformEffect
@jfversluis
jfversluis / SwitchEffect.cs
Created January 16, 2017 17:17
Xamarin.Forms implementation of the SwitchEffect
using System;
using Xamarin.Forms;
namespace EffectsSample
{
public class SwitchEffect : RoutingEffect
{
public SwitchEffect () : base ("MyCompany.SwitchEffect")
{
}
@jfversluis
jfversluis / EffectsSamplePage.xaml
Created January 16, 2017 17:21
Sample app main page
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:EffectsSample" x:Class="EffectsSample.EffectsSamplePage">
<Switch VerticalOptions="Center" HorizontalOptions="Center">
<Switch.Effects>
<local:SwitchEffect />
</Switch.Effects>
</Switch>
</ContentPage>