Archive

Archive for July, 2012

Cache – Behind the Scenes

July 26, 2012 2 comments

Requests not using Caching:

  1. Request comes in for an ASP.NET Page. The request is given to the ASP.NET Http Runtime and is processed through the registered modules and directed to the page handler.
  2. The page handler is unable to find a precompiled version of the page class on disk, so it must grab the file and give it to the ASP.NET engine for parsing.
  3. The ASP.NET Page engine parses the file and generates a page class.
  4. The page class is compiled into a .NET assembly and cached on the disk.
  5. An instance of the requested page’s class is created.
  6. The response generated from the requested page class is sent back to the original caller.
    Subsequent requests not using Output Caching:
  7. Request comes in for an ASP.NET Page.
  8. The page handler finds a cached version of the class and creates an instance.
  9. The response generated from the requested page class is sent back to the caller .
    Requests using Output Caching:
  10. Request comes in for an ASP.NET Page.
  11. Steps 1-6 are repeated for the first request.
  12. The generated response is added to the ASP.NET Cache.
  13. The response is sent back to the caller.
    Subsequent requests using Output Caching
  14. Request comes in for an ASP.NET Page.
  15. When the request is processed by the Http Modules, the Cache module is passed through. If the page response is found within the ASP.NET Cache, the response is copied from the Cache API and sent straight back to the caller.
Advertisements
Categories: ASP.Net

Associate File Extension with Application (Registry + Setup)

July 24, 2012 3 comments

C# Function to Implement With Code-

public static void SetAssociationWithExtension(string Extension, string KeyName, string OpenWith, string FileDescription)
    {
    RegistryKey BaseKey;
    RegistryKey OpenMethod;
    RegistryKey Shell;
    RegistryKey CurrentUser;

    BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
    BaseKey.SetValue("", KeyName);

    OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
    OpenMethod.SetValue("", FileDescription);
    OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
    Shell = OpenMethod.CreateSubKey("Shell");
    Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
    Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
    BaseKey.Close();
    OpenMethod.Close();
    Shell.Close();

    CurrentUser = Registry.CurrentUser.CreateSubKey(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ucs");
    CurrentUser = CurrentUser.OpenSubKey("UserChoice", RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);
    CurrentUser.SetValue("Progid", KeyName, RegistryValueKind.String);
    CurrentUser.Close();
}

Calling Sample

SetAssociationWithExtension(".abc", "ABC File Editor", Application.ExecutablePath, "ABC File");

With Setup-

-1)Open up your solution in Visual studio.
2)Add a Setup Project to your solution by file , add project,New project, Setup & Deployment projects,Setup project
3)Right-click on your setup project in the “Solution Explorer” window,Select view,then select file types.
4)Right-click on “File types on target machine”.the menu will pop up with Add “file type” Click on this.
you’ll see “New document Type#1” added,and “&open”underneath it.
5)The “new document type#1″ YourCompantName.Filetype”,where your company name is your name of your company’s name, and “Filetype” is a descriptive text of your file.
6)Command:Change to the application that you want to run.
Description: This is the description of the file type(if it doesn’t describe it’s self”
Extensions:This your list of extensions for you chosen Program.Separate each one with a “,”
Icon:This will associate the icon with your file type

Categories: C#

Creating a DDL Trigger

CREATE TRIGGER [name of trigger]
ON [scope (database|server)]
FOR [event]
As
–Trigger definition here…

example-

create trigger DDL_Trigger
on database
for create_procedure, alter_procedure, drop_procedure
as

set nocount on

declare @data xml
set @data = EVENTDATA()

insert into dbo.eventslog(eventtype, objectname, objecttype, sqlcommand, username)
values(@data.value(‘(/EVENT_INSTANCE/EventType)[1]’, ‘varchar(50)’),
@data.value(‘(/EVENT_INSTANCE/ObjectName)[1]’, ‘varchar(256)’),
@data.value(‘(/EVENT_INSTANCE/ObjectType)[1]’, ‘varchar(25)’),
@data.value(‘(/EVENT_INSTANCE/TSQLCommand)[1]’, ‘varchar(max)’),
@data.value(‘(/EVENT_INSTANCE/LoginName)[1]’, ‘varchar(256)’)
)

What’s that EVENTDATA() thingy?

EVENTDATA is where we’re going to get our data for the change log system. It’s basically an XML datatype that looks like this:

<EVENT_INSTANCE>
<EventType>event </EventType>

<PostTime>date-time</PostTime>
<SPID>spid</SPID>
<ServerName>name </ServerName>

<LoginName>login </LoginName>
<UserName>name</UserName>
<DatabaseName>name</DatabaseName>

<SchemaName>name</SchemaName>
<ObjectName>name</ObjectName>
<ObjectType>type</ObjectType>

<TSQLCommand>command</TSQLCommand>
</EVENT_INSTANCE>

Categories: SQL