Nuget and .NET Standard

I just pushed out my first production ready library, RandomSelection, to NuGet.  I’ve been meaning to publish it for over a year but never got around to it.  I honestly thought the process was going to be more involved but it was pretty simple.  The library was original written in .NET 4.X but before I published it I wanted to move it over to .NET Standard.  The motivation was to enable its use across a wider range of projects.  To make the change I followed three steps.

First, created a new project in Visual Studio 2019 targeting the .NET Standard Library project template.

Second, copied over the classes and project structure from the original project over to the new one.

Third, updated my tests since the library I was using had made a change that impacted my code.  Also made small updates to the way I was throwing exceptions so that the message received by the caller would be clear.

That was it.  Then to build the NuGet package I used the VS 2019 project properties view to set the parameter values used by NuGet.  For a detailed set of instructions to follow take a look at Microsoft’s Create and publish a package using Visual Studio.  No need to create your own nuspec file or sign it.  Give it a shot.  It was amazingly easy.

Regex String Replace Rescue

I ran into an issue recently where I needed to fix two fields in a SQL statement.  Wasn’t a big deal except there were over 8,000 SQL statements requiring the change.  Would have loved to do a simple Replace String in Notepad++ but each value was unique.  The job that needed to be done was change a value from a string with single quotes around it to be a decimal number.  Simple enough, a value like ‘12.34’ needs to be come 12.34 for the SQL statement to be valid.

Anytime I working with random text files I tend to work in Notepad++.  I like the user experience it presents, it is light-weight, and fast.  Within the application you can perform the standard search and replace or you can use regular expressions to search the file.  I knew my search would have to involve regular expressions but what I wasn’t sure was whether I could replace the text with the cleaned version of itself.  To my surprise, and due to regex ignorance, this was 100% possible.  By taking advantage of a feature called Capture Groups a user can specify a search pattern as well as the specific part of the pattern you want to keep.  Then, for the replace value in the search and replace window you set the replacement value as \1 which represents the first, and in my case only, capture group.

Notepad++ Regular expression string replace

What this all came down to was using the regular expression ‘(d\d\.d\d\)’ created a search term that looked for a two digit number with a decimal and two more digits after the decimal surrounded by single quotes.  The digits and decimal will be saved as part of capture group one.  Now I know there were probably much better ways to create a regex search term but this worked so I went with it.  Thank you to StackOverflow for getting me squared away with this problem.

Developer Podcasts

Back in 2013 I changed from developing embedded systems in Linux with Java and C++ to developing enterprise applications on Microsoft Windows in .NET.  The new development stack turned me into a fish out of water looking for some direction.  I had 30 to 40 minute commute to work so I looked to fill it with podcasts that could give that direction.  Over the the last few years I’ve narrowed them down to a half dozen that I subscribe to and recommend to other developers.

 

One thing I can’t recommend enough is to explore areas outside of your core area of interest.  Broaden your knowledge with podcasts like American History which go out and have a different lecture from across American universities each week.

Don’t forget to remove the end forward slash when enabling CORS

You ever run into an issue with your code, spend way to long looking at it and not get anywhere?  Especially one that you’ve solved before but having a lapse in memory.  That was me all too recently.  I was setting up an app that consisted of three projects in a solution.  One project for the API, one for the DTO, and another for the MVC.  The problem with this setup is that any Javascript call from the MVC project to the API will be blocked when the data comes back due to the browser enforcing same-origin policy.  Microsoft has a great write-up on how to Enable CORS within an ASP.NET Web API 2 project.  For your own sanity please make sure you go the whole through section.  I mean, the whole thing, all the way to the end, because at the end of the section is a rather important fact.  When you are defining the EnableCors attribute on the API controller you need to make sure that the forward slash at the end of the origins parameter is removed.

Good: [EnableCors(origins: "http://localhost:49332", headers:"*", methods:"*")]

Bad: [EnableCors(origins: "http://localhost:49332/", headers:"*", methods:"*")]

That is it.  That single forward slash tripped me up.  The error written to the web DevTools console was
Access to XMLHttpRequest at 'http://localhost:49342/api/users/name/smith/' from origin 'http://localhost:49332' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Hope this helps you waste a little less time.

