Wednesday, 25 March 2015

Tuesday, 24 March 2015

Creating a custom event log under Event Viewer to log server events

Steps:

Add below code in your application
MyProject is: Source type
EventLog.WriteEntry("MyProject", "Error occurred ." + ex.Message, EventLogEntryType.Error, 0x00005082);

MyProject1 is: Source type
EventLog.WriteEntry("MyProject1", "Error occurred ." + ex.Message, EventLogEntryType.Error, 0x00005082);

Now your logs will be created under Event Viewer-->Application and Service logs

Now you can create View to filter your source (MyProject, MyProject1) logs

Open eventvwr (Go to run type: eventvwr)
Expand Event viewer
Right click on Custom Views
Select Create Custom View
In the new window select "By source"
Under "Event source" drop down, you will see your source name (MyProject, MyProject1) which you have created.
Select it.
Ok
You will see new window.
Give Your project name, any name.Ex: MySourceLogs.
Now you will see all logs under your folder MySourceLogs.

Another way is:
The first step is to create the new log. You have to do this in the registry. Open up regedit and navigate to:
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog
Right click on the Eventlog key and click New > Key
Ex: If i give MyProject
New folder will create under : HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog
Expand HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\MyProject
Select HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\MyProject
In the right side canvas, right click.
You will see "New" option, select it..
Expand....
Add below keys one by one...

Type:REG_SZ
Name: Sources
Value: Your project Solution Name
You can give multiple values with space.
Ex: Value: Project1 Project2 Project3
Without adding this, you will not see any logs
---------------------------------------------------
Type: REG_DWORD
Name:AutoBackupLogFiles
Value:0 Hexade
---
Type:REG_Expand_SZ
Name:DisplayNameFile
Value:%SystemRoot%\system32\wevtapi.dll
--------
Type:REG_DWORD
Name:DisplayNameID
Value:100
hex
----------
Type:REG_Expand_SZ
Name:File
Value:%SystemRoot%\system32\winevt\Logs\Application.evtx
-------
Type:REG_DWORD
Name:MaxSize
Value:ed0000
Hexa
----
Type:REG_SZ
Name:PrimaryModule
Value:Application
--
Type:REG_DWORD
Name:RestrictGuestAccess
Value:1
hexa
--------
Type:REG_DWORD
Name:Retention
Value:0
hexa
-------------------------------------------
Open Command prompt as Administrator
Go to this path: C:\WINDOWS\system32
Run this:
eventcreate /l MyProject /t Information /so MySource1 /id 1 /d "Test message"
eventcreate /l MyProject /t Information /so MySource2 /id 1 /d "Test message"

Open eventvwr (Go to run type: eventvwr)
Expand Event viewer
Right click on Custom Views
Select Create Custom View
In the new window select "By source"
Under "Event source" drop down, you will see your project name which you have created.
Select it.
Ok
You will see new window.
Give Your project name, any name.Ex: MyProject.
Now you will see all logs under your folder MyProject.

In your application you have to call like this..

 catch (Exception ex)
            {
                EventLog.WriteEntry("MyProject", "Error occurred ." + ex.Message, EventLogEntryType.Error, 0x00005082);
            }

All logs will move to MyProject view.

If you want to add new Source name and move all that source related logs to "MyProject" view,

First Add source name to regedit
Go to regedit
Select HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\MyProject
You will find
Name: Sources
Edit, Sources
The add New source name. Ex: Module1 Module2

Now go to code..
   EventLog.WriteEntry("Module1", "Error occurred ." + ex.Message, EventLogEntryType.Error, 0x00005082);
   EventLog.WriteEntry("Module2", "Error occurred ." + ex.Message, EventLogEntryType.Error, 0x00005082);

Now you need to add Module1. Module2 source to your view.
Go to eventvwr
Expand Custom View
Right click on MyProject
Select: Filter Current custom view.
Under By Source-->Event Source
Select drop down.
Scroll down, you will see Module1. Module2
Select it
Ok

Now you will see all logs with different source under MyProject

Now how to export this registry in to other systems...
Go to this path:
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\MyProject
Right click Export
You will get .reg file. Name it: Myproject.reg

Now go to other system. Copy Myproject.reg in any drive.
Open Command prompt in administrator mode.
Go to this path: C:\WINDOWS\system32
Run this:
reg import "C:\Myproject.reg"

You will see all registry entries.
------------------------------------------------







Aras Innovator Action Merge

Open Nash tool
Enter Password.
Use below AML to insert item.
Action Merge: If item exist, it will update. If item is not exist, it will create new item in Aras Innovator. type would be Part, Document ,Part BOM or Change

Thursday, 19 March 2015

Add SSIS to existing SQL Server 2014

