Пример #1
0
        private void ExportSheetLayout(dynamic sheet)
        {
            Logger.Info("ExportSheetLayout");
            SheetViewModel svm = new SheetViewModel(sheet);

            switch (Settings.Objects)
            {
            case BatchExportObjects.Charts:
                svm.SelectCharts();
                break;

            case BatchExportObjects.ChartsAndShapes:
                svm.SelectShapes();
                break;

            default:
                Logger.Fatal("ExportSheetLayout: Object type '{0}' not implemented!", Settings.Objects);
                throw new NotImplementedException(Settings.Objects.ToString());
            }
            dynamic selection = Instance.Default.Application.Selection;

            Exporter.FileName = _batchFileName.GenerateNext(sheet, selection);
            Bovender.ComHelpers.ReleaseComObject(selection);
            Exporter.Execute();
        }
Пример #2
0
        public ActionResult Index()
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Manage sheets.
            SheetViewModel model = new SheetViewModel();
            model.Sheets = Sheet.Stack(account.DashboardTitle, Url.Action("index", "home"));
            ViewData["Stack"] = JsonUtils.SerializeObject(model.Sheets);
            
            // Pass inbox to view.
            ViewData["Inbox"] = JsonUtils.SerializeObject(new TaskListViewModel(account.Inbox));

            // Create collection of area view models for area quick links.
            IList<AreaViewModel> areas = new List<AreaViewModel>();
            foreach (Area area in account.Areas)
                areas.Add(new AreaViewModel(area, area.TaskLists));
            ViewData["Areas"] = JsonUtils.SerializeObject(areas);

            // Create collection of tag view models for tag quick links.
            IList<TagViewModel> tags = new List<TagViewModel>();
            foreach (Tag tag in _tagService.AllForAccount(account))
                tags.Add(new TagViewModel(tag));
            ViewData["Tags"] = JsonUtils.SerializeObject(tags);

            // Return view.
            return View(model);
        }
Пример #3
0
        public RowViewModelComparer(SheetViewModel sheetViewModel, ViewStatus viewStatus, IEnumerable <Row> selectedRows)
        {
            SheetViewModel = sheetViewModel;
            ViewStatus     = viewStatus;
            FilteredRows   = sheetViewModel.FilteredRows;
            SelectedRows   = selectedRows;

            selectedCount          = ViewStatus.SelectedCount;
            sortedColumnViewModels = SheetViewModel.ColumnViewModels.Where(
                cvm => cvm.SortOption != SortOption.None
                ).OrderByDescending(cvm => cvm.SortPriority);
            firstNumerical = ViewStatus.FirstNumerical;

            IEnumerable <ColumnViewModel> nonTailCategoricalColumnViewModels = ViewStatus.SelectedColumnViewModels.Where(
                cvm => cvm.Type == ColumnType.Categorical && cvm != ViewStatus.LastCategorical
                );

            IEnumerable <ColumnViewModel> tailCategoricalOrNumericalColumnViewModels = ViewStatus.SelectedColumnViewModels.Where(
                cvm => cvm.Type == ColumnType.Numerical || cvm == ViewStatus.LastCategorical
                ).OrderByDescending(cvm =>
                                    cvm.SortOption != SortOption.None ? cvm.SortPriority : (cvm.Type == ColumnType.Categorical ? 0 : -1)
                                    );

            sortOrder = nonTailCategoricalColumnViewModels.Concat(tailCategoricalOrNumericalColumnViewModels);
            isN       = viewStatus.IsN;

            foreach (Row row in FilteredRows)
            {
                filteredRowDictionary[row] = true;
            }
        }
Пример #4
0
        private void ExportSheetItems(dynamic sheet)
        {
            Logger.Info("ExportSheetItems");
            SheetViewModel svm = new SheetViewModel(sheet);

            if (svm.IsChart)
            {
                svm.SelectCharts();
                ExportSelection(svm.Sheet);
            }
            else
            {
                switch (Settings.Objects)
                {
                case BatchExportObjects.Charts:
                    ExportSheetChartItems(svm.Worksheet);
                    break;

                case BatchExportObjects.ChartsAndShapes:
                    ExportSheetAllItems(svm.Worksheet);
                    break;

                default:
                    Logger.Fatal("ExportSheetItems: Object type '{0}' not implemented!", Settings.Objects);
                    throw new NotImplementedException(
                              "Single-item export not implemented for " + Settings.Objects.ToString());
                }
            }
        }
Пример #5
0
        // GET: Admin
        public ActionResult Index()
        {
            SheetViewModel sheet = new SheetViewModel();

            sheet.SourceDataType = _LookupCategoryBusinessLogic.GetLookupsByLookupCategoryCode("SourceDataType", base.CurrentCulture);
            return(View(sheet));
        }
