Unexpected ReSharper warnings when editing a JavaScript file in a console app - javascript

I wrote a small web app using Nancy. I was originally using ASP.NET hosting, but I decided to try Nancy self hosting so I could deploy the app easily to any Windows machine. This involved replacing my ASP.NET Empty Web Application with a Console Application.
Pretty much everything is working well, but I've run into an issue where using certain window functions, such as alert() or escape(), in the JavaScript editor causes ReSharper warnings.
Here's how it looks in the editor:
I could always disable these warnings (or add window. before every call), but I'm wondering if there's anything I can do to have these functions recognized as if my project were an ASP.NET app.
Edit
If I return to my original project (the ASP.NET app) and type alert, here is what I see:
Could this mean that DHtml.js doesn't get loaded/included for console apps? Is there a way to make that happen?

When you create a web project, ReSharper adds some "hidden" js files to its cache that provide definitions for global objects, including the "Dhtml.js" file you mention. These files aren't added for console applications. There's no decent workaround here - ReSharper's web support is primarily based on the idea that you're in a web project of some kind, so there will be other features that are not enabled due to the fact that you're in a console app project.
However, it looks like it's possible to replicate what ReSharper does to add these files from a plugin - instead of looking to see if the project is a web project, it should look to see if it's a console app that also references Nancy. If so, tell ReSharper to internally reference these "hidden" files. I'd suggest posting a feature request to the Nancy ReSharper plugin project.

Related

Angular app, Inside an Asp.Net Core Project, pros & cons

I would like to create a Single Page Web App with Angular but I couldn't decide to project type.
(Just generated files by tools like angular-cli or that generated files inside an Asp.Net Core Project)
I got some question.
What are the advantages and disadvantages of building angular app on ASP.NET Core Project?
Which cases I should prefer to locate angular app inside a ASP.NET Core Project?
I'd like to take a stab at this. I'll agree that the answer is on some part opinion based though.
I have just been comparing the two versions for a new project that I am involved in.
First some facts
The Angular project created inside of the ASP.Net core application is in no way dependant on the .Net code. You can navigate to the directory and type ng serve and run it by itself.
You can copy the angular code to another directory or repo and host it by itself if you for some reason later on decide that you don't want to combine it. All you have to do is copy paste the angular code, and then remove some lines in startup.cs regarding the internal hosting.
The code that gets added inside of the asp net core template is close to the base angular app with a few examples added on.
If you use the login functionality template it implements an oidc client, and an identity server on the back end, (opinion) pretty much the same way I would have done it myself. There is nothing stopping you from rewriting it if you don't like it. At worst it's a good example of how it can be done.
As of today the template is using Angular 8.0.0, you can just change the package.json to get the latest version and run npm install. It works great.
You can still use Visual Studio Code for the Angular parts with a combined project.
Here are when Id choose the different versions (warning opinions ahead).
When to choose the asp.net core angular project.
Small web app with limited functionality.
Small team, probably same person writing angular code as api code.
If you are unsure. You can always split later.
When to choose separate apps.
Big team with deployment builds and automation.
If you want to host angular and asp.net core separately (for reasons such as to achieve maximum performance and load balancing in apps with thousands of visitors).
Separate people coding angular and asp.net
You don't like having it all in same repo and want to split it up.
In a bigger teams and contexts with multiple APIs you will probably have to deal with CORS anyways, but if not you will have to at least think about it for this to work.
If you are unsure, you can always combine it to one app later.

Azure documentdb how to develop server side?

as a total JavaScript beginner, how do I actually develop for it?
I mean, I've seen https://azure.microsoft.com/en-us/documentation/articles/documentdb-programming/ but there was no mentioning of a development environment.
Is there something like a visual studio project template for server-side javascript?
I use node.js so your mileage may vary if you are developing from .NET, but here's what I do:
First of all, I created an npm package documentdb-utils. It is a wrapper for the DocumentDB node.js package that makes it easier to do a bunch of things.
Then, I created npm package documentdb-mock to write tests for my stored procedures. The source code for documentdb-mock includes 4 example stored procedures along with a test suite for each using nodeunit. You can start with these as they exercise most of the server-side API.
After I have them passing my local unit tests, I write integration tests that exercise my system end-to-end including creating any necessary data for each test run. The only problems that I've found here with sprocs that I didn't see in my mocked testing had to do with reaching certain limits... although, documentdb-mock has been upgraded to simulate many of these now also.
I haven't open sourced this yet, but I have also written a parser/rewriter that will embed any require(d) packages into my sprocs before sending them to DocumentDB. This allows me to write and test in a nicely factored way on node.js even using downloaded packages from within my sprocs, but when they get pushed to DocumentDB any dependencies are automatically embedded inside of the function. I'll open source that at some point (probably adding it to documentdb-utils) but I can share it with you now if you desire.
Here are a few tools that I found helpful for development (especially server-side [by which we mean database-side] scripting):
DocumentDB Studio - https://github.com/mingaliu/DocumentDBStudio/releases
Sample Code - https://github.com/Azure/azure-documentdb-js-server/tree/master/samples/stored-procedures
Here is another nice open source tool for exploring data in documentdb:
documentdb.a7pl.us