Click on SQL server setup (Please note SSIS is not available in SQL server express edition. You need to have SQL server standard edition or higher)
Next Click on ‘New SQL server stand alone installation or add features to an existing installation”
Click Next
Again Click Next
Click on Add Feature to an existing instance of SQL server 2014 and click next
In next page scroll down and click the check box in front of ‘Integration services’ under Shared features
Click next
You will see the account under which SSIS will run, you can change it the service account you With which you run the SSIS later
Click Next
Features summary of SSIS installation will appear
Click Install
The last screen will show status as ‘Succeeded’
You can go to SQL server configuration manager to check that the Integration services are running
Open SQL server configuration manager
Click on SQL Server Services
You should see the SQL Server Integration services Running in the right panel

Converting a console application to a dll in c#

Right-click project -> Properties -> Output Type: 'Class Library'

A project with an Output type of Class Library cannot be started directly



Root cause: Your project Output type is : Class Library.
Solution: Your project Output Type either Console Application or Windows Application 

Steps:
Right click on project in Solution Explorer -> Properties.
In opened tab with properties, click on Application
You will find a comboBox marked with Output Type label.
Select either: Console Application or Windows Application

How to prevent XDocument from adding XML version and encoding information C#


Monday, 16 March 2015

Aras Innovator call C# dll

Create a class library from C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyClass
{
    public class DemoClass
    {

        public string strMy = "";
        public DemoClass(string s)
        {
            this.strMy = s;
        }

        public string GetMethod()
        {
            return "Hell world" + strMy;
        }

    }
}
Note: your class should be public.
Build
Copy the dll.
Go to Aras Server.
Paste your dll in this path: C:\Program Files (x86)\Aras\Innovator\Innovator\Server\bin
Now go to this path and open method-config.xml file.
C:\Program Files (x86)\Aras\Innovator\Innovator\Server\method-config.xml
In the xml file, go to this tag:
<MethodConfig> <ReferencedAssemblies>
Add new tag similar to : <name>$(binpath)/Conversion.Base.dll</name>
Now change dll name: ex: <name>$(binpath)/MyClass.dll</name>
Now in the same file, scroll down.
You will see name space section, where all .net name spaces are added.
Add your dll name space.
Ex: using MyClass;
Do for all references.
Save.
Now Open Aras Innovator from web UI.
Go to Administration
Methods
Right click: New Method
Enter method name,
Select Server-side
Select C#















Now use below IOM code.
IOM Code.
MyClass obj=new MyClass ("Welcome from aras");
Innovator innovator = this.getInnovator();
return innovator.newResult( obj.GetMethod());
Check the syntax.








Run the code using.
ActionsàRun Server Method.
You will get output.

How to set above code to a Item?
First create an Action.
In the action àIt will ask name, enter name.
It will ask method, Enter method name which you have created in earlier.
Save.
Now go to item.
Search for any item ex: “Parts”
Now open part.
Unlock
Under actions, add new action.
Search for your action which you have created.
Save.
Now go to Design
Parts
Search for any part.
Right click on the part you will see your action name.

Click it.

Friday, 6 March 2015

Visual studio run as administrator shortcut prompting for password

Solution:
First make sure you have added the user as administrator, who is trying to open visual studio as administrator.
It should resolve the issue.
If still you are getting the prompting for password
Login to your system as local administrator.
Go to Control Panel
Click on User Accounts
Click on User Accounts
Click on Change User Account Control Settings
You will get a prompt
Scroll down the bar up to Never notify
Ok
Restart the system
Now try, your problem should resolve.

Sunday, 1 March 2015

C# switch statement string contains

C# string replace with escape characters



Input argumenets
#to=test@gmail.com #subject="Welcome to" #server=mail.gmail.com #port=8080 #from=from@gmail.com

#to="test@gmail.com" #subject="Welcome" #server="mail.gmail.com" #port="8080" #from="from@gmail.com"

#to=\"test@gmail.com\" #subject=\"Welcome\" #server=\"mail.gmail.com\" #port=\"8080\" #from=\"from@gmail.com\"

Expected input string to application.
#to=\"test@gmail.com\" #subject=\"Welcome\" #server=\"mail.gmail.com\" #port=\"8080\" #from=\"from@gmail.com\"

Application will get Input argumenets in any format of give 3 type, but business will work for only one type of format, so we have to manipulate rest of the 2 types to 3rd type.

Solution:
I am going to write one exe, to manipulate input args.
Open Visual studio
Create new console project: StringEscapeCharacters
Open: Program.cs file

Please find my code...


Now i have to pass arguments to my exe, i can to multiple ways..
1st way: Open solution explorer, right click on project.
Click on: Properties
Click on: Debug
Under Start Options:
Command line arguments: <Enter arguments>
Ex:
#to=test@gmail.com #subject="Welcome to exe" #server=mail.gmail.com #port=8080 #from=from@gmail.com


You will get out put as in the log file:C:\Temp\mylog.log
#to="test@gmail.com" #subject="Welcome to exe" #server="mail.gmail.com" #port="8080" #from="from@gmail.com"

2nd way passing args:
Build the application.
now go to bin/debug folder,
you will see: StringEscapeCharacters.exe
execute this exe from cmd and pass args.
ex: StringEscapeCharacters.exe #to=test@gmail.com #subject="Welcome to exe" #server=mail.gmail.com #port=8080 #from=from@gmail.com