Пример #6
0
        public void NonExistantBogusPathFileName_Test()
        {
            string file = Path.GetTempFileName();

            File.Delete(file);

            // Relpace the T in Temp with an invalid char
            file = file.Replace('T', Path.GetInvalidPathChars()[0]);

            SheetViewModel svm = new SheetViewModel
            {
                File          = file,
                ContentEngine = new TextCte()
            };
            Macros macros = new Macros(svm);

            Assert.Equal(Path.GetExtension(file), macros.ReplaceMacros(@"{FileExtension}"));
            Assert.Equal(Path.GetFileName(file), macros.ReplaceMacros(@"{FileName}"));
            Assert.Equal(Path.GetFileNameWithoutExtension(file), macros.ReplaceMacros(@"{FileNameWithoutExtension}"));
            // return original path
            Assert.Equal(Path.GetDirectoryName(file), macros.ReplaceMacros(@"{FileDirectoryName}"));
            Assert.Equal(Path.GetFullPath(file), macros.ReplaceMacros(@"{FullPath}"));
            // it's not a real file so, dates should be minvalue
            Assert.Equal($"{DateTime.MinValue}", macros.ReplaceMacros(@"{DateRevised}"));
            Assert.Equal($"{DateTime.MinValue}", macros.ReplaceMacros(@"{DateCreated}"));
        }
Пример #7
0
        public void MoveFirstSheetDown()
        {
            Workbook          wb  = Instance.Default.CreateWorkbook(3);
            WorkbookViewModel wvm = new WorkbookViewModel(wb);

            // Select the first sheet in the collection
            SheetViewModel svm       = wvm.Sheets[0];
            string         sheetName = svm.DisplayString;

            // With no sheets selected, the move-down command should
            // be disabled.
            wb.Sheets[wb.Sheets.Count].Activate();
            wvm.Sheets.First(sheet => sheet.IsSelected).IsSelected = false;
            Assert.IsFalse(wvm.MoveSheetDown.CanExecute(null),
                           "Move-down command is enabled, should be disabled with no sheets selected.");

            wb.Sheets[1].Activate();
            Assert.IsTrue(wvm.MoveSheetDown.CanExecute(null),
                          "Move-down command is disabled, should be enabled with one sheet selected.");

            wvm.MoveSheetDown.Execute(null);
            // Caveat, when accessing the worksheets collection, the index is 1-based!
            Assert.AreEqual(sheetName, wb.Sheets[2].Name,
                            "The first sheet was not moved down");
        }
Пример #8
0
        public void MoveSheetsUp()
        {
            Workbook          wb  = Instance.Default.CreateWorkbook(3);
            WorkbookViewModel wvm = new WorkbookViewModel(wb);

            // Select the second sheet in the collection (index #1)
            SheetViewModel svm       = wvm.Sheets[1];
            string         sheetName = svm.DisplayString;

            // With no sheets selected, the move-up command should
            // be disabled.
            wvm.Sheets.First(sheet => sheet.IsSelected).IsSelected = false;
            Assert.IsFalse(wvm.MoveSheetUp.CanExecute(null),
                           "Move command is enabled, should be disabled with no sheets selected.");

            svm.IsSelected = true;
            Assert.IsTrue(wvm.MoveSheetUp.CanExecute(null),
                          "Move command is disabled, should be enabled with one sheet selected.");
            wvm.MoveSheetUp.Execute(null);

            // The selected sheet should now be the first sheet,
            // which cannot be moved 'up' as it is at the 'top'
            // already; so the command should be disabled again.
            Assert.IsFalse(wvm.MoveSheetUp.CanExecute(null),
                           "Move command is enabled, should be disabled if the very first sheet is selected.");

            // Check the the move was performed on the workbook too.
            Assert.AreEqual(sheetName, wb.Sheets[1].Name,
                            "Moving the sheet was not performed on the actual workbook");
        }
Пример #9
0
        public void Update(Double delayBeforeAnimation)
        {
            if (Items.Children.Count == 0)
            {
                SheetViewModel sheetViewModel = (this.DataContext as TableViewModel).SheetViewModel;
                foreach (ColumnViewModel cvm in sheetViewModel.ColumnViewModels)
                {
                    ColumnHeaderCellPresenter chcp = new ColumnHeaderCellPresenter()
                    {
                        DataContext = cvm
                    };

                    if (this.Name == "BottomColumnHeaderElement")
                    {
                        chcp.AlignContent(VerticalAlignment.Top);
                        chcp.HideTopTypeIndicators();
                    }
                    else
                    {
                        chcp.AlignContent(VerticalAlignment.Bottom);
                        chcp.HideBottomTypeIndicators();
                    }
                    Items.Children.Add(chcp);
                }
            }

            foreach (UIElement ele in Items.Children)
            {
                ColumnHeaderCellPresenter chcp = ele as ColumnHeaderCellPresenter;
                chcp.Update(delayBeforeAnimation);
            }
        }
