/// <summary>
        /// Funkcja zwraca kolor na podstawie statusu Tasku
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        private Color getColorByTaskStatus(Task.TaskStatus status)
        {
            Color c = Color.Violet;

            switch (status)
            {
            case Task.TaskStatus.DONE:
                c = Color.Green;
                break;

            case Task.TaskStatus.INPROGRESS:
                c = Color.Blue;
                break;

            case Task.TaskStatus.OVERTIME:
                c = Color.Red;
                break;

            case Task.TaskStatus.PLANNED:
                c = Color.Black;
                break;

            default:
                c = Color.Gray;
                break;
            }
            return(c);
        }
Exemple #2
0
 public static TaskViewModel.TaskStatus ToTaskViewModelStatus(this Task.TaskStatus status)
 {
     return(status switch
     {
         Task.TaskStatus.Completed => TaskViewModel.TaskStatus.Completed,
         Task.TaskStatus.InProgress => TaskViewModel.TaskStatus.InProgress,
         _ => TaskViewModel.TaskStatus.ToDo
     });
        void btx_DrawText(object sender, Aga.Controls.Tree.NodeControls.DrawEventArgs e)
        {
            Task t = e.Node.Tag as Task;

            e.TextColor = Color.Black;
            Task.TaskStatus status = Task.TaskStatus.ERROR;
            if (t != null)
            {
                status = t.Status;
            }
        }
        /// <summary>
        /// Funkcja obsługująca zdarzenie DrawText na NodeControlle. Bierze status Tasku i zmienia kolor
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btx_DrawText_ColorBlock(object sender, Aga.Controls.Tree.NodeControls.DrawEventArgs e)
        {
            Task t = e.Node.Tag as Task;

            e.TextColor = t.getFontColor();
            Task.TaskStatus status = Task.TaskStatus.ERROR;
            if (t != null)
            {
                status = t.Status;
            }
        }
Exemple #5
0
        public Tuple <List <Task>, List <string> > GetTasksByStatus(Task.TaskStatus status)
        {
            var result = MakeResultTuple();

            using (var db = new ToDoListContext())
            {
                var query = db.Tasks.Where(t => t.Status == status);
                var tasks = RunQueryable(query, result.Item2);
                result.Item1.AddRange(tasks);
            }
            return(result);
        }
        /// <summary>
        /// Funkcja obsługująca zdarzenie DrawText na NodeControlle. Bierze status Tasku i zmienia kolor
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btx_DrawText(object sender, Aga.Controls.Tree.NodeControls.DrawEventArgs e)
        {
            Task t = e.Node.Tag as Task;

            Task.TaskStatus status = Task.TaskStatus.ERROR;
            Color           c      = Color.Violet;

            if (t != null)
            {
                status = t.Status;
            }
            e.TextColor = getColorByTaskStatus(status);
        }
Exemple #7
0
        private Task.OutputComponent AddTaskOutputComponent(string ResourceId, Task.TaskStatus Status)
        {
            var TaskOutputComponent = new Task.OutputComponent();

            TaskOutputComponent.Type        = new CodeableConcept();
            TaskOutputComponent.Type.Coding = new List <Coding>();
            var StatusCoding = new Coding("http://hl7.org/fhir/task-status", Status.GetLiteral(), Status.GetLiteral());

            TaskOutputComponent.Type.Coding.Add(StatusCoding);
            var Ref = new ResourceReference($"{ResourceType.CompartmentDefinition.GetLiteral()}/{ResourceId}");

            TaskOutputComponent.Value = Ref;
            return(TaskOutputComponent);
        }
        private void ProcessCompositeSearchParameters()
        {
            List <SearchParameter> CompositeSearchParameterList = GetCompositeSearchParameterList();

            foreach (SearchParameter SearchParam in CompositeSearchParameterList)
            {
                TotalCounter++;
                IGlobalProperties.ServerReadOnlyModeMessage = SetServerReadOnlyMessage(TotalCounter, _SearchParameterBundle.Entry.Count, _Task.Id);

                using (DbContextTransaction TransactionSet = IUnitOfWork.BeginTransaction())
                {
                    IGlobalProperties.ServerReadOnlyModeMessage = SetServerReadOnlyMessage(TotalCounter, _SearchParameterBundle.Entry.Count, _Task.Id);
                    try
                    {
                        _ResourceIdInProgress = SearchParam.Id;
                        AddSearchParameterResourceToServer(SearchParam);

                        if (!SetSearchParameterServerIndex(SearchParam.Id))
                        {
                            IGlobalProperties.ServerReadOnlyMode = false;
                            ICacheClear.ClearCache();
                            throw new Exception("Failed to Set index!");
                        }
                        _SearchParameterResourceProcessedIdList.Add(_ResourceIdInProgress);
                        TransactionSet.Commit();
                    }
                    catch (Exception Exec)
                    {
                        TransactionSet.Rollback();
                        using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
                        {
                            _InErrorMessage    = Exec.Message;
                            _ResourceIdInError = _ResourceIdInProgress;
                            _CurrentTaskStatus = Task.TaskStatus.Failed;
                            SetParametersOnFailedTaskLoad(_Task);
                            IFhirTaskTool.UpdateTaskAsStatus(_Task.Status.Value, _Task);
                            Transaction.Commit();
                            break;
                        }
                    }
                }
            }
        }
        public bool UpdateTaskAsStatus(Task.TaskStatus TaskStatus, Task Task)
        {
            try
            {
                //Set the task status only if it has not been updated since we got it from the server, using the IfMatch hearder and the VersionId
                var RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{Task.ResourceType.GetLiteral()}/{Task.Id}");
                RequestMeta.RequestHeader         = IRequestHeaderFactory.CreateRequestHeader();
                RequestMeta.RequestHeader.IfMatch = Common.Tools.HttpHeaderSupport.GetETagString(Task.VersionId);

                //Update the Task Properties
                Task.Status = TaskStatus;
                Task.LastModifiedElement = new FhirDateTime(DateTimeOffset.Now);

                this.IResourceTriggerService.TriggersActive = false;
                IResourceServiceOutcome PutResourceServiceOutcome = IResourceServices.Put(Task.Id, Task, RequestMeta);
                this.IResourceTriggerService.TriggersActive = true;
                if (PutResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    Task = PutResourceServiceOutcome.ResourceResult as Task;
                    return(true);
                }
                else if (PutResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    ILog.Error($"Internal Server Error: UpdateTaskAsStatus failed due to Version Conflict, Task reference was: {Task.ResourceType.GetLiteral()}/{Task.Id}/_history/{Task.VersionId}.");
                    return(true);
                }
                else if (PutResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.Created)
                {
                    ILog.Error($"Internal Server Error: UpdateTaskAsStatus failed due to 201 Create being returned when OK Update was expected, Transaction was rolled back. Task reference was: {Task.ResourceType.GetLiteral()}/{Task.Id}");
                    return(false);
                }
                else
                {
                    ILog.Error($"Internal Server Error: UpdateTaskAsStatus failed due to unexpected HTTP status code return, code was {PutResourceServiceOutcome.HttpStatusCode.ToString()}. Task reference was: {Task.ResourceType.GetLiteral()}/{Task.Id}/_history/{Task.VersionId}");
                    return(false);
                }
            }
            catch (Exception Exec)
            {
                ILog.Error(Exec, $"ResourceSeeding on Startup, PUT operations failed with exception. Task reference was: {Task.ResourceType.GetLiteral()}/{Task.Id}/_history/{Task.VersionId}");
                return(false);
            }
        }
        public Task.TaskStatus Run(Task Task)
        {
            _Task = Task;
            IGlobalProperties.ServerReadOnlyMode        = true;
            IGlobalProperties.ServerReadOnlyModeMessage =
                "The server is currently running a first time start-up task which loads all the base FHIR " +
                "specification search parameter resources as active search indexes within the Pyro FHIR server. " +
                $"This Task can be monitored by performing a GET on the servers Task endpoint for the Id of '{_Task.Id}'. " +
                $"For example: 'GET [base]/Task/{_Task.Id}'. While this Task is in progress the server can not allow resource writes " +
                $"to the server as these resources would not have their search parameter values indexed. Only once the Task is finished " +
                $"and all base search parameters are loaded will the server automatically switch out of read only mode. ";



            _SearchParameterResourceProcessedIdList = new List <string>();
            try
            {
                _Task.ExecutionPeriod = new Period();
                _Task.ExecutionPeriod.StartElement = new FhirDateTime(DateTimeOffset.Now);
                //Update the status of the task so that no other processes (instances of the server) also try and process this task can start it.
                //If this fails do nothing as we are to assume some other process is working on this task, just return InProgress.
                if (!IFhirTaskTool.UpdateTaskAsStatus(Task.TaskStatus.InProgress, _Task))
                {
                    IGlobalProperties.ServerReadOnlyMode = false;
                    ICacheClear.ClearCache();
                    return(Task.TaskStatus.InProgress);
                }

                SetParametersBeforeRunningTaskLoad(_Task);

                _Task.Output = new List <Task.OutputComponent>();
                //We process each file in the zip one at a time and commit and update the Task each time.
                //Once the IFhirSpecificationDefinitionLoaderParameters.TaskStatus == Completed we then return, or return is the Load retunes false.
                while (_CurrentTaskStatus == Task.TaskStatus.InProgress)
                {
                    _SearchParameterBundle = LoadFromZip();
                    if (_SearchParameterBundle != null)
                    {
                        TotalCounter = 0;
                        int CommitBlockCounter = 0;
                        IGlobalProperties.ServerReadOnlyModeMessage = SetServerReadOnlyMessage(0, _SearchParameterBundle.Entry.Count, _Task.Id);
                        foreach (var Entry in _SearchParameterBundle.Entry)
                        {
                            TotalCounter++;
                            IGlobalProperties.ServerReadOnlyModeMessage = SetServerReadOnlyMessage(TotalCounter, _SearchParameterBundle.Entry.Count, _Task.Id);
                            if (Entry.Resource != null)
                            {
                                if (Entry.Resource is SearchParameter SearchParam)
                                {
                                    if (!_SearchParameterResourceProcessedIdList.Contains(SearchParam.Id))
                                    {
                                        //Increment Counter end of loop
                                        CommitBlockCounter++;
                                        using (DbContextTransaction TransactionSet = IUnitOfWork.BeginTransaction())
                                        {
                                            try
                                            {
                                                _ResourceIdInProgress = SearchParam.Id;
                                                AddSearchParameterResourceToServer(SearchParam);
                                                if (FilterSearchParametersToSet(SearchParam))
                                                {
                                                    if (!SetSearchParameterServerIndex(SearchParam.Id))
                                                    {
                                                        IGlobalProperties.ServerReadOnlyMode = false;
                                                        ICacheClear.ClearCache();
                                                        throw new Exception("Failed to Set index!");
                                                    }
                                                }
                                                _SearchParameterResourceProcessedIdList.Add(_ResourceIdInProgress);
                                                TransactionSet.Commit();
                                            }
                                            catch (Exception Exec)
                                            {
                                                TransactionSet.Rollback();
                                                using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
                                                {
                                                    _InErrorMessage    = Exec.Message;
                                                    _ResourceIdInError = _ResourceIdInProgress;
                                                    _CurrentTaskStatus = Task.TaskStatus.Failed;
                                                    SetParametersOnFailedTaskLoad(_Task);
                                                    IFhirTaskTool.UpdateTaskAsStatus(_Task.Status.Value, _Task);
                                                    Transaction.Commit();
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    string Message = "Internal Server Error: The search-parameter.xml file contained a non SearchParameter Resource Type as an entry, found type {Entry.Resource.TypeName}.";
                                    using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
                                    {
                                        _InErrorMessage = Message;
                                        SetParametersOnFailedTaskLoad(_Task);
                                        IFhirTaskTool.UpdateTaskAsStatus(_Task.Status.Value, _Task);
                                        Transaction.Commit();
                                    }
                                    IGlobalProperties.ServerReadOnlyMode = false;
                                    ICacheClear.ClearCache();
                                    throw new Exception(Message);
                                }
                            }
                            else
                            {
                                string Message = $"Internal Server Error: The search-parameter.xml file contained a null resource entry.";
                                using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
                                {
                                    _InErrorMessage = Message;
                                    SetParametersOnFailedTaskLoad(_Task);
                                    IFhirTaskTool.UpdateTaskAsStatus(_Task.Status.Value, _Task);
                                    Transaction.Commit();
                                }
                                IGlobalProperties.ServerReadOnlyMode = false;
                                ICacheClear.ClearCache();
                                throw new Exception(Message);
                            }

                            //After each blockSize Commit the current progress to the Task
                            //It is ok if we process SearchParameters that have already been processed as all that will happen is the
                            //SearchParameter Resource will be Updated and the SearchIndex will not be set again.
                            if (CommitBlockCounter == _TaskCommitBlockSize)
                            {
                                using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
                                {
                                    SetParametersInProgressTaskLoad(_Task);
                                    IFhirTaskTool.UpdateTaskAsStatus(_Task.Status.Value, _Task);
                                    Transaction.Commit();
                                }
                                CommitBlockCounter = 0;
                            }
                        }

                        //Finished all so mark as Completed
                        if (_CurrentTaskStatus == Task.TaskStatus.InProgress)
                        {
                            ProcessCompositeSearchParameters();
                            using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
                            {
                                SetParametersOnCompletedTaskLoad(_Task);
                                IFhirTaskTool.UpdateTaskAsStatus(_Task.Status.Value, _Task);
                                Transaction.Commit();
                                _CurrentTaskStatus = Task.TaskStatus.Completed;
                                IGlobalProperties.ServerReadOnlyMode = false;
                                ICacheClear.ClearCache();
                            }
                        }
                    }
                }
                return(_CurrentTaskStatus);
            }
            catch (Exception Exec)
            {
                ILog.Error(Exec, $"Internal Server Error: Transaction was rolled back. " +
                           $"Task reference was: {_Task.ResourceType.GetLiteral()}/{_Task.Id}/_history/{_Task.VersionId} The Task was not processed.");
                IGlobalProperties.ServerReadOnlyMode = false;
                ICacheClear.ClearCache();
                return(Task.TaskStatus.Failed);
            }
        }