Пример #1
0
        /// <summary>
        /// Compares two TextKeyViewModel instances to determine the sort order in the text keys
        /// tree.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public static int Compare(object a, object b)
        {
            TextKeyViewModel ta = a as TextKeyViewModel;
            TextKeyViewModel tb = b as TextKeyViewModel;

            if (ta == null || tb == null)
            {
                return(0);
            }

            bool aNs   = ta.IsNamespace;
            bool bNs   = tb.IsNamespace;
            bool aTxNs = ta.IsNamespace && ta.TextKey == "Tx";
            bool bTxNs = tb.IsNamespace && tb.TextKey == "Tx";

            // Tx: always comes first
            if (aTxNs ^ bTxNs)
            {
                if (aTxNs)
                {
                    return(-1);
                }
                if (bTxNs)
                {
                    return(1);
                }
            }
            // Namespaces come before normal keys
            if (aNs ^ bNs)
            {
                if (aNs)
                {
                    return(-1);
                }
                if (bNs)
                {
                    return(1);
                }
            }
            // Sort everything else by full key name
            //return string.Compare(ta.TextKey, tb.TextKey, StringComparison.InvariantCultureIgnoreCase);
            return(NaturalSort.NatCompare(ta.TextKey, tb.TextKey));
        }
Пример #2
0
        public void refreshCategories()
        {
            clear();

            NaturalSort <String> sort = new NaturalSort <string>();

            foreach (AnatomyFilterEntry filterEntry in anatomyController.FilterEntries)
            {
                createGroup(filterEntry, filterEntry.FilterableItems.OrderBy(i => i, sort));
            }

            topLevelButtons.Selection = anatomyController.TopLevelMode;

            var size = flowLayout.DesiredSize;

            size.Width            = scrollView.Width;
            scrollView.CanvasSize = size;
            var viewCoord = scrollView.ViewCoord;

            size.Width             = viewCoord.width - viewCoord.left;
            scrollView.CanvasSize  = size;
            flowLayout.WorkingSize = size;
            flowLayout.layout();
        }
Пример #3
0
        public List <CategoryViewModel> GetListCategories(int courseId)
        {
            var categories = unitOfWork.Repository <Question>().GetAll()
                             .Where(q => q.CourseId == courseId)
                             .Select(q => new CategoryViewModel
            {
                Id   = q.CategoryId,
                Name = q.CategoryId.HasValue ? q.Category.Name : "[None of category]"
            })
                             .Distinct()
                             .OrderBy(c => c.Name)
                             .ToList();

            foreach (var category in categories)
            {
                #region get learning outcome
                var listString        = new List <string>();
                var categoryLOs       = new List <LearningOutcomeViewModel>();
                var categoryQuestions = unitOfWork.Repository <Question>().GetAll().Where(q => q.CourseId == courseId && q.CategoryId == category.Id && !(q.IsDisable.HasValue && q.IsDisable.Value));

                category.QuestionCount = categoryQuestions.Count();

                category.LearningOutcomes = categoryQuestions.Select(q => new LearningOutcomeViewModel
                {
                    Id   = q.LearningOutcomeId,
                    Name = q.LearningOutcomeId.HasValue ? q.LearningOutcome.Name : "[None of LOC]",
                })
                                            .Distinct()
                                            .OrderBy(lo => lo.Name)
                                            .ToList();
                foreach (var lo in category.LearningOutcomes)
                {
                    if (!listString.Contains(lo.Name))
                    {
                        listString.Add(lo.Name);
                    }
                }
                using (NaturalSort comparer = new NaturalSort())
                {
                    listString.Sort(comparer);
                }
                foreach (string str in listString)
                {
                    var listLO = category.LearningOutcomes.Where(lo => lo.Name == str).ToList().OrderBy(lo => lo.Name);
                    foreach (var lo in listLO)
                    {
                        categoryLOs.Add(lo);
                    }
                }
                category.LearningOutcomes = categoryLOs;
                #endregion
                foreach (var lo in category.LearningOutcomes)
                {
                    #region get level
                    var loQuestion = unitOfWork.Repository <Question>().GetAll().Where(q => q.CourseId == courseId &&
                                                                                       q.CategoryId == category.Id &&
                                                                                       q.LearningOutcomeId == lo.Id &&
                                                                                       !(q.IsDisable.HasValue && q.IsDisable.Value));

                    lo.QuestionCount = loQuestion.Count();

                    lo.Levels = loQuestion.Select(q => new LevelViewModel
                    {
                        Id   = q.LevelId,
                        Name = q.LevelId.HasValue ? q.Level.Name : "[None of level]",
                    })
                                .Distinct()
                                .OrderBy(l => l.Id)
                                .ToList();

                    foreach (var lv in lo.Levels)
                    {
                        lv.QuestionCount = unitOfWork.Repository <Question>().GetAll().Where(q => q.CourseId == courseId &&
                                                                                             q.CategoryId == category.Id &&
                                                                                             q.LearningOutcomeId == lo.Id &&
                                                                                             q.LevelId == lv.Id &&
                                                                                             !(q.IsDisable.HasValue && q.IsDisable.Value))
                                           .Count();
                    }
                    #endregion
                }
            }
            return(categories);
        }
Пример #4
0
        protected async Task RunInternalAsync(PSScriptRunner scriptRunner, string scriptDirectory, IProgress <RunnerProgressDetail> progress = null)
        {
            //Assign progress reporter and set it that it can be used after calling Report()
            _reporter = new ProgressReporter <RunnerProgressDetail>(progress, createNewInstanceAfterReport: true);

            //Report that we are about to start
            _reporter.Content.Action = RunnerAction.Starting;
            _reporter.Report();


            string[] allScripts = Directory.GetFiles(scriptDirectory, Xteq5EngineConstant.ScriptFilePattern);
            NaturalSort.Sort(allScripts);

            foreach (string scriptFilename in allScripts)
            {
                //Set the values we already have
                BaseRecord record = new BaseRecord();
                record.ScriptFilePath = scriptFilename;
                record.Name           = Path.GetFileNameWithoutExtension(scriptFilename);

                try
                {
                    //Report back status
                    ReportProgressScript(scriptFilename);

                    using (ExecutionResult execResult = await scriptRunner.RunScriptFileAsync(scriptFilename))
                    {
                        record.ProcessMessages = execResult.ToString();

                        if (execResult.Successful == false)
                        {
                            ProcessFailure(record);
                        }
                        else
                        {
                            //The script was run OK
                            record.ScriptSuccessful = true;


                            //Search the output
                            Hashtable table          = new Hashtable(); //new() is required or the compiler will complain about an unassigned local variable
                            bool      foundHashtable = false;

                            //Search the output collection for a hashtable
                            foreach (PSObject psobj in execResult.StreamOutput)
                            {
                                if (psobj.BaseObject != null && psobj.BaseObject is Hashtable)
                                {
                                    foundHashtable = true;
                                    table          = psobj.BaseObject as Hashtable;
                                    break;
                                }
                            }

                            if (foundHashtable == false)
                            {
                                //No hashtable was found within output stream. Add this to messages
                                record.AddLineToProcessMessages("No Hashtable was returned");

                                ProcessFailure(record);
                            }
                            else
                            {
                                ProcessHashtableOutputInternal(record, table);
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    //That didn't go well
                    record.ProcessMessages = exc.ToString();

                    //Let the actual implementation decide what to do next
                    ProcessFailure(record);
                }


                //MTH: End of processing with this file. Next one please!
            }


            //Report status that this entire run has finished
            _reporter.Content.Action = RunnerAction.Ended;
            _reporter.Report();
        }