/// <summary> /// Process the request for authentication info /// </summary> /// <param name="req">HTTP Request</param> /// <returns>HTTP status code corresponding to authentication status</returns> public static HttpStatusCode AuthenticateUser(HttpRequestMessage req, TaskStore taskstore) { // Log function entrance LoggingHelper.TraceFunction(); User user = GetUserPassFromMessage(req); // if user/pass headers not found, return 400 Bad Request if (user == null) { // Log failure LoggingHelper.TraceError("Bad request: no user information found"); return HttpStatusCode.BadRequest; } try { // authenticate the user if (Membership.ValidateUser(user.Name, user.Password) == false) return HttpStatusCode.Forbidden; else return HttpStatusCode.OK; } catch (Exception) { // username not found - return 404 Not Found return HttpStatusCode.NotFound; } }
/// <summary> /// Persists a task's progress information to the task store /// </summary> /// <param name="progress">Percentual progress. Can be <c>null</c> or a value between 0 and 100.</param> /// <param name="message">Progress message. Can be <c>null</c>.</param> /// <param name="immediately">if <c>true</c>, saves the updated task entity immediately, or lazily with the next commit otherwise.</param> public virtual async Task SetProgressAsync(int?progress, string message, bool immediately = false) { if (progress.HasValue) { Guard.InRange(progress.Value, 0, 100, nameof(progress)); } // Update cloned task. ExecutionInfo.ProgressPercent = progress; ExecutionInfo.ProgressMessage = message; // Update original task. _originalExecutionInfo.ProgressPercent = progress; _originalExecutionInfo.ProgressMessage = message; if (immediately) { // Dont't let this abort the task on failure. try { await TaskStore.UpdateExecutionInfoAsync(_originalExecutionInfo); } catch { } } }
public static void ImportTasks() { var json = File.ReadAllText("../../../datasets/tasks.json"); var tasks = JsonConvert.DeserializeObject <IEnumerable <TaskDto> >(json); TaskStore.AddTasks(tasks); }
void reloadIter(TreeIter iter) { var task = getTask(iter); TaskStore.SetValue(iter, (int)ColAssign.Name, task.Name); TaskStore.SetValue(iter, (int)ColAssign.State, task.Status.ToString()); }
void removeTask(object sender, System.EventArgs e) { var task = GetSelectedTask(); var iter = GetSelectedIter().Value; Tasks.Remove(task); TaskStore.Remove(ref iter); }
void rebuildStore() { TaskStore.Clear(); CurrentFilter.ClearCache(); foreach (var task in Tasks.EnumerateRoots()) { addHerTaskToStore(task); } CurrentFilter.Refilter(); }
public void ImportOldRepository(string fromImportPath, string toRepoName, string toRepoPath = null) { Repository repository = _repoManager.GetOrCreateRepository(toRepoName, toRepoPath); TaskManager taskManager = TaskStore.LoadTaskManager(repository); var importerFactory = new ImporterFactory(); IImporter importer = importerFactory.CreateOldInfraImporter(); importer.ImportFromFileToTaskManager(fromImportPath, taskManager); TaskStore.SaveTaskManager(repository, taskManager); }
/// <summary> /// Gets the category selected in the category list. /// </summary> /// <returns>The selected category if any; <c>null</c> otherwise.</returns> public Category GetSelectedCat() { TreeIter selIter; if (TaskSelection.GetSelected(out selIter)) { selIter = CurrentFilter.ConvertIterToChildIter(selIter); var id = (int)TaskStore.GetValue(selIter, 0); return(Tasks.GetById <Category> (id)); } return(null); }
void nameChanged(object o, EditedArgs args) { TreeIter iter; CurrentFilter.GetIterFromString(out iter, args.Path); var storeIter = CurrentFilter.ConvertIterToChildIter(iter); var id = (int)TaskStore.GetValue(storeIter, (int)ColAssign.Id); var task = Tasks.GetById <Task> (id); task.Name = args.NewText; Debug.WriteLine(string.Format("{1} renamed task to {0}", task.Name, task.Id)); TaskStore.SetValue(storeIter, (int)ColAssign.Name, task.Name); }
public void Handle(DateTime startDate) { PrepareDataset(); Console.WriteLine("Pripravuje se prostredi"); TaskSearch = RunTask(() => SearchInsolvencyProceedings(startDate, DateTime.Now.AddDays(-1))); TaskWs = RunTasks(WsThreads, () => RequestsToWs()); TaskStore = RunTasks(StoreThreads, () => StoreToHlidacStatu()); var start = DateTime.Now; while (TaskStore.Any(t => t.Status == TaskStatus.Running)) { PrintHeader(); Console.WriteLine($" Nacteno z vyhledavani: {ReadFromSearch}"); Console.WriteLine($" Ceka na nacteni detailu: {ForDetailRequest.Count}"); Console.WriteLine($" Ceka a odeslani do hlidace: {ForStore.Count}"); Console.WriteLine($" Celkove ulozeno: {StoredItems}"); Console.WriteLine(); Console.WriteLine($" Odlisna spisova znacka: {InvalidFileNumber}"); Console.WriteLine($" Znepristupneno: {Disabled}"); Console.WriteLine(); Console.WriteLine($" Posledni nactene obdobi: {LastFinishedPeriodInSearch: dd.MM.yyyy}"); Console.WriteLine($" Posledni ulozeny zaznam: {LastStoredItem: dd.MM.yyyy}"); Console.WriteLine(); Console.WriteLine($" Vyhledavaci vlakno: {TaskSearch.Status}"); Console.WriteLine($" Vlakno WS: {string.Join(", ", TaskWs.Select(t => t.Status.ToString()))}"); Console.WriteLine($" Vlakno ukladani: {string.Join(", ", TaskStore.Select(t => t.Status.ToString()))}"); Console.WriteLine(); var duration = DateTime.Now - start; Console.WriteLine($" Doba behu: {duration.Hours:00}:{duration.Minutes:00}:{duration.Seconds:00}"); Console.WriteLine(); try { if (Errors.Any()) { Console.WriteLine($" Chyby:"); foreach (var error in Errors) { Console.WriteLine($" > {error}"); } } } catch (Exception) { // do nothing } Thread.Sleep(1000); } }
public bool Run(string[] args) { if (args.Length < 1) { PrintUsage(); return(false); } Command command; if (!_commands.TryGetValue(args[0], out command)) { _output.WriteLine("Unknown command '{0}'", args[0]); return(false); } try { command.Proc(args.Skip(1).ToArray()); switch (command.Type) { case CommandType.Task: ListNotDoneTasks(); if (_repoManager.HasRepository(_taskManager.RepositoryName)) { Repository repository = _repoManager.GetRepository(_taskManager.RepositoryName); TaskStore.SaveTaskManager(repository, _taskManager); } break; case CommandType.Repository: PrintRepositories(); TaskStore.SaveRepositoryManager(_repoManager); break; case CommandType.State: ListStates(); TaskStore.SaveStateManager(_stateManager); break; } return(true); } catch (Exception ex) { _output.WriteLine("Error: {0}", ex.Message); _output.WriteLine("Usage: <tw> {1} {2}", _ident, command.Name, command.UsageArgs); return(false); } }
public void ConvertVer1Repository(string repoName) { Repository repository = _repoManager.GetRepository(repoName); TaskManager taskManager = _taskManager.RepositoryName == repoName ? _taskManager : new TaskManager(Enumerable.Empty <TaskItem>(), repository.Name); var importerFactory = new ImporterFactory(); IImporter importer = importerFactory.CreateVer1Importer(); importer.ImportFromFileToTaskManager(repository.Path, taskManager); TaskStore.SaveTaskManager(repository, taskManager); _output.WriteLine("Repository '{0}' converted", repository.Name); }
static void Main(string[] args) { PathHelper.InitializeAppFolder(); RepositoryManager rm = TaskStore.LoadRepositoryManager(); TaskManager tm = TaskStore.LoadTaskManager(rm.CurrentRepository); StateManager sm = TaskStore.LoadStateManager(); var processor = new CommandProcessor(tm, rm, sm); processor.AddCommandsObject(new TaskCommands(tm, sm)); processor.AddCommandsObject(new RepositoryCommands(rm)); processor.AddCommandsObject(new StateCommands(sm)); processor.AddCommandsObject(processor); processor.Run(args); }
public void ExportTask(int taskIndex, string repoName) { TaskItem task = _taskManager.GetByIndex(taskIndex); Repository targetRepo = _repoManager.GetRepository(repoName); if (_taskManager.RepositoryName == targetRepo.Name) { throw new InvalidOperationException("Can't export task to the same repository"); } TaskManager targetTaskManager = TaskStore.LoadTaskManager(targetRepo); targetTaskManager.Import(task); TaskStore.SaveTaskManager(targetRepo, targetTaskManager); _output.WriteLine("Task {0}:'{1}' exported", task.Index, task.Name); }
/// <summary> /// </summary> /// <returns>The store level new task's iter</returns> /// <param name="iter">Store level iter</param> TreeIter addTask(TreeIter?iter) { Task task; if (iter == null) { task = Tasks.AddNew(); task.Name = "Nueva tarea"; return(TaskStore.AppendValues(task.Id, task.Name, task.Status.ToString())); } else { var master = Tasks.GetById <Task> ((int)TaskStore.GetValue(iter.Value, (int)ColAssign.Id)); task = master.CreateSubtask(); task.Name = task.MasterTask.Name + ".Nueva tarea"; //var storeIter = CurrentFilter.ConvertIterToChildIter (iter.Value); return(TaskStore.AppendValues(iter.Value, task.Id, task.Name, task.Status.ToString())); //return CurrentFilter.ConvertChildIterToIter (ret); } }
public void ImportFromFileToTaskManager(string fileName, TaskManager taskManager) { if (String.IsNullOrEmpty(fileName)) { throw new ArgumentException("fileName can't be null or empty", "fileName"); } if (taskManager == null) { throw new ArgumentNullException("taskManager"); } var oldTasks = TaskStore.LoadFromFile <List <T> >(fileName); if (oldTasks == null) { string message = String.Format("Can't load old tasks from '{0}'", fileName); throw new InvalidOperationException(message); } ConvertTasks(oldTasks, taskManager); }
/// <summary> /// Process the request for authentication info /// </summary> /// <param name="req">HTTP Request</param> /// <returns>HTTP status code corresponding to authentication status</returns> public static HttpStatusCode AuthenticateUserBAK(HttpRequestMessage req, TaskStore taskstore) { // Log function entrance LoggingHelper.TraceFunction(); User user = GetUserPassFromMessage(req); // if user/pass headers not found, return 400 Bad Request if (user == null) return HttpStatusCode.BadRequest; try { // look up the user name - if doesn't exist, return 404 Not Found var dbUser = taskstore.Users.Single<User>(u => u.Name == user.Name); if (dbUser == null) return HttpStatusCode.NotFound; try { // authenticate both username and password - if don't match, return 403 Forbidden dbUser = taskstore.Users.Single<User>(u => u.Name == user.Name && u.Password == user.Password); if (dbUser == null) return HttpStatusCode.Forbidden; // return 200 OK and user info return HttpStatusCode.OK; } catch (Exception) { // password doesn't match - return 403 Forbidden return HttpStatusCode.Forbidden; } } catch (Exception) { // username not found - return 404 Not Found return HttpStatusCode.NotFound; } }
public async Task <ProcessTaskEntity> CreateTaskAsync(int processInstanceId, int nodeId, string nodeName, ProcessItemType ItemType) { if (!ProcessItemCheck.IsTask(ItemType)) { throw new FlowNodeException(nodeName, "Task"); } ProcessTaskEntity task = new ProcessTaskEntity() { ProcessInstanceId = processInstanceId, FlowNodeId = nodeId, TaskId = nodeName, TaskType = ItemType, CreatedBy = GetUserId() }; TaskStore.Create(task); await SaveChangesAsync(); return(task); //TODO Add to history //AddHistory(proc.Name, pi.ProcessInstanceName, t.ProcessTaskName, string.Format("User: {0} Created Task '{1}'", user, proc.Name), user); }
Task getTask(TreeIter iter) { var id = (int)TaskStore.GetValue(iter, (int)ColAssign.Id); return(Tasks.GetById <Task> (id)); }
TreeIter addTask(TreeIter?iter, Task task) { return(iter == null? TaskStore.AppendValues(task.Id, task.Name, task.Status.ToString()) : TaskStore.AppendValues(iter.Value, task.Id, task.Name, task.Status.ToString())); }
/// <summary> /// Create a new user /// </summary> /// <param name="req">HTTP request</param> /// <param name="taskstore">The TaskStore database context</param> /// <param name="user">The new user information</param> /// <returns>The HTTP status code to return</returns> public static HttpStatusCode CreateUser(TaskStore taskstore, User user, out MembershipCreateStatus createStatus) { // Log function entrance LoggingHelper.TraceFunction(); try { // create the user using the membership provider MembershipUser mu = Membership.CreateUser(user.Name, user.Password, user.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { // create the user in the TaskStore user table User u = new User() { ID = (Guid)mu.ProviderUserKey /*Guid.NewGuid()*/, Name = user.Name, Password = user.Password, Email = user.Email }; taskstore.Users.Add(u); taskstore.SaveChanges(); // Log new user creation LoggingHelper.TraceInfo("Created new user " + user.Name); return HttpStatusCode.Created; } else { // Log failure LoggingHelper.TraceError("Failed to create new user " + user.Name); return HttpStatusCode.Conflict; } } catch (Exception) { createStatus = MembershipCreateStatus.DuplicateUserName; // Log new user creation LoggingHelper.TraceError("Failed to create new user " + user.Name); return HttpStatusCode.Conflict; } }
/// <summary> /// Common code to process a response body and deserialize the appropriate type /// </summary> /// <param name="resp">HTTP response</param> /// <param name="t">Type to deserialize</param> /// <returns>The deserialized object</returns> public static object ProcessRequestBody(HttpRequestMessage req, TaskStore taskstore, Type t) { // Log function entrance LoggingHelper.TraceFunction(); if (req == null) return null; object value = null; string contentType = req.Content.Headers.ContentType.MediaType; switch (contentType) { case "application/json": DataContractJsonSerializer dcjs = new DataContractJsonSerializer(t); value = dcjs.ReadObject(req.Content.ContentReadStream); break; case "text/xml": case "application/xml": DataContractSerializer dc = new DataContractSerializer(t); value = dc.ReadObject(req.Content.ContentReadStream); break; } if (value == null) { // Log error condition LoggingHelper.TraceError("ProcessRequestBody: content-type unrecognized: " + contentType); } // log the operation in the operations table try { User user = ResourceHelper.GetUserPassFromMessage(req); User dbUser = taskstore.Users.Single<User>(u => u.Name == user.Name && u.Password == user.Password); // initialize the body / oldbody object body = value; object oldBody = null; Type bodyType = t; // if this is an update, get the payload as a list if (req.Method == HttpMethod.Put) { IList list = (IList)value; oldBody = list[0]; body = list[1]; bodyType = body.GetType(); } Guid id = (Guid)bodyType.GetProperty("ID").GetValue(body, null); string name = (string)bodyType.GetProperty("Name").GetValue(body, null); // insert the operation into the Operations table Operation op = new Operation() { ID = Guid.NewGuid(), UserID = dbUser.ID, Username = dbUser.Name, EntityID = id, EntityName = name, EntityType = bodyType.Name, OperationType = req.Method.Method, Body = JsonSerialize(body), OldBody = JsonSerialize(oldBody), Timestamp = DateTime.Now }; taskstore.Operations.Add(op); int rows = taskstore.SaveChanges(); if (rows < 1) { // Log error condition LoggingHelper.TraceError("ProcessRequestBody: couldn't log operation: " + req.Method.Method); } } catch (Exception ex) { // Log error condition LoggingHelper.TraceError("ProcessRequestBody: couldn't log operation: " + ex.Message); } return value; }