views:

26

answers:

1

How can i get data from REMOTE database using OnStart method?

 protected override int OnStart(StudyLoaderArgs studyLoaderArgs)
        {
            ApplicationEntity ae = studyLoaderArgs.Server as ApplicationEntity;
            _ae = ae;

            EventResult result = EventResult.Success;
            AuditedInstances loadedInstances = new AuditedInstances();
            try
            {

                XmlDocument doc = RetrieveHeaderXml(studyLoaderArgs);
                StudyXml studyXml = new StudyXml();
                studyXml.SetMemento(doc);

                _instances = GetInstances(studyXml).GetEnumerator();

                loadedInstances.AddInstance(studyXml.PatientId, studyXml.PatientsName, studyXml.StudyInstanceUid);

                return studyXml.NumberOfStudyRelatedInstances;

            } 
            finally 
            {
                AuditHelper.LogOpenStudies(new string[] { ae.AETitle }, loadedInstances, EventSource.CurrentUser, result);
            }
        }

i need to use OnStart in main project. How cn i use or call OnStart method

A: 

Just a thought, OnStart is an event; if you can provide the StudyLoaderArgs some how, then you can move your code in Init(ApplicationEntity) method and call it like following:

Init(myStudyArgs);

and in OnStart:

protected override int OnStart(StudyLoaderArgs studyLoaderArgs)
{
    Init(StudyLoaderArgs.Server as ApplicationEntity);
}

--EDIT--

  1. Move existing OnStart() body in Init()

    void Init(ApplicationEntity ae) { EventResult result = EventResult.Success; AuditedInstances loadedInstances = new AuditedInstances(); try {

        XmlDocument doc = RetrieveHeaderXml(studyLoaderArgs);
        StudyXml studyXml = new StudyXml();
        studyXml.SetMemento(doc);
    
    
    
    _instances = GetInstances(studyXml).GetEnumerator();
    
    
    loadedInstances.AddInstance(studyXml.PatientId, studyXml.PatientsName, studyXml.StudyInstanceUid);
    
    
    return studyXml.NumberOfStudyRelatedInstances;
    
    } finally { AuditHelper.LogOpenStudies(new string[] { ae.AETitle }, loadedInstances, EventSource.CurrentUser, result); }

    }

  2. Call Init() from OnStart()

    protected override int OnStart(StudyLoaderArgs studyLoaderArgs) { ApplicationEntity ae = studyLoaderArgs.Server as ApplicationEntity; _ae = ae; Init(ae); }

  3. OnStart() is an event, and would be called upon service(assuming that it is a service) start. TO be more specific, events are not there to be called, rather events are raised as a notification that something has happened; all we do is handle the event; i.e. register a method as a handler for that event, and then that method will be invoked each time the event is raised.

So, to achieve want you want, you can call Init() rather than OnStart(); but to call Init() you will have to provide the input arguments, which is what my first sentence says - or it'd be something like OnStart(EventArgs.Empty);

Not sure if this answers your question, but above the top of my skull! (0:

KMan
i don't understand KMAN; can you give me som details???
programmerist
@Programmerist: Please see my edit in response to your comment.
KMan