public void Write(Instance instance)
        {
            var entries = new Dictionary <string, string>();

            var inlineXbrlWriter = new InlineXbrlWriter(_template, _settings);

            instance.Save(inlineXbrlWriter);
            entries[_settings.InlineXbrlFileName] = inlineXbrlWriter.Document.ToString();

            foreach (var taxonomy in instance.Dts.Taxonomies)
            {
                if (taxonomy.EntryPointUri.IsAbsoluteUri)
                {
                    // No need to include taxonomies with absolute entry points in the archive.
                    continue;
                }

                var taxonomyWriter = new ZipArchiveWriter();
                taxonomy.Save(taxonomyWriter);
                var taxonmyEntries = ZipArchiveHelper.ExtractEntries(taxonomyWriter.ZipArchiveBytes);
                foreach (var taxonmyEntry in taxonmyEntries)
                {
                    entries[taxonmyEntry.Key] = taxonmyEntry.Value;
                }
            }

            ZipArchiveBytes = ZipArchiveHelper.CreateFromEntries(entries);
        }
예제 #2
0
        private IEnumerable <int> GetWords(
            ZipArchiveHelper zipArchiveHelper,
            ZipArchiveEntry zipArchiveEntry,
            IDictionary <string, int> wordToId)
        {
            List <int> ids = new List <int>();

            if (zipArchiveEntry != null)
            {
                var text  = zipArchiveHelper.ReadAllTextFromEntry(zipArchiveEntry);
                var words = text.Split(' ', StringSplitOptions.RemoveEmptyEntries);

                foreach (var word in words)
                {
                    if (!wordToId.Keys.Contains(word))
                    {
                        wordToId.Add(word, wordToId.Count);
                    }

                    ids.Add(wordToId[word]);
                }
            }

            return(ids);
        }
예제 #3
0
        public override Stream GetStream(string path)
        {
            Stream stream = null;

            if (!String.IsNullOrEmpty(path))
            {
                stream = ZipArchiveHelper.OpenFile(_zip, path);
            }

            return(stream);
        }
예제 #4
0
        private IEnumerable <string> GetLinks(
            ZipArchiveHelper zipArchiveHelper,
            ZipArchiveEntry zipArchiveEntry)
        {
            if (zipArchiveEntry == null)
            {
                return(new string[0]);
            }

            var text = zipArchiveHelper.ReadAllTextFromEntry(zipArchiveEntry);

            if (text.Contains(Environment.NewLine))
            {
                Console.WriteLine("");
            }

            return(text.Split('\n', StringSplitOptions.RemoveEmptyEntries));
        }
예제 #5
0
        public static Task <IEnumerable <ZipFilePair> > GetPackageFiles(IEnumerable <ZipArchiveEntry> packageFiles, string packageDirectory,
                                                                        PackageSaveModes packageSaveMode, CancellationToken token)
        {
            List <ZipFilePair> effectivePackageFiles = new List <ZipFilePair>();

            foreach (var entry in packageFiles)
            {
                string path = ZipArchiveHelper.UnescapePath(entry.FullName);

                if (PackageHelper.IsPackageFile(path, packageSaveMode))
                {
                    var packageFileFullPath = Path.Combine(packageDirectory, path);
                    effectivePackageFiles.Add(new ZipFilePair(packageFileFullPath, entry));
                }
            }

            return(Task.FromResult <IEnumerable <ZipFilePair> >(effectivePackageFiles));
        }
예제 #6
0
        private async void OnUpload()
        {
            string headerFileName = Path.Combine(FileEndPointManager.Project2Folder, "header.json");

            using (StreamWriter file = File.CreateText(headerFileName))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, EventToAdd);
            }

            string recordJSDirectory  = FileEndPointManager.DefaultPlayXMLFile;
            string recordXMLDirectory = FileEndPointManager.DefaultLatestXMLFile;

            if (!File.Exists(recordJSDirectory) || !File.Exists(recordXMLDirectory))
            {
                //TODO: update this error message.
                MessageBox.Show("There are no record files to save. Please open an existing recording or make a new one.", AppName, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                List <string> fullPathsOfFilesToCompress = new List <string>
                {
                    recordJSDirectory,
                    recordXMLDirectory,
                    headerFileName
                };

                string eventToUploadFileName = Path.Combine(FileEndPointManager.Project2Folder, EventToAdd.FileName + "." + RecordFileExtension);

                ZipArchiveHelper.ArchiveFiles(fullPathsOfFilesToCompress, eventToUploadFileName);

                EventTagService eventTagService = new EventTagService();

                _progressBar = new ProgressBarSharedView("Uploading file. Please wait...");
                _progressBar.Show();
                var result = await eventTagService.CreateEvent(eventToUploadFileName);

                _progressBar.Close();

                MessageBox.Show(result, AppName, MessageBoxButton.OK, MessageBoxImage.Information);

                File.Delete(eventToUploadFileName);
            }
        }
예제 #7
0
        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            using (var diag = new System.Windows.Forms.OpenFileDialog())
            {
                diag.Filter      = FileDialogFilter;
                diag.FilterIndex = 1;

                var result = diag.ShowDialog();

                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    string filePath = diag.FileName;
                    OpenedFile = filePath;

                    ZipArchiveHelper.ExtractFiles(filePath, FileEndPointManager.Project2Folder, true);

                    // Run script as soon as it is opened
                    UpdateStatus(false);
                    Anterior_Click_1(sender, e);
                }
            }
        }
예제 #8
0
        private void Save_As_Click(object sender, RoutedEventArgs e)
        {
            if (!File.Exists(recordJSDirectory) || !File.Exists(recordXMLDirectory))
            {
                //TODO: update this error message.
                MessageBox.Show("There are no record files to save. Please open an existing recording or make a new one.", AppName, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                List <string> fullPathsOfFilesToCompress = new List <string>
                {
                    recordJSDirectory,
                    recordXMLDirectory
                };

                using (var diag = new System.Windows.Forms.SaveFileDialog())
                {
                    diag.SupportMultiDottedExtensions = true;
                    diag.FileOk      += CheckIfFileHasCorrectExtension;
                    diag.Filter       = FileDialogFilter;
                    diag.DefaultExt   = RecordFileExtension;
                    diag.AddExtension = true;

                    var result = diag.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        string destinationPathAndFileName = diag.FileName;
                        ZipArchiveHelper.ArchiveFiles(fullPathsOfFilesToCompress, destinationPathAndFileName);

                        OpenedFile = Path.GetFileName(diag.FileName);
                        UpdateStatus(false);
                    }
                }
            }
        }
예제 #9
0
 public override IEnumerable <string> GetFiles()
 {
     return(ZipArchiveHelper.GetFiles(_zip));
 }
 public static void ExportEnvironment(string fileName, string machProjectFile, string toolsFile, string toolingFile)
 {
     ZipArchiveHelper.ExportEnvironment(fileName, machProjectFile, toolsFile, toolingFile);
 }
 public static bool ImportEnvironment(string fileName, out string machProjectFile, out string toolsFile, out string toolingFile)
 {
     return(ZipArchiveHelper.ImportEnvironment(fileName, out machProjectFile, out toolsFile, out toolingFile));
 }
        public static MachineElementViewModel LoadMachineFromArchive(string machineFile)
        {
            var m = ZipArchiveHelper.Import(machineFile /*, (s) => _lastMachProjectFile = s*/);

            return(ConvertModelToViewModel(m));
        }