Showing posts with label we're. Show all posts
Showing posts with label we're. Show all posts

Wednesday, 23 October 2024

Bring VS Code Themes to Visual Studio

hi everyone today we're going to be talking about how you can convert a vs code theme to work in visual studio we've been on a journey to make visual studio as flexible as possible so that you can code the way you want and now if you're a theme author you can convert your theme to work in visual studio so that a wider audience can get access to your theme let's get started here are the things you'll need in order to convert your theme i'll note that you'll want visual studio 2022 preview 4 or later because it has fallback colors which you'll want just in case the json doesn't cover that area of the ui let's navigate to visual studio to configure our install i have the.net desktop development workload i also have the visual studio extension development workload in components i have net 5 runtime now i'm ready to go i'm going to be converting the winter is coming theme today i've gone ahead and applied it to my visual studio code instance on my keyboard i'm going to press ctrl shift p to bring up the command palette i'm going to select generate color scheme from current settings this is going to give me all the tokens inside this theme that describe the colors i'm going to save this in a folder that i previously created it's going to be a json file not a json c file next i'm going to navigate to our converter tool this is a free open source converter tool and if there's anything you'd like to see improved you're welcome to create a pr or create an issue i'm going to go ahead and clone this tool i'll navigate over to my command line opened in admin mode i'm going to clone using the git clone command after i clone this tool i'm going to navigate over to the folder that i've just created then i'm going to build the tool using.net build next i'm going to navigate into this folder i can run the tool using this command with the flag dash h this is going to give me instructions on how to use the tool i'm going to go ahead and convert my theme the flag dash i is the folder that i've created which contains my json file i can convert several themes at once by including several json files inside this folder the flag dash t is the target visual studio which will open and patch my theme so that i can take a look at it i also have the option of just creating the package def file without opening visual studio after it's loaded i'm going to navigate to tools theme and select my theme it's going to get applied there you are winter is coming next i can package my theme up inside a v6 in order to upload to the marketplace or share with friends i can navigate to file new project or ctrl shift n next i'm going to search for v6 and create an empty v6 project i'm going to name my project and then select create then i'll navigate to properties right click add existing item i'm going to select the package def file that i've just created this is going to be in the same output folder as my json file i'm going to select all files in order to see my package def file once i've selected that it's going to show up in the tree i'm going to select the package chef file and expand the project properties window for copy to output directory i will select copy always and for include in v6 i will select true then i'm going to navigate to the v6 manifest i'll navigate to assets and new then for type i'm going to select microsoft visual dot for source i'll select file on file system and then for path again i'm going to select the package stuff file that i've created and i'll select ok finally i can adjust the metadata inside my theme like my theme name author and version now the last step is to build it i'm going to go ahead and build the extension you can see it's working after i've built the theme i'll see a v6 file inside my output folder i can now upload this theme to the marketplace where there are a lot of other great themes already available and there you are winter is coming on the marketplace if you try the converted tool or if you try any converted themes we'd love to know what you think this process is always iterative always changing and we're always looking to improve thanks everyone

Monday, 21 October 2024

Application Insights The Tool You Never Knew You Needed