Native Plugin For Windows 8 Using Cordova

I am creating a windows8 plugin in cordova but i want to be integarte native build like .winmd with my plugin so that through Winjs i m calling the functions of that library which is in c#. I had already added the reference and code into plugin folder and as well as in project. But still it throws an error WinRt Error : class is not register/JavaScript Error : class in not defined.
I am creating same plugin in WP but there is issue in windows8 plugin development using cordova winjs with native functionality. please help to resolve this issue, provide some samples , links etc.
Updated:
It seems that to reference a WinRT component from a Cordova project using the current VS Tools for Cordova release, you need to follow the instructions here:
https://msopentech.com/blog/2014/11/24/using-windows-runtime-component-with-cordova-project/
In particular, section 1 describes how to inform the Cordova build tools about your WinRT component(s), so that it can reference it/them in the AppX manifest, and include the component binaries in the output package.
Earlier notes:
Do you need to actually write it as a Cordova plug-in? Windows JS apps support really simply integration of custom WinRT components, which can be written in C++ or C#. You just have to create a new Windows Runtime Component project in your solution, define a public sealed class with the methods/properties you want to expose, and then add a reference from your JS app project to the WinRT component (right-click References, select Add Reference, and choose the component project).
That said, be wary of the performance implications of including a C# component (particularly if you need to load it during startup) and the memory usage implications of loading the CLR and all the .NET dependencies. Also remember that C# is not "native" so it isn't really a "native plugin" if you do that :-)
You also might get slightly better advice if you describe your goal (i.e. you need the native plugin for something where you're actually running against JS performance limitations - which is a fairly exceptional case).

How to invoke Javascript in .NET in WPF & WinRT?

Here is a use case. I need to:
Invoke JavaScript from .NET (C#) code
JavaScript won't be compile, it comes from a dynamic source
I need to pass .NET objects to that javascript code, preferable a dynamic object
I also need to receive objects back from this javascript code
I need this code to run in WPF (Windows 7) & Windows Store (WinRT)
So far I've only seen activation of Windows Script Engines (i.e. IActiveScript) or using open source project.
I would prefer to stay clear of Open Source project and would prefer to use IE JavaScript engine (Chakra). Windows Script Engine doesn't seems to work on WinRT. I can live with hosting a browser in my app as it is a UI app.
Code doesn't need to be identical in WPF & WinRT (I can write something to wrap the two implementation behind an common interface).
How can I do that?
Chakra does not expose a public hosting interface, so you won't be able to do what you want without hosting something like V8 inside your application.
Another option for the metro app would be to build the main app in JavaScript and call out to WinRT objects written in .NET for the majority of the work. Won't help you in WPF though.

Referencing javascript embedded resource but intellisense doesn't show anything

I'm stuck... I'm trying to reference a javascript file that has been embedded inside a third party assembly, but it doesn't seem to work:
What I've done:
I have a folder RefAssemblies where this library DLL with embedded javascript file is located
I added a project reference and pointed to this library assembly
I added a line in my javascript file where I want the reference to work ie.
/// <reference name="ScriptName.js" assembly="AssemblyName" />
I tried naming my assembly with name only, and also with full assembly name including name, version, culture and public key token. No difference.
Added my library assembly to my project's web.config inside system.web\assemblies (AFAIK that's the part where you have to add your assembly and make it well-known in your application) so I should be able to access it without referencing assembly at all just resource name. No difference.
And yes I was pressing the Ctrl+Shift+J after any change I've done so Visual studio refreshed Javascript intellisense cache. I even unloaded and reloaded my web project after I changed web project's web.config. Just so that Visual Studio would read the file and reload everything anew.
But still unlucky... And I'm not getting any Javascript Intellisense errors in the General output window either...
I must be missing something...
Additional note:
It may be helpful to know that I'm running ReSharper 6.1.1000.82 within Visual Studio 10.0.40219.1
Other things I've done afterwards
Uninstalled ReSharper from my machine
Reset Visual Studio by running it from command prompt using
devenv /ResetSettings
No luck either.
Do you have any other suggestions I might do?
I'm also having odd problems with embedded resources. I have managed to get it working though by using the fully qualified resource name. You can find that out by using ilspy to open the assembly and then select the Resources folder, then the full name of all the resources will be displayed.
As i said i have gotten this to work in one solution, but in others it doesnt work and i have no idea why.. the non working solution has a diffrent structure where the diffrent assemblies are in diffrent folders, but i have nto been able to isolate that as the cause..
-edit-
After much trial and error it seems like the key thing to making embedded javascript references work is to set the output folder for the project containing the reference to bin and not bin\debug.
from what i can gather, there are no other settings or assembly references that affect the embedded resources, only the output folder of the project that has the reference. i'm guessing that the javascript language service is unable to find the assemblies with embedded resources unless they are in the private path or the gac, but i have yet do understand exactly where this binpath is set.
i've tried setting it on the project itself and on what i think is the actual language service exe, but to no avail.
i made a connect issue here:
https://connect.microsoft.com/VisualStudio/feedback/details/770185/js-references-to-embedded-files-require-the-referencing-project-to-have-outputpath-bin

Categories

Resources