public override void Parse(AnpMsg cmd) { int i = 0; KwsID = cmd.Elements[i++].UInt64; Task = (KwsTask)cmd.Elements[i++].UInt32; }
/// <summary> /// "Import" a workspace that already exists in the KWM. /// </summary> private static void ImportExistingKws(Workspace kws, KwsCredentials creds) { KwsTask task = kws.Cd.CurrentTask; KLogging.Log("Import of existing workspace " + kws.InternalID + " with task " + task + " requested."); // We can only import workspaces that are stopped or working // offline. if (task != KwsTask.Stop && task != KwsTask.WorkOffline) { KLogging.Log("Skipping import due to incompatible task."); return; } // Update the credentials unless they were already accepted. if (kws.Cd.KcdState.LoginResult != KwsLoginResult.Accepted) { KLogging.Log("Updating workspace credentials."); creds.PublicFlag = kws.Cd.Credentials.PublicFlag; kws.Cd.Credentials = creds; } // Make the workspace work online. kws.Sm.RequestTaskSwitch(KwsTask.WorkOnline); // The workspace state has changed. kws.OnStateChange(WmStateChange.Permanent); }
/// <summary> /// Called when the current workspace task is switching. The default /// behavior is to fail if an exception occurred or if the new task /// is not Spawn or WorkOnline. /// </summary> public virtual void HandleTaskSwitch(KwsTask task, Exception ex) { if (ex != null || (task != KwsTask.Spawn && task != KwsTask.WorkOnline)) { if (ex == null) ex = new EAnpExInterrupted(); HandleFailure(ex); } }
/// <summary> /// Set the task the user would like to run when the WM starts. The /// current task is unaffected. /// </summary> public void SetUserTask(KwsTask userTask) { if ((userTask == KwsTask.Stop || userTask == KwsTask.WorkOffline || userTask == KwsTask.WorkOnline) && m_cd.UserTask != userTask) { m_cd.UserTask = userTask; m_kws.OnStateChange(WmStateChange.Permanent); } }
/// <summary> /// Called when the current workspace task is switching. The default /// behavior is to fail if an exception occurred or if the new task /// is not Spawn or WorkOnline. /// </summary> public virtual void HandleTaskSwitch(KwsTask task, Exception ex) { if (ex != null || (task != KwsTask.Spawn && task != KwsTask.WorkOnline)) { if (ex == null) { ex = new EAnpExInterrupted(); } HandleFailure(ex); } }
public override void HandleTaskSwitch(KwsTask task, Exception ex) { // Something went wrong. if (ex != null) { HandleFailure(ex); } else if (task != KwsTask.DeleteRemotely) { HandleFailure(new EAnpExInterrupted()); } // Check if we're ready to pass to the next step. else { UpdateDeleteRemotelyStepIfNeeded(); } }
/// <summary> /// Switch the current task to the task specified. Don't call this /// outside RequestSwitchTask() unless you know what you are doing. /// The state machine will run ASAP to handle the new state. /// </summary> private void SwitchTask(KwsTask task, Exception ex) { // The order of the calls is important here. WmSm.LockNotif(); Debug.Assert(m_taskSwitchFlag == false); m_taskSwitchFlag = true; m_cd.CurrentTask = task; StopAppIfNeeded(ex); DisconnectFromKcdIfNeeded(); LogoutIfNeeded(); StopRebuildIfNeeded(); UpdateKcdEventUpToDateState(); m_kws.OnStateChange(WmStateChange.Transient); RequestRun("task switch to " + task); m_taskSwitchFlag = false; WmSm.QueueNotif(new KwsSmNotifTaskSwitch(m_kws, task, ex)); WmSm.UnlockNotif(); }
/// <summary> /// Called when the current workspace task is switching. /// </summary> public virtual void HandleTaskSwitch(KwsTask task) { // Cancel the operation if we switch to an unexpected task. if (task != KwsTask.Spawn && task != KwsTask.WorkOnline) HandleMiscFailure(new Exception("interrupted operation")); }
/// <summary> /// Request a switch to the task specified, if possible. /// </summary> public void RequestTaskSwitch(KwsTask task) { RequestTaskSwitch(task, null); }
/// <summary> /// Request a switch to the task specified, if possible. 'Ex' is /// non-null if the task switch is occurring because an error occurred. /// </summary> public void RequestTaskSwitch(KwsTask task, Exception ex) { WmSm.LockNotif(); try { // Validate. if (m_taskSwitchFlag || task == KwsTask.Stop && !CanStop() || task == KwsTask.Spawn && !CanSpawn() || task == KwsTask.Rebuild && !CanRebuild() || task == KwsTask.WorkOffline && !CanWorkOffline() || task == KwsTask.WorkOnline && !CanWorkOnline() || task == KwsTask.DeleteLocally && !CanDeleteLocally() || task == KwsTask.DeleteRemotely && !CanDeleteRemotely()) { KLogging.Log("Request to switch to task " + task + " ignored."); return; } KLogging.Log("Switching to task " + task + "."); // Update some state prior to the task switch. if (task == KwsTask.Rebuild) { m_cd.MainStatus = KwsMainStatus.RebuildRequired; m_rebuildStep = KwsRebuildTaskStep.None; } else if (task == KwsTask.WorkOnline) { ResetKcdFailureState(); } else if (task == KwsTask.DeleteLocally) { m_cd.MainStatus = KwsMainStatus.OnTheWayOut; m_kws.AddToKwsRemoveTree(); m_kws.OnStateChange(WmStateChange.Permanent); } else if (task == KwsTask.DeleteRemotely) { ResetKcdFailureState(); m_deleteRemotelyStep = KwsDeleteRemotelyStep.ConnectedAndLoggedOut; } if (task == KwsTask.Spawn || task == KwsTask.Rebuild || task == KwsTask.WorkOffline || task == KwsTask.WorkOnline) { m_cd.LastException = null; m_kws.OnStateChange(WmStateChange.Permanent); } // Perform the task switch, if required. if (task != m_cd.CurrentTask) { SwitchTask(task, ex); } } catch (Exception ex2) { KBase.HandleException(ex2, true); } finally { WmSm.UnlockNotif(); } }
private void SetHomeTabInfos(Workspace kws) { if (kws == null) { panelHome.Visible = false; return; } panelHome.Visible = true; lblKAS.Text = kws.Kas.KasID.Host + ":" + kws.Kas.KasID.Port + " (ID: " + kws.GetExternalKwsID().ToString() + ")"; if (kws.AppException != null) { lblKasError.Text = Base.FormatErrorMsg("application error", kws.AppException); } else if (kws.Kas.ErrorEx != null) { lblKasError.Text = Base.FormatErrorMsg("KAS error", kws.Kas.ErrorEx); } else if ((kws.Sm.GetCurrentTask() != KwsTask.WorkOnline || (kws.Kas.ConnStatus != KasConnStatus.Connected && kws.Kas.ConnStatus != KasConnStatus.Connecting)) && (kws.KasLoginHandler.LoginResult != KwsLoginResult.Accepted && kws.KasLoginHandler.LoginResult != KwsLoginResult.None)) { lblKasError.Text = Base.FormatErrorMsg("login error", kws.KasLoginHandler.LoginResultString); if (kws.KasLoginHandler.LoginResult == KwsLoginResult.BadSecurityCreds && kws.KasLoginHandler.TicketRefusalString != "") { lblKasError.Text += Environment.NewLine + Base.FormatErrorMsg(kws.KasLoginHandler.TicketRefusalString); } } else { lblKasError.Text = ""; } // Determine the status to display and the task the user would // most likely want to undertake. KwsTask curTask = kws.Sm.GetCurrentTask(); String statusText = ""; bool btnEnabled = false; KwsTask btnTask = KwsTask.WorkOnline; String btnText = "Work online"; if (curTask == KwsTask.Spawn) { statusText = "Creating " + Base.GetKwsString(); } else if (curTask == KwsTask.Delete) { statusText = "Deleting " + Base.GetKwsString(); } else if (curTask == KwsTask.Rebuild) { statusText = "Rebuilding " + Base.GetKwsString(); } else if (curTask == KwsTask.Stop) { if (kws.MainStatus == KwsMainStatus.RebuildRequired) { statusText = "Rebuild required"; btnEnabled = true; btnTask = KwsTask.Rebuild; btnText = "Rebuild " + Base.GetKwsString(); } // Assume the workspace was disabled voluntarily and that // the user can work online. This is normally the case. else { statusText = Base.GetKwsString() + " disabled"; btnEnabled = true; } } else if (curTask == KwsTask.WorkOffline) { statusText = "Working offline"; btnEnabled = true; } else if (curTask == KwsTask.WorkOnline) { if (kws.IsOnlineCapable()) { statusText = "Working online"; btnEnabled = true; btnTask = KwsTask.WorkOffline; btnText = "Work offline"; } // We're not currently connecting but we can request to. else if (kws.Sm.CanWorkOnline()) { statusText = "Working offline"; btnEnabled = true; } // We're connecting, allow disconnection. else { statusText = "Connecting"; btnEnabled = true; btnTask = KwsTask.WorkOffline; btnText = "Cancel"; } } // Update the information. KwsStatus.Text = statusText; KwsStatus.ForeColor = m_uiBroker.Browser.GetKwsNodeByKws(kws).GetKwsIconImageKey(); KwsTaskBtn.Enabled = btnEnabled; KwsTaskBtn.Text = btnText; m_kwsTaskBtnTask = btnTask; // Set the workspace general information. picSecure.Visible = kws.CoreData.Credentials.SecureFlag; lblSecureNote.Visible = kws.CoreData.Credentials.SecureFlag; lblName.Text = kws.GetKwsName(); KwsUser creator = kws.CoreData.UserInfo.Creator; if (creator != null) { lblByName.Text = creator.UiFullName; lblByOrgName.Text = creator.OrgName; lblCreationDate.Text = Base.KDateToDateTime(creator.InvitationDate).ToString(); } else { lblByName.Text = lblByOrgName.Text = lblCreationDate.Text = ""; } }
/// <summary> /// Request a switch to the task specified, if possible. 'Ex' is /// non-null if the task switch is occurring because an error occurred. /// </summary> public void RequestTaskSwitch(KwsTask task, Exception ex) { WmSm.LockNotif(); try { // Validate. if (m_taskSwitchFlag || task == KwsTask.Stop && !CanStop() || task == KwsTask.Spawn && !CanSpawn() || task == KwsTask.Rebuild && !CanRebuild() || task == KwsTask.WorkOffline && !CanWorkOffline() || task == KwsTask.WorkOnline && !CanWorkOnline() || task == KwsTask.DeleteLocally && !CanDeleteLocally() || task == KwsTask.DeleteRemotely && !CanDeleteRemotely()) { KLogging.Log("Request to switch to task " + task + " ignored."); return; } KLogging.Log("Switching to task " + task + "."); // Update some state prior to the task switch. if (task == KwsTask.Rebuild) { m_cd.MainStatus = KwsMainStatus.RebuildRequired; m_rebuildStep = KwsRebuildTaskStep.None; } else if (task == KwsTask.WorkOnline) { ResetKcdFailureState(); } else if (task == KwsTask.DeleteLocally) { m_cd.MainStatus = KwsMainStatus.OnTheWayOut; m_kws.AddToKwsRemoveTree(); m_kws.OnStateChange(WmStateChange.Permanent); } else if (task == KwsTask.DeleteRemotely) { ResetKcdFailureState(); m_deleteRemotelyStep = KwsDeleteRemotelyStep.ConnectedAndLoggedOut; } if (task == KwsTask.Spawn || task == KwsTask.Rebuild || task == KwsTask.WorkOffline || task == KwsTask.WorkOnline) { m_cd.LastException = null; m_kws.OnStateChange(WmStateChange.Permanent); } // Perform the task switch, if required. if (task != m_cd.CurrentTask) SwitchTask(task, ex); } catch (Exception ex2) { KBase.HandleException(ex2, true); } finally { WmSm.UnlockNotif(); } }
public KwsSmNotifTaskSwitch(Workspace kws, KwsTask task, Exception ex) : base(kws) { Task = task; Ex = ex; }
public override void HandleTaskSwitch(KwsTask task, Exception ex) { // Something went wrong. if (ex != null) HandleFailure(ex); else if (task != KwsTask.DeleteRemotely) HandleFailure(new EAnpExInterrupted()); // Check if we're ready to pass to the next step. else UpdateDeleteRemotelyStepIfNeeded(); }
/// <summary> /// Set the task the user would like to run when the WM starts. The /// current task is unaffected. /// </summary> public void SetUserTask(KwsTask userTask) { if ((userTask == KwsTask.Stop || userTask == KwsTask.WorkOffline || userTask == KwsTask.WorkOnline) && m_kws.UserTask != userTask) { m_kws.UserTask = userTask; m_kws.SetDirty(); } }
/// <summary> /// Request a switch to the task specified, if possible. /// </summary> public void RequestTaskSwitch(KwsTask task) { try { // Validate. if (m_taskSwitchFlag || task == KwsTask.Stop && !CanStop() || task == KwsTask.Spawn && !CanSpawn() || task == KwsTask.Rebuild && !CanRebuild() || task == KwsTask.WorkOffline && !CanWorkOffline() || task == KwsTask.WorkOnline && !CanWorkOnline() || task == KwsTask.Remove && !CanRemove() || task == KwsTask.DeleteOnServer && !CanDeleteOnServer()) { Logging.Log("Request to switch to task " + task + " ignored."); return; } Logging.Log("Switching to task " + task + "."); // Update some state prior to the task switch. if (task == KwsTask.Rebuild) { m_kws.MainStatus = KwsMainStatus.RebuildRequired; m_rebuildStep = KwsRebuildTaskStep.None; } else if (task == KwsTask.WorkOnline) { ResetKasFailureState(); } else if (task == KwsTask.Remove) { m_kws.MainStatus = KwsMainStatus.OnTheWayOut; m_kws.AddToKwsRemoveTree(); m_kws.SetDirty(); } else if (task == KwsTask.DeleteOnServer) { ResetKasFailureState(); m_deleteOnServerStep = KwsDeleteOnServerStep.ConnectedAndLoggedOut; } if (task == KwsTask.Spawn || task == KwsTask.Rebuild || task == KwsTask.WorkOffline || task == KwsTask.WorkOnline) { m_kws.AppException = null; } // Perform the task switch, if required. if (task != m_currentTask) SwitchTask(task); // Update some state after the task switch. if (task == KwsTask.Spawn) { m_kws.NormalizeAppState(); } } catch (Exception ex) { Base.HandleException(ex, true); } }
/// <summary> /// Switch the current task to the task specified. Don't call this /// outside RequestSwitchTask() unless you know what you are doing. /// The state machine will run ASAP to handle the new state. /// </summary> private void SwitchTask(KwsTask task) { // The order of the calls is important here. Debug.Assert(m_taskSwitchFlag == false); m_taskSwitchFlag = true; m_currentTask = task; StopAppIfNeeded(); DisconnectFromKasIfNeeded(); LogoutIfNeeded(); StopRebuildIfNeeded(); m_kws.StateChangeUpdate(true); SetDeferredNotif("task switch to " + task); m_taskSwitchFlag = false; m_kws.FireKwsSmNotif(new KwsSmNotifEventArgs(KwsSmNotif.TaskSwitch, task)); }
/// <summary> /// Deserializing constructor. /// </summary> public Workspace(SerializationInfo info, StreamingContext context) { Int32 version = info.GetInt32("WorkspaceVersion"); InternalID = info.GetUInt64("m_internalID"); // This is an old workspace which needs to be rebuilt. if (version < 5) { FileKwsDeserializer dsr = (FileKwsDeserializer)KwmSpawner.Instance.KwmDsr.CurKwsDsr; // Get the folder information. try { dsr.FolderID = UInt64.Parse(info.GetString("m_parentFolderID").Substring(6)); dsr.FolderIndex = info.GetInt32("m_indexInFolder"); } catch (Exception) { } // Update the credentials. CoreData.Credentials = ((Credentials)info.GetValue("credentials", typeof(Credentials))).newCreds; // Set the rebuild information. MainStatus = KwsMainStatus.RebuildRequired; KwsRebuildInfo rebuildInfo = CoreData.RebuildInfo; rebuildInfo.DeleteCachedEventsFlag = true; rebuildInfo.DeleteLocalDataFlag = false; rebuildInfo.UpgradeFlag = true; if (version >= 3) { AppKfs appKfs = (AppKfs)info.GetValue("m_appKfs", typeof(AppKfs)); appKfs.Share.CompatLastKwsEventID = info.GetUInt64("m_lastEventID"); appKfs.Initialize(this); AppTree[KAnpType.KANP_NS_KFS] = appKfs; } } // Pre-desintermediation and later. else { MainStatus = (KwsMainStatus)info.GetValue("MainStatus", typeof(KwsMainStatus)); KAnpState = (KwsKAnpState)info.GetValue("KAnpState", typeof(KwsKAnpState)); CoreData = (KwsCoreData)info.GetValue("CoreData", typeof(KwsCoreData)); UserTask = (KwsTask)info.GetValue("UserTask", typeof(KwsTask)); // Post-desintermediation. if (version >= 6) { KasLoginHandler = (KwsKasLoginHandler)info.GetValue("KasLoginHandler", typeof(KwsKasLoginHandler)); AppException = (Exception)info.GetValue("AppException", typeof(Exception)); } } // Create a temporary KAS object. Kas = new WmKas(CoreData.Credentials.KasID); }
public KwsSmNotifEventArgs(KwsSmNotif type, KwsTask task) { Type = type; Task = task; }
public void UpdateUI(Workspace kws) { if (kws == null) return; // Determine the status to display and the task the user would // most likely want to undertake. KwsTask curTask = kws.Sm.GetCurrentTask(); String statusText = ""; bool btnEnabled = false; KwsTask btnTask = KwsTask.WorkOnline; String btnText = "Connect"; if (curTask == KwsTask.Spawn) { statusText = "Creating " + Base.GetKwsString(); } else if (curTask == KwsTask.Remove) { statusText = "Deleting " + Base.GetKwsString(); } else if (curTask == KwsTask.Rebuild) { statusText = "Rebuilding " + Base.GetKwsString(); } else if (curTask == KwsTask.Stop) { if (kws.MainStatus == KwsMainStatus.RebuildRequired) { statusText = "Rebuild required"; btnEnabled = true; btnTask = KwsTask.Rebuild; btnText = "Rebuild " + Base.GetKwsString(); } // Assume the workspace was disabled voluntarily and that // the user can work online. This is normally the case. else { statusText = Base.GetKwsString() + " disabled"; btnEnabled = true; } } else if (curTask == KwsTask.WorkOffline) { statusText = "Disconnected"; btnEnabled = true; } else if (curTask == KwsTask.WorkOnline) { if (kws.IsOnlineCapable()) { statusText = "Connected"; btnEnabled = true; btnTask = KwsTask.WorkOffline; btnText = "Disconnect"; } // We're not currently connecting but we can request to. else if (kws.Sm.CanWorkOnline()) { statusText = "Disconnected"; btnEnabled = true; } // We're connecting, allow disconnection. else { statusText = "Connecting"; btnEnabled = true; btnTask = KwsTask.WorkOffline; btnText = "Cancel"; } } else if (curTask == KwsTask.DeleteOnServer) { statusText = "Deleting from server..."; } // Update the information. KwsBrowserKwsNode node = UiBroker.Browser.GetKwsNodeByKws(kws); lblStatus.Text = statusText; lblStatus.ForeColor = node.GetKwsIconImageKey(); imgKwsStatus.Image = KwmMisc.GetKwmStateImageFromKey(lblStatus.ForeColor); btnKwsTask.Enabled = btnEnabled; btnKwsTask.Text = btnText; m_kwsTaskBtnTask = btnTask; picSecure.Visible = kws.CoreData.Credentials.SecureFlag; UpdateKwsNameLocation(); lblKwsName.Text = kws.GetKwsName(); KwsUser creator = kws.CoreData.UserInfo.Creator; if (creator != null) { DateTime creationDate = Base.KDateToDateTime(creator.InvitationDate); lblCreator.Text = creator.EmailAddress + " (" + creationDate.ToString("ddd, dd MMM yyyy") + ")"; } else { lblCreator.Text = "unkown"; } lblServer.Text = kws.Kas.KasID.Host + " (ID: " + kws.GetExternalKwsID() + ")"; SetKasErrorField(kws); }