Skip to main content

Posts

JSON Viewer: JSONPath Expressions Evaluation

Added a new feature to JSON Viewer extension: evaluation of JSONPath expressions. The source code: https://github.com/marss19/json-viewer-visual-studio-extension The latest release in Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=MykolaTarasyuk.JSONViewer  

Reference Conflicts Analyzer - Visual Studio Extension

This is an extension to Visual Studio for easy visual analysis of the "Could not load file or assembly or one of its dependencies" problem and issues related to referenced assemblies. The tool allows selecting a .Net assembly (.dll or .exe file) and get a graph of all referenced assemblies with hightlighted conflicting references. Source code: https://github.com/marss19/reference-conflicts-analyzer Download: https://marketplace.visualstudio.com/vsgallery/051172f3-4b30-4bbc-8da6-d55f70402734 Documentation After installation, it is available in the main menu: Tools -> Analyze Assembly Dependencies. Screenshot 1. Tool settings Assembly to analyse : .Net DLL or EXE file which dependencies should be analysed. Related config file : .exe.config for EXE file or web.config in case a web application DLL is selected. The extension inserts the related config automatically after the assembly is selected but it is also possible to select it manually. Ignore system ass...

Search for Movies and TV-series from the Chrome Context Menu

I noticed that sometimes, having a free evening and wishing to spend it watching a movie, I spent a lot of time selecting this movie, checking online movie databases for ratings, reviews, etc. As it was rather unproductive wasting of the time I created a simple Chrome extension helping to do the search easier and faster. The extension adds context menu items executing search for a selected text (movie name). There are also lots of sites which web masters overcomplicated them with scripts and CSS and made a simple selection of text quite a tricky thing. For these particular cases it is also possible to search without selection; for a focused text at cursor. The extension is configurable: you can select preferable online movies databases. Link:  https://chrome.google.com/webstore/detail/movies-tv-series-search/miploifkaagebhdlcdaaomgnenchiocf?hl=en&gl=PL Preview:

Caching HTTP Handlers

There comes a time in an ASP.Net developer's life when he must write own HTTP handler. Quite often the handler has to return a static or a rarely changable content and the developer should implement caching of it. Step 1. Specify how long data should retain cached. Someone does it this way: context.Response.Cache.SetExpires(DateTime.Now.AddDay(1)); Someone likes this approach: context.Response.Cache.SetMaxAge(86400); //1 day in seconds The most careful developers use both: context.Response.Cache.SetExpires(DateTime.Now.AddDay(1)); context.Response.Cache.SetMaxAge(86400); All the above are correct in their own way. The first example sets an absolute expiration date. In the list of headers it looks like this: Expires: Mon, 25 Jul 2016 19:50:09 GMT This header was introduced in the HTTP/1.0 specification but it is supported by HTTP/1.1 too. A small pitfall related to this header is that the expiration date and time are set explicitly and it may cause issues ...

JIRA REST API: Cookie-based Authentication

Three authentication methods are proposed by the JIRA REST API documentation: Basic Authentication is a simple but not very safe approach. Credentials are sent in the header on every request and encoding to Base64 is not a proper protection in this case; HTTPS connection is required. OAuth authentication - looks a bit complex and requires additional configuration at the JIRA server that is not always possible. Cookie-based Authentication - this approach seems to be the most convinient one: credentials are checked once, then the authentication cookie only is sent on subsequent requests. However, trying to use the cookie-based authentication I encountered an issue. The approach described in the documentation worked partially: I was able to create a new session and get the response containing the session cookie but all subsequent requests using this session cookie were rejected as unauthorized. Spending some time investigating this I found the cause of the issue: JSESSIO...

JSON Viewer. Part 2

JSON Viewer extension has now a few new features: ability to print formatted data ability to format input data keeping JSON markup ability to compare 2 JSON data Source code and binaries to download are here: https://github.com/marss19/json-viewer-visual-studio-extension After installation the viewer appears in the main menu: Tools -> JSON Viewer. Applicable to VS 2012 and 2013. UPDATE The source code has been migrated to GitHub: https://github.com/marss19/json-viewer-visual-studio-extension The latest release is available for download in Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=MykolaTarasyuk.JSONViewer

JSON Viewer

Made a simple extension to Visual Studio to view JSON data in a more user-friendly format. Source code and binaries to download are here: https://github.com/marss19/json-viewer-visual-studio-extension . After installation the viewer is available in the main menu: Tools -> JSON Viewer. Applicable to VS 2012 and 2013. Please note that custom VS extensions cannot be installed into Express editions of Visual Studio due to a Microsoft policy. UPDATE The source code has been migrated to GitHub: https://github.com/marss19/json-viewer-visual-studio-extension The latest release is available for download in Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=MykolaTarasyuk.JSONViewer

