Showing posts with label tips n tricks. Show all posts
Showing posts with label tips n tricks. Show all posts

Friday, September 20, 2019

Dot Net CORE Tips

(1) Razor Pages: For dotnet core application, we can have advantage of building Razor Pages just like we have ".axpx" pages in traditional web application. But there is also an added advantage of MVC pattern can be implemented with existing structure.

(2) Microsoft.Windows.Compatibility: This package is essential whenever we are performing any operation which is available in .net framework implementation.
for e.g. dataSet.Tables[0].AsEnumerable() - This functionality will not available until you will not add above package. As this is dot net native functionality and to laverage this we need this package support. There are many other functionalities are still there.

(3) File Operation: To perform file operation in web, we have practices of using Server.MapPath(filepath) to work with files. But with dotnet core web app this operation is replace with below
private IHostingEnvironment _env;

public MyController(IHostingEnvironment env)
        {
            _env = env;
        }
var webRoot = _env.WebRootPath;

Now, here _env.webRootPath will be your application wwwroot folder path and here you can perform your operation of saving/sp-net-core
- https://gunnarpeipman.com/aspnet/aspnet-core-content-web-root/
- https://www.mikesdotnetting.com/article/302/server-mappath-equivalent-in-asp-net-core
- https://stackoverflow.com/questions/43992261/how-to-get-absolute-path-in-asp-net-core-alternative-way-for-server-mappath

(4) Upload/Save Image
- https://www.codeproject.com/Tips/4051593/How-to-Upload-Images-on-an-ASP-NET-Core-2-2-MVC-We
- https://stackoverflow.com/questions/42741170/how-to-save-images-to-database-using-asp-net-core

(5) To get all the output in json with no case applied on output of json result, in this case just add below line of code to Startup.cs file under ConfigureServices function.
services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

(6) To work with tag helpers below package to install
Microsoft.AspNetCore.Razor.Runtime

(7) To work with sessions user below package 
Microsoft.AspNetCore.Session

(8) Cookie Authentication
https://www.c-sharpcorner.com/article/cookie-authentication-with-asp-net-core-2-0/

(9) StaticFiles: to work with static files like images, html, js files use below  package
Microsoft.AspNet.StaticFiles

(10) It gives us access to the assemblies and classes provided by the framework.
Microsoft.AspNet.Mvc

(11) to build bundle files for css/js use below package
BuildBundlerMinifier
(1) https://marketplace.visualstudio.com/items?itemName=MadsKristensen.BundlerMinifier
(2) https://www.c-sharpcorner.com/article/bundling-and-minifying-in-asp-net-core-applications/
(3) https://docs.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-2.2&tabs=visual-studio

(12) When there is issue of tag is not properly rendered
- In this case, check with Taghelper is added to _ViewImport.cshtml page or not, if not then add like below
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
- https://github.com/aspnet/AspNetCore/issues/534


Wednesday, August 21, 2019

Logging with NLog

Here are some links and tips & tricks for nLog nuget extension. Find how to work with it and additionally there are some tips to make some more change in its configuration to achieve specific needs.

ASP.NET Core Web API – Logging With NLog

Introduction to NLog

NLog: Rules and filters

- To check with configuration of file
Configuration file

- To working from code base
Configure from code

Things your Dad never told you about NLog

- Tips & Tricks
Turn off Logging during Release from Nlog.config

How to turn ON and OFF logging for specific levels in NLog

how to disable the particular log, dynamically in Nlog using C#?

- Additionally
(1) To log only Info message

<logger name="*" minlevel="Info" maxlevel="Info" writeTo="logfile" />

or

<logger levels="Info" name="*" writeTo="logfile"/>

(2) To log multiple message, below change will log messages for Error and Info and that way we can add other too
<logger levels="Info,Error" name="*" writeTo="logfile"/>

(3) To disable logging set enable to false
<logger name="*" minlevel="Debug" writeTo="logfile"  enabled="false" /
>

Wednesday, June 12, 2019

MySQL Basic Operations

Here are some basic operations need to keep in mind for the MySQL beginners jumping into it from MS-SQL
- First things is, need to have MySQL Workbench to be installed for the same
- For MYSql most of the syntaxes remains same but still there are some points to note and are belows.

(1) ";" required for multiple query in batch
- For query to execute, it requires ";" at the end of statement. Also, same would be apply if there are multiple queries are there .
- for e.g.
MS-SQL - Select * From Table1
Select * From Table2
MySQL  - Select * From Table1;
Select * From Table2;

