28 Ağustos 2018 Salı

Note Defteri Varsayılan Kaydetme Formatını Değiştirme

Default UTF-8 encoding for new Notepad documents

Short of using a third party editor, is there a way to configure Notepad so that new documents are automatically saved in Unicode without having to change manually the encoding every single time from default ANSI to UTF-8?

Typical scenario:

- Start typing some text with no extended characters
- Save the file: It is automatically in ANSI
- Open the file again to edit, add some extended characters, save again:
  Notepad tells you the extended characters will be lost if you confirm the save operation.

At least that last message offers the possibility to backup and "Save as" to choose UTF-8, but 1) this is very cumbersome, and 2) files with no extended characters will still be saved in ANSI by default.

Windows won't really be fully Unicode if the default Notepad encoding is still the obsolete ANSI code page, but, even if I reluctantly admit changing default behaviors is tricky for compatibility reasons, there should at least be a user option to select the default encoding for new documents, like other third party editors offer, such as Notepad++.

Currently, Windows forces me to replace Notepad file associations to use other text editors. Not a bad thing given the poor set of features in Notepad, but it would have been great to have this option in the standard O.S.

 This thread is locked. You can follow the question or vote as helpful, but you cannot reply to this thread. I have the same question (208)   
Question Info
Last updated August 28, 2018
Views 163,222
Applies to:
Windows Windows 7  / Programs
Image Answer
MA
Maneuver Replied on May 12, 2010
ReplyIn reply to Chimel's post on May 4, 2010

1. Right click -> New -> Text Document
2. Open "New Text Document.txt". Do NOT type anything!
3. Go to "File -> Save As... " and choose UTF-8 under "Encoding:", press "Save" and overwrite existing file. Close the file.
4. Rename "New Text Document.txt" to "TXTUTF-8.txt"
5. Copy "TXTUTF-8.txt" to "C:\WINDOWS\SHELLNEW"
6. Go to "Start -> Run..." and type
---------
regedit
---------
Press OK.
7. Navigate to
-------------------------------------------
HKEY_CLASSES_ROOT\.txt\ShellNew
-------------------------------------------
8. Right click in the right window -> New -> "String Value" and rename it to
-----------
FileName
-----------
9. Double click on "FileName" and put
----------------
TXTUTF-8.txt
----------------
into "Value data:" field and press OK.
10. It's finished.

11. Test it: Create new .txt document (Right click -> New -> Text Document). Open it and go to "File -> Save As... " and see that encoding is set by default to UTF-8 . :-)

Credits go to Robert Clemenzi and his explanation of "FileName" string (and its linkage with "Template directory") within registry:
http://mc-computing.com/WinExplorer/WinExplorerRegistry_ShellNew.htm

NOTE: These steps are ONLY for creating new and blank UTF-8 .txt documents. If .txt is already saved with ANSI encoding, it will stay ANSI when saving it next time - so if UTF-8 is needed (in this case), it must be set manually.

P.S. Also change "fSavePageSettings" & "fSaveWindowPositions" DWORD values to "1" within following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Notepad

Info: http://www.pc1news.com/saving-changes-to-notepad-configuration-1216.html

evrenpehlivan.com

evren pehlivan

16 Ağustos 2018 Perşembe

Loader on Form Submit using JQuery and Ajax



As we all know, users are impatient. We also know that if we don’t tell them our application is “doing something” they tend to do silly things like click the mouse repeatedly, seeking some sign that the requested action is indeed being performed.
For this reason, it is a good idea to throw up some sort of “busy” indicator when a user-initiated action may invoke a long-running process which requires them to wait.
In this article we are going to demonstrate a very basic way to achieve this which will be effective in most cases.
If you are new to ASP.NET MVC, you may want to check out my previous posts on Routing Basics and Route Customization as well. While not critical to understanding what we discuss here, some background on the basics of MVC routing will certainly help in understanding what’s going on in places.
The fully-functioning source code for the example used in this article is available from my Github Repo. You will need to use Nuget Package Restore to pull down all the package goodness so that the project will run. If you are unsure what that means, see Keep Nuget Packages Out of Source Control with Nuget Package Manager Restore.

What the Hell is Ajax?

