summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Pages.Azure
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Pages.Azure')
-rw-r--r--Xamarin.Forms.Pages.Azure/AzureDataSource.cs149
-rw-r--r--Xamarin.Forms.Pages.Azure/AzureEasyTableSource.cs26
-rw-r--r--Xamarin.Forms.Pages.Azure/AzureSource.cs21
-rw-r--r--Xamarin.Forms.Pages.Azure/Properties/AssemblyInfo.cs30
-rw-r--r--Xamarin.Forms.Pages.Azure/Xamarin.Forms.Pages.Azure.csproj99
-rw-r--r--Xamarin.Forms.Pages.Azure/packages.config8
6 files changed, 333 insertions, 0 deletions
diff --git a/Xamarin.Forms.Pages.Azure/AzureDataSource.cs b/Xamarin.Forms.Pages.Azure/AzureDataSource.cs
new file mode 100644
index 00000000..907421cb
--- /dev/null
+++ b/Xamarin.Forms.Pages.Azure/AzureDataSource.cs
@@ -0,0 +1,149 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json.Linq;
+
+namespace Xamarin.Forms.Pages.Azure
+{
+ public class AzureDataSource : BaseDataSource
+ {
+ readonly ObservableCollection<IDataItem> _dataItems = new ObservableCollection<IDataItem>();
+ Task _currentParseTask;
+ bool _initialized;
+ AzureSource _source;
+
+ public AzureDataSource()
+ {
+ }
+
+ internal AzureDataSource(JToken rootToken)
+ {
+ ParseJsonToken(rootToken);
+ }
+
+ public AzureSource Source
+ {
+ get
+ {
+ return _source;
+ }
+ set
+ {
+ if (_source == value)
+ return;
+ _source = value;
+
+ _dataItems.Clear();
+ if (value != null && _initialized)
+ {
+ _currentParseTask = ParseJson();
+ _currentParseTask.ContinueWith(t => { throw t.Exception; }, TaskContinuationOptions.OnlyOnFaulted);
+ }
+ }
+ }
+
+ protected override async Task<IList<IDataItem>> GetRawData()
+ {
+ if (!_initialized)
+ {
+ Task task = _currentParseTask = ParseJson();
+ await task;
+ }
+ else if (_currentParseTask != null && _currentParseTask.IsCompleted == false)
+ await _currentParseTask;
+ return _dataItems;
+ }
+
+ protected override object GetValue(string key)
+ {
+ IDataItem target = _dataItems.FirstOrDefault(d => d.Name == key);
+ return target?.Value;
+ }
+
+ protected override bool SetValue(string key, object value)
+ {
+ IDataItem target = _dataItems.FirstOrDefault(d => d.Name == key);
+ if (target == null)
+ {
+ _dataItems.Add(new DataItem(key, value));
+ return true;
+ }
+ if (target.Value == value)
+ return false;
+ target.Value = value;
+ return true;
+ }
+
+ object GetValueForJToken(JToken token)
+ {
+ switch (token.Type)
+ {
+ case JTokenType.Object:
+ case JTokenType.Array:
+ return new AzureDataSource(token);
+ case JTokenType.Constructor:
+ case JTokenType.Property:
+ case JTokenType.Comment:
+ throw new NotImplementedException();
+ case JTokenType.Integer:
+ return (int)token;
+ case JTokenType.Float:
+ return (float)token;
+ case JTokenType.Raw:
+ case JTokenType.String:
+ return (string)token;
+ case JTokenType.Boolean:
+ return (bool)token;
+ case JTokenType.Date:
+ return (DateTime)token;
+ case JTokenType.Bytes:
+ return (byte[])token;
+ case JTokenType.Guid:
+ return (Guid)token;
+ case JTokenType.Uri:
+ return (Uri)token;
+ case JTokenType.TimeSpan:
+ return (TimeSpan)token;
+ default:
+ return null;
+ }
+ }
+
+ async Task ParseJson()
+ {
+ _initialized = true;
+
+ if (Source == null)
+ return;
+
+ IsLoading = true;
+ var jtoken = await Source.GetJson();
+ ParseJsonToken(jtoken);
+ IsLoading = false;
+ }
+
+ void ParseJsonToken(JToken token)
+ {
+ var jArray = token as JArray;
+ var jObject = token as JObject;
+ if (jArray != null)
+ {
+ for (var i = 0; i < jArray.Count; i++)
+ {
+ JToken obj = jArray[i];
+ _dataItems.Add(new DataItem(i.ToString(), GetValueForJToken(obj)));
+ }
+ }
+ else if (jObject != null)
+ {
+ foreach (KeyValuePair<string, JToken> kvp in jObject)
+ {
+ _dataItems.Add(new DataItem(kvp.Key, GetValueForJToken(kvp.Value)));
+ }
+ }
+ }
+ }
+}
diff --git a/Xamarin.Forms.Pages.Azure/AzureEasyTableSource.cs b/Xamarin.Forms.Pages.Azure/AzureEasyTableSource.cs
new file mode 100644
index 00000000..1d5a24f0
--- /dev/null
+++ b/Xamarin.Forms.Pages.Azure/AzureEasyTableSource.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Threading.Tasks;
+using Microsoft.WindowsAzure.MobileServices;
+using Newtonsoft.Json.Linq;
+
+namespace Xamarin.Forms.Pages.Azure
+{
+ public class AzureEasyTableSource : AzureSource
+ {
+ public static readonly BindableProperty TableNameProperty =
+ BindableProperty.Create(nameof(TableName), typeof(string), typeof(AzureEasyTableSource), null);
+
+ public string TableName
+ {
+ get { return (string)GetValue(TableNameProperty); }
+ set { SetValue(TableNameProperty, value); }
+ }
+
+ public override async Task<JToken> GetJson()
+ {
+ var mobileServiceClient = new MobileServiceClient(Uri);
+ var table = mobileServiceClient.GetTable(TableName);
+ return await table.ReadAsync(string.Empty);
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Pages.Azure/AzureSource.cs b/Xamarin.Forms.Pages.Azure/AzureSource.cs
new file mode 100644
index 00000000..ec2b2984
--- /dev/null
+++ b/Xamarin.Forms.Pages.Azure/AzureSource.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Threading.Tasks;
+using Newtonsoft.Json.Linq;
+
+namespace Xamarin.Forms.Pages.Azure
+{
+ public abstract class AzureSource : Element
+ {
+ public static readonly BindableProperty UriProperty =
+ BindableProperty.Create(nameof(Uri), typeof(Uri), typeof(AzureSource), null);
+
+ [TypeConverter(typeof(UriTypeConverter))]
+ public Uri Uri
+ {
+ get { return (Uri)GetValue(UriProperty); }
+ set { SetValue(UriProperty, value); }
+ }
+
+ public abstract Task<JToken> GetJson();
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Pages.Azure/Properties/AssemblyInfo.cs b/Xamarin.Forms.Pages.Azure/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000..8c6b8dac
--- /dev/null
+++ b/Xamarin.Forms.Pages.Azure/Properties/AssemblyInfo.cs
@@ -0,0 +1,30 @@
+using System.Resources;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Xamarin.Forms.Pages.Azure")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Xamarin.Forms.Pages.Azure")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: NeutralResourcesLanguage("en")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Xamarin.Forms.Pages.Azure/Xamarin.Forms.Pages.Azure.csproj b/Xamarin.Forms.Pages.Azure/Xamarin.Forms.Pages.Azure.csproj
new file mode 100644
index 00000000..c8d47fd8
--- /dev/null
+++ b/Xamarin.Forms.Pages.Azure/Xamarin.Forms.Pages.Azure.csproj
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{C9696465-7657-4843-872E-3C01891C4A9B}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Xamarin.Forms.Pages.Azure</RootNamespace>
+ <AssemblyName>Xamarin.Forms.Pages.Azure</AssemblyName>
+ <DefaultLanguage>en-US</DefaultLanguage>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <TargetFrameworkProfile>Profile259</TargetFrameworkProfile>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <NuGetPackageImportStamp>
+ </NuGetPackageImportStamp>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <!-- A reference to the entire .NET Framework is automatically included -->
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AzureDataSource.cs" />
+ <Compile Include="AzureEasyTableSource.cs" />
+ <Compile Include="AzureSource.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.WindowsAzure.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <HintPath>..\packages\Microsoft.Azure.Mobile.Client.2.0.1\lib\portable-win+net45+wp8+wpa81+monotouch+monoandroid\Microsoft.WindowsAzure.Mobile.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Net.Http.Extensions, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Extensions.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Primitives.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj">
+ <Project>{57b8b73d-c3b5-4c42-869e-7b2f17d354ac}</Project>
+ <Name>Xamarin.Forms.Core</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Xamarin.Forms.Pages\Xamarin.Forms.Pages.csproj">
+ <Project>{d6133dbd-6c60-4bd5-bea2-07e0a3927c31}</Project>
+ <Name>Xamarin.Forms.Pages</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Xamarin.Forms.Xaml\Xamarin.Forms.Xaml.csproj">
+ <Project>{9db2f292-8034-4e06-89ad-98bbda4306b9}</Project>
+ <Name>Xamarin.Forms.Xaml</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
+ <Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
+ <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+ <PropertyGroup>
+ <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
+ </PropertyGroup>
+ <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
+ </Target>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/Xamarin.Forms.Pages.Azure/packages.config b/Xamarin.Forms.Pages.Azure/packages.config
new file mode 100644
index 00000000..035d1e5d
--- /dev/null
+++ b/Xamarin.Forms.Pages.Azure/packages.config
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.Azure.Mobile.Client" version="2.0.1" targetFramework="portable45-net45+win8+wp8+wpa81" />
+ <package id="Microsoft.Bcl" version="1.1.10" targetFramework="portable45-net45+win8+wp8+wpa81" />
+ <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="portable45-net45+win8+wp8+wpa81" />
+ <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="portable45-net45+win8+wp8+wpa81" />
+ <package id="Newtonsoft.Json" version="6.0.4" targetFramework="portable45-net45+win8+wp8+wpa81" />
+</packages> \ No newline at end of file