[EditorBrowsable(EditorBrowsableState.Never)]
public static Session GetInstance(int sessionUID)
{
- s_sessionInstances.TryAdd(sessionUID, new Session(sessionUID));
+ if (!s_sessionInstances.ContainsKey(sessionUID))
+ s_sessionInstances.TryAdd(sessionUID, new Session(sessionUID));
return s_sessionInstances[sessionUID];
}
_replyMap[taskID] = (int result, IntPtr data) =>
{
- _replyMap.Remove((int)data);
try
{
CheckError((SessionError)result, "Interop failed to remove a subsession user");
+ task.SetResult(true);
}
catch (Exception exception)
{
task.SetException(exception);
return;
}
-
- task.SetResult(true);
+ finally
+ {
+ _replyMap.Remove((int)data);
+ }
};
SessionError ret = Interop.Session.SubsessionRemoveUser(SessionUID, userName, _replyMap[taskID], (IntPtr)taskID);
_replyMap[taskID] = (int result, IntPtr data) =>
{
- _replyMap.Remove((int)data);
-
try
{
CheckError((SessionError)result, "Interop failed to switch to a different subsession user");
+ task.SetResult(true);
}
catch (Exception exception)
{
task.SetException(exception);
return;
}
-
- task.SetResult(true);
+ finally
+ {
+ _replyMap.Remove((int)data);
+ }
};
SessionError ret = Interop.Session.SubsessionSwitchUser(SessionUID, userName, _replyMap[taskID], (IntPtr)taskID);
/// <exception cref="UnauthorizedAccessException">Not permitted</exception>
/// <exception cref="NotSupportedException">Not supported</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler<SwitchUserCompletionEventArgs> SwitchUserCompletion
+ public event EventHandler<SwitchUserCompletionEventArgs> SwitchUserCompleted
{
add
{
return;
Log.Error(SessionErrorFactory.LogTag, msg);
- SessionErrorFactory.ThrowException(ret);
+ Exception ex = SessionErrorFactory.CreateException(ret);
+ if (ex == null)
+ {
+ Log.Error(SessionErrorFactory.LogTag,
+ "Unexpected exception type for SessionError: " + Enum.GetName(typeof(SessionError), ret));
+ throw new InvalidOperationException("Unrecognized error");
+ }
+ throw ex;
}
private void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
{
internal const string LogTag = "Tizen.System.Session";
- internal static void ThrowException(SessionError err)
+ internal static Exception CreateException(SessionError err)
{
SessionError error = (SessionError)err;
if (error == SessionError.InvalidParameter)
{
- throw new ArgumentException("Invalid parameter");
+ return new ArgumentException("Invalid parameter");
}
else if (error == SessionError.Io)
{
- throw new IOException("I/O error");
+ return new IOException("I/O error");
}
else if (error == SessionError.OutOfMemory)
{
- throw new OutOfMemoryException("Out of memory");
+ return new InvalidOperationException("Out of memory");
}
else if (error == SessionError.AlreadyExists)
{
- throw new InvalidOperationException("Already exists");
+ return new InvalidOperationException("Already exists");
}
else if (error == SessionError.NotAvailible)
{
- throw new InvalidOperationException("Not availible");
+ return new InvalidOperationException("Not availible");
}
else if (error == SessionError.ResourceBusy)
{
- throw new InvalidOperationException("Resource busy");
+ return new InvalidOperationException("Resource busy");
}
else if (error == SessionError.PermissionDenied)
{
- throw new UnauthorizedAccessException("Permission denied");
+ return new UnauthorizedAccessException("Permission denied");
}
else if (error == SessionError.NotSupported)
{
- throw new NotSupportedException("Not supported");
+ return new NotSupportedException("Not supported");
}
- }
+ else
+ {
+ return null;
+ }
+ }
}
}