Ajax is an acronym for Asynchronous JavaScript and XML. Ajax represents a broad range of technologiesused to facilitate client-server communication without interfering with the current state of the page.
In the main, we most often use the term when we speak of making an Ajax Request to the server, usually in the context of posting or retrieving data, and updating only a portion of the page, as opposed to completely refreshing a page simply because a small sub-area needs to be updated.
Upon the introduction of the term circa 2005, XML represented what many believed would be the primary data interchange format for this type of client-server transaction. Since then, JavaScript Object Notation (JSON) has become more and more of a standard. While XML is not gone, you are as likely to send and receive JSON in the course of an Ajax request as you are XML.
At present, we often find Ajax used in conjunction with JQuery (more properly, one often uses JQuery to make an Ajax request) when we need to retain the current state of our page while a request is made to the server and then update the portion of the page affected by the information returned from the request.

Adding a Busy indicator to a Page with JQuery and Ajax

The common way to display a busy indicator on a page while we wait for a long-running request to return from the server is to throw up an animated Gif, to let users know something is in fact happening. Equally as often, we need to then remove or hide the animation when the process completes, and refresh the portion of the page affected by our new data.
There really is no good way to do this from the server side in an MVC application – we need to use Ajax. We do this with JavaScript. in this case, we are going to use the popular JQuery library, because it is ubiquitous, it ships with and in integrated into the core MVC project.
Let’s take a look at a quick example.

Basic Example – The View

First we will look at a basic view. We’ve kept it simple here – we will display a couple of data entry fields, and a button to submit the data entered by the user. The essential cshtml code for this is as follows:
A Basic View:
@model JqueryBusyExample.Models.DemoViewModel
@{
    ViewBag.Title = "Home Page";
}
  
<h3>Enter Your Name and Submit:</h3>
  
@using (Html.BeginForm("LongRunningDemoProcess", 
    "Home", FormMethod.Post, 
    new { encType = "multipart/form-data", id="myform", name = "myform" }))
{
    <div class="form-group">
        @Html.LabelFor(model => model.FirstName, 
            new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.FirstName)
            @Html.ValidationMessageFor(model => model.FirstName)
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.LastName, 
            new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>
    </div>
    
    <input type="submit" name="operation" id="process" value="process" />
}
As we can see, there is nothing unusual here. We use standard Razor syntax to create a form with a couple data entry fields for First and Last names, and a submit button. In the opening of the using statement, The form is wired to a method named LongRunningDemoProcess on our HomeController.
In the form declaration, the syntax is:
Html.BeginForm(<actionName>, <controllerName>, <Http Method Type>, <Html Attributes>)
The above basically determines what happens when the form is submitted, and specifies a specific method, and a specific controller as a target for the Http request. It also defines the request method type (GET, POST, PUT, DELETE).
In our example case, we want to send our model data in the POST body. On our controller, the LongRunningDemoProcess method will need to be decorated with the [HttpPost] attribute, and accept the POST body payload as an argument.
Now let’s take a look at our Home controller.

Basic Example – The Controller

For our purpose here, I have simply added a method named LongRunningDemoProcess to the stock ASP.NET MVC Home Controller which is part of the default MVC 5 project template:
A Basic Controller with Long-Running Process:
public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public JsonResult LongRunningDemoProcess(DemoViewModel model)
    {
        Thread.Sleep(1000);
        return Json(model, "json");
    }

    public ActionResult About()
    {
        ViewBag.Message = "Your application description page.";
        return View();
    }
 
    public ActionResult Contact()
    {
        ViewBag.Message = "Your contact page.";
        return View();
    }
}
In the above, we use Thread.Sleep to mimic a long-running process on the server. You will need to add a reference to the System.Threading namespace in the using statement imports at the top of your file.
As we can see, LongRunningDemoProcess is the target of for our HTTP Post request from the Index view when form submission occurs. We want to use the Json data returned from the request to update our view, and let the user know their submit succeeded.
At the moment, though, things are not all they could be. We can load up our page, type some data into the form, and hit submit. What happens next, though, is that our page freezes up while the long-running process runs, and then our Json data is returned to a new tab in our browser (Chrome) or we are prompted to Save or Open (IE).
What we WANT to happen is to display a busy indicator, and then somehow indicate to the user that their submission was successful (or something!).

Get a Busy Indicator GIF

One of the more useful little sites I’ve found recently is AjaxLoad.Info, which presents a handy library of various customizable animated GIFs. You can specify some basic parameters (Size, Type, Foreground Color, etc.) and then download, ready to use.
Go get one, add it to your project in a location which makes sense (I am using ASP.NET MVC 5 project in VS 2013, so I placed mine at the root level of the Content folder).
Next, let’s modify our view, and add a div we can show and hide as needed, and which contains our gif:

The View, with Animated GIF and Placeholder for Submission Result