Generating Entity Framework classes for Database First project

Not all projects, or development teams, use Code First with Entity Framework for building and maintaining their database.  There are plenty of reasons for doing it either way but that discussion is outside of the scope of this post.  What this post is going to focus on is generating your EF classes in a Database First environment.

Microsoft has plenty of great documentation for developers and one such post that I used recently was Getting Started with EF Core on ASP.NET Core with an Existing Database.  My setup is Visual Studio 2017 Community Edition and a .NET Core 2.1 project structure.  The database is running on a free, local instance of SQL Server 2017 and consists of a handful of tables.  To generate the classes I utilized the Package Manager Console (PMC) in Visual Studio and the Scaffold-DbContext command.

Scaffold-DbContext "Data Source=localhost\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=True;" Microsoft.EntityFrameworkCore.SqlServer -outputDir Repository -Verbose

The connection string is pretty basic.  I’m telling it to connect to a database on my machine called MyDatabase and use my Windows Credentials for authentication.  The files generated should go into the directory called Repository in my project.  And for help with debugging any problems I include the -Verbose parameter.

Upon completion all generated files were open in my VS instance for inspection and located in the folder I set as the output destination.  If this didn’t happend and you have an error message make sure that your project builds on its own.  If the project doesn’t build then the Scaffold-DbContext won’t be able to generate the files.  One thing to check before you submit your code to any repository is that in your Context.cs class the connection string used for Scaffold-DbContext is hard-coded into the file.  If the code is going to a public repository you’ll want to make sure this line is removed.

Using AdMobFree plugin with Ionic 3

Recently I updated one of my applications to use the Cordova Plugin AdMobFree to show advertisements in my Ionic app to generate revenue. There are several plugins available to Ionic developers to use for showing ads from AdMob but this one provided the core features I needed without a bunch of bells and whistles I didn’t. This post will go over the steps I took in order to get the plugin to work in my project. If you run into any issues let me know and I’ll see if I missed a step.

To start, let me be clear that this is geared to projects developed utilizing the Ionic 3 framework. It should work for Ionic 2 applications as well but I would not base an Ionic 4 application off of this code given all the changes that have been made for that framework.

Installation

$ ionic cordova plugin add cordova-plugin-admob-free --save --variable ADMOB_APP_ID="<YOUR_ADMOB_APP_ID_AS_FOUND_IN_ADMOB>"
$npm install --save @ionic-native/admob-free@4

Make sure you include your APP ID from AdMob. You can get the value by going to AdMob then clicking on the application under Apps and going to App Settings.

In your config.xml file you should see a section for cordova-plugin-admob-free that has the ADMOB_APP_ID variable defined with the value you passed in during the installation. If not then run the remove command for the plugin and try adding it again.  

One thing worth remembering is that if you run into build issues where errors are reported about the Android version or support libraries used then you’ll want to install the Cordova Android Support Gradle Release npm package.  

When it comes to installing your Android platform I recommend installing version 6.3.0. 

$ ionic cordova platform add android@6.3.0

With that you should have all of the packages and configuration completed.  It is now time to dive into the code.

Code

The first changes to your code have to be made in the app.modules.ts file.  You’ll need to import the plugin and add it to the providers section.

import { AdMobFree, AdMobFreeBannerConfig } from '@ionic-native/admob-free';

@NgModule({
declarations: [...],
imports: [...],
bootstrap: [...],
entryComponents: [...],
providers: [...
AdMobFree,
....]
})

On the page you want to show the ads you’ll only need to make changes to the underlying TypeScript file.  You’ll first want to import the necessary packages.

import { AdMobFree, AdMobFreeBannerConfig } from '@ionic-native/admob-free';
In the constructor include the AdMobFree declaration.  
 
constructor(...,
    private admob:  AdMobFree) {}
 
private createBanner() {
let logger:LoggingProvider=this.logProvider;

try {
let bannerConfig:any= {
id: <android banner id>,
autoShow: true,
isTesting: true
};

this.admob.banner.config(bannerConfig);
this.admob.banner.prepare()
.then(() => {
//We have a banner :)
}).catch((error) => {
// Handle the error case
});
});
}
catch (exception) {
// Something bad happened
}
}

