ICreateDocumentTask IDocumentService.CreateCreateDocumentTask(Uri uri, Guid guid, string persistentInfo)
        {
            return(CreateDocumentTask.FromFactory(() =>
            {
                if (uri.Scheme == Uri.UriSchemeFile)
                {
                    var path = uri.LocalPath;
                    if (path == null || !UnifiedFile.Exists(path))
                    {
                        return null;
                    }

                    var fileViewer = this.GetFileViewerService(UnifiedPath.GetExtension(path));
                    if (fileViewer == null)
                    {
                        return null;
                    }

                    return this.CreateDocument(guid, uri, fileViewer);
                }
                else if (uri.Scheme == StreamScheme)
                {
                    var streamId = uri.Host + uri.PathAndQuery;
                    StreamInfo streamInfo;
                    if (!_registeredStreams.TryGetValue(streamId, out streamInfo))
                    {
                        this.LogWarning("no registered stream with ID '{0}' found", streamId);
                        return null;
                    }

                    _registeredStreams.Remove(streamId);

                    if (!streamInfo.StreamReference.IsAlive)
                    {
                        this.LogWarning("the registered stream with ID '{0}' is no more alive", streamId);
                        return null;
                    }

                    var fileViewer = this.GetFileViewerServiceOrNotifyMissing(streamInfo.FileType);
                    if (fileViewer == null)
                    {
                        return null;
                    }


                    IFeature[] features;

                    var viewer = fileViewer.CreateViewer(streamInfo.StreamReference.Target, out features);

                    var document = DocumentInfo.CreateTemporary(streamInfo.OwnerRepository.ID, streamInfo.Title, uri, viewer, features);
                    document.Description = streamInfo.Description;

                    return document;
                }
                else
                {
                    throw new NotSupportedException();
                }
            }));
        }
        public ICreateDocumentTask CreateCreateDocumentTask(Uri uri, Guid guid, string persistentInfo)
        {
            return(CreateDocumentTask.FromFactory(() =>
            {
                var docType = uri.Host;

                switch (docType)
                {
                case RepositoryManagerDomain:
                    return RepositoryManagerDocumentService.Instance.CreateDocument(uri, guid, persistentInfo);

                default:
                    throw new NotSupportedException();
                }
            }));
        }
        public ICreateDocumentTask CreateCreateDocumentTask(Uri uri, Guid guid, string persistentInfo)
        {
            var targetRepositoryId = uri.LocalPath;
            var refMatch           = Regex.Match(uri.Query, @"\?ref\=(.+)");

            if (!refMatch.Success)
            {
                this.LogWarning("invalid patchnote Uri format: {0}", uri);
                return(null);
            }

            var referenceRepositoryId = Uri.UnescapeDataString(refMatch.Groups[1].Value);

            var targetRepository = RepositoryManager.Instance[targetRepositoryId];

            if (targetRepository == null)
            {
                this.LogWarning("invalid target repository: {0}", targetRepositoryId);
                return(null);
            }

            var referenceRepository = RepositoryManager.Instance[referenceRepositoryId];

            if (referenceRepository == null)
            {
                this.LogWarning("invalid reference repository: {0}", referenceRepositoryId);
                return(null);
            }

            return(CreateDocumentTask.FromFactory(() =>
            {
                var view = new PatchnoteGeneratorDocumentView();
                var vm = new PatchnoteGeneratorDocumenVM(view.CommandBindings, targetRepository, referenceRepository, persistentInfo);
                view.ViewModel = vm;

                var docInfo = new DocumentInfo(guid: guid,
                                               repositoryId: targetRepositoryId,
                                               uri: uri,
                                               title: this.L("patchnote_generator", "document_title"),
                                               content: view,
                                               persistentInfoProvider: vm.PersistentInfo);

                return docInfo;
            }));
        }
        protected override ICreateDocumentTask CreateCreateDocumentTask(Uri uri, Guid guid, IRepository repository, string persistentInfo)
        {
            return(CreateDocumentTask.FromFactory(() =>
            {
                var view = new TechTreeDocumentView();
                var vm = new TechTreeDocumentVM(this, view.CommandBindings, repository, persistentInfo);
                view.ViewModel = vm;

                var docInfo = new DocumentInfo(guid: guid,
                                               repositoryId: repository.ID,
                                               uri: uri,
                                               title: this.L("techtree", "document_title"),
                                               content: view,
                                               persistentInfoProvider: vm.PersistentInfo);

                return docInfo;
            }));
        }
        protected override ICreateDocumentTask CreateCreateDocumentTask(IRepository repository,
                                                                        Uri uri,
                                                                        Guid guid,
                                                                        IXQueryable tank,
                                                                        string persistentInfo)
        {
            return(CreateDocumentTask.FromFactory(() =>
            {
                var tankInstance = TankInstanceManager.GetInstance(repository, tank);

                var view = new TankModuleTreeDocumentView();
                var vm = new TankModuleTreeDocumentVM(this, view.CommandBindings, tankInstance, persistentInfo);
                view.ViewModel = vm;

                return new DocumentInfo(guid: guid,
                                        repositoryId: repository.ID,
                                        uri: uri,
                                        title: string.Format("{0} [module tree]", tankInstance.Tank.Name),
                                        content: view,
                                        features: new IFeature[] { vm });
            }));
        }
Пример #6
0
        protected override ICreateDocumentTask CreateCreateDocumentTask(IRepository repository,
                                                                        Uri uri,
                                                                        Guid guid,
                                                                        IXQueryable tank,
                                                                        string persistentInfo)
        {
            return(CreateDocumentTask.FromFactory(() =>
            {
                var tankInstance = TankInstanceManager.GetInstance(repository, tank);

                var view = new ModelDocumentView();
                var vm = new ModelDocumentVM(this, view.CommandBindings, tankInstance, persistentInfo);
                view.ViewModel = vm;

                return new DocumentInfo(guid: guid,
                                        repositoryId: repository.ID,
                                        uri: uri,
                                        title: this.L("model_inspector", "document_title", tankInstance.Tank.Name),
                                        content: view,
                                        features: new IFeature[] { vm },
                                        persistentInfoProvider: vm.PersistentInfo);
            }));
        }
        public override ICreateDocumentTask CreateCreateDocumentTask(Uri uri, Guid guid, string persistentInfo)
        {
            return(CreateDocumentTask.FromFactory(() =>
            {
                var view = new StatComparisonDocumentView();
                var vm = new StatComparisonDocumentVM(this, view.CommandBindings, persistentInfo);
                view.ViewModel = vm;

                var docInfo = new DocumentInfo(guid: guid,
                                               repositoryId: null,
                                               uri: uri,
                                               title: this.L("stat_comparer", "new_comparison_default_title"),
                                               content: view,
                                               features: new IFeature[] { vm },
                                               persistentInfoProvider: vm.PersistentInfo)
                {
                    IconSource = StatComparerModule.CompareIcon
                };
                vm.DocumentInfo = docInfo;

                return docInfo;
            }));
        }