Пример #10
0
        public void MoveSheetsDown()
        {
            Workbook          wb  = Instance.Default.CreateWorkbook(6);
            WorkbookViewModel wvm = new WorkbookViewModel(wb);

            // Select the second-to-last sheet in the collection
            SheetViewModel svm       = wvm.Sheets[wvm.Sheets.Count - 2];
            string         sheetName = svm.DisplayString;

            // With no sheets selected, the move-down command should
            // be disabled.
            wvm.Sheets.First(sheet => sheet.IsSelected).IsSelected = false;
            Assert.IsFalse(wvm.MoveSheetDown.CanExecute(null),
                           "Move-down command is enabled, should be disabled with no sheets selected.");

            svm.IsSelected = true;
            Assert.IsTrue(wvm.MoveSheetDown.CanExecute(null),
                          "Move-down command is disabled, should be enabled with one sheet selected.");
            wvm.MoveSheetDown.Execute(null);

            // The selected sheet should now be the last sheet,
            // which cannot be moved 'down' as it is at the 'bottom'
            // already; so the command should be disabled again.
            Assert.IsFalse(wvm.MoveSheetDown.CanExecute(null),
                           "Move-down command is enabled, should be disabled if the very last sheet is selected.");

            // Check the the move was performed on the workbook too.
            Assert.AreEqual(sheetName, wb.Sheets[wb.Sheets.Count].Name,
                            "Moving the sheet down was not performed on the actual workbook");
        }
Пример #11
0
        public void ValidSheetNames(string testName, bool isValid)
        {
            string s = isValid ? "" : "not ";

            Assert.AreEqual(
                isValid,
                SheetViewModel.IsValidName(testName)
                );
        }
Пример #12
0
        /// <summary>
        /// Gets the sheet token.
        /// </summary>
        /// <param name="sheetModel">The sheet model.</param>
        /// <returns>return a JToken that represents the SheetViewModel</returns>
        private static JToken GetSheetToken(SheetViewModel sheetModel)
        {
            var sheet = new JObject {
                { "name", sheetModel.SheetName },
                { "rows", GetRows(sheetModel) },
                { "columns", GetColumns(sheetModel) }
            };

            return(sheet);
        }
Пример #13
0
        public void NewContentTypeEngineTest()
        {
            SheetViewModel svm = new SheetViewModel();

            (svm.ContentEngine, svm.ContentType, svm.Language) = ContentTypeEngineBase.CreateContentTypeEngine(CteClassName);
            Assert.NotNull(svm.ContentEngine);

            Assert.Equal(CteClassName, svm.ContentEngine.GetType().Name);
            Assert.Equal("text/plain", svm.ContentType);
        }
Пример #14
0
        /// <summary>
        /// Gets the JToken that represent the rows of the SheetViewModel.
        /// </summary>
        /// <param name="sheetModel">The sheet model.</param>
        /// <returns>return the JToken that represents the sheet view model</returns>
        private static JToken GetRows(SheetViewModel sheetModel)
        {
            var rows      = new JArray();
            var sheetRows = sheetModel.Rows;

            foreach (var row in sheetRows)
            {
                rows.Add(GetRow(row, sheetModel));
            }

            return(rows);
        }
Пример #15
0
        public void CreateContentTypeEngine_CteClassName()
        {
            foreach (var cte in ContentTypeEngineBase.GetDerivedClassesCollection())
            {
                var            CteClassName = cte.GetType().Name;
                SheetViewModel svm          = new SheetViewModel();
                (svm.ContentEngine, svm.ContentType, svm.Language) = ContentTypeEngineBase.CreateContentTypeEngine(CteClassName);
                Assert.NotNull(svm.ContentEngine);

                Assert.Equal(CteClassName, svm.ContentEngine.GetType().Name);
                Assert.Equal(cte.SupportedContentTypes[0], svm.ContentType);
            }
        }
Пример #16
0
        /// <summary>
        /// Gets the rowModel.
        /// </summary>
        /// <param name="rowModel">The rowModel.</param>
        /// <returns></returns>
        private static JToken GetRow(Row rowModel, SheetViewModel sheetModel)
        {
            var rowJObject = new JObject {
                { "height", rowModel.Height }, { "index", rowModel.Index }
            };
            var cells = new JArray();

            foreach (var cell in rowModel.RowCells)
            {
                GetCell(cell, cells, sheetModel);
            }
            rowJObject.Add("cells", cells);
            return(rowJObject);
        }