And that is it.  You should have a basic banner displaying on the application.  Once you are ready to go to production you’ll want to change the isTesting parameter to false so real advertisements come through.

If you want to give the option for your users to go advertisement free there is an easy method call to remove the banner.

this.admob.banner.remove(); 

When I get some time I’ll try to put up an example project or put in a pull request for a demo on the AdMobFree repo.  Until then, let me know if I missed anything and I’ll update the instructions.

Divide by Zero

You know what might ease tensions? If everyone took a break from political shows, web sites, radio, and news for a while. Take the soap opera drama that passes as news and just detox for a good few days, weeks, months, or years. Maybe the superficial hate will dissappear. Maybe the imaginary lines that have been drawn will fade away. Because if not this constant division will get to the point where you can’t divide society any further. That is when you divide by zero and everything falls apart.

A Break from Facebook

This past June I took some time off from Facebook.  The site was consuming too much time and always made me feel a bit empty after using it.  So, from June through most of August I was Facebook free.  I’d say it was nice but it wasn’t…the time off was GREAT!

I have no idea how much time I was able to get back but it had to be several hours a week.  And I honestly felt happier than before.  Now I will admit that I have Instagram and when I suspended my Facebook account I started spending a bit more time there, which is also owned by Facebook, but the draw to be on the app was far less.  Instead of checking multiple times a day I’d check once or twice every few days.  And when I was on Instagram the amount of time didn’t even compare to Facebook since I was only browsing photos of friends or organizations I followed and the numbers I follow are far less than the “Friends” I have on Facebook.

But, like so many other good things, the break came to an end.  The choice to reactivate the account was actually uncomfortable because I was afraid I’d go back to wasting time on the site.  The reason for re-activating was simple, my coworkers all message, trade and sell things, and setup work events through Facebook so if I wanted to be apart of the group I’d have to rejoin the social network.  I’m hoping that this will only be a temporary affair or that I’ll use the site sparingly now that I know how nice it is without it.  I hope…but if the hope doesn’t pan out then I may just need to suspend the account again.

Give it a try.  Try suspending your account for a few days, weeks, or months.  See what life is like without it.  You can still use the Messenger app with your account suspended.  And if you have any apps or sites that you login with your Facebook account you can do a “Forgot my password” option and just provide the email address you use for Facebook to get a temporary password.  Go ahead, see what life is like outside the blue of Facebook.

ion-toggle Toggle/Change event handling

I’m working on an Ionic v2+ app that requires some extra logic to be executed when a toggle switch, also known as a radio button, is changed.  In Ionic this component is called an ion-toggle.  I tried using the normal Angular.io decorators like (change) or (click) but none of them were firing.  What I didn’t realize, mainly because I didn’t see it in the Ionic documents was that in order to handle changes in the state I needed to use the (ionChange) decorator on the component.  With this I could pass in more details to the function being executed.

<ion-toggle id="toggle{{parent.name}}{{child.name}}"
     [(ngModel)]="child.selected"
     (ionChange)="onChildSelection(parent.name, child.name, child.selected)">
</ion-toggle>
 In the above example the id of the component is being set to include the name of the parent and child.  The state is based on the child.selected state which in this case is a boolean value.

Philadelphia Region Tech Employers

One of the hard things when looking for a job is getting a good listing of companies that hire in your field. Over the years I’ve kept track of companies that have posted jobs related to software development or developer operations in the Philadelphia, Pennsylvania region. There are a few that are more north in the Lehigh Valley region but I didn’t take them out as they are all within commuting distance. Hopefully this helps out fellow technologists find the next step in their careers in southeast Pennsylvania.

Last updated 01 July 2019