Not So Primitive Types

A few nuances about the primitive types in .Net which are not so obvious: If you add two short s you will get int . The same with byte s. Arithmetic operators for these types are not implemented in .Net therefore the values are implicitly converted to int before calculation. short x = 2, y = 2; var z = x + y; Console.WriteLine(z.GetType()); //output: System.Int32 Chuck Norris is not the only person who can divide by zero. Every .Net developer can do this. Just use floating point numbers. var z = 1.0 / 0; Console.WriteLine(z); //output: Infinity

Bulk Generation of Tasks in TFS

It usually took me hours to add all tasks for my team for the next sprint in TFS. Existing UIs for this purpose were too sl-o-o-o-w, both built-in Team Explorer and Web Access (I mean Web Access for TFS 2010; 2012 is better in this context). The most annoying thing is that I usually need to specify just title and estimate for tasks but have to wait until the whole complex task entry form is loaded and then closed. I also found bulk work items generation by means of Excel is not that convenient for addition of hierarchical (parent-child) data. So I made a small utility for this purpose. Details and source code are here:   https://github.com/marss19/bulk-task-generation-in-tfs How to use The main form is divided in 3 parts: main menu: you can select a TFS project here, specify an area and/or an iteration to filter displayed work items and select a template for tasks creation. The default template containing all required fields is created automatically for each p...

Two facts you may not know about storing ASP.Net Session in SQL DB

  If saving of large objects in the Session in InProc mode is bad practice then doing the same in SQLServer mode is real evil. The main problem in this case is serialization/deserialization data on every request to the server. Each user's session is a single record in ASPStateTempSessions table so all objects need to be deserialized even if you request something which is rather small. Symptoms of this problem: you notice using a profiler that usual int userId = Session["UserId"] takes a few seconds!!! to execute.     If you noticed that ASPStateTempSessions table is rather large and permanently grows and grows then check if the SQL Server agent is running. It is responsible for deleting of expired sessions. It should have a job to execute the DeleteExpiredSessions stored procedure every minute (by default).

How to merge cells with equal values in the GridView

