Opening a Project
This sample demonstrates event handling in the context of opening a project. It shows how to set the parameters for opening the project, retrieve a project interface and then open the project. This example uses the IProject81 (Open) IApplication81 (ExecutablePath) and SGWorld (OnLoadFinished) properties and methods.
private void OpenProject()
{
string tMsg = String.Empty;
// A. Set Project "Open" Method parameters
string tProjectUrl = @"C:\SomePath\SomeFile.fly";
bool bIsAsync = false;
string tUser = String.Empty;
string tPassword = String.Empty;
// B. Instantiate Terra Explorer Globe and retrieve Project Interface
try
{
var sgworld = newSGWorld81();
// C. Register to OnLoadFinished globe event
sgworld.OnLoadFinished += new_ISGWorld81Events_OnLoadFinishedEventHandler(OnProjectLoadFinished);
// D. Open Project in synchronous mode
sgworld.Project.Open(tProjectUrl, bIsAsync, tUser, tPassword);
MessageBox.Show("Opening project " + tProjectUrl + " in async mode");
}
catch (Exception ex)
{
tMsg = String.Format("OpenProjectButton_Click Exception: {0}", ex.Message);
MessageBox.Show(tMsg);
}
}
void OnProjectLoadFinished (bool bSuccess)
{
string tMsg = String.Empty;
try
{
// OnLoadFinished event Received
MessageBox.Show("Received project loaded event: " + ((bSuccess) ? "Success" : "Failure"));
}
catch (Exception ex)
{
tMsg = String.Format("OnProjectLoadFinished Exception: {0}", ex.Message);
MessageBox.Show(tMsg);
}
}