using the ReSharper Tool with VS.NET IDE 2010 for code improvements - resharper-5.0

I am new to ReSharper and have integrated with Visual Studio 2010. I have found a suggestion in the code as follows,
string query;
query = "SELECT * FROM Employee";
The ReSharper tool asked me to change the above code to
const string query = "SELECT * FROM Employee";
What is the performance benefit i get from this?

Almost certainly very little (or none), but the code is more correct (if the string is not being reassigned, which ReSharper has determined it not to be).
After all, it's easier to sleep at night with clean code! ;)

Related

Which tool of Progress Developer Studio for OpenEdge can I use for testing ABL queries?

I've just written following erroneous ABL query:
FOR EACH T1 (WHERE T1.some-date = ' ') AND
(integer(T1.num1) >= 100) AND
(integer(T1.num1) <= 200) AND
(T1.some-other-date = 01/12/2021) AND
(T2.Name = itsme),
EACH T2 WHERE T2.num2 = T1.num2
BY T1.num1
As you can see, this is wrong because I've put the first bracket in front of "WHERE" instead of behind it. In top of that, my name "itsme", is not put between quotes, so the ABL query will never work.
I've been looking in my development environment ("Tools" menu), but I couldn't find an ABL query tester. I've also checked the directory "C:\Progressx86\OpenEdge\bin", but being a newbie I didn't find anything.
I have downloaded the "DataDigger" application, which contains a so-called "MCF Query Tester", but this only works on single table and only checks criteria, not entire ABL queries.
Does anybody know where I can find an ABL query tester, first for syntax checking (the bracket in front of the "WHERE") and (if possible) for data testing (01/12/2021, is that January 12th or December 1st?)?
Thanks in advance
Dominique
Create a new OpenEdge project in Progress Developer Studio for Openedge. Create a new ABL procedure under the project with the necessary database connection. Copy the above ABL code into the procedure file and you should be able to see the errors and warnings in your procedure file.
The ABL Scratch Pad view of Progress Developer Studio allows to execute ad-hoc queries.
https://knowledgebase.progress.com/articles/Knowledge/000055088
You don't mention which editor you're using, but in general terms, the ABL COMPILE statement performs syntax checking. There's no separate/independent executable that compiles/checks syntax. Generally you'll need to write a .P to perform the compilation.
You can use the PCTCompile Ant task if you'd like to use an Ant- or Gradle-based build system.
As to date formats, I thought that was in the doc, but no. Dates always have a MM/DD/YYYY format when hard-coded; decimals always use a . decimal separator (ie 123.45) when hard-coded.
Another way to test a query you're working on would be to use query-prepare which accepts a string.
DEFINE QUERY q-Test FOR T1, T2.
QUERY q-test:HANDLE:QUERY-PREPARE("your query string here").
One of my colleagues showed me an incredible easy solution:
Copy the query in a separate procedure window and add the results you want to see, something like this:
FOR EACH T1 (WHERE T1.some-date = ' ') AND
(integer(T1.num1) >= 100) AND
(integer(T1.num1) <= 200) AND
(T1.some-other-date = 01/12/2021) AND
(T2.Name = itsme),
EACH T2 WHERE T2.num2 = T1.num2
BY T1.num1
/* To be added for viewing results */
DISPLAY T1.Field1 T1.Field2 T2.Field5
END.
And launch this inside the programming environment (F2).
In case of syntax mistakes, the compiler shows the errors. In case the syntax is correct, a pop-up window is started, showing the results.

VSIX - Minor visual studio version