so we're gonna be talk about application insights today my name is Isaac Levin I'm an application development manager at Microsoft and what I do for my job is I work with customers so I work with customers to better the developer experience so one of the things that I like to talk about with my customers is how we can do better as it pertains to getting data from our applications to help us fix issues iterate faster and bring value to our customers so I have a website it's listed and I also have a Twitter and github if you'd like to follow me there I would greatly appreciate it so I'm gonna say this word a lot over the course of this talk so the word telemetry so what is the definition of the word telemetry so the Wikipedia / Webster you know definition is telemetry is a collection of measurements or other data at remote or inaccessible points and their automatic transmission to receiving equipment from monitoring that is a very long definition but how Isum s it for applications is all the data that our application creates that's not immediately related to things that the user sees on the screen so we know what we say that what kind of questions do we consider when we can think about telemetry and how we can do better by our customers I'm not gonna drain these obviously but you know one of the things that I like to see from a customer's perspective is how we can report on how our application functions and some of this data to provide insights that are going to better the business so you know we're here to talk about app insight so maybe we should talk about what is app insights so app insights in its purest form it's a REST API so it's a REST API that's hosted in Azure that allows you to collect telemetry related to your applications so it's a REST API and the data is stored behind the scenes in a no sequel data store so you send your JSON data from your application to the REST API it goes through a process to aggregate the data and make it available in that data store and obviously from a dotnet perspective since read Netcom you know is an existing SDK owned by Microsoft for application sites both for the web I believe that there's one for the desktop it's create was created by Orrin Novotny and for every other application that uses app that wants to use application sites there's either an SDK forward or you could create one yourself so when we talk about telemetry what kind of telemetry we were referring to so out-of-the-box application sites collects all of the telemetry that you see here so request response information third-party calls such as sequel or HTTP page views for browser-based applications and everything that you see here one thing to call out is wealth is really exciting about the release of dotnet core is that application insights now collects event counter data so for instance like garbage collection and more intricate performance data around dotnet core applications so that's available as of dotnet core 3 oh and one of the great things about application side since it's a no sequel solution you can basically use or pass any data that you like in tap insights and be able to report on it so you know think about you know domain data that you could use to be able to report on in some capacity I like to show this slide when I talk about application insights because it's really valuable think about what application is it at a holistic level way up top right so on the left hand side you have your web pages and your services and then all of your dependencies right web pages of client apps that would be like your static site or a front-end only app like a spa and web service obviously is any you know back-end type of service that's use and then dependencies or all the things I mentioned here mostly sequel and HTTP so all that data that gets sent into app insights and it gets massaged in a way that allows you to report on in a bunch of different capacities so you can build power bi reports or you can look at the data in Visual Studio and you also there's an arrest API that's available for application size they can you can get the raw data out and do with it whatever you like so the first thing you're probably thinking is okay this sounds interesting you know I imagine it costs a lot well what if I told you that the cost for applications that are actually in it scale are pretty pretty inexpensive right so you get five gigabytes per customer per month so what that means is that putting data into app insights and taking data out of app insight so you get five gigabytes of flattened jacent per month and if you need additional storage it's two dollars and thirty cents per gigabyte per month one thing to call out about the data retention as well is that application insights just recently changed the data retention so let's now configure a role in the portal so you have the ability to change how long you want that data to be stored for so we're moving on how do we actually get application insights turned on in our applications so for a.net developer you most more than likely the easiest way for us to do it is inside a visual studio you have other ways to do it especially if you're in the IT pro world you can install an extension on Azure app service or add your VM especially and if you have an application that's hosted on Prem you can still take you can still leverage application insights by using a status monitoring tool which instruments you know a nice application i as web server so when you configure it through Visual Studio all you have to do is right-click on your CS proj go to add add application insights telemetry it'll come up with a UI or wizard that looks like this right so it asks you to specify what your as your subscription is and what you want the resource to be but one thing to call out at the bottom is that you can just add the SDK to try local only so what that allows you to do is play around with that application insights and see if you actually are going to get the value out of it that you know is warranted by sliding it up in Azure so what that I'll do is it'll just add the SDK and the wiring for it and then in the situation where you do want to deploy to the cloud you would just kind of follow this you want this wizard again and create the resource inside of the azure portal so once you click register it goes through a couple of things that in the.net core world it's going to add some new get packages obviously and it's going to add a line to your startup so yes and we'll see what that looks like in a second but when you're all done it's going to give you a No percent and three green bars meaning that you're ready to go so I think this is a good time to actually show how easy it is to turn on application insights so what I'm going to do is I'm gonna go into my Windows terminal and what I'm going to do is I'm just going to create a new dotnet project so if I go dotnet new web app which is going to create a razor pages application I'm gonna call it no insights and then I'm going to specify the output folder as no insights so what that's going to do is that's going to scaffold out a razor page application and dotnet core 3 oh and I I should probably type a bit not as fast so Dada new web app note no insights so again this is gonna scaffold out razor page for us and what I'm gonna do is I'm going to hop in here and I'm going to open it up in visual studio and then I'm going to instrument app insights on this application so if I go inside here and you know one of the cool things I like using it the visual studio terminal I'm not a visual studio command line or PowerShell is I can actually just point it dev NV which is the executable that runs Visual Studio at my CS proj so I don't have to then hop out of my command line and go into Windows Explorer to find that particular file so what this is going to do is it's gonna load up Visual Studio for me and visually is not responding but it's it's back now so as you can see here this is just a really really basic application if I go into my dependencies there's nothing really fancy in here so there's some analyzers and some frameworks and we'll wait for this to be restored and available in Visual Studio and if you look inside of my startup all I do is all in my configure services I just had razor pages and then some static files right so once I actually want to light up application insights I just right click on it right click on the CS proj well maybe right-clicks not gonna work right now but if you right-click on the CS progeny you go down to ad and then you can actually specify ad application insights and then go through the process of setting up that wizard so it seems like Visual Studio is hanging so one of the things that I can do is I have a similar version of this talk actually available on YouTube that you can take a look at as well for whatever reason Visual Studio is just having a hard time and I don't want to have everybody look at Visual Studio lagging or whatever so we're gonna just move on to kind of how we can consume our application data using application science so what do I do with this data so you know one of the things that we have the ability to do in a pin sites is take a look at some of the rich reporting that exists inside of the azure portal so it this dashboard that you see here this is a one button click from your app insights resource so once you click that button it'll generate a dashboard for you that's going to give you a lot of really valuable information so you also have the ability to see application map which is a holistic at a high level all the dependencies and services instances that you have for your application running you also have the ability to look at profile information so in the situation where you have a low performant call you can take a look and see line by line execution by execution what's taking all the time to run and you know that gives you a ton of insight into ok where can I clean up this application code flow to be a bit more performant one thing that's great as well about looking at a pin size data in the azure portal is you have the ability to create these visualizations using metric Explorer so these are you can build them either using kql instead of log analytics which is the querying language for application insights data or you can just do it in a WYSIWYG sort of fashion also since application insights it does do some things behind the scenes once you send the data into it the data that you see it does take you know it can take a couple of minutes to get in there but if you need to see what's going on your application in real time you have live metric stream which is over the wider viewing of the telemetry that's being passed into your app insights resource and obviously in the world of reporting you know we have the ability to export our application insights telemetry into power bi and do all sorts of things with it this is just a default user report that's built out for you when you connect application insights to it so you have the ability to see some demographic information like where the users are coming from as well as what operating systems that are using I was going to show pulling this up individuals pulling up applications I did in Visual Studio one of the things that you can do is while you're debugging locally you can actually see all of the data that's being passed into the app insights resource at runtime while you're collecting all this and be able to see some of the details and operations that are flying around and then finally you know I mentioned one of the things that there is a file a data retention the application size doesn't hold on to your data forever so if you do value having long term storage of your application telemetry you have the ability to use what's called continuous export which frankly what it does is it exports the data into an azure blob storage container and from there you're able to do whatever you like with it for as long as you like so I think now we've took we took a look at how you light up an application that's kind of like a dotnet new what I want to show is a more baked solution so I have an application here which is a angular 8 application that uses the dotnet core 3 Web API back-end so as you can see here this is just a tour of Heroes and some of the heroes here some of the folks that were familiar with in the.net comp so if I take a look here I can fly around them but one thing that I see is that whenever I do a search I get an exception and I don't know why however if I wanted to just look at this at application insights I can fly over to live metrics stream right here and what this will do is this will actually pull up the over the wire viewing of what's going on with my application and I can actually jump around here and you'll see some of the things on the left-hand side start to light up so you'll see that there's dependencies information going on there's incoming requests and there's I can see the CPU utilization for my app service and the community member but one thing is well that's really valuable is I can actually see sample Channel Emma tree over the wire so if I do a search here for Scott for a Miss type name and it'll show oh there's a request that returned to 500 and I can see that exception here if I drill into this exception it says that it's an argument out of range and if I scroll it gives me line numbers right so that's really really valuable so in taking a look at some of the ways that we can help triage issues in production you know that's really really valuable and what's the data is actually in app insights I can click investigate in application map and it'll show at a holistic level all the things that are going on right so I have one central instance it's hitting a sequel database I really have some availability tests that are checking the application if I drill on the sequel side here I can take a look and do an investigation of some of the performance for some of these calls so the average duration for my sequel calls is actually very good at seventy-seven point one but if it was milliseconds but if that was too slow I can have the ability to drill in and then look at sample data for these particular sequel calls so if I click on one of these end-to-end transactions I can actually see the sequel query that gets executed on my database behind the scenes so obviously this is just a select but if you had a more complex database database call it would be all in there and that's one of the really valuable things that you can do with app insights is you can see kind of the end to end transaction so let's take a look at a particular example here so if I go into this back into that app insight resource and if I look at my failures I can see all the failures that have happened over a particular x time slice so as you can see here I have two types of exceptions a file not found in argument out of range I saw earlier when I looked at a live stream that I was getting some argument out of range exceptions when I do a search and what I can do is I can click on the operations and then view one of these particular end-to-end transaction details and I'll tell me what's going on so if I minimize all of this it'll see that it made a call and then there's an exception before you know it will hit the database and click on that it gives me a bunch of information about the exception which i think is really valuable but if I scroll away to the bottom I got a call stack and you know since I'm doing a lot of this all these I'm using async to do a lot of this some of the sometimes the call stack can be confusing to read so if I click just my code it'll actually show the code right so line 53 and my hero service in line 31 in my heroes controller so it gives me the ability to get a ton of value for when I'm triaging application issues in production and finally one of the great things about application insights that you can take view of is you can look at all this data great in tools but sometimes people just want to see the data so if I click on view and logs I can take any of these things top exception types for instance and view them in log analytics directly so like I said earlier log analytics is the storing mechanism for all application size data as well as all as your monitor data which application insights is a part of so as you can see here it's gonna load up a query and then it's gonna show me that particular data let me just maximize this and scroll all the way over all right so as you can see here I have 139 argument out of range in 24 files that's really really valuable but let's say for instance the business comes to me for with a particular request and they say hey Isaac I really want to get a slice over the last day where our users are from and I could easily say okay well I know that all requests are stored and maybe I want to summarize that account of all the unique clients or countries by that client or country so right and then they say and I can run this and then it gives me a table in the last 24 hours so 23,000 folks from the United States but also looks like we have people from Brazil and the Netherlands and Singapore viewing our application and they say well this is a data table I really don't like that way rather prefer is that rather prefer a chart and then you provided in this chart and they say well this is a bar chart and I drill are stacked column I'd really don't that you know in the past when we've been building reports for customers this process of just building reports takes a long time but they say I want to donut and then one-click and you have a donut for them so just think of how quickly you were able to provide that request to your user and they say well I don't really want to go to this particular page to see this report and you say okay that's fine I can just export it to power bi or if you want to look at the data yourself I can export to CSV for you so again we're talking about adding tools to our tool belt that are gonna make things more successful one thing is well like like I mentioned earlier with especially with dotnet cores you can collect extra performance data so I want to show you what that looks like so if I look at just the performance counters table or collection I'm sorry it's gonna show me all sorts of information right so I have exceptions thrown per second I have private bytes and system run time but then as you see here I have information about garbage collection so in the situation where your application isn't handling memory very well you can take a look and see what are the GC count values in particular situations what the thread pool count is and this gives you the ability to get even deeper into why our application isn't performing the way you want so that's how some of them what quick ways that we can take a look at telemetry in our application to be more successful so moving on to the final part of this talk one of the things that I think the application has a ton of value in is per you know thick our triaging production issues so I showed some of the cool things that you can do there but there's additional tools that exist inside of app insights and visuals to do enterprise that gives you even more tools to be successful so how many times have we been in a situation where somebody comes to our desert says there's an issue in production I don't care what you're doing fix it now right so what are the first things that we think of that can cause production issues right so I think of the primary things is there's change to the environment there's some data that's causing issues with code and you have scaling issues but really anything else can cause issues in production and when we look to actually try to fix these things what are some of the things that we actually do we can copy some form of production data to a local environment to test you know in some situations that's just not scalable especially for large applications you know in some in other scenarios we have the ability to look at a production staging environment which maybe has more telemetry turned on or we can actually you know spin up an environment to actually look at things a bit better we can read logs if we really don't like our lives we can read IAS logs and DB logs and what-have-you and then you know at the end of the day sometimes it's just really really valuable to see what's going on live so a lot of people will do something like this right they'll attach a debugger to production and there's a ton of reasons as to why you don't want to do that the biggest one is that if anybody wants to use your site they can't anymore so I'm gonna say that's not a good idea right we don't want to be in a position where we're affecting the experience of our users to fix an issue right we want to be able to create an environment where we can outside of the scope of that production application get more information and one of the ways that you can do that is using snapshot debugger so snapshot debugger like I said it's a tool inside of Visual Studio Enterprise that allows you to connect to a point in time exception for your application that's lit up with a pin sites so that doesn't mean that it's only an add your only feature so you can have a VM hosted on Prem and still take advantage of snapshot debugger so let's snap shot debugger actually look like so you have the when you go in through the azure portal you have the ability to look at the call stack as well as some of the local variables that existed for a particular point in time of the exception and one of the things that's important to call out here is you can actually download that snapshot so what I want to do is I want to show you what that looks like because I think it's really really awesome so if I open up whoops clicked on the wrong thing so if I go to one of these failures right one of these failures we saw earlier I'm going to drill into that and when we reset our intent transaction details for an exception we can take a look and there's a little button here that says open debug snapshot so what I can do is I can click on that and what's going to do is it's going to initialize a gateway and it's actually going to start to process what's going on so what actually is snapshot debugger so snapshot debugger is a process that runs side by side with your application and what it's doing is it's basically collecting information while your application is running and then it's taking the PD B's that are deployed to your production server and it's massaging them into a way that you can take a look at the exception so as you can see here on the left hand side I have a call stack and I'm gonna click into right here so it looks like I did a search for Scott and it threw an argument out of range exception so that's really really valuable but maybe the exception is a bit more complex one of the things that I have the ability to do is I can actually download that snapshot if I click download snapshot it's gonna start to download a file so that download can take some time so what I did is I actually downloaded one herb from earlier today about 45 minutes ago when you open up that file which add I accession file you get this very interesting message I always that you know think it's kind of cute that you know we get a warning that you know we got something from us a source intercept source and that source just happened to be a sure in this case you open up this file in Visual Studio and what it's going to do is it's going to give you a mini dump summary and what that mini dump summary is is it's a collection of all the data related to this exception so as you can see there's modules here there's times when the exception occurred so the OS and the CLR version and I have this ability to click debug with managed only and what that's gonna do is it's going to load all the symbols that exist for this particular exception and it's going to actually spin up an experience similar to when you're breaking an application in production and one thing the call-out here is that the actual exception was thrown inside of throw Hobart CS which is part of system core Lib that might be not be valuable to a lot of folks but I have the ability to look at the call stack and I see my heroes there and I see an exception was thrown on line 53 of this particular class and was this exception actually doing so it looks like I pass in a name a string and then I make a query from a database and then I tried to get the the fourth item in that array what could possibly go wrong when you're trying to access the specific number of array that array might not have that particular instance so you get an argument out of range exception so this is obviously a silly example but I just want to show the thing that you have so you have the ability to use tooltip and as you can see the name is Bill if I take a look at the heroes I have tooltip here I also have watch an immediate window so I can actually pull up watch and type in name and it's a bill and then if obviously I can go into the immediate window as well and type in name and that's gonna give me bill so again really really simple scenario but it just shows you just the power of what snapshot debugger can do so we have about five minutes left so I want to take some time for questions so if you have you know if you want to take a look at some of the samples or additional documentation for this applet for this talk you know I'm using the URL list so shout out to Burke and sessile for putting that together I use it all the time so if you click on that particular URL or not click on it but if you go to that particular URL it's it'll take you it'll give you a handful of links so you know access to the github repository to see the tour of Heroes demo as well as some really valuable documentation on Doc's on Microsoft calm about snapshot debugger and application insights so we have about five minutes left like I said so let's take some questions perfect hey I say thank you so much Shane you got any questions we had a we had one question that came up sooner but looks like I got answered and I'll just let you speak to it real quick and the initial an't question was is it only for web apps I think we we kind of know the answer no it's not just for web apps but if you want to kind of expand on maybe some of the capabilities of the SDK that's out there for other types of apps other than web apps yeah so so one in particular so there is an SDK for WinForms so that that was built by the community and what that gives you is it gives you additional telemetry tracking for when you switch views in an in a win form right so that's one example you know there's is well one thing to call out is that even though we talked about dotnet a lot here any programming language can take advantage of a pin sites and there's SDKs that exist just for dotnet but for Java nodejs PHP and a lot of the SDKs are either owned by Microsoft or owned by major community members one good question that came up too is can I use a snapshot the bugger in docker yes you can so you have the ability to connect to I believe you it's and I believe that the AKS is in preview currently but you should be able to connect to docker applications even hosted in Linux school and I think your URL URL list that you had up there does that have some links to the docs about finding out more about snapshot and websites and all that it sure does okay and one last question I think we might have some time for here is how can i migrate normal logging to a pin size is it just a matter of using the SDK and things that are in the docs yeah so that so there's some documentation around that so if you're using like a pretty well-known library like an log or log Fernet or serial log so there are actually adapters that exist which will basically log all of the N log data into a pin sites as well so it's not a matter of you having to rewrite your login mechanism from scratch you can just append on to that by adding it into a pin sites and then obviously if you want to extend app insights you have the ability to do so with you know code and dotnet so you can write like track events and track exceptions and all that sort of thing to get all the telemetry you want I can add something to you know so I said I'm not sure if you know this but we're actually using a pin sites on the.net comp website so I would hope so cuz it's awesome yes it's awesome so we used it because for it tonight talk about might whoa originally was written dotnet and dotnet framework with nbc5 and so forth so we migrated it down at court - - and in case we wanted to figure out what's the performance are we missing anything so by using app insights we were able to figure out where we had missing files because we can actually see the 404 so we were doing we can look at our browser performance JavaScript performance so it was great for us to kind of fine-tune it and go as we like so it's a great tool especially for like migration or just to figure out what's going on your app and and really all we did is we deployed it to an azure app service when the left-hand side and said app insights emailed and that was it and the magic happened yeah exactly so then that's one of the great things about app in sites is that lighting it up is really easy so even if you don't have an application that's hosted in Azure it's pretty easy on Prem as well so there's a UI based instrumentation tool without code and there's also a PowerShell driven one as well so you don't need the code to actually turn on tap insights which is great yeah I know and that's some people in the chat I was as you were talking about while also bringing about Google Analytics sounds like you used Google Analytics app insights and like for us we're using both yeah why not yeah for us analytics is great to figure out how many people they're at where they're coming from and it's a nice quick little dashboard overview but it provides some information not all information that we care about how the act website is performing like we were able to see CPU a good example of this when the Kino started the CPU was getting hotter hotter and hotter and hotter we were 75 80 % CPU and a fairly large app service instance and we were able to get those details thanks to app insights yeah that's awesome sweet all right we're right on time so we're gonna get finished here so thank you so much I said we got syed here talking about vicious vicious to do for mac so we're gonna flip here a little bit and we'll be right back

