public void ExecuteTlOperation(ETimelogOperation operation) { ITimelogWrapper wrapper = new TimelogWrapper(this); CurrentOperation = operation; switch (operation) { case ETimelogOperation.GetTasks: { if (wrapper.IsValidSecurityToken()) { wrapper.GetTimelogTasks(); } else { //login has to be performed before if (isLoginBackground && !String.IsNullOrEmpty(url) && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password)) { wrapper.LoginTimelog(url, username, password); } else { timelogUsingView.ShowErrorMessage("You need to login to timelog first!"); timelogUsingView.NavigateLogin(); } } break; } case ETimelogOperation.UploadWorkunits: { if (wrapper.IsValidSecurityToken()) { ObservableCollection <WorkUnit> insertUnits = new ObservableCollection <WorkUnit>(); ObservableCollection <WorkUnit> updateUnits = new ObservableCollection <WorkUnit>(); foreach (WorkTask worktask in tlWorktaskCollection) { if (worktask.ToRegister) { WorkUnit _unit = new WorkUnit(); _unit.TaskID = worktask.TimelogTask.TimelogTaskID; _unit.StartDateTime = worktask.DayDate; _unit.EmployeeInitials = username; if (!String.Equals(worktask.WorkDescription, AppResources.ExampleTaskDescription)) { _unit.Description = worktask.WorkDescription; } _unit.EndDateTime = worktask.DayDate.AddTicks(worktask.WorkTimeTicks); _unit.Duration = TimeSpan.FromTicks(worktask.WorkTimeTicks); if (String.IsNullOrEmpty(worktask.TimelogWorkunitGUID)) { _unit.GUID = System.Guid.NewGuid(); insertUnits.Add(_unit); } else { _unit.GUID = System.Guid.Parse(worktask.TimelogWorkunitGUID); updateUnits.Add(_unit); } } } if (insertUnits.Count > 0 || updateUnits.Count > 0) { wrapper.UploadWorkunits(insertUnits, updateUnits); } } else { //login has to be performed before if (isLoginBackground && !String.IsNullOrEmpty(url) && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password)) { wrapper.LoginTimelog(url, username, password); } else { timelogUsingView.ShowErrorMessage("You need to login to timelog first!"); timelogUsingView.NavigateLogin(); } } break; } case ETimelogOperation.Login: { if (!String.IsNullOrEmpty(url) && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password)) { wrapper.LoginTimelog(url, username, password); } else { timelogUsingView.ShowErrorMessage("Make sure you typed in username, password and the timelogsite!"); } break; } } }
public void ChangeState(ETimelogState newState, ETimelogOperation operationRunning, string message) { CurrentState = newState; switch (operationRunning) { case ETimelogOperation.GetTasks: { switch (newState) { case ETimelogState.Error: { timelogUsingView.ShowErrorMessage(message); break; } } break; } case ETimelogOperation.UploadWorkunits: switch (newState) { case ETimelogState.Error: { timelogUsingView.ShowErrorMessage(message); break; } } break; case ETimelogOperation.Login: { switch (newState) { case ETimelogState.Successfull: { if (currentOperation != operationRunning) { ExecuteTlOperation(currentOperation); } else { //only navigate back in case the login is not automatically if (!isLoginBackground) { timelogUsingView.NavigateBack(); } } break; } case ETimelogState.Error: { timelogUsingView.ShowErrorMessage(message); timelogUsingView.NavigateLogin(); break; } } break; } } }