|
He shared it the VB in the office afterall. Might as well have qualified people look at it.
I was hoping it was a small snippet, not the usual CodeProject source code repository posting.
only two letters away from being an asset
|
|
|
|
|
I'll cut it down to a respectable size and post it shortly
|
|
|
|
|
Hi,
Code snippet is below. I've tried to include only sections that are of interest. When I instantiate this class, the addParameter method is run without invoking the public property AddParameter:
<br />
public class foo<br />
{<br />
<br />
private string[,] m_strParams = new string[c_RowArrayMaxValue,c_ColArrayMaxValue];<br />
private int m_ParamCount = 0;<br />
<br />
<br />
public Boolean AddParameter<br />
{<br />
get<br />
{<br />
return addParameter(m_ParamName, m_ParamValue, m_ParamDataType, ref m_ParamCount);<br />
}<br />
}<br />
<br />
<br />
protected Boolean addParameter(string strParamName, string strParamValue, string strParamDataType, ref int intParamCount)<br />
{<br />
<br />
try<br />
{<br />
<br />
m_strParams[Convert.ToInt32(intParamCount), 0] = strParamName;<br />
m_strParams[Convert.ToInt32(intParamCount), 1] = strParamValue;<br />
m_strParams[Convert.ToInt32(intParamCount), 2] = strParamDataType;<br />
<br />
intParamCount += 1;<br />
<br />
return true;<br />
}<br />
catch (Exception e)<br />
{<br />
Debug.WriteLine("Foo.cs - addParameter - Exception found: " + e.InnerException);<br />
return false;<br />
}<br />
}<br />
<br />
}<br />
Thanks,
Stuart
|
|
|
|
|
As metioned elsewhere in the thread, it's very possible that the debugger is evaluating the properties.
Why are you using a property to move data in the class? That contradicts what a property is intended for. Just make it a method, and the code almost makes sense.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
There is nothing in the code you have posted that would do that, although its obvious that you've missed out some of your original code as there are no m_ParamValue,m_ParamDataType etc variables defined.
However, the fact that a get accessor invokes the method you think is being called, makes me think you have a watch defined somewhere in the IDE which is being evaluated as soon as this object comes into scope.
|
|
|
|
|
Does this happen in Release mode?
I suspect the debugger is pulling all the protected properties to stick in the watch window
|
|
|
|
|
A former co-worker got stung with that one LOL...I had a good laugh. He was getting quite pissed off and swearing at these properties because they were getting called before running code that accessed them. I looked down at his watch window & had a big fat laugh.
Anyway, To the poster: If you've added these properties to the watch window OR if you even mouse over them while debugging, the code inside will be executed by the debugger WITHOUT stopping at your breakpoints inside the get/set.
|
|
|
|
|
Hi,
Thanks for this post; I removed the watch items related to the instantiated object, and this has resolved the issue with all methods being called.
Thanks,
Stuart
|
|
|
|
|
When I run in Release mode I get the same outcome.
|
|
|
|
|
Are you running in release mode through the IDE? i.e. debugging the release mode?
Is the "AddParameter" in your watch window? If so, remove it. In fact, remove everything from your watch window and DON'T use the mouseover in the debugger to see the public property value either. It will cause the code in the property to run and breakpoints will be ignored.
|
|
|
|
|
G'day,
I am quite new, developing C# applications and now I stuck. Maybe one of you guys might help me. I build a TreeView using a DataTemplate for displaying the item nodes. There are different type of item node. For one type I want to create a context menu. So far so good. When I click the item in the context menu, I need to get the object which is the source of the node item.
Here are the interesting code parts:
At first the XAML-Part:
<code>
<treeview name="tvExplorer">
<treeview.itemtemplateselector>
<pe:projectexplorertemplateselector />
</treeview.itemtemplateselector>
<treeview.resources>
<hierarchicaldatatemplate x:key="ProjectOpenTemplate" datatype="{x:Type pebe:Project}" itemssource="{Binding Path=ContentCategories}">
<stackpanel orientation="Horizontal">
<image source="../Media/applications_system.png" margin="1 1 2.5 1" width="16" height="16" />
<textblock text="{Binding Path=Name}" margin="2.5 1 1 1" />
<stackpanel.contextmenu>
<contextmenu name="potContext" opened="potContext_Opened">
<menuitem header="Close project" name="potContextClose" click="potContextClose_Click" />
<menuitem header="Rename" name="potContextRename" click="potContextRename_Click" />
<menuitem header="Properties" name="potContextOpenWith" />
</contextmenu>
</stackpanel.contextmenu>
</stackpanel>
</hierarchicaldatatemplate>
...
</treeview.resources></treeview></code>
Now the DataTemplateSelector:
<code>
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
FrameworkElement fe = container as FrameworkElement;
if (fe != null)
{
DataTemplate pot = fe.TryFindResource("ProjectOpenTemplate") as DataTemplate;
DataTemplate pct = fe.TryFindResource("ProjectCloseTemplate") as DataTemplate;
DataTemplate potCategories = fe.TryFindResource("ProjectCategoriesTemplate") as DataTemplate;
if (item is Project){
Project objProject = item as Project;
if (objProject.IsOpen && pot != null) {
return pot;
}
if (!objProject.IsOpen && pct != null) {
return pct;
}
}
...
</code>
And here comes the part where I am stucked, the click event for context menu item :
<code>
private void potContextClose_Click(object sender, RoutedEventArgs e)
{
MenuItem objMnuItem = sender as MenuItem;
var temp = VisualTreeHelper.GetParent(objMnuItem);
StackPanel stck = temp as StackPanel;
//How do I get tree node, which has opened the context menu
</code>
Unfortunately the right clicked tree node must not be the currently selected tree node.
Any ideas would be very appreciated.
Thanks in advance.
Rob
<div class="ForumMod">modified on Friday, February 29, 2008 10:45 AM</div>
|
|
|
|
|
RobSmith77 wrote: //How do I get tree node, which has opened the context menu
Never worked with WPF/XAML or .NET3, yet, not sure I ever want to but will probably have to, and this is from memory but I believe I dealt with that in the past by handling a mouse message like maybe rightclick and use the TreeView.HitTest or something to discover the node and cache it for use in the context menu handler.
Hope that helps
led mike
|
|
|
|
|
I will check this on monday, now it is time for weekend.
Have a nice weekend too and thanks for answering.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Data.SqlClient;
namespace GUI
{
public partial class GUI : Form
{
public GUI()
{
InitializeComponent();
}
private void GUI_Load(object sender, EventArgs e)
{
}
private void btnCreate_Click(object sender, EventArgs e)
{
if (ifthursday())
{
CreateDatabase(GetDatabasename());
CreateDatatable(GetTableName(), GetDatabasename());
}
}
///
/// Gets the name of the database from datetime picker and returns the value to the createDatabase Method
///
/// <returns>
///
public void Kill()
{
return;
}
public string GetDatabasename()
{
string namedatabase = dateTimePicker1.Value.ToString("MMdd");
string nameDB = "CustList_PGE_" + namedatabase;
MessageBox.Show("The name of the database will be CustList_PGE_" + namedatabase);
return nameDB;
}
public bool ifthursday()
{
//string dayisthursday= dateTimePicker1.Value.ToString("")
if (dateTimePicker1.Value.DayOfWeek.ToString().Equals("Thursday"))
{
MessageBox.Show("Thursday");
}
else if (MessageBox.Show("The selected date is not Thursday,Do you want to continue?", "Options", MessageBoxButtons.YesNo,MessageBoxIcon.Warning) == DialogResult.No)
{
return false;
}
return true;
}
///
/// Gets the name of the table from the datetime picker and returns the value to the createDatatable Method
///
/// <returns>
public string GetTableName()
{
string nameTable = dateTimePicker1.Value.ToString("MMddyy");
string nameTB = "CustList_PGE" + nameTable;
MessageBox.Show("The name of the Table will be CustList_PGE" + nameTable);
return nameTB;
}
//public void con()
//{
// Businesslayer.Businesslayer newobj = new Businesslayer.Businesslayer();
//}
///
///Creates an object to communicate to the Business Layer to create the DataBase
///
/// <param name="dbName" />
public int CreateDatabase(string dbName)
{
Businesslayer.Businesslayer createObj = new Businesslayer.Businesslayer();
int i=createObj.createDatabase(dbName);
if (i == 1801)
{
MessageBox.Show("The Database already exists");
return false;
}
}
///
/// Creates an object to communicate to the Business Layer for creating the Datatable
///
/// <param name="tableName" />
/// <param name="dbName" />
public void CreateDatatable(string tableName,string dbName)
{
Businesslayer.Businesslayer tableObj = new Businesslayer.Businesslayer();
tableObj.createTable(tableName, dbName);
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace Businesslayer
{
public class Businesslayer
{
//public void createObject()
//{
// Datalayer.Datalayer obj = new Datalayer.Datalayer();
//}
public int createDatabase(string databaseName)
{
Datalayer.Datalayer createObj = new Datalayer.Datalayer();
int i = createObj.CreateDatabase(databaseName);
return i;
}
public void createTable(string tableName,string dbName)
{
Datalayer.Datalayer tableObj = new Datalayer.Datalayer();
tableObj.createTable(tableName, dbName);
}
public void get(SqlException ex)
{
}
}
}
>>>>>>>>>>>>>>>>>>>
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace Datalayer
{
public class Datalayer
{
string Test3;
string Testldf3;
SqlConnection conObj;
public void conSql()
{
try
{
//string con = "Data Source=TSPL-DEV07;Initial Catalog=PGEImport;Integrated Security=True";
conObj = new SqlConnection();
conObj.ConnectionString = ConfigurationSettings.AppSettings["con"];
if (conObj.State == ConnectionState.Closed)
{
conObj.Open();
}
}
catch (SqlException ex)
{
}
}
public int CreateDatabase(string nameDB)
{
int value =0;
try
{
conSql();
SqlCommand cmdObj = new SqlCommand();
cmdObj.Connection = conObj;
cmdObj.CommandText = "CreateDataBases";
cmdObj.CommandType = System.Data.CommandType.StoredProcedure;
cmdObj.Parameters.AddWithValue("@databaseName", nameDB);
// cmdObj.Parameters.AddWithValue("@databaseName_Log", nameDB + "CustList_PGE_0228_log");
cmdObj.Parameters.AddWithValue("@databaseName_Log", nameDB + "_log");
//CreateStrings(nameDB);
string Assign = CreateStrings(nameDB);
CreateConnections(Assign, cmdObj);
string Assignldf = CreateStringsldf(nameDB);
CreateConnectionsldf(Assignldf, cmdObj);
value = cmdObj.ExecuteNonQuery();
#region Comments
// CreateConnections(CreateStrings());
//cmdObj. = ConfigurationSettings.AppSettings["pathM"];
//string Test = ConfigurationSettings.AppSettings["pathM"];
//string Test1 = nameDB+".mdf";
//string Test2 = Test;
//string Test3 = Test2 + Test1;
//cmdObj.Parameters.AddWithValue("@mdfName",Test3);
//string Testldf = ConfigurationSettings.AppSettings["pathL"];
//string Testldf1 = nameDB + ".ldf";
//string Testldf2 = Testldf;
//string Testldf3 = Testldf2 + Testldf1;
// cmdObj.Parameters.AddWithValue("@ldfName", Testldf3);
//cmdObj.Parameters.AddWithValue("@ldfName",Testldf);
//cmdObj.CommandText = ConfigurationSettings.AppSettings["pathL"];
//cmdObj.Parameters.AddWithValue("@mdfName", @"C:\mssql1\data\0225.mdf");
//cmdObj.Parameters.AddWithValue("@ldfName", @"C:\mssql1\data\0225.ldf");
#endregion
return value;
}
catch (SqlException ex)
{
if (ex.Number == 1801)
{
value = 1801;
}
return value;
}
finally
{
if (conObj.State == ConnectionState.Open)
{
conObj.Close();
}
}
}
public string CreateStrings(string nameDB)
{
string Test = ConfigurationSettings.AppSettings["pathM"];
string Test1 = nameDB + ".mdf";
string Test2 = Test;
Test3 = Test2 + Test1;
return Test3;
}
public string CreateStringsldf(string nameDB)
{
string Testldf = ConfigurationSettings.AppSettings["pathL"];
string Testldf1 = nameDB + ".ldf";
string Testldf2 = Testldf;
Testldf3 = Testldf2 + Testldf1;
return Testldf3;
}
public void getstringfromBL()
{
}
//public void CreateConnections(string Test3, Datalayer cmdObj)
//{
// cmdObj.Parameters.AddWithValue("@mdfName", Test3);
//}
public void CreateConnections(string Assign,SqlCommand cmdObj)
{
cmdObj.Parameters.AddWithValue("@mdfName", Test3);
}
public void CreateConnectionsldf(string Assignldf,SqlCommand cmdObj)
{
cmdObj.Parameters.AddWithValue("@ldfName", Testldf3);
}
public void createTable(string tableName, string nameDB)
{
conSql();
SqlCommand cmdObj = new SqlCommand();
try
{
cmdObj.Connection = conObj;
cmdObj.CommandText = "createTable";
cmdObj.CommandType = System.Data.CommandType.StoredProcedure;
cmdObj.Parameters.AddWithValue("@databaseName", nameDB);
cmdObj.Parameters.AddWithValue("@databaseTable", tableName);
cmdObj.Parameters.AddWithValue("@primaryKey", @"ClientCoCustListID");
cmdObj.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
}
}
}
}
|
|
|
|
|
|
35 postings, 5 of them voted 1, with one 2 voter. Think that speaks for itself.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Trustapple, Trustapple, Trustapple.... you just don't learn do you?
|
|
|
|
|
Last I checked, the CodeProject site didn't become a source code repository. You might want to ask an actual question on this code before someone start flaming you...oh, wait... My bad! I was too late!
|
|
|
|
|
You might want to consider investing in a source control system or moving this to the recylce bin. Either way, don't clutter up the forums. But I do have to catch you with this bit:
Trustapple wrote: try
{
cmdObj.Connection = conObj;
cmdObj.CommandText = "createTable";
cmdObj.CommandType = System.Data.CommandType.StoredProcedure;
cmdObj.Parameters.AddWithValue("@databaseName", nameDB);
cmdObj.Parameters.AddWithValue("@databaseTable", tableName);
cmdObj.Parameters.AddWithValue("@primaryKey", @"ClientCoCustListID");
cmdObj.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
}
}
Never ever catch an exception and do nothing with it - and certainly don't have a finally block that does nothing.
|
|
|
|
|
Hi all,
I have an application written in C#, and it is using P/Invoke to access functions defined in a custom (open source) dll, written in C++. My app is running as a service at client site, and occasionally it has failed, leaving an entry in the System Event Log, and the log message hasn't been terribly helpful. Basically it has said that an error occurred in this particular module (the native C++ one), but nothing more than that.
I have the full source code for this module, and I believe all compiler settings are correctly set in the release build configuration (Generate Debug Info, Program Database etc.). What is my best shot at getting as much information about the crash when it occurs?
Obviously, I'm handling all managed exceptions in my own code.
Any help whatsoever would be great.
Regards,
Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
You should be able to create a C++ / CLI mixed mode assembly that catches the native exception and then throws a managed exception back up to the C# code.
led mike
|
|
|
|
|
What is in the .NET3.x framework the "state of the art" way to implement role-based user authentication in a c# application?
I found some examples based on the "Authorization Manager" e.g. http://msdn.microsoft.com/msdnmag/issues/03/11/authorizationmanager/default.aspx
A solution with the "authorization manager" and the microsoft.interop.security.azroles.dll is from a functional view exactly what I would like to have but I suggest that it is not "state of the art" for a new application. I also found a lot of articles/examples on cardspace and concepts based on System.Security (Principal, Identity, etc.) but I don't see at the moment which of those implementation possibilities is the correct and best way for a new application. Thanks for any suggestions or hint or links on this topic.
|
|
|
|
|
rok0815 wrote: but I suggest that it is not "state of the art" for a new application.
See if this helps[^]
led mike
|
|
|
|
|
|
Member 4370898 wrote: i am fresh gruduate
I can see the education was well worth it.
only two letters away from being an asset
|
|
|
|
|