Пример #17
0
        public static AnimationHint Create(SheetViewModel sheetViewModel, TableViewModel tableViewModel)
        {
            AnimationHint hint = new AnimationHint()
            {
                TableViewState = tableViewModel.State
            };

            foreach (ColumnViewModel cvm in sheetViewModel.ColumnViewModels)
            {
                hint.ColumnViewModelPosition[cvm] = cvm.X;
            }

            return(hint);
        }
Пример #18
0
        private static JToken GetColumns(SheetViewModel sheetModel)
        {
            var columns      = new JArray();
            var sheetColumns = sheetModel.Columns;

            foreach (var column in sheetColumns)
            {
                var columnJObject = new JObject {
                    { "index", column.Index }, { "width", column.Width }
                };
                columns.Add(columnJObject);
            }

            return(columns);
        }
Пример #19
0
        /// <summary>
        /// Gets the cell.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <param name="cells">The cells.</param>
        private static void GetCell(Cell cell, JArray cells, SheetViewModel sheetModel)
        {
            var column      = sheetModel.Columns[cell.Column];
            var row         = sheetModel.Rows[cell.Row];
            var cellJObject = new JObject
            {
                { "value", cell.Value },
                { "index", cell.Column }
            };

            CellAlignment(cell, cellJObject);
            CellLock(cell, cellJObject);
            CellColor(cell, cellJObject);
            CellFont(cell, cellJObject);
            cells.Add(cellJObject);
        }
Пример #20
0
        public void CountSelectChartObjects()
        {
            Workbook     wb  = Instance.Default.CreateWorkbook();
            Worksheet    ws  = wb.Worksheets.Add();
            ChartObjects cos = ws.ChartObjects();

            cos.Add(10, 10, 200, 100);
            cos.Add(250, 10, 200, 100);
            SheetViewModel svm = new SheetViewModel(ws);

            Assert.AreEqual(2, svm.CountCharts(), "CountCharts()");
            Assert.AreEqual(2, svm.CountShapes(), "CountGraphicObjects()");
            Assert.IsTrue(svm.SelectCharts(),
                          "SelectCharts() should return true if the sheet contains an embedded chart.");
            Assert.IsTrue(svm.SelectShapes(),
                          "SelectGraphicObjects() should return true if the sheet contains an embedded chart.");
        }
Пример #21
0
        public void CountSelectShapes()
        {
            Workbook  wb  = Instance.Default.CreateWorkbook();
            Worksheet ws  = wb.Worksheets.Add();
            Shapes    shs = ws.Shapes;

            shs.AddLine(10, 10, 20, 30);
            shs.AddLine(50, 50, 20, 30);
            SheetViewModel svm = new SheetViewModel(ws);

            Assert.AreEqual(0, svm.CountCharts());
            Assert.AreEqual(2, svm.CountShapes());
            Assert.IsFalse(svm.SelectCharts(),
                           "SelectCharts() should return false if the sheet contains only shapes.");
            Assert.IsTrue(svm.SelectShapes(),
                          "SelectGraphicObjects() should return true if the sheet contains shapes.");
        }
Пример #22
0
        public void DisplayString()
        {
            Sheets         sheets = Instance.Default.Application.Sheets;
            Worksheet      ws     = sheets.Add();
            SheetViewModel svm    = new SheetViewModel(ws);

            Assert.AreEqual(ws.Name, svm.DisplayString);

            svm.DisplayString = "HelloWorld";
            Assert.AreEqual(ws.Name, svm.DisplayString,
                            "DisplayString is not written through to sheet object.");

            if (Marshal.IsComObject(sheets))
            {
                Marshal.ReleaseComObject(sheets);
            }
        }
