public void RegisterViewer(IFileViewerService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            if (service.SupportedFileTypes == null || service.SupportedFileTypes.Length == 0)
            {
                throw new ArgumentException("service", "one or more supported file types required");
            }

            foreach (var fileType in service.SupportedFileTypes)
            {
                var normalizedExtensionName = FileDocumentService.NormalizeExtensionName(fileType.ExtensionName);
                this.LogInfo("registering FileViewerService '{0}' for file type '{1}'", service.Name, normalizedExtensionName);

                IFileViewerService existedService;
                if (_services.TryGetValue(normalizedExtensionName, out existedService))
                {
                    this.LogWarning("a FileViewerService '{0}' of file type '{1}' is already existed, it will be replaced",
                                    existedService.Name,
                                    normalizedExtensionName);
                }

                _services[normalizedExtensionName]  = service;
                _fileTypes[normalizedExtensionName] = fileType;
            }
        }
 public FirstLookViewModel()
 {
     this.GenerateCommand      = new Command(async() => await this.Generate());
     this.resourceService      = Xamarin.Forms.DependencyService.Get <IResourceService>();
     this.fileViewerService    = Xamarin.Forms.DependencyService.Get <IFileViewerService>();
     this.SelectedExportFormat = this.ExportFormats.ElementAt(0);
 }
        public FindAndReplaceViewModel()
        {
            this.GenerateSampleCommand = new Command(this.GenerateSampleExecute);
            this.ReplaceAndSaveCommand = new Command(this.ReplaceAndSaveExecute);

            this.fileViewerService = Xamarin.Forms.DependencyService.Get <IFileViewerService>();
        }
Ejemplo n.º 4
0
        public ContentLogic(IContentService contentService, IAttachmentService attachmentService, ILegacyContentService legacyContentService, IFileViewerService fileViewerService)
        {
            if (contentService == null)
            {
                throw new ArgumentNullException("contentService");
            }

            if (attachmentService == null)
            {
                throw new ArgumentNullException("attachmentService");
            }

            if (fileViewerService == null)
            {
                throw new ArgumentNullException("fileViewerService");
            }

            if (legacyContentService == null)
            {
                throw new ArgumentNullException("legacyContentService");
            }

            ContentService       = contentService;
            AttachmentService    = attachmentService;
            LegacyContentService = legacyContentService;
            FileViewerService    = fileViewerService;
        }
        public async void ViewFormattedDocument(object parameter)
        {
            IWorkbookFormatProvider provider = new XlsxFormatProvider();
            Workbook workbook;

            try
            {
                Assembly assembly = typeof(ConditionalFormattingViewModel).Assembly;
                string   fileName = assembly.GetManifestResourceNames().First(n => n.Contains("SpreadProcessingDocument2.xlsx"));

                using (Stream stream = assembly.GetManifestResourceStream(fileName))
                {
                    workbook = provider.Import(stream);
                }
                this.AddRules(workbook);

                Stream mystream = await OpenStreamAsync(workbook);

                using (mystream)
                {
                    IFileViewerService fileViewerService = DependencyService.Get <IFileViewerService>();
                    await fileViewerService.View(mystream, fileName);
                }
            }
            catch
            {
                IMessageService messageService = DependencyService.Get <IMessageService>();
                await messageService.ShowMessage("An error occured", "An error occured, please try again.");
            }
        }
        public ContentLogic(IContentService contentService, IAttachmentService attachmentService, ILegacyContentService legacyContentService, IFileViewerService fileViewerService)
        {
            if (contentService == null)
            {
                throw new ArgumentNullException("contentService");
            }

            if (attachmentService == null)
            {
                throw new ArgumentNullException("attachmentService");
            }

            if (fileViewerService == null)
            {
                throw new ArgumentNullException("fileViewerService");
            }

            if (legacyContentService == null)
            {
                throw new ArgumentNullException("legacyContentService");
            }

            ContentService = contentService;
            AttachmentService = attachmentService;
            LegacyContentService = legacyContentService;
            FileViewerService = fileViewerService;
        }
Ejemplo n.º 7
0
        private static async Task ViewDocumentAsync(Workbook workbook, string fileName)
        {
            Stream stream = await OpenStreamAsync(workbook);

            using (stream)
            {
                IFileViewerService fileViewerService = DependencyService.Get <IFileViewerService>();
                await fileViewerService.View(stream, fileName);
            }
        }
        private DocumentInfo CreateDocument(Guid guid, Uri uri, IFileViewerService fileViewerService)
        {
            IFeature[] features;
            var        viewer   = fileViewerService.CreateViewer(uri.LocalPath, out features);
            var        document = new DocumentInfo(guid: guid,
                                                   repositoryId: this.RepositoryManager.FindOwner(uri.LocalPath).ID,
                                                   uri: uri,
                                                   title: UnifiedPath.GetFileName(uri.LocalPath),
                                                   content: viewer,
                                                   features: features)
            {
                Description = uri.LocalPath,
                IconSource  = this.RepositoryManager.FindOwner(uri.LocalPath).GetMarker()
            };

            return(document);
        }
Ejemplo n.º 9
0
        public static string GetFilter(this IFileViewerService service, bool generateAllFiles = true)
        {
            var builder = new StringBuilder();

            foreach (var fileType in service.SupportedFileTypes)
            {
                builder.AppendFormat("{0} (*.{1})|*.{1}|", fileType.Description, fileType.ExtensionName);
            }

            if (generateAllFiles)
            {
                builder.Append("All Files(*.*)|*.*");
            }
            else
            {
                builder.Remove(builder.Length - 1, 1);
            }

            return(builder.ToString());
        }
Ejemplo n.º 10
0
        private async Task GenerateAsync()
        {
            try
            {
                Workbook workbook = this.CreateWorkbook();
                Stream   stream   = await OpenStreamAsync(workbook);

                using (stream)
                {
                    string             fileName          = string.Format("RadSpreadProcessingFile.xlsx");
                    IFileViewerService fileViewerService = DependencyService.Get <IFileViewerService>();
                    await fileViewerService.View(stream, fileName);
                }
            }
            catch
            {
                IMessageService messageService = DependencyService.Get <IMessageService>();
                await messageService.ShowMessage("An error occured", "An error occured, please try again.");
            }
        }
Ejemplo n.º 11
0
        private async static Task GenerateAsync(string exportFormat)
        {
            try
            {
                Workbook workbook = workbookCache ?? await ImportAndCacheWorkbookAsync();

                Stream stream = await OpenStreamAsync(workbook, exportFormat);

                using (stream)
                {
                    string             fileName          = string.Format("RadSpreadProcessingConvertedFile.{0}", exportFormat);
                    IFileViewerService fileViewerService = DependencyService.Get <IFileViewerService>();
                    await fileViewerService.View(stream, fileName);
                }
            }
            catch
            {
                IMessageService messageService = DependencyService.Get <IMessageService>();
                await messageService.ShowMessage("An error occured", "An error occured, please try again.");
            }
        }
Ejemplo n.º 12
0
 public FirstLookViewModel()
 {
     this.Save              = new Xamarin.Forms.Command(async(p) => await this.Export(p));
     this.resourceService   = Xamarin.Forms.DependencyService.Get <IResourceService>();
     this.fileViewerService = Xamarin.Forms.DependencyService.Get <IFileViewerService>();
 }
Ejemplo n.º 13
0
 public ExportViewModel()
 {
     this.ExportCommand        = new Command(this.ExportCommandExecute);
     this.fileViewerService    = DependencyService.Get <IFileViewerService>();
     this.SelectedExportFormat = this.ExportFormats.ElementAt(0);
 }