ok, I tried to include as little code as possible. The app uses three
different assemblies as follows:
//
//Here are the the code snippets of the classes in my TSC.VXMLEngine Assembly
//In a nutshell the VXmlApplication is a singleton class
//which has one VXmlDocuments object containing 0 -n VXmlDocument objects.
Each VXmlDocument contains 0 - n VXmlDialog objects
// when a VXmlDialog is added. I am calling RaiseEventDialogAdded of the
VXmlApplication Instanace which should fire the event
//but it doesn't
using System;
namespace TSC.VXMLEngine
{
public class VXmlApplication
{
private static volatile VXmlApplication _instance = null;
private static object syncRoot = new object();
public int iObjectID = 0;
//declare delegates (event handlers) for event subscribers
public delegate void DocumentAddedHandler(object sender, VXmlDocument
document);
public delegate void DialogAdded(object sender, VXmlDialog dialog);
//declare event for to be handled by the delegates
public event DocumentAddedHandler OnDocumentAdded;
public event DialogAdded OnDialogAdded;
private static volatile VXmlDocuments _vxmlDocuments;
// make the default constructor protected, so that no one can directly
create it.
protected VXmlApplication()
{
if (_vxmlDocuments == null)
_vxmlDocuments = new VXmlDocuments();
}
// public property that can only get the single instance of this class.
public static VXmlApplication Instance
{
get
{
// only create a new instance if one doesn't already exist.
if (_instance == null)
{
// use this lock to ensure that only one thread is access
// this block of code at once.
lock(syncRoot)
{
if (_instance == null)
{
_instance = new VXmlApplication(); //create new instance of this class
}
}
}
// return instance where it was just created or already existed.
return _instance;
}
}
public VXmlDocuments Documents
{
get
{
return _vxmlDocuments;
}
}
internal void RaiseEventDocumentAdded(VXmlDocument document)
{
//if anyone has subsribed, then notify them
if (OnDocumentAdded != null)
{
OnDocumentAdded(this, document);
}
}
internal void RaiseEventDialogAdded(VXmlDialog dialog)
{
//if anyone has subsribed, then notify them
if (OnDialogAdded != null)
{
OnDialogAdded(this, dialog);
}
}
}
public class VXmlDocument
{
private VXmlDialogs _dialogs;
private DocumentTypes _documentType;
private VXmlApplication _ownerApplication;
private string _name;
private string _fileName;
public VXmlDocument()
{
_dialogs = new VXmlDialogs();
}
public VXmlDialogs Dialogs
{
get
{
return _dialogs;
}
}
public string Name
{
get
{
return _name;
}
set
{
_name = value;
_fileName = _name + ".vxml";
}
}
}
public class VXmlDocuments
{
public VXmlDocuments()
{
}
public int Add(VXmlDocument value)
{
VXmlApplication.Instance.RaiseEventDocumentAdded(v alue);
return base.List.Add(value as VXmlDocument);
}
}
public abstract class VXmlDialog
{
public VXmlDialog()
{
}
}
public class VXmlDialogs
{
public VXmlDialogs()
{
}
public int Add(VXmlDialog value)
{
VXmlApplication.Instance.RaiseEventDialogAdded(val ue);
return base.List.Add(value as VXmlDialog);
}
}
}
//Here is my derived classes in a different assembly
using System;
using System.IO;
using TSC.VXMLEngine;
namespace SurveyCast.Designer.Engine.Voice
{
public class VoiceEngine : VXmlEngine
{
private static volatile VoiceEngine _instance = null;
private static object syncRoot = new object();
public int iObjectID = 0;
private SurveyCast.Designer.Engine.Voice.VoiceSurveyProjec t _currentSurvey;
// make the default constructor protected, so that no one can directly
create it.
protected VoiceEngine()
{
}
// public property that can only get the single instance of this class.
public static VoiceEngine Instance
{
get
{
// only create a new instance if one doesn't already exist.
if (_instance == null)
{
// use this lock to ensure that only one thread is access
// this block of code at once.
lock(syncRoot)
{
if (_instance == null)
_instance = new VoiceEngine(); //create new instance of this class
}
}
// return instance where it was just created or already existed.
return _instance;
}
}
public VoiceSurveyProject CreateSurveyProject()
{
//_currentSurvey = VoiceSurveyProject.Create();
_currentSurvey = new VoiceSurveyProject();
_currentSurvey.OnDialogAdded +=new
TSC.VXMLEngine.VXmlApplication.DialogAdded(_curren tSurvey_OnDialogAdded);
return _currentSurvey;
}
}
public class VoiceSurveyProject : VXmlApplication
{
private VXmlDocument _currentDocument;
//prevent direct creation
public VoiceSurveyProject()
{
}
public VXmlDocument CurrentDocument
{
get
{
return _currentDocument;
}
set
{
_currentDocument = value;
}
}
public static VoiceSurveyProject Create()
{
return new VoiceSurveyProject();
}
public void Load()
{
VXmlDocument document = new VXmlDocument();
document.Name = "Document1";
_currentDocument = document;
base.Documents.Add(document);
}
public void AddSingleChoice()
{
VoiceSingleChoice singleChoice = new VoiceSingleChoice();
_currentDocument.Dialogs.Add(singleChoice);
}
}
public class VoiceSingleChoice : VXmlDialog
{
public VoiceSingleChoice()
{
}
}
}
//finally, here is my windows application snippet
// note: the btnAddDialog_Click add a VoiceSingleChoice object which is a
VXmlDialog
using SurveyCast.Designer.Engine.Voice;
using TSC.VXMLEngine;
namespace SurveyCast.Designer.GUI.Voice
{
public class FormMain : System.Windows.Forms.Form
{
public FormMain()
{
AddEvents();
StartEngine();
}
private void StartEngine()
{
_voiceEngine = VoiceEngine.Instance;
_survey =_voiceEngine.CreateSurveyProject();
_survey.OnDialogAdded+=new
TSC.VXMLEngine.VXmlApplication.DialogAdded(_survey _OnDialogAdded);
_survey.Load();
}
private void btnAddDialog_Click(object sender, System.EventArgs e)
{
VoiceSingleChoice singleChoice = new VoiceSingleChoice();
_survey.CurrentDocument.Dialogs.Add(singleChoice);
}
private void _survey_OnDialogAdded(object sender, VXmlDialog dialog)
{
// I never get here
}
}
}
Whew! Hope you can figure out what I am trying to do.
Thanks for your help
"Jon Skeet [C# MVP]" wrote:
Opa <Op*@discussions.microsoft.com> wrote: I wasn't sure if it would get lost in the stack.
It won't. New posts will always show up as new posts.
Yes, I am still having this problem.
I've tried for hours to figure it out. I'm still no where, can you help.
Certainly. Just post a short but complete program which demonstrates
the problem, and I'm sure it won't be too hard to fix.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too