Пример #23
0
        private void AnalyzeOtherWorkbooks()
        {
            Logger.Info("AnalyzeOtherWorkbooks");
            string activeWorkbookName = Instance.Default.ActiveWorkbook.Name;

            _otherWorkbooksHaveCharts      = false;
            _otherWorkbooksHaveManyCharts  = false;
            _otherWorkbooksHaveShapes      = false;
            _otherWorkbooksHaveManyObjects = false;
            int       charts;
            int       shapes;
            Workbooks workbooks = Instance.Default.Application.Workbooks;

            Logger.Info("AnalyzeOtherWorkbooks: {0} workbook(s) are currently open", workbooks.Count);
            for (int i = 1; i <= workbooks.Count; i++)
            {
                Logger.Info("AnalyzeOtherWorkbooks: [{0}]", i);
                Workbook workbook = workbooks[i];
                if (workbook.Name != activeWorkbookName)
                {
                    Sheets sheets = workbook.Sheets;
                    for (int j = 1; j <= sheets.Count; j++)
                    {
                        object         sheet = sheets[j];
                        SheetViewModel svm   = new SheetViewModel(sheet);
                        charts = svm.CountCharts();
                        shapes = svm.CountShapes() - charts;
                        _otherWorkbooksHaveCharts      |= charts > 0;
                        _otherWorkbooksHaveManyCharts  |= charts > 1;
                        _otherWorkbooksHaveShapes      |= shapes > 0;
                        _otherWorkbooksHaveManyObjects |= charts + shapes > 1;
                        Bovender.ComHelpers.ReleaseComObject(sheet);
                    }
                    Bovender.ComHelpers.ReleaseComObject(sheets);
                }
                else
                {
                    Logger.Info("AnalyzeOtherWorkbooks: [{0}] is the active workbook", i);
                }
                Bovender.ComHelpers.ReleaseComObject(workbook);
            }
            Logger.Info("AnalyzeOtherWorkbooks: Releasing workbooks object");
            Bovender.ComHelpers.ReleaseComObject(workbooks);
        }
Пример #24
0
        private int CountInSheetItems(dynamic worksheet)
        {
            Logger.Info("CountInSheetItems");
            SheetViewModel svm = new SheetViewModel(worksheet);

            switch (Settings.Objects)
            {
            case BatchExportObjects.Charts:
                return(svm.CountCharts());

            case BatchExportObjects.ChartsAndShapes:
                return(svm.CountShapes());

            default:
                Logger.Fatal("CountInSheetItems: Object type '{0}' not implemented!", Settings.Objects);
                throw new NotImplementedException(String.Format(
                                                      "Export of {0} not implemented.", Settings.Objects));
            }
        }
Пример #25
0
        private bool CanExportFromSheet(object sheet)
        {
            SheetViewModel svm = new SheetViewModel(
                Instance.Default.Application.ActiveSheet);

            switch (Objects.AsEnum)
            {
            case BatchExportObjects.Charts:
                return(svm.CountCharts() > 0);

            case BatchExportObjects.ChartsAndShapes:
                return(svm.CountShapes() > 0);

            default:
                Logger.Fatal("CanExportFromSheet: Unknown case: {0}", Objects.AsEnum);
                throw new InvalidOperationException(
                          "Cannot handle " + Objects.SelectedItem);
            }
        }
Пример #26
0
 private void AnalyzeActiveSheet()
 {
     if (Instance.Default.Application.ActiveSheet != null)
     {
         Logger.Info("AnalyzeActiveSheet");
         SheetViewModel sheetVM = new SheetViewModel(Instance.Default.Application.ActiveSheet);
         int            charts  = sheetVM.CountCharts();
         int            shapes  = sheetVM.CountShapes() - charts;
         _activeSheetHasCharts      = charts > 0;
         _activeSheetHasManyCharts  = charts > 1;
         _activeSheetHasShapes      = shapes > 0;
         _activeSheetHasManyObjects = charts + shapes > 1;
         _activeSheetName           = sheetVM.DisplayString;
     }
     else
     {
         Logger.Info("AnalyzeActiveSheet: No active sheet");
     }
 }
Пример #27
0
        // GET: Sheets/Create
        public async Task <ActionResult> Create(Guid id)
        {
            var currentStudent = (await GetCurrentUserAsync()) as Student;
            var currentExam    = await DB.Exams.FirstOrDefaultAsync(e => e.Id == id);

            var            currentPaper = currentExam.Paper;
            SheetViewModel model        = new SheetViewModel();

            model.Id                = id;
            model.ExamName          = currentExam.ExamName;
            model.StudentName       = currentStudent.TrueName;
            model.TeacherName       = currentPaper.Teacher.TrueName;
            model.MultipleQuestions = currentPaper.Questions.Where(q => q.Type == QuestionType.多选题).Select(q => new SheetMultipleQuestionViewModel
            {
                Id      = q.Id,
                Content = q.Content,
                Type    = q.Type,
                Options = (q as ChoiceQuestion).Options.OrderBy(o => o.OptionId).Select(o => new SheetMultipleOptionViewModel
                {
                    OptionId       = o.OptionId,
                    OptionProperty = o.OptionProperty,
                }).ToList()
            }).ToList();
            model.SingleQuestions = currentPaper.Questions.Where(q => q.Type == QuestionType.单选题).Select(q => new SheetSingleQuestionViewModel
            {
                Id      = q.Id,
                Content = q.Content,
                Type    = q.Type,
                Options = (q as ChoiceQuestion).Options.OrderBy(o => o.OptionId).Select(o => new SheetOptionViewModel
                {
                    OptionId       = o.OptionId,
                    OptionProperty = o.OptionProperty
                }).ToList()
            }).ToList();
            model.TrueOrFalseQuestions = currentPaper.Questions.Where(q => q.Type == QuestionType.判断题).Select(q => new SheetTrueOrFalseQuestionViewModel
            {
                Id      = q.Id,
                Content = q.Content,
                Type    = q.Type,
            }).ToList();
            return(View(model));
        }
