EnterpriseXamarinTips and TricksRobin [email protected]

Why am I qualified to talk to you?“Being a small shop, we have thrived by learning how to do more withless. We share our techniques that leverage code generation and inspireothers to rethink their approach to software craftsmanship.” -PaulRobin Schroeder Coding since 1998 - VBA, Java, VB6, SQL, web applications Started C# in 2008, Win 8.1, and UWP Full Stack - Mostly Middle and Front-End, Backend Azure Currently specializing in Xamarin mobile, UWP, iOS and Android Photography, Guitar, 3D Printing, Hololens, Unity, etc Fox Valley Girls Coding Club

What are we going to talk about? Tooling Mobile Data Storage & GUIDs Sample Project – Bingo Buzz Cross Platform Mobile Architecture (Xamarin Specific) Dependency Injection & Platform Specific Code Memory Management Enterprise Plugins Authentication App Center: Analytics, Metrics, Crashes & CI/CD Application Insights and Beyond App Store vs Enterprise Deployments Where to read more

Tooling Development Visual Studio 2017 on PC Visual Studio for Mac (MacBook & MacMini) XCode Telerik Fiddler / Orchestra ( SQLite Expert ( Postman ( Code Maid VS Extension for PC Vysor (Android) and Reflector (iOS) Visual Studio App Center Account Apple Developer Program Membership Azure Account SQL Server Management StudioCode Generation Reverse POCOCodeGenHero

S.O.L.I.D.S – Single-responsibility principleO – Open-closed principleL – Liskov substitution principleI – Interface segregation principleD – Dependency Inversion principle

Two Mobile App Strategies for Data StorageNo long term storageData connection requiredSecurity sensitive informationPKs aren't importantDTOs don't match source DBOK candidate for Code GenerationLong term data storage (SQLite, etc.)Data connection not required – Offline CRUDGenerally not sensitive informationPK are generally GUIDsClient DB schema usually mirrors server DBGreat candidate for Code Generation

Capturing Data with GUIDsMultiple DevicesRunning SQLiteUse GUIDs as the primary key datatypeGUID Global Unique IdentifierUUID Universally Unique Identifier72468510-244a-4af5-bd8e-f8820c211b6cOne CentralCloud DB

Sample Project: e/dev/src/Samples/BingoBuzz

What the heck is BingoBuzz?Virtual meeting bingo game! Game is played as a virtual meeting is occurring All players have a randomized game board Players tap squares matching meeting events All phones 'buzz' when someone gets bingo Scores and stats are persisted Basically, it makes boring meetings funTechnologies: Xamarin.Forms client - iOS, Android & UWP WebAPI and Azure SQL DB

/BingoBuzzDemo.MP4?dl 0

So Where do the biz rules go? .Net Standard 2.0 Xamarin.Forms Resources for shared assets Controls for shared UI piecespopups, header, icon label ModelData for SQLite Helpers for high level biz rules ModelObj for more specific biz rulesThese are partial classes ViewModels for INPC & MVVMOnly minimal biz rules here Views for UINo Biz rules here Services, Interfaces & Modules for DI Generated CodeNo generated code in the platform specific projectsHandwritten partial models kept in Extensions folderCodeGenHero configuration has its own project (bottom)

All your model are belong to usMVVM Mobile Data FLOWDTOData TransferObjectsWebAPIWHY?SerializableIn and out ofJSONDataModelSQLitemapWHY?mapStorable inSQLiteNo childrenObject ModelINPCViewModelViewWHY?Object ModelINotifyPropertyChanged

Service Layer Data FlowDTO - DataModel - ObjModelDTO - DataModelUnit TestsMock DataServiceDemo DataDataLoaderServiceIDataLoaderServiceDataModel - PIDataLoaderServiceViewModels

What Can Be Generated?DTO - DataModel - ObjModelDTO - DataModelUnit TestsMock DataServiceDemo DataDataLoaderServiceIDataLoaderServiceDataModel - PIDataLoaderServiceViewModels

Dependency Injectionpublic MyViewModel (IDataService iDS, IAnalyticsService iAS, ILoggingService iLS,IPermissionsService iPS, ILocationService iLocS){//Now I have an instance of each of the services I need to make a new viewmodel//and the specific type of that service can vary based on my platform or test}Graphic From: dency-injection

Platform Specific CodeBACK END: I need to storemy SQLite database in adifferent place on eachplatform specific file system,but the db connectionneeds to be used by theshared business logic.SHARED CODE: I need tohide the Bluetooth printingbutton in my app on UWP,but show the same buttonin iOS and Android.FRONT END: The clientwants the text fields lookexactly the same on allthree platforms: yellowbackground with purpleborder and green text.How do I do that?How do I do that?How do I do that?Platform SpecificServicesDetect the OS ina conditionalCustom RenderersXamarin Effects

Memory Management New is Glue In XF, we worry about: Apps that use lots of pictures, videos, pdfs, data Apps that will be open all day Worry most about Android, less about iOS, not at all about UWP Worry some about Xamarin.iOS outside of XF Xamarin Profiler – stand alone app Build/run your iOS or Android app, then run it again in Xamarin Profiler Take snapshots to see improvements between builds Works on Visual Studio Enterprise 2017 on a PC or Visual Studio for Mac Version must be kept in sync with VS Alternatives: Instruments for iOS DI Memory Reporter Service (like the one in Bingo Buzz) Use Diagnostic Tools in VS for UWP (if you must)“The point of "New is Glue" is notto say that "new is bad", butrather to raise awareness. Youshould think about the fact thatyou're tightly coupling the currentfunction or class to a particularimplementation when you use thenew keyword. In many cases,after briefly considering this, you'llconclude that you're fine with thecoupling and continue on. But insome cases you may realize thatyou're about to add tightcoupling to an implementation,and the current code isn't whereyou want to make that decision. ”@ardalis

App is loading User entering Welcome page Game board Welcome page Statistics page Welcome page Game board Welcome pageAllocations on only live objects!

Plugins & ComponentsBe Careful with Plugins in Enterprise Applications! Required dependencies? Is the Nuget in Preview? (exception MSAL) When was the last time this plugin was updated on Git? Do I know anything about the author? What are the git issue history related to the plugin? Does it make more sense to learn from the open source code and bake only thefunctionality I need into my project? 3rd Party Components - Syncfusion, Telerik, Mr Gestures, Infragistics, etc. Major Exceptions James Montemagno’s Xamarin.Essentials will probably always work Xamarin.Android Support libraries – don’t update until you are absolutely forced

directory-b2c/Azure Active Directory B2CAzure Active Directory Business to ConsumerSame system that handles Office 365 – high availability and secure.Free up to 50,000 users. Can use Facebook, make a local account, etc.Great documentation. You can customize the UI. If you don’t want to use itfor production, it works well for Dev and QA.

CLIENT LIBS: MSAL & directory/develop/active-directory-v2-libraries MSAL – Azure AD v2.0: MicroSoft Authentication Library technically in “production-ready preview” Supports industry-standard OAuth 2.0 Supports OpenID Connect 1.0 protocols ADAL – Azure AD v1.0: Azure Active Directory Authentication Libraries Older libraries

App Center is Great Build – Works great for iOS and Android, no so much for UWP Test – Xamarin Test Cloud Awesome Distribute – Great for QA and Enterprise Distributions Diagnostics – Crashes and errors with stack traces Analytics – Events and real time log flow – you can pipe these into AzureApplication Insights and then on to Power BI Push Notifications – To a group or an individual (via InstallationId), very easyto set up, silent (ios only) and non-silent (ios and droid), toast notifications inUWP – huge improvement over doing this for each platform.

Application Insights Everything is recorded as a Custom Event inApplication Insights Need to export if you want to save more than60 days of analytics data Application Insights can dump into Power BIeasilyunion customEvents where timestamp ime("2018-10-14T00:00:00.000Z")) summarize Sessions dcount(session Id) by bin(timestamp, 1h) order by timestamp asc render barchart

Enterprise Deployments

App Stores iTunes: Requires a real person reviews the app Expect to be rejected the first time for something minor You will need to create a production user and include credentials with app submission, this can sometimes be tricky whenpromoting code into prod and waiting for the store to review your app Hard to nail down exactly when the app will be ready for release – allow 4-5 days to be safe. Minor resubmissions can usually bedone in 24-36 hours during the week. Allow another 12 hours to be fully indexed in the iTunes store search Expect that your app size will DOUBLE once the build hits the store! Expect that you will not be able to modify app metadata without a store resubmission 100 a year, D&B number required for companiesGoogle Play: Digital review, takes about 5 minutes, no human required Has really cool built-in tools for submitting potential release candidates so you can test in parallel Lots of tools for sifting through the thousands of android devices and deciding which ones your app should be available on Easy to modify the metadata for your app 25 one time paymentWindows Store App in the Windows store that you run against your release build that catches problems

Where to read more