My solution is not the first; however, I think, it is rather universal and very short - less than 20 lines of the code. The algorithm is simple: to bypass all the rows, starting from the second at the bottom, to the top. If a cell value is the same as a value in the previous (lower) row, then increase RowSpan and make the lower cell invisible, and so forth. The code that merges the cells is very short: public class GridDecorator { public static void MergeRows(GridView gridView) { for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--) { GridViewRow row = gridView.Rows[rowIndex]; GridViewRow previousRow = gridView.Rows[rowIndex + 1]; for (int i = 0; i < row.Cells.Count; i++) { if (row.Cells[i].Text == previousRow.Cells[i].Text) { row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 : ...

Charts: let Google work for you

I can't class myself as an developer who is always hip to the latest news in the software industry, partly through laziness and partly through necessity to write code, and not merely to surf the Internet :) That is why I missed appearance of a very cute and handy service from Google , which allowed to integrate charts into the web pages. For the time being it is only half a year old as far as I can judge by the date of the first record in the discussion group, therefore I think this information can be interesting for someone else besides me. The service allows to dynamically generate practically all essential types of charts such as bar charts, pie charts and so on. The only thing you have to do to get the chart is forming the url in concordance with some rules and the service will return the PNG-format image. As an example I decide to use data from another Google service, namely Google Analytics, which together with all its merits has one lack: the absence of public access to the ...

How to use standard FileUpload in AJAX-enabled web applications

I would like to note that this article is not about the ability to upload files to the server without the postback. There are a lot of articles on this topic, just type "AJAX FileUpload" on any search engine and you'll get many examples. However with AJAX they actually have little in common, because the XMLHttpRequest does not support asynchronous uploading of files to the server, they are rather a variety of imitations, for example, using hidden IFRAME element. Nevertheless I want to emphasize that the article is not about that but about the standard FileUpload control. There are two problems you might encounter when using it on UpdatePanel. Problem 1 If the postback is caused by the control which lies on UpdatePanel, FileUpload is always empty when it has come to the server, regardless whether a file has been selected or not. Example: <asp:UpdatePanel ID="UpdatePanel1" runat=server> <ContentTemplate> <asp:FileUpload ID="FileUpload1...

Simultaneous Selection of Checkboxes in a GridView's column

If you are using checkboxes in GridView in order to select a few rows, then, no doubt, you have been faced with the task how to select/deselect all checkboxes in a selected column at a time. Usually it is solved by addition of special buttons somewhere or addition a checkbox in the GridView's column header. I want to dwell on the second variant. In order to refrain from repetition of code all of required functionality can be hidden inside of a special control. This control is inherited from the CheckBox and have only one method overriden (OnLoad). Inside the method a script is registered, this script allows to select/deselect all checkboxes in a GridView's column if a checkbox in the GridView's header is clicked. Besides, the script tracks situation when all checkboxes in rows are selected one by one and selects the checkbox in the column's header. public class GridViewCheckBox : CheckBox { protected override void OnLoad(EventArgs e) { GridViewRow parentRow = th...

Dynamic Rounded Panel

This is another variant of the rounded panel creation (the first one you can see here ), that uses images to present curved corners. To be more precise, the only image is used, the one that is build based on the specified circle radius, the background color, the border color and width. The panel appearance varies according to all these parameters and can be dynamically changed in runtime. Picture 1. The structure of the top part of the rounded panel a - the left part where the upper left part of the image is shown. b - the middle that is filled with the background color and contains a block element (d). The d element imitates the image border. c - the right part where the upper right part of the image is shown. Of course, the middle can be simpler if to use the only block that is filled with the background color and has the upper border. But different browsers interpret borders ambiguously, some of them enlarge total height of the block element. It caused a small complication of th...

How to avoid unexpected postback after pressing Enter in textbox

Problem You fill a form with many input fields. After filling first textbox you mechanically press Enter and see that the page are submitted to the server. Inasmuch as the rest of the fields stay blank the result of this submit is either saving incomplete data or a few validators of type "Field XXX is required." are shown. The well-known situation, is not it? It is not very good to allow such behaviour in a web application, especially because it easily can be corrected. Of course, there are situations when this is useful (e.g.: you have a single search box and after typing a search keyword it is very convenient to start search by pressing Enter). But in the most cases such behaviour just annoys visitors. Solution Surprisingly, but this inconvenience caused by built-in browser conveniences. :) Convenience #1. If a form contains only textbox then regardless of the submit button presence pressing Enter will send the form to the server. http://msdn2.microsoft.com/en-us/library/...

How to Register Stylesheet Created in Runtime

Here is an example from MSDN : // Create a Style object for the section of the Web page. Style bodyStyle = new Style(); bodyStyle.ForeColor = System.Drawing.Color.Blue; bodyStyle.BackColor = System.Drawing.Color.LightGray; // Add the style to the header of the current page. Page.Header.StyleSheet.CreateStyleRule(bodyStyle, this, "BODY"); It is the simple and handy method but has a few flaws. 1. Output is far from optimal. For example, following code that adds a border someStyle.BorderColor = System.Drawing.Color.Red; someStyle.BorderStyle = BorderStyle.Solid; someStyle.BorderWidth = new Unit("1px"); produces this output border-color:Red;border-width:1px;border-style:Solid; instead of border:Solid 1px Red; It has no matter if you don't pay attention to the size of pages you develop, but it is taken into consideration if you take into consideration your visitor's needs (sorry for tautology). But it's a trifle, of course. I mentioned it just for completene...

How to Add Additional Element to GridView Pager without PagerTemplate

PagerTemplate allows to create any configuration of pager but it also requires custom paging to be implemented. Sometimes built-in paging completely meet all needs but a little modification is reduired, for example, ability to change page size. That can be done within RowCreated event handler. <asp:GridView ID="GridView1" runat=server AllowPaging="True" OnRowCreated="GridView1_RowCreated" ... Code behind: protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Pager) { DropDownList ddl = new DropDownList(); //adds variants of pager size ddl.Items.Add("5"); ddl.Items.Add("10"); ddl.AutoPostBack = true; //selects item due to the GridView current page size ListItem li = ddl.Items.FindByText(GridView1.PageSize.ToString()); if (li != null) ddl.SelectedIndex = ddl.Items.IndexOf(li); ddl.Se...

Rounded Panel without Images

Panels with rounded borders are widely used in the web site design. So widely that it is hard to add something new. I just try to wrap existing ideas in the form of a web control. Features: Can be set radius of the circle, back color and border color Without images (pure HTML) Only 130 lines of code Easy to use (see examples below this article) <cc:RoundedPanel ID="RoundedPanel1" runat="server" CssClass="r1" BorderColor="Gold" BackColor="Beige" Radius="9"></cc:RoundedPanel> I inherit control from WebControl. Mainly it will be a container for another elements so it needs PersistChildrenAttribute and ParseChildrenAttribute to be set correctly. BackColor and BorderColor properties have been defined in the base class, only radius of circle has to be added. [PersistChildren(true), ParseChildren(false), ToolboxData("<{0}:RoundedPanel runat=\"server\"></{0}:RoundedPanel>"), Designer(typ...

Image-Based Bot Detector

Image-Based Bot Detector is a variant of image-based CAPTCHAs that uses human ability to recognize a distorted region on the image he never seen before. Licence Copyright (c) 2007, Mykola Tarasyuk All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The name of the copyright holder may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ME...