{
private enum State
{
- Unknown,
+ None,
Created,
Started,
Resumed,
}
private ApplicationContext _context;
- private State _state = State.Unknown;
+ private State _state = State.None;
private AppControl _appcontrol;
protected Page MainPage { get; set; }
protected AppControl ReceivedAppControl { get { return _appcontrol; } }
+ protected ApplicationContext Context { get { return _context; } }
protected virtual void OnCreate() { }
protected virtual void OnStart() { }
}
}
+ internal void Terminate()
+ {
+ if (_state != State.None)
+ {
+ OnTerminate();
+ _state = State.None;
+ }
+ }
+
protected void StartActor(Type actorType, AppControl appControl)
{
_context.StartActor(actorType, appControl);
{
public static class Application
{
- private static Dictionary<string, Type> _actorMap = new Dictionary<string, Type>();
private static Dictionary<AppControlFilter, Type> _filterMap = new Dictionary<AppControlFilter, Type>();
private static List<ApplicationContext> _contextList = new List<ApplicationContext>();
private static Window _window = null;
public static event EventHandler ApplicationInit;
public static event EventHandler ApplicationExit;
- public static ApplicationContext CurrentContext { get { return _contextList.LastOrDefault(null); } }
+ private static ApplicationContext CurrentContext { get { return _contextList.LastOrDefault(null); } }
public static int Run(string[] args)
{
Interop.Application.UIAppLifecycleCallbacks ops;
ops.OnCreate = (userData) =>
{
- _contextList.Add(new ApplicationContext());
ApplicationInit(null, null);
if (_window == null)
_window = new Window();
{
if (item.Key.IsMatch(appControl))
{
- // Relaunch?
- if (appControl.IsLaunchOperation() && CurrentContext != null && !CurrentContext.Empty())
- {
- // TODO: Resume should be called by windows event
- CurrentContext.Resume();
- }
- // Create new context and new actor when launching first or receiving appcontrol except launch.
- else
+ if (CurrentContext == null || !appControl.IsLaunchOperation())
{
ApplicationContext ctx = new ApplicationContext();
+ ctx.ReleaseContext += Ctx_ReleaseContext;
_contextList.Add(ctx);
Actor actor = ctx.StartActor(item.Value, appControl);
-
- // TODO: Resume should be called by windows event
if (!_window.Visible) {
_window.Active();
_window.Show();
- actor.Resume();
+ ctx.Resume();
}
}
break;
};
ops.OnTerminate = (userData) =>
{
- // TODO: Remove context and actors
- ApplicationExit(null, null);
+ Exit();
};
TizenSynchronizationContext.Initialize();
return ret;
}
+ public static void Hide()
+ {
+ throw new NotImplementedException();
+ }
+
+ public static void Exit()
+ {
+ ApplicationExit(null, null);
+ throw new NotImplementedException();
+ }
+ private static void Ctx_ReleaseContext(object sender, EventArgs e)
+ {
+ var ctx = sender as ApplicationContext;
+ if (ctx != null)
+ {
+ _contextList.Remove(ctx);
+ if (_contextList.Count > 0)
+ {
+ Hide();
+ } else
+ {
+ Exit();
+ }
+ }
+ }
public static void AddActor(Type clazz)
{
if (!clazz.IsSubclassOf(typeof(Actor)))
throw new ArgumentException(clazz.FullName + " is not a subclass of Actor.");
- _actorMap[clazz.FullName] = clazz;
-
foreach (var prop in clazz.GetProperties())
{
foreach (var attr in prop.GetCustomAttributes(false))
{
private List<Actor> _actorList;
+ internal event EventHandler ReleaseContext;
+
internal Actor TopActor { get { return _actorList.LastOrDefault(null); } }
internal ApplicationContext()
return found;
}
+ internal void FinishActor(Actor actor)
+ {
+ Actor found = _actorList.Find(s => s == actor);
+ if (found == null)
+ {
+ throw new ArgumentException("Could not found the actor in current context.");
+ }
+
+ found.Pause();
+ found.Terminate();
+ _actorList.Remove(found);
+
+ if (IsEmpty())
+ {
+ ReleaseContext(this, null);
+ }
+ }
+
internal void Pause()
{
if (TopActor != null)
}
}
- internal bool Empty()
+ internal bool IsEmpty()
{
return _actorList.Count == 0;
}