|
Right. As a feature in my Animation engine, I want to be able to read an XML file for frame information.
In the engine I have an enum for storing specific types of frames.
For example one being for where the bitmap of the frame is stored.
public enum BitmapLocations
{
InExe,
Filesystem
}
Now, I have a dataset for reading an XML file into. I can cast any standard types easily. Such as:
(string)row["name"]
But when it comes to this enum value, I keep getting an invalid cast exception. I've tried:
XML:
<location>InExe</location>
C#:
(BitmapLocation)row["location"]
And this throws the exception.
I've also tried assigning the enum values to a number and using that instead, but still no luck.
Any ideas?
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "But a fresh install - it's like having clean sheets" - C. Maunder Lounge 3 Mar '03
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
BitmapLocations dummy = BitmapLocations.InExe; // dummy assignment, does not matter
String s = "Filesystem";
// convert string to enum
BitmapLocations bl = (BitmapLocations) Enum.Parse(dummy.GetType(), s);
|
|
|
|
|
Hi,
We are soon going to start to distribute .NET components/controls.
If you have something for .NET you think could be sold please contact us at info[at]compona.com for more info.
//Roger
|
|
|
|
|
Hey .
As I understood , this property , if set explicitly , should
disable the autmatically expantion of the array when using "Add" ,when the Count equals to Capacity ..
well .. this doesn't work for me .
I just don't want the ArrayList to be expanded automatically when adding item , when Count equals to Capacity.
instead I'd expect that it will raise some exception .
of course I can do all that in my own class that using the ArrayList , but
I'd like that to be done in ArrayList itself .
anyone knows how to do it ?
Alex
ICQ : 10676475
email : alexyag@inter.net.il
===================================================
"The harder you fall, the higher you bounce." - American Proverb
|
|
|
|
|
I'm pretty sure Capacity just pre-assigns the memory, so if you have 5 items and a capacity of 10 then it's holding on to the memory for the other 5. But then when you put the 11th item in, your Capacity is increased to 11.
What do you actually want to do when item 11 is added?
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
Paul Riley wrote:
I'm pretty sure Capacity just pre-assigns the memory
Yes.
public virtual void System.Collections.ArrayList.set_Capacity(int value) {
object[] local0;
if (value != (int) this._items.Length) {
if (value < this._size)
throw new ArgumentOutOfRangeException(...);
if (value > 0) {
local0 = new Object[checked((uint) value)];
if (this._size > 0)
Array.Copy(this._items, 0, local0, 0, this._size);
this._items = local0;
return;
}
this._items = new Object[16];
}
}
|
|
|
|
|
You can fix the size of the ArrayList like so ...
// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add( "The" );
myAL.Add( "quick" );
myAL.Add( "brown" );
myAL.Add( "fox" );
myAL.Add( "jumped" );
myAL.Add( "over" );
myAL.Add( "the" );
myAL.Add( "lazy" );
myAL.Add( "dog" );
// Create a fixed-size wrapper around the ArrayList.
ArrayList myFixedSizeAL = ArrayList.FixedSize( myAL );
An exception will be thrown whenever yuo add or remove an item from
the array. However, you can modify the items currently in myFixedSizeAL.
|
|
|
|
|
In SQL Server is it possible to have a trigger that will throw an event which could be caught by C# program running in the back ground?
Is this even possible? If it is, have u any links to help/examples?
a better description of the problem...
What I want to happen is that when we import data in to our database
(INSERT) that a trigger is called.
The trigger passes that data into a validation tool that cleans that
data and writes it back to a new clean database.
There needs to be two tables, one containing the raw original data and
one containing the cleaned up data.
The reason this is not done using a program to load the data is to
ensure any data loaded in to the database is cleaned.
Tommy
|
|
|
|
|
Hello,
does anybody know a way to find out if the following array
contains a certain element without iterating through it?
int[] arr = {1,3,5,7...};
Thanx in advance...
Brian
|
|
|
|
|
Array.IndexOf
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
|
Dear all:
I would like to register personal protocol the same as http.
what I want is the look and feel the same as http, you know, the richtextbox support such protocol, while you typing http://w3c.org, then a link wa shown.
I do not want to use ole to solve this.
|
|
|
|
|
Lookup CodeProject for an auto-fill combo[^] article.
|
|
|
|
|
|
I need to be able to see the status a printer ie. Paper Jammed, On-Line, Off-Line etc. but have got no idea were to start looking?
|
|
|
|
|
I have been playing around with .NET remoting for a while (roughly two weeks), and today is the first time I noticed that the code in my remoted object is always being run on the client. I have made a benchmark test for this. When I run the test on my main machine (P4XP), I get in the 100's for the result. I start up a server session on a remote machine (ATHLON), and then I run, from P4XP, the same test, but supposedly on ATHLON. The big surprise is that I still get nearly the same benchmark result and I can see my CPU working 100%, on the local machine. When I run the other way around (from ATHLON to P4XP), I get the result for ATHLON, so I always get the result for the local machine. So my question is, is this normal behavior for .NET remoting? Can I do anything to offset the work to the remote machine? Your help is greatly appreciated.
--Dacris
|
|
|
|
|
Well, I've solved this problem. The remoting object was passed by-reference, but the remoting object was a collection of benchmark tests. The tests themselves were marked serializable, so they were run locally. Changing the tests to derive from MarshalByRefObject solved the problem.
--Dacris
|
|
|
|
|
i want to get username and password in active directory,but i don't konw how can i.
|
|
|
|
|
can I read a binary registry key in C# - or do I have to revert to C++?
Specifically, I'm trying to enumerate TIMEZONE information from the registry
(HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones), which turned from a little side hack into a complete research project
specifically the tzi value, which contains a binary Win32 TIME_ZONE_INFORMATION gives me headaches - esp. since it contans arrays.
Any idea how I can read it?
Italian is a beautiful language. amare means to love, and amara bitter.
sighist | Agile Programming | doxygen
|
|
|
|
|
To read from the registry you use the System.Win32.Registry class. The System.Win32.Registry class has a method for each "hive". Use one of the methods to return its key as a RegistryKey object. You get/set values as objects, using the GetValue and SetValue methods of the RegistryKey object.
|
|
|
|
|
The following is a chunk of code that I can't get to evaluate properly:
if( (lv.Tag.ToString().Equals((object)"dir")) )
{
MessageBox.Show("it's a dir")
}
else
{
MessageBox.Show("it's a file")
}
For example, if the value of "lv.Tag.ToString()" is "file", the expression evaluates to "true" and the "dir" branch is entered, so it thinks "file" an "dir" are equal.
if I change the chunk of code to reverse the logic like this:
if( (lv.Tag.ToString().Equals((object)"file")) )
{
MessageBox.Show("it's a file")
}
else
{
MessageBox.Show("it's a dir")
}
and send it a "dir" for the value of lv.Tag.ToString(), it evaluates to "false" and jumps to the proper logic...
Is this a known problem or am I doing something wrong...??
thanks.
|
|
|
|
|
I am using Crystal reports in my .NET project.
Do i need to buy any user/developer copy of
Crystal Reports when I am distributing the software?
(do I have to pay or not?)
I have legal copy of .NET, and I did not register with Crystal Reports (they let you use it when you are in development I guess)
PS.And their licensing aggreement is just so confusing.
Thanks
~Mithat
|
|
|
|
|
I have been trying to develop a connection gateway which opens a fixed number of connections to a database using OLEDB in c#. This gateway keeps those XX connections opens and the idea is to have a thread/Session request a connection, use it, then return back to the queue. The request and return operations utilize a unique string called a SessionID to determine which connection to put back on the queue. Since this object will be accessed from several threads I have been trying to make it thread safe, but I have not developed far enough in thread programming to utilize this successfully. I am going to paste the code here and see if any of you can determine what is wrong with the code. Any help would be greatly appreciated.
Thank you.
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Threading;
namespace FritoLay.Data.Gateway
{
///
/// Summary description for ConnectionGateway.
///
public class ConnectionGateway : System.ComponentModel.Component
{
// Maximum Number of Database Connections
const int MAX_CONNECTIONS = 50;
// Maximum Number of Iterations in Sleep thread.
const int MAX_LOOPS = 60;
// Database Connection String
protected string connectionString = "";
// List of assigned connections with unique SessionID as Key
private System.Collections.SortedList connections = new System.Collections.SortedList(50);
// Queue of ready to use connections
private System.Collections.Queue connectionQueue = new System.Collections.Queue(50);
// Thread safe version of the assigned connections
private System.Collections.SortedList synchConnections = null;
// Thread safe version of the ready to use connections
private System.Collections.Queue synchQueue = null;
// Mutex to control threaded access to the ready to use connection queue
private System.Threading.Mutex mutex;
System.TimeSpan tSpan = new System.TimeSpan(0, 0, 0, 0, 100);
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public ConnectionGateway(System.ComponentModel.IContainer container)
{
///
/// Required for Windows.Forms Class Composition Designer support
///
container.Add(this);
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.synchConnections = System.Collections.SortedList.Synchronized(this.connections);
this.synchQueue = System.Collections.Queue.Synchronized(this.connectionQueue);
this.mutex = new System.Threading.Mutex();
}
public ConnectionGateway()
{
///
/// Required for Windows.Forms Class Composition Designer support
///
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.synchConnections = System.Collections.SortedList.Synchronized(this.connections);
this.synchQueue = System.Collections.Queue.Synchronized(this.connectionQueue);
this.mutex = new System.Threading.Mutex();
}
#region Component Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
public string ConnectionString
{
get { return this.connectionString; }
set { this.connectionString = value; }
}
public void Initialize()
{
if(this.connectionString != "")
{
for(int i = 0; i < ConnectionGateway.MAX_CONNECTIONS; i++)
{
System.Data.OleDb.OleDbConnection cnn = new System.Data.OleDb.OleDbConnection(this.connectionString);
cnn.Open();
this.connectionQueue.Enqueue(cnn);
}
}
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
public System.Data.OleDb.OleDbConnection GetConnection(string SessionID)
{
lock(this.connections)
{
try
{
//if(this.connectionQueue.Count == 0)
//{
//System.Threading.ThreadStart ts = new System.Threading.ThreadStart(this.Sleep);
//System.Threading.Thread thread = new System.Threading.Thread(ts);
//thread.Name = "Sleeper";
//thread.Start();
//thread.Join();
//}
int counter = 0;
while(this.connections.Count == ConnectionGateway.MAX_CONNECTIONS)
{
Monitor.Wait(this.connections, tSpan);
Monitor.Pulse(this.connections);
if(counter > ConnectionGateway.MAX_LOOPS)
break;
counter++;
}
if(this.connectionQueue.Count == 0)
{
//this.mutex.ReleaseMutex();
throw new FritoLay.Data.Gateway.TimeOutException("No Available Connections");
}
System.Data.OleDb.OleDbConnection conn = (System.Data.OleDb.OleDbConnection)this.synchQueue.Dequeue();
this.synchConnections.Add(SessionID, conn);
return conn;
}
catch(System.Exception ex)
{
throw ex;
}
finally
{
}
}
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
public void ReturnConnection(string SessionID)
{
lock(this.connections)
{
try
{
System.Data.OleDb.OleDbConnection conn = (System.Data.OleDb.OleDbConnection)this.synchConnections.GetByIndex(this.connections.IndexOfKey(SessionID));
if(conn.State == System.Data.ConnectionState.Closed)
{
conn.ConnectionString = this.connectionString;
conn.Open();
}
if(conn.ConnectionString != this.connectionString)
{
conn.Close();
conn.ConnectionString = this.connectionString;
conn.Open();
}
this.synchQueue.Enqueue(conn);
this.synchConnections.Remove(SessionID);
}
catch(System.Exception ex)
{
throw ex;
}
finally
{
}
}
}
private void Sleep()
{
try
{
this.mutex.WaitOne();
int counter = 0;
while(counter <= ConnectionGateway.MAX_LOOPS)
{
Thread.Sleep(this.tSpan);
//Monitor.Wait(this.connectionQueue, tSpan);
if(this.connectionQueue.Count > 0)
{
Thread.CurrentThread.Abort();
break;
}
counter++;
}
}
catch(System.Exception ex)
{
}
finally
{
this.mutex.ReleaseMutex();
}
}
public void Terminate()
{
if(this.connectionQueue.Count > 0)
{
for(int i = 0; i < this.connectionQueue.Count; i++)
{
System.Data.OleDb.OleDbConnection conn = (System.Data.OleDb.OleDbConnection)this.connectionQueue.Dequeue();
conn.Close();
conn = null;
}
}
this.connectionQueue.Clear();
if(this.connections.Count > 0)
{
System.Collections.IEnumerator ie = this.connections.GetEnumerator();
while(ie.MoveNext())
{
System.Collections.DictionaryEntry de = (System.Collections.DictionaryEntry)ie.Current;
System.Data.OleDb.OleDbConnection conn = (System.Data.OleDb.OleDbConnection)de.Value;
conn.Close();
conn = null;
}
}
}
}
}
|
|
|
|
|
I have added a context menu to my TreeView, but when i use TreeView.SelectedNode it doesnt return the node that the user right clicked on only the node that was last left clicked.
Is there anyway to get a TreeView to select the node the mouse is over on right click?
Thanks
Tim
|
|
|
|
|
Use the "GetNodeAt" Function on the MouseDown event of the TreeView and then Set the SelectedNode to that one.
|
|
|
|