In the highlighted area below, we have added a div element to contain our Gif. While we’re at it, we also added another div, to hold the result when our long-running process returns:
Modified View with Animated Gif and Placeholder Div:
@model JqueryBusyExample.Models.DemoViewModel
@{
    ViewBag.Title = "Home Page";
}
  
<h3>Enter Your Name and Submit:</h3>
  
@using (Html.BeginForm("LongRunningDemoProcess", "Home", FormMethod.Post, 
    new { encType = "multipart/form-data", id="myform", name = "myform" }))
{
    <div class="form-group">
        @Html.LabelFor(model => model.FirstName, 
            new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.FirstName)
            @Html.ValidationMessageFor(model => model.FirstName)
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.LastName, 
            new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>
    </div>
    
    <input type="submit" name="operation" id="process" value="process" />
}
   
// We want to show this while the server process is running:
<div id="divProcessing">
    <p>Processing, please wait . . . <img src="../../Content/ajax-loader.gif"></p>
</div>
  
// We want to display the result from our submission in here:
<div id="divResult">
</div>
Now, in order to tie all this together, we need to add an Ajax request.

Adding the Ajax Request

The easiest way to achieve what we want is to use JavaScript on the client to show our animated gif, and then submit our data to the server. We also want to be able to respond when the Json is returned by the server by updating our page, without refreshing the whole thing.
For our example, I am going to add the JavaScript right on the view. This may or may not make sense in a production application, but we will do it here for simplicity.
I’ve added the JQuery code below our now-familiar view:
The View, with JQuery Added:
@model JqueryBusyExample.Models.DemoViewModel
@{
    ViewBag.Title = "Home Page";
}
  
<h3>Enter Your Name and Submit:</h3>
  
@using (Html.BeginForm("LongRunningDemoProcess", "Home", FormMethod.Post, 
    new { encType = "multipart/form-data", id="myform", name = "myform" }))
{
    <div class="form-group">
        @Html.LabelFor(model => model.FirstName, 
            new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.FirstName)
            @Html.ValidationMessageFor(model => model.FirstName)
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.LastName, 
            new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>
    </div>
    
    <input type="submit" name="operation" id="process" value="process" />
}
    
// We want to show this while the server process is running:
<div id="divProcessing">
    <p>Processing, please wait . . . <img src="../../Content/ajax-loader.gif"></p>
</div>
    
// We want to display the result from our submission in here:
<div id="divResult">
  
</div>
  
@section Scripts {
  @Scripts.Render("~/bundles/jqueryval")
  
  <script type="text/javascript">
  
    $(document).ready(function () {
  
      // Hide the "busy" Gif at load:
      $("#divProcessing").hide();
  
      // Attach click handler to the submit button:
      $('#process').click(function () {
          $('#myform').submit();
      });
  
      // Handle the form submit event, and make the Ajax request:
      $("#myform").on("submit", function (event) {
        event.preventDefault();
  
        // Show the "busy" Gif:
        $("#divProcessing").show();
        var url = $(this).attr("action");
        var formData = $(this).serialize();
        $.ajax({
          url: url,
          type: "POST",
          data: formData,
          dataType: "json",
          success: function (resp) {
  
            // Hide the "busy" gif:
            $("#divProcessing").hide();
  
            // Do something useful with the data:
            $("<h3>" + resp.FirstName + " " + resp.LastName + "</h3>").appendTo("#divResult");
          }
        })
      });
    });
  </script>
}
In the above, we start with the standard JQuery document.ready function, and hide the div containing our animated Gif.
We then attach the form submit event to the click event of the submit button we defined in our View (Isn’t it already attached, you ask? We’ll get to why we do this in a moment), and then we handle the form submitevent.

Handling the Form Submit Event with an Ajax Request

This is where things get interesting. There are a few things occurring inside this function, in a rather specific order. Let’s walk through it.
First, we want to prevent the default action using (wait for it . . .) the JQuery preventDefault() method when the form submit event occurs, otherwise, form submission will proceed automatically, as before, and any code we place in our handler will not work properly.
Next, we show our animated Gif. Once shown, it will do its thing, giving the user the impression that something  useful is happening.
Finally, we collect what we need from our form in order to submit our Ajax request. First, we grab the Url and stow it in a variable by accessing the form’s action attribute using JQuery. The action attribute essentially pulls a Url which matches the route we specified in the form declaration (remember?  ActionMethod, ControllerName, HttpMethodType, etc?).
Next, we serialize the form data ( in this case, our model data) into another variable, again using JQuery.
Once we have collected these things, we can set up our Ajax request by making the property assignments shown. Note that we need to specify the data type as Json, so that when the request returns, JQuery will recognize it as valid Json. Then, we come to the all-important success property.
We have assigned a function here, which will execute when our long-running process returns a response. The resp argument will contain the Json returned from our controller method. In this very simple case, it is merely the data we already submitted. However, it could just as easily be the result of persisting some data in a database on the server. In any case, we know that when this function is called, our remote, long-running task has completed.
That being the case, the first thing we want to do is hide our animated Gif. Next, we push the returned data into the div we set up as a placeholder (after doing a little formatting, of course).