– 3Gtms https://www.3gtms.com/
– Accolade, Inc https://www.accolade.com
– Acurian https://www.acurian.com/
– Alion Science and Technology http://alionscience.com/
– Allied Wire & Cable http://www.awcwire.com/
– Almac https://www.almacgroup.com/
– Alphapoint https://alphapoint.com/
– Amdocs https://www.amdocs.com/
– AmerisourceBergen https://www.amerisourcebergen.com/abcnew/
– Arrowroot Capital https://www.arrowrootcapital.com/
– AWeber https://www.aweber.com/
– Azavea https://www.azavea.com/
– Bainbridge Health https://www.bainbridgehealth.com/
– Benefits Data Trust http://www.bdtrust.org/
– Bentley Systems https://www.bentley.com/
– Betterment https://www.betterment.com/
– Blackfynn http://www.blackfynn.com/
– Blackrock https://www.blackrock.com/
– Blue Cadet http://www.bluecadet.com/
– Boeing http://www.boeing.com/
– Bolt On Technology http://boltontechnology.com/
– Brio Solutions http://www.briosolutions.com/
– Brooks Instruments https://www.brooksinstrument.com/
– BULOGICs http://bulogics.com/
– Cadent http://www.cadent.tv/
– CardConnect https://cardconnect.com/
– CDM Smith https://cdmsmith.com/
– Cerner https://www.cerner.com/
– Chariot Solutions http://chariotsolutions.com/
– CHI Systems http://www.chisystems.com/
– Cloudreach https://www.cloudreach.com/
– Cobham plc https://www.cobham.com/
– Comcast http://corporate.comcast.com/
– Converge Consulting http://convergeconsulting.org/
– CreativeMMS http://creativemms.com/
– Creedence Solutions Inc http://credence-llc.com/
– Curalate https://www.curalate.com/
– Dell http://www.dell.com/en-us/home/
– Dick’s Sporting Goods https://www.dickssportinggoods.com/
– Dorman Products https://www.dormanproducts.com/
– Drama Fever https://www.dramafever.com/
– Drexel University Libraries https://www.library.drexel.edu/
– Elsevier https://www.elsevier.com/
– ECRI https://www.ecri.org/
– Elsevier https://www.elsevier.com/
– eMoney Advisor http://emoneyadvisor.com/
– EmployVision https://employvision.com/
– empowr http://www.empowr.com/
– EPAM Systems https://www.epam.com/
– Equisoft https://www.equisoft.com/
– Evantage Technologies Inc http://evantagetechnologies.com/
– Evolve IP https://www.evolveip.net/
– FBI https://www.fbi.gov
– Express Scripts https://express-scripts.com/index.html
– Freedom Pay http://corporate.freedompay.com/
– Frontage Laboratories http://www.frontagelab.com/
– GlaxoSmithKline https://www.gsk.com/
– goPuff https://gopuff.com/
– Greystones Group https://www.greystonesgroup.com/
– Grubhub https://www.grubhub.com/
– Guru https://www.getguru.com/
– HealthJump http://www.healthjump.com/
– Healthverity http://healthverity.com/
– HomeNet Auto https://www.homenetauto.com/
– Honeywell https://www.honeywellprocess.com
– I-CAT https://www.i-cat.com/
– ICON plc https://www.iconplc.com/
– Inspire http://www.inspire.com/
– Integrity Applications Incorporated https://www.integrity-apps.com/
– Interactive Mechanics http://interactivemechanics.com/
– Invata Intralogistics http://www.invata.com/
– IQVIA https://www.iqvia.com/
– JOOR Engineering https://www.jooraccess.com/
– Kenexa (IBM) https://www.ibm.com/software/smarterworkforce/
– Kepler Group http://www.keplergrp.com/
– KL Discovery https://www.kldiscovery.com/
– Kulicke & Soffa https://www.kns.com/
– LifeShield http://www.lifeshield.com/
– Linode https://www.linode.com/
– Lockheed Martin http://www.lockheedmartin.com/
– Lutron http://www.lutron.com/
– McKesson https://www.mckesson.com/
– McNeil Consumer Healthcare https://www.jnj.com
– MeetMe http://www.meetme.com/
– Merck http://merck.com/
– Microsoft http://www.microsoft.com/en-us
– Mikros Systems https://www.mikrossystems.com/
– Miles Technologies https://www.milestechnologies.com/
– MMIT https://www.mmitnetwork.com/
– Molecular Devices http://www.moleculardevices.com
– Monetate http://www.monetate.com/
– Moven https://www.moven.com/
– Music Choice http://musicchoice.com/
– Nartal Systems http://nartal.com/
– National Board of Medical Examiners https://www.nbme.org/
– NCC Automated Systems http://www.nccas.com/
– Neat https://www.neat.com/
– Northrop Grumman http://www.northropgrumman.com/
– NuCitrus Technologies https://www.nucitrus.com/
– Oracle https://www.oracle.com/index.html
– ORS Partners https://www.orspartners.com/
– Pariveda https://www.parivedasolutions.com/
– Penn Mutual https://www.pennmutual.com/
– PerPay http://www.perpay.com
– Philadelphia Housing Authority https://www.pha.phila.gov/
– Philadelphia Media Network https://www.philly.com/
– Pinnacle 21 https://www.pinnacle21.com/
– PMA Companies https://www.pmacompanies.com/
– Practice https://www.practice.xyz/
– PracticeFusion http://www.practicefusion.com/
– Proconex https://www.proconexdirect.com/
– Promptworks https://www.promptworks.com/
– PTC https://www.ptc.com/
– Pure Storage https://www.purestorage.com/
– Push10 https://www.push10.com/
– QuantaVerse http://www.quantaverse.net/
– QVC https://www.qvc.com/
– Red Tettemer https://rtop.com/
– RELX Group https://www.relx.com/
– RevZilla https://www.revzilla.com/
– Ring (Amazon) https://ring.com/
– RJMetrics https://rjmetrics.com/
– ROAR for good http://www.roarforgood.com/
– RS Energy Group https://www.rseg.com/
– s2s Communications http://www.s2scommunications.com/
– Sabre Systems http://www.sabresystems.com/
– Sapient https://sapient.indistries
– Sapling Inc https://sapling-inc.com/
– Sapvix http://www.sapvix.com/home.php?pageid=home
– SAS https://www.sas.com/
Scientific Search https://scientificsearch.com/
– SEI Investment Company http://www.seic.com/enUS/index.htm
– ShareTracker https://www.sharetracker.net/
– Sidecar https://www.side.cr/
– Siemens https://www.siemens.com/us/en/home.html
– Skyhook https://www.skyhook.com/
– smithwise http://smithwise.com/
– Stratus EMS https://stratisems.com/
– SRI https://www.sri.com/
– Subaru of America https://www.subaru.com/
– Susquehanna International Group http://www.sig.com/
– Syapse https://www.syapse.com/
– Syncro Medical http://www.syncro.com/
– Tabula Rasa HealthCare https://www.tabularasahealthcare.com/
– TechField https://www.techfield.com/
– Temenos https://www.temenos.com/en/
– The Meet Group https://www.themeetgroup.com/
– Therapy Notes https://www.therapynotes.com/
– Think Company https://www.thinkcompany.com/
– Tonic Design Co. https://www.tonicdesign.com/
– trizic https://www.trizic.com/
– Turn5 https://www.turn5.com/
– Tyndale USA http://tyndaleusa.com/
– Unisys http://www.unisys.com/
– Universal Health Services http://www.uhsinc.com/
– UPenn School of Medicine http://www.med.upenn.edu/
– URBN http://www.urbn.com/
– USLI https://www.usli.com/
– Vandegrift http://www.vandegriftinc.com/
– Vanguard http://www.vanguard.com/
– Vertex https://www.vertexinc.com/our-company
– VertMarkets https://www.vertmarkets.com/
– Vistar Media http://www.vistarmedia.com/
– Vitaver & Associates http://www.vitaver.com/
– West Pharmaceutical Services https://www.westpharma.com/
– Weather Trends International http://www.weathertrends360.com/
– Weblinc https://www.weblinc.com/
– We Buy Any Car https://www.webuyanycar.com/
– Wildbit https://wildbit.com/
– WipFli https://www.wipfli.com/
– Wirecard https://www.wirecard.us/
– YPrime https://www.yprime.com/

If you have any questions or suggestions leave a comment below.