Adding Images to Comments with Coderush

today on vs toolbox we're gonna do something we've never done in the history of coding before what's that we're gonna take Robert Greene and we're gonna shrink him down and inject him into the source code just like that take a look hi welcome to visual studio tool box I'm your host Robert Greene and joining me today is Mark Miller hey Mark hi Robert welcome back on the show oh thank you gosh it's been a while it has been but I'm so excited to be here we're excited to have you well thank you I explain to the audience who you are and then we'll dive in okay my name is Mark Miller I work for DevExpress I work on the ID tool teams at DevExpress and I've been developing IDE tools for about thirty thirty years well developer tools specifically an IDE tools for about 23 years all right one of which is code rush code rush is one of those today yeah and I asked you to come on the show and show us some cool stuff cuz it's been quite some time and you claimed that you were gonna show me something that was gonna not only knock my socks off but that is impossible to do well it appears impossible to do it is impossible I should say that I always blow the demo I blow the demo by setting expectations so incredibly high at the beginning that there's no way that we can achieve those but I'm super excited about what we're going to show today guys it is when you look at it when you see it working it is arguably impossible it looks impossible to build yet it's not and this is a feature of code rush inside visual studio inside visual studio and it is available it's available now as you watch this sweet so it's available now can't wait all right so on my machine right here I'm just gonna go out here I've got a couple links here I'm in some HTML right here and I've got a link here says I'm saying I'm so excited to be meeting with Robert Greene today of channel 9 now one of the things that we're we're doing here if you'll notice Robert Green is a little bolder and so is channel 9 we have the ability to kind of mark those comments to kind of enhance them and what I want to show you today is is a lot it's about enhancing the documentation of the code that we write ok right and so I've got that let me go over here I'm going to click on on this link right here so Robert I'm going to come up here I'm going to right click on your image and I'm going to choose copy image and I want to do something kind of really cruelly groundbreaking in history-making today I'm gonna make me handsome I'm gonna make you handsome and not only am I gonna make you handsome but we are good you are going to be the first human being ever to be injected into source code that's what we're going to do so I just copied your image right huh and now inside the comment I'm just going to come down here and I'm just gonna hit the paste key like that and now there you are in the code and I'm gonna right-click you and I'm gonna choose crop image and I'm going to just grab right up here drag it down to about right there let me click up that image again and I might resize it let's hold down the shift key so we keep our original aspect ratio and now I've got you right there in the code and now that I've got you there in in the code I can come up and let's just copy that URL to Twitter let's right-click you let's choose link and let's open a URL let's specify that and click OK and now when I come and click on you like that we jump right up and we go right up to the so you could put a screenshot of a mock-up of the UI or something put it in the docs yeah you put it in the code is what you can do in fact let me show you the code on the comments on that yeah I got it let me show you this is this app that we're running right that we run right now so this is an application that I built for my twitch channel okay okay and this is going to be a bot that's going to have a rocket in it that's going to be remotely controlled by our chat the people in chat room so they'll be able to launch they'll be able to launch the bot like this and then fly it around and collect coins for example or maybe they'll be able to drop meteors that'll go down and blow up while I'm coding live in visual studio in JavaScript or C sharp so it's a little bit crazy right but you were talking about you were talking about screenshots right and if you look at my engine right here my let's go back over but if you look at my engine right here you'll notice that in the upper lot that in the the bottom right right here that engine is not quite lined up right so let's just do exactly what you said let's take a screenshot like that okay let's go over to my rocket this is the class that does the does that particular work let's use the visual studio function to go find that draw function let's get out to the draw function let's put a comment right here and let's paste it in okay and let's come in here and let's crop the image like this whoops not quite where I wanted to crop it right there and right there and now let's come in and let's do something called pixel scale and pixel scale is going to zoom in on this and and keeping the pixels in place as you as you as you zoom in is as opposed to having a smooth kind of scale so you can see the individual pixels of each piece in here so we'll do a pixel scale on there and now we can just put the comment move the engine to the left a bit now here's what's cool about this right this is not a comment that's going to stay in the code for the lifetime of the application this is a comment to myself or to another developer later right but it's increased in its visual capacity to communicate right that's what's kind of super cool about this right now let's say you now check this into source code and somebody also happens to have code rush they would see that and if they didn't have code rush what would they see oh okay good question so what would they say if they didn't have code rush there's an option here to turn this off for example I can just turn this off like this I get essentially what looks like markdown right there in the comment right and so there's a reference to engi file that PNG file is part of the solution what's really cool about this in fact is watch this I can take this code and I can cut it copy it move it somewhere else I can take it with other even the method the whole function take the whole draw function right which is pretty big take that come down take it put it in a new place paste it right come back in here let's rien a belay Topa nning this up on a machine with code rush on it and the comment moves with it okay right I can take and move and copy so comments in fact even if I do undo right now images in source code work with undo and redo stack as well right so here on undoing through all those changes I made right and then I can also redo and go backwards as well sweet right copy on the clipboard undo redo plus let's say I do have a developer on my team right that I don't want to that doesn't have code Russian I want to I don't want to leave them out right I can just come here and say see put a little note to them that's a see image in solution or whatever I'm going to see there and then now if I hover over that I'll see that as well if I have code right and if I don't I can still see it and I can still use it and work with it all right so that is that's one of the things that you can do with comments is you can extend the documentation can I show you another example all right okay so now I'm going to go over jump over to plain 3d jjs it's a JavaScript file and I've got a function here called get line intersection this determines the intersection between a line and a flat plane right where is it and if I look at the code at first glance if I'm a new user or if I haven't worked on this function in a while and I come back in it's not immediately obvious how the code works right understanding this code is going to take some effort to figure it out right in part because it uses established formulas in part also because I've got a return null here I've got a return line here and I've got a return point here right there is this comment right here that says hey based on formulas found over here on Wikipedia so let's let's bring that up and oh this is what's going on here no intersection point or line is in the plane those are the three different possibilities so let's copy the image let's come over here to the source code let's come over here put a comment marker right there we're gonna come in here on parallel that's this one on the left so we're gonna crop the image we're just going to take this drag this over here like that and bring that up there a little bit and there's our parallel right take that copy that to the clipboard come down paste it in there let's paste it down one more time and we'll reason we will readjust each of these so here's this one the line I'm gonna go here and crop the image again bring it to the line that's when the line is contained in the plane entirely and let's come down here we're going to crop this image and let's it's the point it's the one right in the middle right so we have the ability to incredibly quick things so cool put images in code modify them as if they're first-class citizens right without hitting without an impacting compiled time editor performance or any other metric you might you know be concerned about and this works with all project types any version of the framework does what does it rely on other than Visual Studio 2017 in code right our understanding languages so right now we're supporting HTML CSS Visual Basic C sharp okay JavaScript typescript and F sharp okay so we're getting the big ones and other ones like Python and other other languages will likely add support for those because it's once what the engine the magic has the hard work is done right supporting a new language is generally not that hard because all we have to do is understand the comments sure I'll show you it can work cool things you can do absolutely you know to have a threshold for cool do you because if I don't want to I don't want to see the show all right excellent yeah excellent so see these Kannada limiters in the beginning I can get rid of those by just putting a back tick at the beginning of them like that and the comments still there but it just kind of cleans things up a little bit and I can also you know I can move this right just by putting spaces in it I can add things before I texted before or after it like that and and it works it also works with debugging too right so when you're stepping through code everything still works the only feature we haven't cracked yet is printing that's the only piece that we haven't cracked and and if there's a lot of enthusiasm for this as I as I think there might be we're likely to figure that out too okay and salt printing for you let me show you a couple other uses of it actually do you have I want to stop because I don't want to barrel all the way through do you have any questions or anything like that no this point okay any questions I have I will let you know okay let me show you another kind of cool thing that you can do I have this is my animation for the meters when we drop the meteors I'm and as you know if you know me I'm a little crazy I've got 63 frames of animation for this rotating medium that's what I do my explosions got something like 200 frames of animation those are all PNG files that do that exploding at the bottom right so I go a little crazy but one of the things that would be very cool to do in the meteor class that's right there I just opened this up in Visual Studio right I just double clicked on my asset out there I hit control a to select all control C to copy and now I'm gonna go into my meteor class and I'm just gonna up at the top here in this comment I'm just gonna paste and then now what I've done is in my meteor class I've got a picture of the class some visual representation it's a sign post right and what's really cool about this is when I'm flipping through files right I'm going from one file to another right and then all the sudden I land on it I immediately get that visual recognition I am I'm on board I with the file I know the file that much faster instead of having to look at the code and recognize right right because you're using a serial process which takes so much more time to recognize instead I instantly see it right so that's kind of a cool thing you can do you can also you can do things like this where I've got here look at this I've got a setting that's not default that which bots oo auth token and right next to it I've just embedded an image at the end of the line I've hidden the comment right so if we come over here and we look at this there's that little the back tick to hide the to hide the comment there's what it really looks like and what's going on let me right click this so you can see this if I right-click this and choose link when I click it it's going to execute a visual studio command project properties so I'm here in the code looking at one of my project properties right this setting it's out here I can click on this like this and it opens it up for me and now I can see it make changes write code code that connects with acid tools or control commands a visual studio in some way you can invoke those commands codes that are related you can get to those other places let me show you something else let me jump over here into Excel and I've got some shortcut here that I need to implement I haven't implemented them yet right right okay I'm just going to select that choose copy I'm gonna come back over here and that's gonna be my main that I need to do look hey there's more key bindings that I need to add right here that's this comment well let's just put that in while I'm working right so I've got the spreadsheet from Visual Studio write anything that's out there with regards to you know any application that copies and supports a copy is an image we can put it in here and even if it's a temporary thing like this is an example what just while I work right it's information in parallel instead of having to switch over to it now you know the spreadsheet come back I've got it right in the code I can work a little faster and it is an image it's not a live link back to bright red sheet right right right more cool you ready for more cool yes all right so you can see why it's a little bit excited about this right so here I'm in this formula over here called distance a point right here and there's a comment says hey it's based on this formula to calculate the shortest distance well the formula is given to me in latex which is essentially a structured way of representing formulas now you can go online right over here there's a link right here in the editor you can go online and type in your equation well you can use these buttons so I'll just paste in what we had there and you can see there it is there I'm gonna make it a little bit bigger so we can see it maybe even bigger than that very large like that there's the formula that's what was happening in the code right there I'm going to right click it copy it to the clipboard come back over here and I'm going to just kind of replace all of this with the formula just like that cool so I can put that formula right out there right one last thing let me switch over into I'm going to switch over into f-sharp now so I'm in F sharp now I'm not an F sharp guy yet I do not I'm not an expert I'm barely barely holding on okay you're learning it right but I do know math and I know mathematic symbols so when I'm in here looking at this code right here this code says it's based on the have her sign formula and if I were to just look at this I'd be like a little bit lost I'll go look it up but if I look at this I see oh I think I see what's happening here now I understand the f-sharp I am getting myself up to speed faster because somebody left a comment here that included the formula and also if I hover over there's a link and if I click on the link it takes me out to the Wikipedia page on it and I can just if I want to augment this I just would take this image for example right click it copy the image come back over here and let's put it right up right up above so we just put a comment here paste it in let's use that symbol to hide those hide the beginning let's Center it on the page okay like that and there we go and that's it very cool so that's it that's like that's like the high speed run through and I'm just like I'm like I would say well I could take go long or you go short you know depending on what we do but I think I have a feeling if I look at the clock it's gonna be like said we're under 20 talk to us a little bit about what it took to make this okay because you were telling me earlier that even that this has been something you've been working on for a very long time yeah I tried this in Visual Studio before there was net and I had only linking and embedding mm-hm where I drop them in but the problem was storage is the problem one of the biggest problems with this always is storage and we might want to take a look at behind the scenes how that magic is happening yeah but but the first what I was doing is I was just encoding the comments into essentially a base64 and putting these giant comments in the code the problem is is that you changed the compile times right you compile times grow as the file size grows right right it's not not a good idea the advantage is it's there and if I give it to you and you edit the file it's it stays in this position mm-hmm right I tried that and and and that's how far I got ultimately I got to a point where I was like you you cannot release it the upside of all of that though is that I could actually at the time in beared actual spreadsheets actual audio files any the object could go in right right now we're just scaling back to be only images now we're saying only images with this with this release and then I tried again when I was in when I was working on code rush for Delphi and and I I kind of got close again but again we ran into the storage problem so I was storing I think externally at the time I had you know a file it there but you run into problems when you're storing externally separate from the file right what happens if somebody like you know is also pasting in images for example that sort of thing how do you resolve all of that so there's never ever any collision right and then how do you have you open up a code file without having to download the external image or if it's stored loped or stored remotely how do you work offline there's all kinds of issues right there there are loads and loads of issues in solving this problem um in fact most of the most of what you've seen most of these examples are really showing you the UI solution to the UI part of the problem mm-hmm right how do we get it so it's it's it's so crazy easy to take it from one place and stick it somewhere else right how do we get it so what it feels like it's really there right I can take this and I can click on it with the mouse right and there it's selected right I can change the size just like I can anywhere else right and there it is there's the resize right there right let me go ahead and I'll restore the original image right there so we can get back to that right so how does it how do we get it to work with cut and copy and undo stack and reduce tack right all of those that's the UI part of the problem right the storage part is trickier but we have a really clever way and this was I was telling you this so we we basically I think about a year ago or half a year ago we were like let's try it again because we had the rich text comments right right up here to notice real time is Boulder right to emphasize it right so we've got that ability right up there we had that going and I was like let's give it another stab and one of my developers sent me essentially a prototype and and then the prototype the file name was curious to me and I'll show it to you right up here so if we look at this file name right up here we look inside this we have to go inside it and there it is there's the file name and I'm like what is this finally miss I didn't go in because we talked about using Goods and and there are even problems with using goods because if you copy an image and then you paste it into several files you're gonna now have multiple copies of that image stored out on disk and we don't want that either we want to have an efficient efficiently stored set of images out on disk in fact if I take if I take this image and right-click and copy it just like that let's go we'll go over here into PowerPoint and I'll just paste it in here I should be able to paste it in there it is right there but it looks like that had transparency so it came in black on there in the background but I think we're probably gonna see the same thing with transparency here but I'll right-click here copy that because that also has transparency Oh looks like that one's okay so maybe it doesn't either it doesn't have transparency or it could be an issue in the face but but the hold on I'm like totally I was so like distracted by that I'm like we're only back image name oh the image name right so if we were to take this like say we're going to take it from here and copy this to the clipboard and then come in and like say okay let's paste it either multiple times in the file or through multiple files in my project right so the first time I paste this in the image name is three two starts with 320 alright next time I paste it in right if we were using goods we would advance it but this is not the second time and it's a bitmap that's on the clipboard I'm not pasting text it's a bitmap right mm-hmm so what's going on here and he says oh I'm using a hash of the image and it was like oh and I started going through all the problems that we were having before with storage and I realized oh hash of the image really is nice because what happens now is when I when I paste that in right the I only get one file that's out there right the other thing that's cool about that is you you go out to that file and you modify it it updates everything and where is that file stored let's look at that so if we come in here and we go into the solution and we right-click and we say open file and file explorer like this we jump up over in here there's a folder inside the solution dot CR okay and inside there is a folder called images and if you take that and you can just upload those contents right there that's what you can do now we're seeing several DS because of what I was doing in the demo prior to this but but they're not all not all of these are used here we go back over to the other one I think you'll see something that looks a little bit cleaner because I cleaned them all out before I started today let's open that up and go to see our images and there are all the images right there and then you can just add these to source control and they go up with with the codes exactly and come down with the count as well yeah and I just it just reminded me of another thing that you can do if you have a code that's not so good like for example right here I've got a lot of hard-coded strings in here right I might be able to I think I have a template in here called scary do I know I don't well I can create one I do have one called nice I think right like that well that's not what I want I might want to have I have another one called P you like that this code stinks right like that and so you can put a message to your fellow developers right to get their attention and get the whole team's attention yeah as you're scrolling through the code right so you can put icons in there and what I just demonstrated there was a code rush template right I'm if I type in a slash nice I created a template that is just going to expand to the image right then it's already part of the project and put it in there very cool I may be the only time this emoji has shown up I'm gonna scroll that off screen so we don't get in trouble this is so awesome alright so to wrap up this is a feature of code rush it available now it is it as it is and people can we'll put a link to it in the show notes people can go check this out as well as figure it out look at all the other things that code Russia does horse I'll put outside just put in some of mine right there you can use it also for branding right I can't you stop right the beginning yeah yeah and it's if you go to DevExpress comm slash Holy Grail huh behind-the-scenes on how all of this is done you know there's nothing really proprietary about it at all we're just saying here's what we are here's what we're doing is what we're building this is the experience very very nice thank you Robert so much cool stuff hope you enjoyed that and we will see you next time on visual studio toolbox [Music]