Пример #28
0
        public void CountSelectChartSheet()
        {
            Workbook       wb  = Instance.Default.CreateWorkbook();
            Worksheet      ws  = wb.Worksheets.Add();
            SheetViewModel svm = new SheetViewModel(ws);

            Assert.IsFalse(svm.SelectCharts(),
                           "SelectCharts() should return false if worksheet does not contain charts.");
            Assert.IsFalse(svm.SelectShapes(),
                           "SelectGraphicObjects() should return false if worksheet does not contain any.");
            Chart chart = wb.Charts.Add();

            svm = new SheetViewModel(chart);
            Assert.AreEqual(1, svm.CountCharts());
            Assert.AreEqual(1, svm.CountShapes());
            Assert.IsTrue(svm.SelectCharts(),
                          "SelectCharts() should return true if sheet is a chart.");
            Assert.IsTrue(svm.SelectShapes(),
                          "SelectGraphicObjects() should return true if sheet is a chart.");
        }
Пример #29
0
        public void RealFileName_Test()
        {
            string file = Path.GetTempFileName();

            SheetViewModel svm = new SheetViewModel
            {
                File          = file,
                ContentEngine = new TextCte()
            };
            Macros macros = new Macros(svm);

            Assert.Equal(Path.GetExtension(file), macros.ReplaceMacros(@"{FileExtension}"));
            Assert.Equal(Path.GetFileName(file), macros.ReplaceMacros(@"{FileName}"));
            Assert.Equal(Path.GetFileNameWithoutExtension(file), macros.ReplaceMacros(@"{FileNameWithoutExtension}"));
            Assert.Equal(Path.GetDirectoryName(file), macros.ReplaceMacros(@"{FileDirectoryName}"));
            Assert.Equal(Path.GetFullPath(file), macros.ReplaceMacros(@"{FullPath}"));
            Assert.Equal($"{File.GetLastWriteTime(file)}", macros.ReplaceMacros(@"{DateRevised}"));
            Assert.Equal($"{File.GetCreationTime(file)}", macros.ReplaceMacros(@"{DateCreated}"));

            File.Delete(svm.File);
        }
Пример #30
0
        public void MoveSheetsToTop()
        {
            Workbook          wb  = Instance.Default.CreateWorkbook(8);
            WorkbookViewModel wvm = new WorkbookViewModel(wb);

            wvm.Sheets.First(sheet => sheet.IsSelected).IsSelected = false;

            // Without sheets selected, the Move-to-top command should be disabled
            Assert.IsFalse(wvm.MoveSheetsToTop.CanExecute(null),
                           "The Move-to-top command should be disabled without selected sheets.");

            // // Select the fourth and sixth sheets and remember their names
            // SheetViewModel svm4 = wvm.Sheets[3];
            // svm4.IsSelected = true;
            // string sheetName4 = svm4.DisplayString;

            SheetViewModel svm6 = wvm.Sheets[5];

            svm6.IsSelected = true;
            string sheetName6 = svm6.DisplayString;

            // With sheets selected, the Move-to-top command should be disabled
            Assert.IsTrue(wvm.MoveSheetsToTop.CanExecute(null),
                          "The Move-to-top command should be enabled with selected sheets.");

            wvm.MoveSheetsToTop.Execute(null);

            // Since a selected sheet was moved to the top, the command should
            // now be disabled again.
            Assert.IsFalse(wvm.MoveSheetsToTop.CanExecute(null),
                           "The Move-to-top command should be disabled if the first sheet is selected.");

            // Verify that the display strings of the view models correspond to
            // the names of the worksheets in the workbook, to make sure that
            // the worksheets have indeed been rearranged as well.
            // Assert.AreEqual(sheetName4, wb.Sheets[1].Name,
            //     "Moving the sheets to top was not performed on the actual workbook");
            Assert.AreEqual(sheetName6, wb.Sheets[1].Name,
                            "Moving the sheets to top was not performed for all sheets on the actual workbook");
        }