Does somebody know if/how it is possible to obtain the minor Visual Studio version that is currently running, from within a VSIX extension?
I've already found the following property, but we would like to have the more detailed version number (more parts). https://learn.microsoft.com/en-us/dotnet/api/envdte._dte.version?view=visualstudiosdk-2017
The following code shows "16.0.29306.81 D16.2" in my VS 2019:
var shell = (package as System.IServiceProvider).GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsShell)) as Microsoft.VisualStudio.Shell.Interop.IVsShell;
object ver = null;
shell.GetProperty((int)Microsoft.VisualStudio.Shell.Interop.__VSSPROPID5.VSSPROPID_ReleaseVersion, out ver);
System.Windows.MessageBox.Show(ver.ToString());
Assuming you may want the level like X.Y.Z instead of X.0 or X.Y. (e.g: VS2017-15.9.13=>15.9=>15.0).
Sergey's great answer can help you resolve the issue if the format X.Y is enough for you. But if you want to get the full details like VS version+version number, you can consider using registry key.
For VS2015 and earlier versions you can see this vsx document and this similar issue, you can try to use RegistryKey to access the info you want from HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\DevDiv\vs\Servicing\<version>.
But since the installation experience of VS2017 has changed for the vs installer.exe. We can't access the version details about VS2017 and VS2019 under that registry key any more.
For VS2017 and VS2019, I find we can access the related info at HKEY_CURRENT_USER\Software\Microsoft\VSCommon\15.0 or 16.0\SQM\PIDs\.
If in the machine only has one edition of VS2017 and VS2019, you can use code like this to get details:
DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;
string version = dte.Version;
string editon = dte.Edition;
RegistryKey key = Registry.CurrentUser;
RegistryKey pidsKey = key.OpenSubKey("Software\\Microsoft\\VSCommon\\" + version + "\\SQM\\PIDs\\", true);
string[] instances = new string[10];
instances = pidsKey.GetSubKeyNames();
RegistryKey instanceKey = key.OpenSubKey("Software\\Microsoft\\VSCommon\\" + version + "\\SQM\\PIDs\\" + instances[0], true);
//read the details about VSManifestID
string versionInfo = instanceKey.GetValue("VSManifestID").ToString();
The versionInfo's format see here: VisualStudio/15.9.13+28307.xxx (Apart from VSManifestID, you can also use VSChanelID...)
But this won't work if you have more than one edition of same VS version in PC.(VS20xx community and enterprise in same machine). In this situation you have to add much more judgement logic with the help of dte.Version and dte.Edition.
The easiest way to find the minor part of VS is to get version information from the file "devenv.exe":
var devenvInfo = FileVersionInfo.GetVersionInfo(dte.FullName);
return new Version(devenvInfo.FileMajorPart, devenvInfo.FileMinorPart);

ASP.NET: Errors in autogenerated .Designer.cs file for Model

I'm new to ASP.NET and having a problem with a tutorial.
I've created a new MVC4 Project in VS2012 Express for Web.
And I've added a SQL Database with 1 Table "Persons" and filled it with some random testdata:
Id int (primary key, is identity=true)
name varchar(50)
birthdate date
adam 01.01.2001
berta 02.02.2002
As a Model I've used ADO.NET Entity Data Model, named it "PersonsModel.edmx"
and used the Personsdatabase for it.
To see the PersonsModel.Designer.cs file, I activated "Codegeneration Status" to "Standard". Refreshed and clicked on the PersonsModel.Designer.cs file.
But in this file I've errors... So I wanted to use something like this in my controller:
HomeController.cs:
PersonsEntities1 db = new PersonsEntities();
db.person...
but it doesn't work, and I think(?) it's because of the errors in the .Designer.cs file.
PersonsModel.Designer.cs: e.g.:
public PersonsEntities1() : base("name=PersonsEntities1", "PersonsEntities1")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
errors in the base: ... line
and in ContextOptions.
Unfortunately I've no english VS, but it says something like:
The best accordance für the overloaded System.Data.Entity.DbContext(string, System.Data.Entity.Infrastructure.DbCompiledModel)-Method has some invalid arguments
And no definition found for "ContextOptions", there is no method "ContextOptions" which accepts "MvcApplication7.Models.PersonsEntities1" as a first argument.
I'm a bit confused, because I did it like in the tutorial explained.
I think this code is in error:
base("name=PersonsEntities1", "PersonsEntities1")
There is no constructor that takes two strings. Your second argument is supposed to be of type DbCompiledModel. (See here.)
Now, I don't know why your designer would produce code that can't compile, so I'm wondering whether you have the wrong version of Entity Framework installed.
Apparently the problem was VS2012. It all works with VS2010.
I've downloaded the installer again from asp.net/mvc and added Visual Web Developer 2010 Express. After installation of VS2010 and all dependencies I tried the tutorial again and all works fine now. No wrong code in the .Designer.cs file :).
Thanks a lot Ann L. for your support. Your hint (wrong version of Entity Framework installed) prompt me to try another VS version.
In addition I've to say: I also tried VS2012 Ultimate (complete DVD version) but it didn't help.

