In VS, uncheck Enable Just My Code option under Options->debugging->general, when a process crashed, go to Attach to Process->and choose the process, click on Break All breakpoints and should be able to view the stack trace and the line of code that caused the crashed.
Your operating system's system log may also have a crash report. The information will probably include the name of the module that caused the crash. On recent Windows versions, go to Start > Settings > Control Panel > Administrative Tools > Event Viewer. In the application tab, right-click on the event and select Properties. When you report the event, you should copy the information from the log.
Monday, January 24, 2011
Tuesday, January 18, 2011
Redirect console to a file
string sourceDirectory = @"C:\Log";
if (!Directory.Exists(sourceDirectory))
Directory.CreateDirectory(sourceDirectory);
//write to a log file also all the output messages for debugging later
using (FileStream fs = new FileStream(Path.Combine(sourceDirectory, "CreateGroups.log"), FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
Console.SetOut(sw);
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Starting to add group " + groupName);
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Found the NT directory.");
sw.Close();
}
}
if (!Directory.Exists(sourceDirectory))
Directory.CreateDirectory(sourceDirectory);
//write to a log file also all the output messages for debugging later
using (FileStream fs = new FileStream(Path.Combine(sourceDirectory, "CreateGroups.log"), FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
Console.SetOut(sw);
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Starting to add group " + groupName);
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Found the NT directory.");
sw.Close();
}
}
Monday, January 17, 2011
DirectoryServices, create groups, add users to group
using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
using System.Diagnostics;
using System.IO;
namespace CreateQSPRUserGroups
{
class Program
{
private string QTM_Directory = @"C:\Program Files\QUALCOMM\QDART\bin";
private const string SUBKEY = "Path";
private const string QSPR_POWER_USERS = "QSPR Power Users";
private const string QSPR_GROUP_DESCRIPTION = "QSPR Power Users have Engineer Privileges to run QSPR";
private const string QSPR_TECH_USERS = "QSPR Tech Users";
private const string QSPR_TECH_GROUP_DESCRIPTION = "QSPR Tech Users have Technician Privileges to run QSPR";
static void Main(string[] args)
{
//write to a log file also all the output messages for debugging later
using (FileStream fs = new FileStream("CreateGroups.log", FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
Console.SetOut(sw);
CreateUserGroup(QSPR_POWER_USERS, QSPR_GROUP_DESCRIPTION);
CreateUserGroup(QSPR_TECH_USERS, QSPR_TECH_GROUP_DESCRIPTION);
AddAdminUsersToGroup();
sw.Close();
}
}
}
private static void CreateUserGroup(string groupName, string groupDescription)
{
try
{
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Starting to add group " + groupName);
DirectoryEntry entry = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Found the NT directory.");
DirectoryEntry qtmGroup = entry.Children.Add(groupName, "group");
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Setup the group");
qtmGroup.Invoke("Put", new object[] { "Description", groupDescription });
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Setup the group's description");
qtmGroup.CommitChanges();
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + groupName + " added");
}
catch (Exception ex)
{
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + string.Format("Failed to create user group {0}, Error: {1}, InnerException: {2}",
groupName, ex.Message, ex.InnerException));
}
}
private static void AddAdminUsersToGroup()
{
try
{
DirectoryEntry AD3 = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
DirectoryEntry grp;
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Finding the QSPR Power users");
grp = AD3.Children.Find(QSPR_POWER_USERS, "group");
if (grp != null)
{
using (DirectoryEntry groupEntry = new DirectoryEntry("WinNT://./Administrators,group"))
{
foreach (object member in (System.Collections.IEnumerable)groupEntry.Invoke("Members"))
{
using (DirectoryEntry memberEntry = new DirectoryEntry(member))
{
try
{
grp.Invoke("Add", new object[] { memberEntry.Path.ToString() });
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Adding user " + memberEntry.ToString());
}
catch (Exception ex)
{
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "User already added." + ex.Message);
}
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + string.Format("Add admin users failed, Error: {0}, InnerException: {1}", ex.Message, ex.InnerException));
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
using System.Diagnostics;
using System.IO;
namespace CreateQSPRUserGroups
{
class Program
{
private string QTM_Directory = @"C:\Program Files\QUALCOMM\QDART\bin";
private const string SUBKEY = "Path";
private const string QSPR_POWER_USERS = "QSPR Power Users";
private const string QSPR_GROUP_DESCRIPTION = "QSPR Power Users have Engineer Privileges to run QSPR";
private const string QSPR_TECH_USERS = "QSPR Tech Users";
private const string QSPR_TECH_GROUP_DESCRIPTION = "QSPR Tech Users have Technician Privileges to run QSPR";
static void Main(string[] args)
{
//write to a log file also all the output messages for debugging later
using (FileStream fs = new FileStream("CreateGroups.log", FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
Console.SetOut(sw);
CreateUserGroup(QSPR_POWER_USERS, QSPR_GROUP_DESCRIPTION);
CreateUserGroup(QSPR_TECH_USERS, QSPR_TECH_GROUP_DESCRIPTION);
AddAdminUsersToGroup();
sw.Close();
}
}
}
private static void CreateUserGroup(string groupName, string groupDescription)
{
try
{
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Starting to add group " + groupName);
DirectoryEntry entry = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Found the NT directory.");
DirectoryEntry qtmGroup = entry.Children.Add(groupName, "group");
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Setup the group");
qtmGroup.Invoke("Put", new object[] { "Description", groupDescription });
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Setup the group's description");
qtmGroup.CommitChanges();
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + groupName + " added");
}
catch (Exception ex)
{
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + string.Format("Failed to create user group {0}, Error: {1}, InnerException: {2}",
groupName, ex.Message, ex.InnerException));
}
}
private static void AddAdminUsersToGroup()
{
try
{
DirectoryEntry AD3 = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
DirectoryEntry grp;
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Finding the QSPR Power users");
grp = AD3.Children.Find(QSPR_POWER_USERS, "group");
if (grp != null)
{
using (DirectoryEntry groupEntry = new DirectoryEntry("WinNT://./Administrators,group"))
{
foreach (object member in (System.Collections.IEnumerable)groupEntry.Invoke("Members"))
{
using (DirectoryEntry memberEntry = new DirectoryEntry(member))
{
try
{
grp.Invoke("Add", new object[] { memberEntry.Path.ToString() });
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "Adding user " + memberEntry.ToString());
}
catch (Exception ex)
{
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + "User already added." + ex.Message);
}
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("{0} - ", DateTime.Now) + string.Format("Add admin users failed, Error: {0}, InnerException: {1}", ex.Message, ex.InnerException));
}
}
}
}
Monday, January 10, 2011
Serialize and deserialize an xml file and convert to xsd
http://msdn.microsoft.com/en-us/library/2baksw0z.aspx on Controlling XML Serialization Using Attributes
- Convert an xml file to xsd by using the VS command promt xsd.exe /c filename.xml to get xsd
- convert from an xsd to .net class xsd.exe /c filename.xsd to get .cs file
can use XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
writer = XmlWriter.Create(Console.Out, settings);
public void SaveParamViewLayout()
{
TextWriter writer = null;
try
{
string fileNameGridLayout = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), Path.Combine(QTM.FeatureConfigInfo.ConfigDirectory, ConfigFileNameConst.TTD_PARAM_VIEW_LAYOUT_FNAME));
ParamViewLayout currLayout = new ParamViewLayout(ultraGridInput.Size, ultraGridOutput.Size);
writer = new StreamWriter(fileNameGridLayout);
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(ParamViewLayout));
//serialize it to the file
x.Serialize(writer, currLayout);
writer.Close();
}
catch
{ }
finally
{
if (writer != null)
writer.Close();
}
}
private void RestoreParamViewLayout()
{
FileStream fs = null;
try
{
string fileNameGridLayout = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), Path.Combine(QTM.FeatureConfigInfo.ConfigDirectory, ConfigFileNameConst.TTD_PARAM_VIEW_LAYOUT_FNAME));
if (File.Exists(fileNameGridLayout))
{
ParamViewLayout layout;
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(ParamViewLayout));
fs = new FileStream(fileNameGridLayout, FileMode.Open);
layout = (ParamViewLayout)x.Deserialize(fs);
fs.Close();
ultraGridInput.Dock = DockStyle.None;
ultraGridOutput.Dock = DockStyle.None;
ultraGridInput.Size = layout.inputParamSize;
ultraGridOutput.Size = layout.outputParamSize;
ultraGridInput.Dock = DockStyle.Fill;
ultraGridOutput.Dock = DockStyle.Bottom;
}
}
catch //(Exception)
{
//ignore this exception
}
finally
{
if (fs != null)
fs.Close();
}
}
- Convert an xml file to xsd by using the VS command promt xsd.exe /c filename.xml to get xsd
- convert from an xsd to .net class xsd.exe /c filename.xsd to get .cs file
can use XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
writer = XmlWriter.Create(Console.Out, settings);
public void SaveParamViewLayout()
{
TextWriter writer = null;
try
{
string fileNameGridLayout = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), Path.Combine(QTM.FeatureConfigInfo.ConfigDirectory, ConfigFileNameConst.TTD_PARAM_VIEW_LAYOUT_FNAME));
ParamViewLayout currLayout = new ParamViewLayout(ultraGridInput.Size, ultraGridOutput.Size);
writer = new StreamWriter(fileNameGridLayout);
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(ParamViewLayout));
//serialize it to the file
x.Serialize(writer, currLayout);
writer.Close();
}
catch
{ }
finally
{
if (writer != null)
writer.Close();
}
}
private void RestoreParamViewLayout()
{
FileStream fs = null;
try
{
string fileNameGridLayout = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), Path.Combine(QTM.FeatureConfigInfo.ConfigDirectory, ConfigFileNameConst.TTD_PARAM_VIEW_LAYOUT_FNAME));
if (File.Exists(fileNameGridLayout))
{
ParamViewLayout layout;
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(ParamViewLayout));
fs = new FileStream(fileNameGridLayout, FileMode.Open);
layout = (ParamViewLayout)x.Deserialize(fs);
fs.Close();
ultraGridInput.Dock = DockStyle.None;
ultraGridOutput.Dock = DockStyle.None;
ultraGridInput.Size = layout.inputParamSize;
ultraGridOutput.Size = layout.outputParamSize;
ultraGridInput.Dock = DockStyle.Fill;
ultraGridOutput.Dock = DockStyle.Bottom;
}
}
catch //(Exception)
{
//ignore this exception
}
finally
{
if (fs != null)
fs.Close();
}
}
Subscribe to:
Posts (Atom)