Пример #31
0
        public void NonExistantGoodFileName_Test()
        {
            string file = Path.GetTempFileName();

            File.Delete(file);

            SheetViewModel svm = new SheetViewModel
            {
                File          = file,
                ContentEngine = new TextCte()
            };
            Macros macros = new Macros(svm);

            Assert.Equal(Path.GetExtension(file), macros.ReplaceMacros(@"{FileExtension}"));
            Assert.Equal(Path.GetFileName(file), macros.ReplaceMacros(@"{FileName}"));
            Assert.Equal(Path.GetFileNameWithoutExtension(file), macros.ReplaceMacros(@"{FileNameWithoutExtension}"));
            Assert.Equal(Path.GetDirectoryName(file), macros.ReplaceMacros(@"{FileDirectoryName}"));
            Assert.Equal(Path.GetFullPath(file), macros.ReplaceMacros(@"{FullPath}"));
            // it's not a real file so, dates should be minvalue
            Assert.Equal($"{DateTime.MinValue}", macros.ReplaceMacros(@"{DateRevised}"));
            Assert.Equal($"{DateTime.MinValue}", macros.ReplaceMacros(@"{DateCreated}"));
        }
Пример #32
0
        public ActionResult Inbox(List<Sheet> sheets)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Manage sheets.
            Queue<Sheet> defaultStack = new Queue<Sheet>();
            defaultStack.Enqueue(new Sheet() { Title = account.DashboardTitle, Url = Url.Action("index", "home") });
            SheetViewModel model = new SheetViewModel(sheets);
            model.Sheets = Sheet.Stack("Inbox", Url.Action("inbox", "home"), defaultStack, model.Sheets);
            ViewData["Stack"] = JsonUtils.SerializeObject(model.Sheets);

            // Pass inbox to view.
            ViewData["Inbox"] = JsonUtils.SerializeObject(new TaskListViewModel(account.Inbox));

            // Create a task list view model with tasks.
            TaskListViewModel taskListViewModel = new TaskListViewModel(account.Inbox, account.Inbox.Tasks);

            // Pass task list view model to view.
            ViewData["TaskList"] = JsonUtils.SerializeObject(taskListViewModel);

            // Create collection of area view models for the task list menu.
            IList<AreaViewModel> areas = new List<AreaViewModel>();
            foreach (Area area in account.Areas)
                areas.Add(new AreaViewModel(area, area.TaskLists));
            ViewData["Areas"] = JsonUtils.SerializeObject(areas);

            // Create collection of tag view models for the tags menu.
            IList<TagViewModel> tags = new List<TagViewModel>();
            foreach (Tag tag in _tagService.AllForAccount(account))
                tags.Add(new TagViewModel(tag));
            ViewData["Tags"] = JsonUtils.SerializeObject(tags);

            // Return view.
            return View(model);
        }
Пример #33
0
        public ActionResult Due(List<Sheet> sheets)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Create an area model to hold "due" tasks.
            Area area = new Area();
            area.Title = "Due";

            // Create list of task lists to hold each due list.
            IList<TaskList> dueLists = new List<TaskList>();

            // Overdue.
            TaskList overdueList = _taskListService.GetDueList(DueListType.Overdue, false, account);
            dueLists.Add(overdueList);

            // Today.
            TaskList todayList = _taskListService.GetDueList(DueListType.Today, false, account);
            dueLists.Add(todayList);

            // Tomorrow.
            TaskList tomorrowList = _taskListService.GetDueList(DueListType.Tomorrow, false, account);
            dueLists.Add(tomorrowList);

            // This week.
            TaskList thisWeekList = _taskListService.GetDueList(DueListType.ThisWeek, false, account);
            dueLists.Add(thisWeekList);

            // Next week.
            TaskList nextWeekList = _taskListService.GetDueList(DueListType.NextWeek, false, account);
            dueLists.Add(nextWeekList);

            // Later
            TaskList laterList = _taskListService.GetDueList(DueListType.Later, false, account);
            dueLists.Add(laterList);

            // Create an area view model with task lists and tasks.
            AreaViewModel areaViewModel = new AreaViewModel(area, dueLists, true);

            // Pass area view model to view.
            ViewData["Area"] = JsonUtils.SerializeObject(areaViewModel);

            // Manage sheets.
            Queue<Sheet> defaultStack = new Queue<Sheet>();
            defaultStack.Enqueue(new Sheet() { Title = account.DashboardTitle, Url = Url.Action("index", "home") });
            SheetViewModel model = new SheetViewModel(sheets);
            model.Sheets = Sheet.Stack("Due", Url.Action("due", "home"), defaultStack, model.Sheets);
            ViewData["Stack"] = JsonUtils.SerializeObject(model.Sheets);

            // Pass inbox to view.
            ViewData["Inbox"] = JsonUtils.SerializeObject(new TaskListViewModel(account.Inbox));

            // Create collection of area view models for the task list menu.
            IList<AreaViewModel> areas = new List<AreaViewModel>();
            foreach (Area ar in account.Areas)
                areas.Add(new AreaViewModel(ar, ar.TaskLists));
            ViewData["Areas"] = JsonUtils.SerializeObject(areas);

            // Create collection of tag view models for the tags menu.
            IList<TagViewModel> tags = new List<TagViewModel>();
            foreach (Tag tag in _tagService.AllForAccount(account))
                tags.Add(new TagViewModel(tag));
            ViewData["Tags"] = JsonUtils.SerializeObject(tags);

            // Return view.
            return View(model);
        }