What is the equivalent of ASP(VB) Server.CreateObject("ADOX.Catalog") in ASP.net (VB.net)

Hi
I am trying to convert a asp page to asp.net.
I changed everything except this one line
Set dbC = Server.CreateObject("ADOX.Catalog")
Can anyone suggest an equivalent to this ADOX.Catalog in asp.net
This dbC is being used in the following way in asp
Set cm = Server.CreateObject("ADODB.Command")
cm.CommandText = Request("qry")
sN = Request("sN")
Set tmpTable = dbC.Tables(sN)
if NOT IsObject(tmpTable) then
dbC.Views.Append sN, cm
else
tmpTble.Command = cm
end if
Although I do not have direct experience, this article seems like it would be of assistance to you:
How To Retrieve Schema Information by Using GetOleDbSchemaTable and Visual C# .NET
Try adding a reference into your project called, Microsoft ADO ext.6.0 for DLL and security or something similar.
Once you add it, you'd be able to write code like:
Dim dbc as New ADOX.Catalog
Ps: Not answering from a windows m/c to verify. Got this from another forum post

Is it possible to detect if Microsoft Excel is installed from a Web Application

I'm working on a web app (ASP.NET) that has some features that require Microsoft Excel installed on the client. I'd like to disable those features if Excel is not present.
Windows/IE/Excel only solutions are fine. This is not a multi-browser, multi-OS web app.
Any clever JavaScript out there to accomplish this?
No.
You're not allowed to dive into the client machine deep enough to figure out that part. The best you can do is to either assume it is installed, and ponder hard about what happens if it is not, or just ask the user.
You can do something like this, but you'll get all kinds of security warnings:
<script>
var excelInstalled;
try
{
var excel = new ActiveXObject("Excel.Application");
excelInstalled = true;
}
catch(e)
{
excelInstalled = false;
}
alert("excelInstalled: " + excelInstalled);
</script>
Why Excel? What if I have OpenOffice.org instead?
Just warn the user what you're going to send them, mark the link with "Excel file", and let him decide.
function hasOfficePlugin() {
var toCheckExt = ['', '12', '13', '14', '15'], i, n, mt;
for (i = 0, n = toCheckExt.length; i < n; i++) {
mt = navigator.mimeTypes['application/x-msoffice' + toCheckExt[i]];
if (mt && mt.enabledPlugin && mt.enabledPlugin.name) {
return true;
}
}
return false;
}
I've tested the above with Office 11 (2003), and Office 12 (2007), and it seems to work well in Firefox, Safari, Chrome, and Opera. Though it doesn't work in IE, because the navigator.mimeTypes objects in IE is always empty.
It's checking for the existence of an MS Office plugin. I don't know much about this plugin - quite possibly it's not always installed with office... But I think that, if the above returns true, it's a pretty strong signal that Excel is installed. Course it's probably of limited use since it doesn't work in IE, but maybe you can do something with it...
you can not access client information outside of the web browser context, using standard technologies. but I see one of answers is using some ActivX object to detect Excel. anyway these kinds of technologies work only on Internet Explorer on windows. what about Mac? what about other browsers like opera or firefox or chrome on windows?
I think it is better to let the user inform you about this. just ask the user if she has excel installed or not:
var isExcel = window.confirm('dear user if you have Microsoft Excel installed please click on ok, otherwise click on cancel. thank you.');
This is bad idea at start. What ever you are trying to do - reconsider.
If you still insist:
Try to crete ActiveXObject for Excel and then for OpenOffice.
If it fails, redirect to NoExcel.html or send XMLRequest to server.
Also, you can try to find out via JavaScritp if there is XLS file extension handler.
And last, you can install your ActiveX which checks if Excel is installed.
This is for windows. No idea for mac, linux, mobile...
You can bet that any way you make it work will stop working with next hotfix.

Resources