Fairly Simple, but Not Always Obvious

And there you have it. The example we have examined is pretty basic, but gives a good look at how to both display a busy indicator, and how to make Ajax requests from your ASP.NET MVC page.
There is a lot more to learn about Ajax, and it provides a foundation for much of the interactivity found in today’s modern websites. I welcome comments and constructive criticism in the comments section below (especially if I got something wrong here . . .)!
You can clone or download the example project from my Github Repo. Note that you will need to use Nuget Package Restore to pull in all the package dependencies. If you don’t know what that means, see Keep Nuget Packages Out of Source Control with Nuget Package Manager Restore.



15 Ağustos 2018 Çarşamba

Foreach içerisindeki modeli post etme

for (var i = 0; i < Model.ToList< RequestCredit>().Count; i++)
{
@Html.HiddenFor(m => Model.ToList< RequestCredit>()[i].Id)


<div class="row" style="margin-bottom: 8px;">
<div class="col-sm-3" style="padding-top:7px;">
<h4 style="margin:0;">
@Html.DisplayFor(m => Model.ToList< RequestCredit>()[i].RequestPriceRangeText)
</h4>
</div>
<div class="col-sm-9">
@Html.TextBoxFor(m => Model.ToList< RequestCredit>()[i].RequestCreditAmount ,
new {@class="form-control", type = "number" })
</div>
</div>



Foreach içerisinde iterasyona tutulan Ienumerable listesi post edilirken sorun yaşandığında bu yöntem kullanılabilir.



10 Ağustos 2018 Cuma

4 Ağustos 2018 Cumartesi

SQL Server Temporary Table Caching

SQL Server Temporary Table Caching


evren pehlivan







Problem
When local or global temporary tables are created or dropped, its metadata are inserted or removed from the tempdb system catalog. If there is a very high rate of workload trying to create and drop temporary tables, this can lead to Data Definition Language (DDL) contention in the tempdb system catalog and throttle the workload throughput.
This tip will describe the condition to allow caching of temporary table and a demonstration to benchmark the performance between a cached vs. non-cached temporary table.
Solution
Caching of a temporary table is a feature available since SQL Server 2005. If certain conditions are met, the temporary table metadata will still remain in the tempdb system catalog when the user request has completed its task. From the user's perspective, the temporary table is no longer accessible as if the temporary table was dropped. But when a user session calls the same routine again that creates the temporary table, SQL Server internally can reuse the temporary table created earlier.
The conditions to allow caching of temporary table are:
  • Named constraints are not created
  • DDL statements that affect the table are not run after the temporary table has been created, such as the CREATE INDEX or CREATE STATISTICS statements
  • Temporary table is not created by using dynamic SQL
  • Temporary table is created inside another object, such as a stored procedure or trigger
Developers could write efficient queries, but because the temporary table caching feature works internally in SQL Server, it is not easily noticeable unless there is an awareness of this built-in feature and the condition to allow caching of a temporary table.

DDL Performance Between Cached vs. Non-Cached Temporary Table in SQL Server

The demonstration will be using a stored procedure which contains DDL only to benchmark the performance difference. This is also an example use case where caching of a temporary table can provide significant performance improvement on workloads that loop to process large amounts of records concurrently in a few batches. This tip is not stating the example is a good or bad design, but the focus is on demonstrating the behavior of temporary table caching.
All the T-SQL written in this tip is executed on SQL Server 2016 Enterprise RTM.
Two stored procedures are created with DDL definitions only as below:
USE tempdb
GO

CREATE PROCEDURE dbo.pr_NewTempTable
AS
BEGIN
 SET NOCOUNT ON;

 CREATE TABLE #T (A INT IDENTITY(1,1), val varchar(20))

 CREATE UNIQUE CLUSTERED INDEX AA ON #T (A)

END
GO

CREATE PROCEDURE dbo.pr_CachedTempTable
AS
BEGIN
 SET NOCOUNT ON;

 CREATE TABLE #T (A INT IDENTITY(1,1) PRIMARY KEY CLUSTERED, val varchar(20))

END
GO
Query SQL Server sys.dm_os_performance_counters DMV to get the Temp Tables Creation Rate counter. SQL Server service was restarted prior to this test so that counter is showing 0.
SELECT * FROM sys.dm_os_performance_counters 
WHERE counter_name = 'Temp Tables Creation Rate' 
AND OBJECT_NAME = 'SQLServer:General Statistics' 
GO 


Query SQL Server sys.dm_os_performance_counters DMV to get the Temp Tables Creation Rate counter value of 0
Open a new query session and execute the stored procedure dbo.pr_NewTempTable 100 times and check the Temp Tables Creation Rate counter again. The counter has incremented by 100 as a result of temp tables created from each of the dbo.pr_NewTempTable executions. The temporary table is not cached in this stored procedure due to DDL statement on the temporary table.
EXEC tempdb.dbo.pr_NewTempTable
GO 100

SELECT * FROM sys.dm_os_performance_counters
WHERE counter_name = 'Temp Tables Creation Rate'
AND OBJECT_NAME = 'SQLServer:General Statistics'      
GO


Query SQL Server sys.dm_os_performance_counters DMV to get the Temp Tables Creation Rate counter value of 100
Execute the stored procedure dbo.pr_CachedTempTable 100 times and this time SQL Server will show the Temp Tables Creation Rate has only incremented by one, because the temp table was cached and reused.
EXEC tempdb.dbo.pr_CachedTempTable
GO 100

SELECT * FROM sys.dm_os_performance_counters
WHERE counter_name = 'Temp Tables Creation Rate'
AND OBJECT_NAME = 'SQLServer:General Statistics'      
GO


Query SQL Server sys.dm_os_performance_counters DMV to get the Temp Tables Creation Rate counter value of 101
Assume stored procedure pr_CachedTempTable is executed concurrently at the same time in three different query sessions, then the Temp Tables Creation Rate counter will increase by three. If at any point in time the concurrent execution of pr_CachedTempTable is equal or less than three, then you will not see the counter Temp Tables Creation Rate increase. So, SQL Server will automatically create additional cached temporary tables to cater for concurrent requests.
To illustrate tempdb DDL contention, we will open three new query sessions and start the execution of dbo.pr_NewTempTable10,000 times under each session around the same time. The same test is repeated for dbo.pr_CachedTempTable and the ad-hoc query below.
-- Ad-Hoc Query
SET NOCOUNT ON;
DECLARE @i int = 1

WHILE @i <= 10000
BEGIN
 CREATE TABLE #T (A INT IDENTITY(1,1) PRIMARY KEY CLUSTERED, val varchar(20))
 DROP TABLE #T

 SET @i += 1
END
Below is a screenshot of dbo.pr_NewTempTable execution across three query sessions. All three sessions execution were started around the same time to simulate concurrent execution.
dbo.pr_NewTempTable execution across three query sessions
Below are the execution duration captured for the execution of dbo.pr_NewTempTable, dbo.pr_CachedTempTable and the ad-hoc query. DDL performance for cached temporary tables obviously has a noticeable shorter duration compared to a temporary table which is not cached.
Run#1
Run#2Run#3
EXEC tempdb.dbo.pr_NewTempTable61 seconds53 seconds58 seconds
EXEC tempdb.dbo.pr_CachedTempTable20 seconds21 seconds22 seconds
Ad-hoc Query65 seconds55 seconds65 seconds

Summary

DDL contention occurs when a high number of threads trying to access and update the SQL Server tempdb system catalog due to creation and dropping of temporary tables. This should not be confused with tempdb DML contention which typically relates to contention in PFS, SGAM or GAM pages.
In the demonstration, the temporary table pr_NewTempTable was unable to cache the temporary table, because it was mixing DDL with DML. By replacing the DDL "CREATE UNIQUE CLUSTERED INDEX" with the "PRIMARY KEY" constraint, the DDL becomes an inline statement and SQL Server was able to cache the temporary table.
However, not all DDL prevents the caching of a temporary table. An exception is the "DROP TABLE" DDL which still allows a temporary table to be cached. This means if there was an explicit "DROP TABLE #T" specified in pr_CachedTempTable, SQL Server would still be able to cache and reuse temporary table #T.

kaynak
https://www.mssqltips.com/sqlservertip/4406/sql-server-temporary-table-caching/

evren pehlivan yazılım

evren pehlivan yazılım, evren pehlivan yazılım geliştirici