Пример #34
0
        public ActionResult Search(List<Sheet> sheets, string searchFor)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Create a task list model to hold "important" tasks.
            TaskList taskList = new TaskList();
            taskList.Title = String.Format("Search Results for '{0}'", searchFor);

            // Find matching tasks.
            IList<Task> tasks = _taskService.Find(searchFor, account);
            
            // Create a task list view model with tasks.
            TaskListViewModel taskListViewModel = new TaskListViewModel(taskList, tasks);

            // Pass task list view model to view.
            ViewData["TaskList"] = JsonUtils.SerializeObject(taskListViewModel);
            
            // Pass search text to view.
            ViewData["SearchText"] = searchFor;
            
            // Manage sheets.
            // NOTE: We always use the default stack for the search results page.
            // ALSO: The url needs to include the search query paramater.
            var url = Url.Action("search", "home") + "/?searchfor=" + searchFor;
            Queue<Sheet> defaultStack = new Queue<Sheet>();
            defaultStack.Enqueue(new Sheet() { Title = account.DashboardTitle, Url = Url.Action("index", "home") });
            SheetViewModel model = new SheetViewModel(sheets);
            model.Sheets = Sheet.Stack("Search Results", url, defaultStack);
            ViewData["Stack"] = JsonUtils.SerializeObject(model.Sheets);

            // Pass inbox to view.
            ViewData["Inbox"] = JsonUtils.SerializeObject(new TaskListViewModel(account.Inbox));

            // Create collection of area view models for the task list menu.
            IList<AreaViewModel> areas = new List<AreaViewModel>();
            foreach (Area ar in account.Areas)
                areas.Add(new AreaViewModel(ar, ar.TaskLists));
            ViewData["Areas"] = JsonUtils.SerializeObject(areas);

            // Create collection of tag view models for the tags menu.
            IList<TagViewModel> tags = new List<TagViewModel>();
            foreach (Tag tag in _tagService.AllForAccount(account))
                tags.Add(new TagViewModel(tag));
            ViewData["Tags"] = JsonUtils.SerializeObject(tags);

            // Return view.
            return View(model);
        }
Пример #35
0
        public ActionResult Area(long id, List<Sheet> sheets)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Get area.
            Area area = _areaService.Load(id, account);

            // Create an area view model with task lists and tasks.
            AreaViewModel areaViewModel = new AreaViewModel(area, area.TaskLists, true);

            // Pass area view model to view.
            ViewData["Area"] = JsonUtils.SerializeObject(areaViewModel);

            // Check for replace sheet option.
            bool replaceSheet = Request.Params["option"] != null && Request.Params["option"] == "replace";
            if (replaceSheet)
                sheets.RemoveAt(sheets.Count - 1);

            // Manage sheets.
            Queue<Sheet> defaultStack = new Queue<Sheet>();
            defaultStack.Enqueue(new Sheet() { Title = account.DashboardTitle, Url = Url.Action("index", "home") });
            SheetViewModel model = new SheetViewModel(sheets);
            model.Sheets = Sheet.Stack(area.Title, Url.Action("area", "home", new { id = id }), defaultStack, model.Sheets);
            ViewData["Stack"] = JsonUtils.SerializeObject(model.Sheets);

            foreach (Sheet s in model.Sheets) {
                Logger.Debug(s.Title + " : " + s.Url);
            }

            // Pass inbox to view.
            ViewData["Inbox"] = JsonUtils.SerializeObject(new TaskListViewModel(account.Inbox));

            // Create collection of area view models for the task list menu.
            IList<AreaViewModel> areas = new List<AreaViewModel>();
            foreach (Area ar in account.Areas)
                areas.Add(new AreaViewModel(ar, ar.TaskLists));
            ViewData["Areas"] = JsonUtils.SerializeObject(areas);

            // Create collection of tag view models for the tags menu.
            IList<TagViewModel> tags = new List<TagViewModel>();
            foreach (Tag tag in _tagService.AllForAccount(account))
                tags.Add(new TagViewModel(tag));
            ViewData["Tags"] = JsonUtils.SerializeObject(tags);

            // Return view.
            return View("Area", model);

        }