A Gentle Intro to Azure Cosmos DB for the ASP NET and SQL Server Developer

hey everybody we're back at dotnet Comp 2019 I have a new co-host my earth how's it going good yeah I know thank you so much for joining us so as you probably noticed with the entire conference we've shifted co-host just because we're doing this 24 hours yes it's pretty tiring after a while so thank you for all of our current or future and current co-hosts for taking the time to do this in particular I would like to thank our speaker Santosh how's it going hey I'm doing good how are you we're doing great thank you so you're here to talk about cosmos DB for asp.net and C Co server developers take it away yeah let me share my screen are you anime there we go perfect alright are you guys able to see them all looks good alright perfect I'm gonna go ahead and get started before it hello and welcome to dotnet conf my name is Santosh and I will be talking about cosmos DB today in particular what I'll be focusing on is introducing cosmos DB to the asp.net and sequel server developer a little bit about myself before we get started I am a Microsoft MVP in Azure and I'm also a consultant at new signature so today what I want to do is I want to talk about cosmos DB which is as we'll see Microsoft's database as a service for a variety of models and my whole approach to this is based around the fact that as a consultant I go out into the field and talk to customers I often see that people who have been working for a long time in the asp.net sequel server world especially in the relational database world they have a little bit of difficulty transitioning over to a more schema agnostic well that cosmos DB brings so I will be talking about some of the aspects of cosmos DB that I have learned along the way that I think are important and also I was looking at the schedule and there there is a data modeling talk couple of talks after mine so I highly recommend that you are listen to that one also because it's kind of complementary to this one so with that I'll get started so what is cosmos DB cosmos DB is Microsoft Dodgers database as a service this is proprietary to Azure which means that if you go to AWS or any other provider you would not find cosmos DB on there so let's forget that right off of the bat it's a horizontally scalable database it is schema agnostic which means that it you can save data on a wide variety of schemas and it really it will allow you to do that it's a globally distributed database which you can looking at this map you can click on you know in different regions or for Microsoft all over the world and it'll automatically spin up a cosmos DB instance for you over there so it's a very easy to use to be globally it's a multi model database which means it has it accommodates four different types of data the sequel API and MongoDB and I'll be talking about this shortly or document or unit cassandra is a column-oriented database and then you have table API and gremlin which is a graph database you can elastically scale throughput and storage so technically there are hypothetically speaking there is no limit to the amount of throughput and storage that you can provision for a cosmos instance and you can do this across the world in different Azure regions with a click of a button cosmos DB is super fast like you know you probably heard about this by now it's like single-digit millisecond latency and we'll talk about all of that but the most important thing about cosmos DB is that unlike sequel server it's not you're not connecting over TCP or you could do that but it's a club a bunch of cloud-based REST API and these are encrypted address so you can connect to this as you would connect to any REST API so and a lot of the SDKs and everything else is built around that so let's keep that in mind as we move along let's talk about the multi modal aspects the sequel API is a document oriented database it stores data in JSON format which as you know is the most widely used format and it provides sequel like query capabilities and below is an example of the type of data it stores is similar to sequel in that it's a document oriented data I would say that the distinguishing factor is that is it suppose the MongoDB wire protocol which means that if you write your code geared towards MongoDB chances are chances are high that he can part it to the API at cosmos and it would just work so he can simply move from you know a hosted instance on Prem to the call to the azure cloud by simply pointing your connection string to cosmos our table API we have talked about assured we have heard about as your table storage previously our table API I call this as a premium version of as your table storage it's the provides exactly the same type of you can store exactly the same type of data with the same code except that you get much better throughput and you can leverage the global distribution of cosmos DB so seek you know with as your table storage we have you know read access zone redundancy and all of that we can easily scale or we can easily you enable global distribution by clicking on a map and I'm kind of moving fast because we're running you know we're running behind so bear with me gremlin API you know data as we know is in the real world is it cannot you know often we find it hard to describe in relational databases with gremlin API it's a graph database and it's super relation I call it super relational which means that he can easily spin up vertices which are the round entities and edges which are the relationships that are shown by their lines and you can spin this up real quick and attach them real quick which means that they're you can do multiple levels of nesting of relationships something relational databases find it hard to handle a cassandra idea is a column or in a database by grouping columns together you often lured entire set of columns and memory for super fast calculations great use cases for these is time series data talking of the different types different models use cases for these are usually found in industries like retail IOT and gaming this screen we are seeing right here is a great example of some use of cosmos because it uses the change feed which we'll be talking about later in the stock and you know it leverages micro-services with the change feed to handle different functions in the retail industry so cosmos DB can you can really power up your applications by using cosmos TV along the way through my talk I'll be talking about different developer tips and for this particular section I'll say that leverage here you have the appropriate data model based on the scenario so if you want relational somewhat super relational data you can use the graph API or you know if you want tabular data you can use the table API and finally you know these models are meant to complement each other and not replace each other so and talking speaking of that I want to give you a thought experiment so let's say if you are building your own linked end or I was building my own LinkedIn this is how I would do the MVP I would use the sequel API to do the profile pages and the posts and to do things to do research on people I may know I may use the gremlin API to list the graph or to log the visit so I may use the table API to run summary calculations on years of experience I may use Cassandra and finally for the sign up and building modules because I want them to be transactional I'm actually use sequel server so there's no bad answer what I'm saying is that you should use cosmos DB and complementary technology and appropriate scenarios hopefully if you can take something out of the dark let this be it but you know I have other great stuff in store for you and quick note this point forward I will not be talking about the other models I'll be sticking to the sequel server sequel API in cosmos speaking of the global distribution cosmos DB provides turnkey global distribution you can easily spin up replicas you can spin up replicas by clicking on the map so you can spin up different instances one region if you have your cosmos DB hosted in only one region you get four nines SLA which is 99.99 if you have greater than one region you get five nights which is obviously better and then you also want to talk about you know whether I want single region right or multi region rights and this may vary based on your scenario so if you have a red heavy application it's easy to ingest your data and then with a single region right so for instance your writer may be located on East us so you ingest in East US and then you distribute all over the world so that when someone in Australia tries to read the data it uses this feature called multihoming API is for cosmos DB and it connects to the nearest instance which is an Australia to read the data so that makes it super fast multi-region writes I would use this in a scenario like if you have clients all over the world trying to write data instead of sending someone from Australia to East us I would enable multi region right which means that they write to the Australian instance and it would sink up over time cosmos DB provides low latency for reads and writes and you can see that you know then single-digit milliseconds or customs deep provides five well-defined consistency models most databases that accompany does often provide like to which is strong and eventual but cosmos TV provides five I will say that strong is very similar to the acid compliant relational databases but it only works in one region so if you expand beyond one region you'd have to use one of the other for bonded stillness that you know your reads and writes are never out of order but the data lags by a certain interval or prefix now within this interval it's strongly consistent session session consistency provides strong consistency within a particular session that's connected to cosmos DB consistent prefix make sure that your reads are always in order with the writes but there's no strong consistency anywhere and eventually it means that your rights could be out of order with your rates through part this is one of the most important now we are getting to some of the important parts which impact performance throughput actually is measured in request units and it's a combination of memory plus CPU plus I ops and one request unit is the equivalent of reading a one kilobyte document I will say that writes obviously consume more than more throughput because of indexing and also depending on the consistency if you have strongly consistent was this somewhat eventual consistent it may consume different amount of our use the same write operation partitioning there are two types of partitioning logical and physical logical is controlled by the user by providing a partitioning key physical partitioning is because it's horizontally partition and store disks this is completely handled by the cosmos DB engine and transparent to the users the choice of partitioning key can make or break your data based performance which is why I will reiterate that you should attend the data modeling session after mine this is what a cosmos DB instance looks like we start with account choose create an account our account can have 0 or more databases and these databases have containers of data not to be confused with docker containers these containers can have different elements like stored procedures triggers user-defined functions and items items like the actual data not depending on the model of Cosmos like for instance if you are in sequel API you would call your container a collection and you would call your item a document so that's that's what this diagram represents obviously with your occur once you create your account you get an endpoint and connection Keys one quick another additional note on this there's readwrite keys and read-only keys so use these judiciously when you are designing a document like if you're doing a CQRS system you could reuse the readwrite keys on the right side and read-only keys on the reach side and the database the database is the unit under which container of containers of data is stored but you can provision throughput at the database level now if you have multiple containers under the database the throughput your provision here is the cap collections were with the collections in sequel or the containers that store the data you do not incur any charges until you create a collection so you can create as many databases as you want with no charge and at the collection level you can also provision you can cap an individual collection for a certain throughput otherwise it would vary based on what's the usage may vary based on what's provisioned at the database level and how many other collections so there are documents now these are the action this is the actual record example of a record that may be stored in a sequel API collection so for instance if you take JSON document that looks like the one on the left and store it you'll end up with one that looks like the one on the right and this is even though we say that our data ask schema agnostic cosmos DB adds some fields as you can see at the bottom the ID represents a unique name within a logical partition it can be system generated are user defined if the user doesn't provide an ID it will automatically generate one e tag is used for optimistic concurrency control which means that if there are multiple clients writing to the database this same record then it may use the e tag to resolve that concurrency issues ts is the timestamp and self is the actual URI for the item on the internet so how do I develop cosmos in Cosmos locally so and this is where you can you can go to you can google cosmos DB cosmos DB emulator and it's a simple Windows installer and it runs a service on your computer excuse me sorry so this loads Explorer this lots a emulator on a computer and you get the connection URI and the primary key for the emulator now the one thing to keep in mind is the local emulator stores multi models for instance you also see the MongoDB connection string and you see a data Explorer that will show you the data but unfortunately this data Explorer as I remember if I remember correctly is not available for Cassandra graph and table and that may change so the next thing I want to talk about is before we dive into code is the azure cosmos DBE dark net as decay since we're talking about you know dotnet code three this goes very well with that this is the latest instance of the sdk and it has some improvements on it and i'll be i'll dive into this shortly so definitely if you are using cosmos DB use the dotnet sdk v3 and with that i will jump into some code so I'll quickly show you the difference between dotnet core SDK version 2 and 3 so so for my dark net core SDK version 2 this is an example for the.net Korres decay version 2 so generally what you do is you instantiate client that with the endpoint and the URL that you get from the cosmos once you create a cosmos instance you get particular cosmos account you get the key and the URLs you instantiate a document client and then you create a database and generally in the cloud it's always Duty is defensive programming techniques which means that you don't assume something exists you always created and then use it I you plan for creating it or a plan that it doesn't exist so in this instance it goes through it reads the list of databases and creates a database now this is version 2 version 3 actually is in version 3 the cost the document client has been replaced by a Kosmos client so that's cool because obviously you want to have a more generic one and you can use the cosmos client and the create database if not exists that call and similar calls at the database and collection level have been made much more stable and where you don't have to go through and catch the exceptions before you create the database so it's it's a more intuitive developer experience so there's definitely improvements on that side so let's see freaking one or the other thing that the dotnet SDK v3 has introduced as it's using streaming api's and the advantage of using streaming api's is that previous versions always did serializing and deserializing of the data each time you requested data and that kind of incurs eye overhead and the streaming API is cut down on that because the stream or the wire so I if you want to pass if you want to get data from the container and pass it on to something else you can use the streaming API and not have the overhead of serializing deserializing in between so next thing I want to do is jump into this cosmos D beta obviously provides sequel style query so we will see if we can find a collection that has data in it and obviously I have a collection and this collection has some data in it so we'll run some queries in here so let's look at the form let me look at a data record and see what I can query so I'll query for all the records that have day of week Fridays and see what comes up so when I say select see third day of week equals Friday probably oh it's kiss and still so you gotta watch out for that so obviously this query Dan and it can zoomed you can see that it's only showing hundred records because when you get your records back if you don't want to display all of them we can paginate them and that's always a good practice and this 400 records it's consumed about 12 our resource unit so you know as you can see can run sequel style queries and it's it's the one thing I would watch out for is every time you run a query always keep tabs on the request charge and you want to get your requests you want to constantly monitor a request charge because that may decide how much resource request units your provision for your collections so this is an example of how I would run a query from a class from a c-sharp client so in this instance I'm getting a query stream iterator and I'm passing in the actual query I'm passing in the actual query and and I'm using the partition key bridgetta in the partition last name so I'm in providing the family name Anderson and that will return some data so this one thing to keep in mind as if he generally when you run your queries if you wanted to get if you want to get the best efficiency in a in a large amount of if you have a large amount of data and you want to get the best efficiency somehow try to include the partition key in the query indexing so this is what this is another component that impacts query performance so in the so far let's take a look at this instance so this in this instance if I ran a query on locations where the city is Berlin it'll go through my collection and it'll filter out all the all the data that have fields called location and that have location fields and this location fields will have city subfields and the city will be called world and so it's filtering out all so if you have multiple schemas so let's say I have other records and my collection that have headquarters these don't have locations or city so in this case it will completely ignore those records so this is another way this not only helps filtering out data and making a query small efficient but it also helps with schema agnosticism I'll say that other things you want to think in here is you want to measure your request units per query and sure you have provisioned enough throughput when you run your you want to use always use partition key like I was saying earlier you want to follow SDK best practices like direct connectivity and all of these are listed in the documentation and also try to write a query swith in the same they account for network overhead when you run them server-side programming this is important because often when you get data you want to validate and transform your data before you before you store it or right after you store it and in that case you use something like a trigger or there's also stored procedures and user-defined functions that cosmos DB runs these runs server side because the JSON JavaScript code they can basically map to the JSON data and perform optimizations like lazy materialisation the other thing about server-side programming is that you can guarantee the database offs within stored procedures and triggers in particular or Atomics you can some amount of a in asset transactions talk about change feed processor which is one of the best features of Cosmos DB it's a basically a persistent log of documents so when Kosmos DB ingest data or updates data the it must maintains a persistent log and you can connect multiple clients to your logs and these clients basically use another cosmos color collection called leases that way even if they drop their connection they can come back and resume from a check point so this makes it really resilient and it's used in scenarios like even sourcing and you know even near real-time migration so for instance if you ever did the wrong partition key which happens you know more often than we I admit he can perform a near real-time migration by updating the records in your collection and then reading them through the change feed and copying them to different collections so he can actually use your change feed in a whole bunch of cool scenarios definitely something that should read more into entity framework three obviously in Lantana say where a discussion of cost cosmos in a darknet conference would be incomplete without entity framework three but because I'm running short on time I'll quickly see if I can you package and in your context you would use your basically over idea on configuring method to use the cosmos and in this case it uses the local connection string but obviously if you are deploying this to as your you would replace this with the as your connection strings and yeah so once you do that your context can use the cosmos client and then it kept performed it can access the database on the container and it can just work like any of the cosmos client and I see that I'm running clothes from pack so I'll keep this smaller I was gonna say where we're right on that whole a DevOps no no discussion of cosmos is complete without DevOps I want to talk about a couple of things a CentOS answer which I was gonna say if we're right on time ok ok I'll quickly wrap this up so cosmos DB provides the emulator and that you can use and you can actually connect your tests to that emulator so you can perform integration testing on your DevOps pipeline with cosmos and I will wrap up with a couple of thoughts and after that if time permitting I will take questions so my parting thoughts are get start started right away download the emulator it has sample projects you can get started polyglot data you know the LinkedIn example I gave so if we that's an interesting thought experiment to get you started but you you know they can use a whole bunch of different scenarios shift your focus from like thinking of course to thinking of what value it adds and TCR it's that total cost of ownership or non ownership so you don't have to host anything or that's really important and then understand partitioning throughput how it impacts performance attend the data modeling talk that's an hour from now learn to leverage server-side code like triggers and stored procedures use the change feed I'm sure that you'll find a good use case for that and finally use good coding and DevOps practices and these are some resources and that's mindful if you have a one on it till you get in touch with me the best way to do it as Twitter and I'll take any questions or if you have one time then I'll just wrap up yeah we're over on time so everybody if you have questions you want to bring up your your Twitter slide there buddy Santosh you can you bring it up for us minimize the Skype and she'll get quick so people can see that so anybody if you can any questions go ahead and put them there and we will get started thank you so much Santosh for taking the time to talk to us and we'll get here going with Steve and talking about the eShop ok thank you so much everybody pick

Building Bots Part 1

it's about time we did a toolbox episode on BOTS hi welcome to visual studio toolbox I'm your host Robert green and jo...