Exemple #1
0
        public void AddPage(WorkbookPage workbookPage)
        {
            if (workbookPage == null)
            {
                throw new ArgumentNullException(nameof(workbookPage));
            }

            pages.Add(workbookPage);

            if (pages.Count == 1)
            {
                workbookPage.TreeNode.IsSelected = true;
            }

            workbookPage.PropertyChanged += WorkbookPage_PropertyChanged;

            filesystem.Add(workbookPage.TreeNode);

            if (pages.Count == 1)
            {
                PlatformTargets = workbookPage.PlatformTargets;
            }
            else
            {
                PlatformTargets = PlatformTargets
                                  .Intersect(workbookPage.PlatformTargets)
                                  .ToImmutableArray();
            }
        }
Exemple #2
0
        public void RemovePage(WorkbookPage workbookPage)
        {
            if (workbookPage == null)
            {
                throw new ArgumentNullException(nameof(workbookPage));
            }

            workbookPage.PropertyChanged -= WorkbookPage_PropertyChanged;

            pages.Remove(workbookPage);

            if (pages.Count == 0)
            {
                PlatformTargets = ImmutableArray <AgentType> .Empty;
            }
            else
            {
                PlatformTargets = pages [0].PlatformTargets;

                if (pages.Count > 1)
                {
                    var intersection = new HashSet <AgentType> (PlatformTargets);
                    foreach (var page in pages.Skip(1))
                    {
                        intersection.IntersectWith(page.PlatformTargets);
                    }

                    PlatformTargets = intersection.ToImmutableArray();
                }
            }
        }
Exemple #3
0
        protected WorkbookPageViewModel(ClientSession clientSession, WorkbookPage workbookPage)
        {
            ClientSession = clientSession
                            ?? throw new ArgumentNullException(nameof(clientSession));

            WorkbookPage = workbookPage
                           ?? throw new ArgumentNullException(nameof(workbookPage));
        }
Exemple #4
0
        void Open(FilePath openPath, bool isDirectory, params AgentType [] platformTargets)
        {
            pages.Clear();

            var indexPage = new WorkbookPage(this, platformTargets);

            if (openPath.IsNull)
            {
                WorkingPath = FilePath.Empty;
                AddPage(indexPage);
                return;
            }

            FilePath readPath;

            if (isDirectory)
            {
                indexPage.Path      = indexPageFileName;
                readPath            = openPath.Combine(indexPage.Path);
                openedFromDirectory = true;
            }
            else
            {
                // If we are opening a file within a .workbook directory somewhere,
                // actually open that directory. This is to mostly address issues
                // on Windows where you cannot open a directory via Explorer.
                //
                // FIXME: The file within the workbook directory is intentionally
                // ignored for now, so this will effectively open index.workbook,
                // hitting the 'isDirectory' path above via the recursive Open call.
                // In reality for now it does not matter since we do not support
                // workbooks with multiple pages.
                for (var parentPath = openPath.ParentDirectory;
                     !parentPath.IsNull;
                     parentPath = parentPath.ParentDirectory)
                {
                    if (parentPath.DirectoryExists && parentPath.Extension == dottedExtension)
                    {
                        LogicalPath = parentPath;
                        Open(parentPath, true, platformTargets);
                        return;
                    }
                }

                indexPage.Path = openPath.Name;
                readPath       = openPath;
            }

            using (var stream = new FileStream(
                       readPath,
                       FileMode.Open,
                       FileAccess.Read,
                       FileShare.Read)) {
                if (!isDirectory)
                {
                    if (ZipArchiveExtensions.SmellHeader(stream))
                    {
                        OpenZip(stream, platformTargets);
                        return;
                    }

                    // seek back to start since we just checked for a Zip header
                    stream.Seek(0, SeekOrigin.Begin);
                }

                indexPage.Read(new StreamReader(stream));
            }

            AddPage(indexPage);
            WorkingPath = openPath;
        }