(2) Finding top item
- With respect to fetch top 1 item, here in MySQL same would be fetched by limit
- for e.g
MS-SQL - Select top 1 * from Table
MySQL  - Select * From Table limit 1;

(3) Call Stored Procedure
MS-SQL - exec procname
MySQL  - CALL `dbname`.`procname`(parameter, if any);

(4) Get Current Date
MS-SQL - GETDATE()
MySQL  - NOW()

(5) Null Check for field
MS-SQL - ISNULL(field, 'default value')
MySQL  - IFNULL(field. 'default value')

(6) If Exist: 
MS-SQL - 
If Exists(Select ID From Table Where ID = 10)
Begin
End
Else
Begin
End
MySQL
if exists(select Id from users where Id=_UserId) then

else

end If;

(7) Temporary Table
MS-SQL - There are couple of way to do so
- Temporary CREATE TABLE #TableName
(
column1 VARCHAR(50) 
)
- Global Temporary Table
SELECT column1 INTO ##TempTable

MySQL
- CREATE TEMPORARY TABLE TempTable

Saturday, May 25, 2019

DevExpress Report Basic Operations

Here are some basic operations performed with dev express reports.
(1) Display Report as LandScape

- Set report landscape property to true
this.Landscape = true;
- Set Page width
this.PageWidth = 1500;
- Define paperkind property
this.PaperKind = System.Drawing.Printing.PaperKind.LegalExtra;
- to show this report as landscapre your ReportToolbar should have width set to width that you want

(2) Access Report's controls: If there needs way where you have to load your report dynamically and before load it you want to assign/change value of your report's controls then perform below steps.
- make control public
On your report, suppose there is one label "Label1", then set its "Modifiers" property to public

- once above step is done, after your report declaration access this label below way
subReport subReporDetail = new subReport();
subReporDetail.Label1.Text = "Your Text";

- Once you are done with report control property changes then load that report dynamically and your label will be loaded with text you have set.

(3) Dynamically assign datasource: Suppose you are loading your report dynamically but before loading it you want to assign its datasource fetch from API/database then follow below steps
- define your report, subReport and datasource
XRSubreport subReport = new XRSubreport();
myDataSource dsource = new myDataSource();
myReport rpt1 = myReport();

- fetch your datasource 
DataTable dt= fetch data from API/database

- assign your service data to datasource
dsource.EnforceConstraints = false;
dsource.Tables["DataTableName"].Merge(dt);

- assign source and then load it to subreport
rpt1.DataSource = dsource.Tables["DataTableName"];
subReport.ReportSource = subReporDetail;

- Once your subreport has been bind with report and its dynamic data, load it dynamically.

(4) Add Button to ReportToolbar
- To add new button to your report toolbar, add like below way

- write client side events to button click callback
                    if (e.item.name == 'rptcustomevent') {
                        Callback1.PerformCallback(e.item.name);
                    }
                }" />
- write callback function at your javascript
$("#dashboard_menu_custom_button_id").click(function () {
... on click of above button, it will comes to here for your logic on button click
});

Tuesday, May 17, 2011

Some Links for DOS/Windows

(A) Windows Basic
(1) Windows4all.com - online virtual operating system

(2) How Do I Kill All the iexplore.exe Processes at Once? :: the How-To Geek

(3) How To Stop Automatic Updates From Restarting your PC

(4) Forensically interesting spots in the Windows 7, Vista and XP file system and registry

(5) LDAP Attributes. Properties Active Directory Users Computers Distinguished name

(6) Windows Server 2003 Resource Kit Tools                  

(B) Some windows fixes
(1) How to troubleshoot TCP/IP connectivity with Windows XP 

(2) How To Diagnose and Test TCP/IP or NetBIOS Network Connections in Windows 2000

(3) Microsoft Windows 2000 TCP/IP implementation

(4) FIX: Error message when you try to install a large Windows Installer package or a large Windows Installer patch package in Windows Server 2003 or in Windows XP: "Error 1718. File was rejected by digital signature policy"

(5) An application that is started by a non-administrative user cannot listen to the HTTP traffic of the computer on which the application is running in Windows Vista, Windows Server 2003, or Windows XP
          
(C) Dos Basic
(1) A-Z List (DOS commands)

(2) Robocopy                    

(3)
Shutdown remote computer 

(4) 10 Windows Command Line Tips You Should Check Out          

(5) A Beginners Guide To The Windows Command Line              

(6) Quick Tip: Change the Windows User Password via Command Line    

(D) Launch Windows Application from Command Line
(1) Launching Control Panel Apps from the Command Line    

(2) Description of Control Panel (.cpl) Files    

(3) The Command Line in Windows XP: Start-Run Line