├── .gitignore ├── LICENSE ├── README.md ├── art ├── connected-dots-01.png └── connected-dots-01.svg └── src ├── Sample └── Forms │ ├── Droid │ ├── Assets │ │ └── AboutAssets.txt │ ├── FodyWeavers.xml │ ├── MainActivity.cs │ ├── Properties │ │ ├── AndroidManifest.xml │ │ └── AssemblyInfo.cs │ ├── Resources │ │ ├── AboutResources.txt │ │ ├── Resource.designer.cs │ │ ├── drawable-hdpi │ │ │ └── icon.png │ │ ├── drawable-xhdpi │ │ │ └── icon.png │ │ ├── drawable-xxhdpi │ │ │ └── icon.png │ │ ├── drawable │ │ │ ├── icon.png │ │ │ └── xamarin_logo.png │ │ ├── layout │ │ │ ├── Tabbar.axml │ │ │ └── Toolbar.axml │ │ └── values │ │ │ └── styles.xml │ ├── Sample.Droid.csproj │ └── packages.config │ ├── Sample │ ├── App.xaml │ ├── App.xaml.cs │ ├── Models │ │ └── TodoItem.cs │ ├── Sample.projitems │ ├── Sample.shproj │ ├── Services │ │ └── TodoService.cs │ ├── ViewModels │ │ └── TodoViewModel.cs │ └── Views │ │ ├── MainPage.cs │ │ ├── PostView.xaml │ │ ├── PostView.xaml.cs │ │ ├── TodoView.xaml │ │ └── TodoView.xaml.cs │ └── iOS │ ├── AppDelegate.cs │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Entitlements.plist │ ├── FodyWeavers.xml │ ├── Info.plist │ ├── LaunchScreen.storyboard │ ├── Main.cs │ ├── Resources │ ├── tab_about.png │ ├── tab_about@2x.png │ ├── tab_about@3x.png │ ├── tab_feed.png │ ├── tab_feed@2x.png │ ├── tab_feed@3x.png │ ├── xamarin_logo.png │ ├── xamarin_logo@2x.png │ └── xamarin_logo@3x.png │ ├── Sample.iOS.csproj │ └── packages.config ├── TinyHttpClientPool.Tests ├── DummyMessageHandler.cs ├── TinyHttpClientPool.Tests.csproj ├── TinyHttpClientPool.Tests.sln └── TinyHttpClientTest.cs ├── TinyHttpClientPool.sln └── TinyHttpClientPool ├── ITinyHttpClientPool.cs ├── State.cs ├── TinyHttpClient.cs ├── TinyHttpClientPool.cs ├── TinyHttpClientPool.csproj ├── TinyHttpClientPool.sln └── TinyHttpClientPoolConfiguration.cs /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/visualstudio,xamarinstudio 3 | 4 | ### XamarinStudio ### 5 | bin/ 6 | obj/ 7 | *.userprefs 8 | .packages 9 | 10 | ### VisualStudio ### 11 | ## Ignore Visual Studio temporary files, build results, and 12 | ## files generated by popular Visual Studio add-ons. 13 | ## 14 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 15 | 16 | # User-specific files 17 | *.suo 18 | *.user 19 | *.userosscache 20 | *.sln.docstates 21 | 22 | # User-specific files (MonoDevelop/Xamarin Studio) 23 | 24 | # Build results 25 | [Dd]ebug/ 26 | [Dd]ebugPublic/ 27 | [Rr]elease/ 28 | [Rr]eleases/ 29 | x64/ 30 | x86/ 31 | bld/ 32 | [Bb]in/ 33 | [Oo]bj/ 34 | [Ll]og/ 35 | 36 | # Visual Studio 2015 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # MSTest test Results 42 | [Tt]est[Rr]esult*/ 43 | [Bb]uild[Ll]og.* 44 | 45 | # NUNIT 46 | *.VisualState.xml 47 | TestResult.xml 48 | 49 | # Build Results of an ATL Project 50 | [Dd]ebugPS/ 51 | [Rr]eleasePS/ 52 | dlldata.c 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | **/Properties/launchSettings.json 59 | 60 | *_i.c 61 | *_p.c 62 | *_i.h 63 | *.ilk 64 | *.meta 65 | *.obj 66 | *.pch 67 | *.pdb 68 | *.pgc 69 | *.pgd 70 | *.rsp 71 | *.sbr 72 | *.tlb 73 | *.tli 74 | *.tlh 75 | *.tmp 76 | *.tmp_proj 77 | *.log 78 | *.vspscc 79 | *.vssscc 80 | .builds 81 | *.pidb 82 | *.svclog 83 | *.scc 84 | 85 | # Chutzpah Test files 86 | _Chutzpah* 87 | 88 | # Visual C++ cache files 89 | ipch/ 90 | *.aps 91 | *.ncb 92 | *.opendb 93 | *.opensdf 94 | *.sdf 95 | *.cachefile 96 | *.VC.db 97 | *.VC.VC.opendb 98 | 99 | # Visual Studio profiler 100 | *.psess 101 | *.vsp 102 | *.vspx 103 | *.sap 104 | 105 | # TFS 2012 Local Workspace 106 | $tf/ 107 | 108 | # Guidance Automation Toolkit 109 | *.gpState 110 | 111 | # ReSharper is a .NET coding add-in 112 | _ReSharper*/ 113 | *.[Rr]e[Ss]harper 114 | *.DotSettings.user 115 | 116 | # JustCode is a .NET coding add-in 117 | .JustCode 118 | 119 | # TeamCity is a build add-in 120 | _TeamCity* 121 | 122 | # DotCover is a Code Coverage Tool 123 | *.dotCover 124 | 125 | # Visual Studio code coverage results 126 | *.coverage 127 | *.coveragexml 128 | 129 | # NCrunch 130 | _NCrunch_* 131 | .*crunch*.local.xml 132 | nCrunchTemp_* 133 | 134 | # MightyMoose 135 | *.mm.* 136 | AutoTest.Net/ 137 | 138 | # Web workbench (sass) 139 | .sass-cache/ 140 | 141 | # Installshield output folder 142 | [Ee]xpress/ 143 | 144 | # DocProject is a documentation generator add-in 145 | DocProject/buildhelp/ 146 | DocProject/Help/*.HxT 147 | DocProject/Help/*.HxC 148 | DocProject/Help/*.hhc 149 | DocProject/Help/*.hhk 150 | DocProject/Help/*.hhp 151 | DocProject/Help/Html2 152 | DocProject/Help/html 153 | 154 | # Click-Once directory 155 | publish/ 156 | 157 | # Publish Web Output 158 | *.[Pp]ublish.xml 159 | *.azurePubxml 160 | # TODO: Uncomment the next line to ignore your web deploy settings. 161 | # By default, sensitive information, such as encrypted password 162 | # should be stored in the .pubxml.user file. 163 | #*.pubxml 164 | *.pubxml.user 165 | *.publishproj 166 | 167 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 168 | # checkin your Azure Web App publish settings, but sensitive information contained 169 | # in these scripts will be unencrypted 170 | PublishScripts/ 171 | 172 | # NuGet Packages 173 | *.nupkg 174 | # The packages folder can be ignored because of Package Restore 175 | **/packages/* 176 | # except build/, which is used as an MSBuild target. 177 | !**/packages/build/ 178 | # Uncomment if necessary however generally it will be regenerated when needed 179 | #!**/packages/repositories.config 180 | # NuGet v3's project.json files produces more ignorable files 181 | *.nuget.props 182 | *.nuget.targets 183 | 184 | # Microsoft Azure Build Output 185 | csx/ 186 | *.build.csdef 187 | 188 | # Microsoft Azure Emulator 189 | ecf/ 190 | rcf/ 191 | 192 | # Windows Store app package directories and files 193 | AppPackages/ 194 | BundleArtifacts/ 195 | Package.StoreAssociation.xml 196 | _pkginfo.txt 197 | 198 | # Visual Studio cache files 199 | # files ending in .cache can be ignored 200 | *.[Cc]ache 201 | # but keep track of directories ending in .cache 202 | !*.[Cc]ache/ 203 | 204 | # Others 205 | ClientBin/ 206 | ~$* 207 | *~ 208 | *.dbmdl 209 | *.dbproj.schemaview 210 | *.jfm 211 | *.pfx 212 | *.publishsettings 213 | orleans.codegen.cs 214 | 215 | # Since there are multiple workflows, uncomment next line to ignore bower_components 216 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 217 | #bower_components/ 218 | 219 | # RIA/Silverlight projects 220 | Generated_Code/ 221 | 222 | # Backup & report files from converting an old project file 223 | # to a newer Visual Studio version. Backup files are not needed, 224 | # because we have git ;-) 225 | _UpgradeReport_Files/ 226 | Backup*/ 227 | UpgradeLog*.XML 228 | UpgradeLog*.htm 229 | 230 | # SQL Server files 231 | *.mdf 232 | *.ldf 233 | *.ndf 234 | 235 | # Business Intelligence projects 236 | *.rdl.data 237 | *.bim.layout 238 | *.bim_*.settings 239 | 240 | # Microsoft Fakes 241 | FakesAssemblies/ 242 | 243 | # GhostDoc plugin setting file 244 | *.GhostDoc.xml 245 | 246 | # Node.js Tools for Visual Studio 247 | .ntvs_analysis.dat 248 | node_modules/ 249 | 250 | # Typescript v1 declaration files 251 | typings/ 252 | 253 | # Visual Studio 6 build log 254 | *.plg 255 | 256 | # Visual Studio 6 workspace options file 257 | *.opt 258 | 259 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 260 | *.vbw 261 | 262 | # Visual Studio LightSwitch build output 263 | **/*.HTMLClient/GeneratedArtifacts 264 | **/*.DesktopClient/GeneratedArtifacts 265 | **/*.DesktopClient/ModelManifest.xml 266 | **/*.Server/GeneratedArtifacts 267 | **/*.Server/ModelManifest.xml 268 | _Pvt_Extensions 269 | 270 | # Paket dependency manager 271 | .paket/paket.exe 272 | paket-files/ 273 | 274 | # FAKE - F# Make 275 | .fake/ 276 | 277 | # JetBrains Rider 278 | .idea/ 279 | *.sln.iml 280 | 281 | # CodeRush 282 | .cr/ 283 | 284 | # Python Tools for Visual Studio (PTVS) 285 | __pycache__/ 286 | *.pyc 287 | 288 | # Cake - Uncomment if you are using it 289 | # tools/** 290 | # !tools/packages.config 291 | 292 | # Telerik's JustMock configuration file 293 | *.jmconfig 294 | 295 | # BizTalk build output 296 | *.btp.cs 297 | *.btm.cs 298 | *.odx.cs 299 | *.xsd.cs 300 | 301 | 302 | # Code 303 | .vscode/ 304 | 305 | ### VisualStudio Patch ### 306 | # By default, sensitive information, such as encrypted password 307 | # should be stored in the .pubxml.user file. 308 | 309 | # End of https://www.gitignore.io/api/visualstudio,xamarinstudio -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Johan Karlsson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TinyHttpClientPool 2 | A HttpClient Pool that allows for reuse of http clients by assuring that you have the full and only access to an HttpClient during your use of it. 3 | 4 | It is Tiny and only a few classes big. 5 | 6 | ## Build status 7 | 8 | ![Build status](https://io2gamelabs.visualstudio.com/_apis/public/build/definitions/be16d002-5786-41a1-bf3b-3e13d5e80aa0/13/badge) 9 | 10 | ## Why use it? 11 | 12 | * Exclusive access to an HttpClient while calling 13 | * Allows for custom headers per request while reusing HttpClients 14 | * Pools are cool 15 | 16 | ## Why is it created 17 | 18 | It's created with Xamarin in mind and that's where we use it. 19 | 20 | ## Usage 21 | 22 | ### Getting an instance of the pool manager 23 | 24 | There are a few ways to get a hold of an instance. 25 | 26 | ```csharp 27 | // A) Just create a new instance 28 | var pool = new TinyHttpClientPool(); 29 | 30 | // B) Use the static helpers 31 | TinyHttpClientPool.Initialize(); 32 | var client = TinyHttpClientPool.FetchClient(); 33 | 34 | // C) Register the interface into your favorite IoC container 35 | var pool = Resolver.Resolve(); 36 | ``` 37 | 38 | The usage from this point on is pretty straight forward 39 | 40 | ```csharp 41 | // Create an instance in any way above 42 | var pool = new TinyHttpClientPool(); 43 | 44 | // Always use a using around the client! 45 | using (HttpClient client = pool.Fetch()) 46 | { 47 | // As long as you are in the using, the instance 48 | // is yours and yours alone 49 | var result = await client.GetStringAsync(url); 50 | } 51 | 52 | // At this point it is returned to the pool 53 | ``` 54 | 55 | ## Initialization 56 | > Note: We are currently working on a better way to initialize the pool. But for the time being, you can hook up to the ```ClientInitialization``` action and configure each new ```HttpClient``` with default values. 57 | > 58 | > What we are thinking of is a configuration object passed into the constructor of the Initialize call and/or the constructor of the TinyHttpClientPool class. 59 | 60 | For example, setting a common base url on each new ```HttpClient```is done like this: 61 | ```csharp 62 | TinyHttpClientPool.Current.ClientInitializationOnCreation = (obj) => obj.BaseAddress = new Uri(BackendUrl); 63 | ``` 64 | 65 | You can also run common code on each fetch. 66 | ```csharp 67 | TinyHttpClientPool.Current.ClientInitializationOnFetch = (obj) => ChangeHeaders(obj); 68 | ``` 69 | 70 | ## Monitoring 71 | 72 | You can monitor the pool size and number of available ```HttpClients``` and hook up to the ```PoolChanged``` event to be notified if something changes. 73 | 74 | ```csharp 75 | TinyHttpClientPool.Current.PoolChanged += (sender, e) => 76 | { 77 | PoolSize = TinyHttpClientPool.Current.TotalPoolSize; 78 | Available = TinyHttpClientPool.Current.AvailableCount; 79 | } 80 | ``` 81 | 82 | ## Cleanup 83 | 84 | If you want to flush the pool, simply call ```Flush()``` 85 | 86 | ```csharp 87 | pool.Flush(); 88 | ``` 89 | 90 | This will dispose any ```HttpClient``` that is in the ```Available``` state but not touch those who are in the ```InUse``` state. 91 | 92 | ## Important 93 | 94 | For this to work, you must dispose the client when you are done with it. There is no other way to return it to the pool. Well, there is one way... 95 | 96 | The returned client isn't really an ```HttpClient```, but rather a ```TinyHttpClient``` that inherits from ```HttpClient```. 97 | 98 | So you could manually set the state to ```State.Available``` but that is at your own risk. 99 | 100 | ```csharp 101 | var client = pool.Fetch() as TinyHttpClient; 102 | 103 | // do stuff with client here 104 | 105 | // Mark it as ready for the pool to reuse 106 | client.State = State.Available; 107 | ``` 108 | 109 | 110 | ## Roadmap 111 | 112 | There isn't really any roadmap to this since it's pretty much done the way it's supposed to work. But if you're missing a feature, create an issue or better yet, create a PR. :) -------------------------------------------------------------------------------- /art/connected-dots-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinyStuff/TinyHttpClientPool/293f33ab8be2977b64638f1bdde42fc50ca95614/art/connected-dots-01.png -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with your package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); 20 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Android.App; 4 | using Android.Content; 5 | using Android.Content.PM; 6 | using Android.Runtime; 7 | using Android.Views; 8 | using Android.Widget; 9 | using Android.OS; 10 | 11 | namespace Sample.Droid 12 | { 13 | [Activity(Label = "Sample.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 14 | public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity 15 | { 16 | protected override void OnCreate(Bundle bundle) 17 | { 18 | TabLayoutResource = Resource.Layout.Tabbar; 19 | ToolbarResource = Resource.Layout.Toolbar; 20 | 21 | base.OnCreate(bundle); 22 | 23 | global::Xamarin.Forms.Forms.Init(this, bundle); 24 | 25 | LoadApplication(new App()); 26 | } 27 | 28 | protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) 29 | { 30 | base.OnActivityResult(requestCode, resultCode, data); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using Android.App; 4 | 5 | // Information about this assembly is defined by the following attributes. 6 | // Change them to the values specific to your project. 7 | 8 | [assembly: AssemblyTitle("Sample.Droid")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("")] 13 | [assembly: AssemblyCopyright("(c) Johan Karlsson")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 18 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 19 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 20 | 21 | [assembly: AssemblyVersion("1.0.0")] 22 | 23 | // The following attributes are used to specify the signing key for the assembly, 24 | // if desired. See the Mono documentation for more information about signing. 25 | 26 | //[assembly: AssemblyDelaySign(false)] 27 | //[assembly: AssemblyKeyFile("")] 28 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.axml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable/ 12 | icon.png 13 | 14 | layout/ 15 | main.axml 16 | 17 | values/ 18 | strings.xml 19 | 20 | In order to get the build system to recognize Android resources, set the build action to 21 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called "R" 24 | (this is an Android convention) that contains the tokens for each one of the resources 25 | included. For example, for the above Resources layout, this is what the R class would expose: 26 | 27 | public class R { 28 | public class drawable { 29 | public const int icon = 0x123; 30 | } 31 | 32 | public class layout { 33 | public const int main = 0x456; 34 | } 35 | 36 | public class strings { 37 | public const int first_string = 0xabc; 38 | public const int second_string = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main 43 | to reference the layout/main.axml file, or R.strings.first_string to reference the first 44 | string in the dictionary file values/strings.xml. 45 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Resources/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinyStuff/TinyHttpClientPool/293f33ab8be2977b64638f1bdde42fc50ca95614/src/Sample/Forms/Droid/Resources/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Resources/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinyStuff/TinyHttpClientPool/293f33ab8be2977b64638f1bdde42fc50ca95614/src/Sample/Forms/Droid/Resources/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Resources/drawable-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinyStuff/TinyHttpClientPool/293f33ab8be2977b64638f1bdde42fc50ca95614/src/Sample/Forms/Droid/Resources/drawable-xxhdpi/icon.png -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Resources/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinyStuff/TinyHttpClientPool/293f33ab8be2977b64638f1bdde42fc50ca95614/src/Sample/Forms/Droid/Resources/drawable/icon.png -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Resources/drawable/xamarin_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinyStuff/TinyHttpClientPool/293f33ab8be2977b64638f1bdde42fc50ca95614/src/Sample/Forms/Droid/Resources/drawable/xamarin_logo.png -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Resources/layout/Tabbar.axml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Resources/layout/Toolbar.axml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Resources/values/styles.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | 6 | 24 | 27 | 28 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/Sample.Droid.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {02B448B3-0535-4D73-BF7A-BA1AE3483771} 9 | {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | Library 11 | Sample.Droid 12 | Sample.Droid 13 | v7.1 14 | True 15 | Resources\Resource.designer.cs 16 | Resource 17 | Properties\AndroidManifest.xml 18 | Resources 19 | Assets 20 | false 21 | 22 | 23 | true 24 | full 25 | false 26 | bin\Debug 27 | DEBUG; 28 | prompt 29 | 4 30 | None 31 | arm64-v8a;armeabi;armeabi-v7a;x86 32 | 33 | 34 | true 35 | pdbonly 36 | true 37 | bin\Release 38 | prompt 39 | 4 40 | true 41 | false 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ..\..\..\TinyHttpClientPool\packages\Newtonsoft.Json.10.0.3\lib\netstandard1.3\Newtonsoft.Json.dll 53 | False 54 | 55 | 56 | ..\..\..\TinyHttpClientPool\packages\Xam.Plugin.Connectivity.3.0.3\lib\MonoAndroid10\Plugin.Connectivity.Abstractions.dll 57 | False 58 | 59 | 60 | ..\..\..\TinyHttpClientPool\packages\Xam.Plugin.Connectivity.3.0.3\lib\MonoAndroid10\Plugin.Connectivity.dll 61 | False 62 | 63 | 64 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Annotations.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Annotations.dll 65 | 66 | 67 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Compat.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Compat.dll 68 | 69 | 70 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Core.UI.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Core.UI.dll 71 | 72 | 73 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Core.Utils.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Core.Utils.dll 74 | 75 | 76 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Media.Compat.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Media.Compat.dll 77 | 78 | 79 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Fragment.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Fragment.dll 80 | 81 | 82 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Transition.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Transition.dll 83 | 84 | 85 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.v4.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v4.dll 86 | 87 | 88 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.v7.CardView.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.CardView.dll 89 | 90 | 91 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.v7.Palette.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.Palette.dll 92 | 93 | 94 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.v7.RecyclerView.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.RecyclerView.dll 95 | 96 | 97 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Vector.Drawable.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Vector.Drawable.dll 98 | 99 | 100 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Animated.Vector.Drawable.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Animated.Vector.Drawable.dll 101 | 102 | 103 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.v7.AppCompat.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.AppCompat.dll 104 | 105 | 106 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.Design.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Design.dll 107 | 108 | 109 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Android.Support.v7.MediaRouter.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.MediaRouter.dll 110 | 111 | 112 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\FormsViewGroup.dll 113 | 114 | 115 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Core.dll 116 | 117 | 118 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll 119 | 120 | 121 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Platform.dll 122 | 123 | 124 | ..\..\..\TinyHttpClientPool\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll 125 | 126 | 127 | ..\..\..\TinyHttpClientPool\packages\PropertyChanged.Fody.2.2.4.0\lib\netstandard1.0\PropertyChanged.dll 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | {DFB4D488-DE81-4A33-AF0D-1638A54557AB} 155 | TinyHttpClientPool 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /src/Sample/Forms/Droid/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/App.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | #2196F3 6 | #1976D2 7 | #96d1ff 8 | #FAFAFA 9 | #C0C0C0 10 | #4d4d4d 11 | #999999 12 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Sample.Services; 3 | using TinyHttpClientPoolLib; 4 | using Xamarin.Forms; 5 | 6 | namespace Sample 7 | { 8 | public partial class App : Application 9 | { 10 | public static bool UseMockDataStore = true; 11 | public static string BackendUrl = "https://jsonplaceholder.typicode.com"; 12 | 13 | public App() 14 | { 15 | InitializeComponent(); 16 | 17 | // Initialize like this, or simply create an instance of 18 | // TinyHttpClientPool and keep track of it yourself. 19 | TinyHttpClientPool.Initialize(); 20 | 21 | // You can supply an action on what to do to initialize any new HttpClient 22 | // DO NOT keep a reference to the passed HttpClient since it must be controlled 23 | // by the pool. 24 | TinyHttpClientPool.Current.ClientInitializationOnCreation = (obj) => obj.BaseAddress = new Uri(BackendUrl); 25 | 26 | DependencyService.Register(); 27 | 28 | MainPage = new NavigationPage(new MainPage()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/Models/TodoItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | using Xamarin.Forms; 4 | 5 | namespace Sample.Models 6 | { 7 | public class TodoItem 8 | { 9 | [JsonProperty("userId")] 10 | public int UserId { get; set; } 11 | 12 | [JsonProperty("id")] 13 | public int Id { get; set; } 14 | 15 | [JsonProperty("title")] 16 | public string Title { get; set; } 17 | 18 | [JsonProperty("completed")] 19 | public bool Completed { get; set; } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/Sample.projitems: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {0F8994F0-A6BC-41AD-BD5D-92A10B3AE0D1} 7 | 8 | 9 | Sample 10 | 11 | 12 | 13 | 14 | App.xaml 15 | 16 | 17 | 18 | TodoView.xaml 19 | 20 | 21 | PostView.xaml 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | Designer 30 | MSBuild:UpdateDesignTimeXaml 31 | 32 | 33 | Designer 34 | MSBuild:UpdateDesignTimeXaml 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/Sample.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {0F8994F0-A6BC-41AD-BD5D-92A10B3AE0D1} 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/Services/TodoService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using Sample.Models; 5 | using TinyHttpClientPoolLib; 6 | 7 | namespace Sample.Services 8 | { 9 | public class TodoService 10 | { 11 | public async Task> GetTodoItems(bool slow = false) 12 | { 13 | using(var client = TinyHttpClientPool.FetchClient()) 14 | { 15 | if (slow) 16 | { 17 | await Task.Delay(3000); 18 | } 19 | 20 | var url = "/todos"; 21 | var json = await client.GetStringAsync(url); 22 | return Newtonsoft.Json.JsonConvert.DeserializeObject>(json); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/ViewModels/TodoViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using System.Windows.Input; 5 | using Sample.Models; 6 | using Sample.Services; 7 | using TinyHttpClientPoolLib; 8 | using Xamarin.Forms; 9 | 10 | namespace Sample.ViewModels 11 | { 12 | [PropertyChanged.AddINotifyPropertyChangedInterface] // Using PropertyChanged.Fody to auto generate INotifyPropertyChanged implementation 13 | public class TodoViewModel 14 | { 15 | public IEnumerable Items { get; set; } 16 | 17 | public int PoolSize { get; set; } 18 | public int Available { get; set; } 19 | 20 | public TodoViewModel() 21 | { 22 | TinyHttpClientPool.Current.PoolChanged += (sender, e) => UpdateStats(); 23 | } 24 | 25 | public ICommand GetItemsSlow 26 | { 27 | get 28 | { 29 | return new Command(async () => 30 | { 31 | var service = DependencyService.Get(); 32 | Items = await service.GetTodoItems(slow: true); 33 | }); 34 | } 35 | } 36 | 37 | public ICommand Flush 38 | { 39 | get 40 | { 41 | return new Command(() => 42 | { 43 | TinyHttpClientPool.Current.Flush(); 44 | }); 45 | } 46 | } 47 | 48 | private void UpdateStats() 49 | { 50 | PoolSize = TinyHttpClientPool.Current.TotalPoolSize; 51 | Available = TinyHttpClientPool.Current.AvailableCount; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/Views/MainPage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Sample.Views; 3 | using Xamarin.Forms; 4 | 5 | namespace Sample 6 | { 7 | public class MainPage : TabbedPage 8 | { 9 | public MainPage() 10 | { 11 | Children.Add(new TodoView()); 12 | Children.Add(new PostView()); 13 | 14 | Title = Children[0].Title; 15 | } 16 | 17 | protected override void OnCurrentPageChanged() 18 | { 19 | base.OnCurrentPageChanged(); 20 | Title = CurrentPage?.Title ?? string.Empty; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/Views/PostView.xaml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/Views/PostView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | using Xamarin.Forms; 5 | 6 | namespace Sample.Views 7 | { 8 | public partial class PostView : ContentPage 9 | { 10 | public PostView() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Sample/Forms/Sample/Views/TodoView.xaml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 |