public PortraitsRessources(SSDirectory directory) { Directory = directory; ReferencedFiles = (from KeyValuePair <string, ISSGroup> kv in Directory.GroupedFiles where kv.Value is SSFactionGroup select kv.Value as SSFactionGroup).ToList(); IEnumerable <JsonValue> ReferencedPortrait = ReferencedFiles.SelectMany(g => { List <JsonToken> result = new List <JsonToken>(); if (g.MalePortraits != null) { result.AddRange(g.MalePortraits.GetOriginalContent()); } if (g.FemalePortraits != null) { result.AddRange(g.FemalePortraits.GetOriginalContent()); } return(result); }).Distinct().Cast <JsonValue>(); foreach (JsonValue referenced in ReferencedPortrait) { string pathRelative = referenced.ToString().Replace('/', '\\'); Portraits port = this.FindBinaryFromDirectory(pathRelative); if (port != null) { RessourceCorrespondance.Add(pathRelative, port); } } }
/// <summary> /// Save as allows saving experiment in different location with referenced files copied. /// </summary> /// <param name="experiment">The experiment.</param> /// <param name="fileName">Name of the file.</param> /// <param name="referencedFilesProcessing">The referenced files processing.</param> /// <returns></returns> public static bool SaveAs(Experiment experiment, string fileName, ReferencedFiles referencedFilesProcessing) { if (fileName == null) { throw new ArgumentNullException("fileName"); } string oldExperimentFilePath = experiment.ExperimentInfo.FilePath; bool success = false; try { //update its FilePath info to the new file location experiment.ExperimentInfo.FilePath = fileName; if (referencedFilesProcessing == ReferencedFiles.KEEPREFERENCE) { //Filepath of experiment has changed so update all referenced files before saving the file //only this changes the Relative properties of FilePaths and DirectoryPaths //the Relative property is the only one that is serialized SetNewRootLocationToReferencedFiles(experiment, true); } success = Save(experiment); if (success == true) { // process the components Path config values in the experiment - to update their Absolute and DataRoot properties to new location // if copy has been selected copy files accordingly // note KeepReference is not processed, as it was already processed before (because Relative property is being serialized. switch (referencedFilesProcessing) { case ReferencedFiles.COPY: CopyReferencedFiles(experiment, oldExperimentFilePath, false); break; case ReferencedFiles.COPYOVERWRITE: CopyReferencedFiles(experiment, oldExperimentFilePath, true); break; case ReferencedFiles.IGNORE: SetNewRootLocationToReferencedFiles(experiment, false); break; } } } finally { if (success == false) { experiment.ExperimentInfo.FilePath = oldExperimentFilePath; //go back to old filepath //Roll back the changes to Relative properties of FilePaths and DirectoriesPaths. SetNewRootLocationToReferencedFiles(experiment, true); } } return(success); }
public override int GetHashCode() { unchecked { var hashCode = Generation.GetHashCode(); hashCode = (hashCode * 397) ^ (SegmentsFileName != null ? SegmentsFileName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ReferencedFiles != null ? ReferencedFiles.GetHashCode() : 0); hashCode = (hashCode * 397) ^ IsIndexCorrupted.GetHashCode(); return(hashCode); } }
public void LoadTaxonomyDocument(string path) { //remove hash if (path.Contains("#")) { path = path.Remove(path.IndexOf("#")); } var loaded = _LoadedSourcePathes.FirstOrDefault(i => i == path); if (loaded == null) { _LoadedSourcePathes.Add(path); var fullpath = path; //var taxonomydocument = Engine.CurrentEngine.TaxonomyDocuments.FirstOrDefault(i => i.SourcePath == path); var sourcepath = path; if (Utilities.Strings.IsRelativePath(sourcepath)) { sourcepath = Utilities.Strings.ResolveRelativePath(SourceFolder, path); } var localpath = Utilities.Strings.GetLocalPath(XbrlEngine.LocalFolder, sourcepath); var localrelpath = Utilities.Strings.GetRelativePath(LogicalModel.TaxonomyEngine.LocalFolder, localpath); //Logger.WriteLine(localpath); var taxonomydocument = Taxonomy.FindDocument(localrelpath); if (taxonomydocument == null) { //Logger.WriteLine(path); taxonomydocument = new XbrlTaxonomyDocument(path, this); Taxonomy.AddTaxonomyDocument(taxonomydocument); taxonomydocument.LoadReferences(); } //var reference = References.FirstOrDefault(i => i.SourcePath == path); var reference = References.FirstOrDefault(i => i.LocalRelPath == localrelpath); if (reference == null) { References.Add(taxonomydocument); ReferencedFiles.Add(taxonomydocument.LocalRelPath); } } }
private void SetRelativePathsProcessing(int selected) { if (selected == _copyId) { m_referencedFilesProcessing = ReferencedFiles.COPY; } else if (selected == _copyOverwriteId) { m_referencedFilesProcessing = ReferencedFiles.COPYOVERWRITE; } else if (selected == _keepReferenceId) { m_referencedFilesProcessing = ReferencedFiles.KEEPREFERENCE; } else { m_referencedFilesProcessing = ReferencedFiles.IGNORE; } }
protected bool Equals(IndexSegmentsInfo other) { var theSameNumberOfItems = ReferencedFiles.Count == other.ReferencedFiles.Count; var theSameReferencedFiles = true; if (theSameNumberOfItems) { if (ReferencedFiles.Any(file => other.ReferencedFiles.Contains(file) == false)) { theSameReferencedFiles = false; } } else { theSameReferencedFiles = false; } return(theSameReferencedFiles && Generation == other.Generation && string.Equals(SegmentsFileName, other.SegmentsFileName) && IsIndexCorrupted.Equals(other.IsIndexCorrupted)); }
public void Refresh() { ReferencedFiles.Clear(); if (ReferencedFileSave != null) { TaskManager.Self.AddAsyncTask(() => { var contentDirectory = GlueState.Self.ContentDirectory; var files = GlueCommands.Self.FileCommands.GetFilesReferencedBy(ReferencedFileSave, EditorObjects.Parsing.TopLevelOrRecursive.Recursive); files = files .Select(item => { if (FileManager.IsRelativeTo(item, contentDirectory)) { return(FileManager.MakeRelative(item, contentDirectory)); } else { return(item); } }) .Distinct() .OrderBy(item => item); MainGlueWindow.Self.Invoke(() => { foreach (var file in files) { ReferencedFiles.Add(file); } }); }, "Refreshing unreferenced files"); } }
/// <summary> /// Save as allows saving experiment in different location with referenced files copied. /// </summary> /// <param name="experiment">The experiment.</param> /// <param name="fileName">Name of the file.</param> /// <param name="referencedFilesProcessing">The referenced files processing.</param> /// <returns></returns> public static bool SaveAs(Experiment experiment, string fileName, ReferencedFiles referencedFilesProcessing) { if (fileName == null) throw new ArgumentNullException("fileName"); string oldExperimentFilePath = experiment.ExperimentInfo.FilePath; bool success = false; try { //update its FilePath info to the new file location experiment.ExperimentInfo.FilePath = fileName; if (referencedFilesProcessing == ReferencedFiles.KEEPREFERENCE) { //Filepath of experiment has changed so update all referenced files before saving the file //only this changes the Relative properties of FilePaths and DirectoryPaths //the Relative property is the only one that is serialized SetNewRootLocationToReferencedFiles(experiment, true); } success = Save(experiment); if (success == true) { // process the components Path config values in the experiment - to update their Absolute and DataRoot properties to new location // if copy has been selected copy files accordingly // note KeepReference is not processed, as it was already processed before (because Relative property is being serialized. switch (referencedFilesProcessing) { case ReferencedFiles.COPY: CopyReferencedFiles(experiment, oldExperimentFilePath, false); break; case ReferencedFiles.COPYOVERWRITE: CopyReferencedFiles(experiment, oldExperimentFilePath, true); break; case ReferencedFiles.IGNORE: SetNewRootLocationToReferencedFiles(experiment, false); break; } } } finally { if (success == false) { experiment.ExperimentInfo.FilePath = oldExperimentFilePath; //go back to old filepath //Roll back the changes to Relative properties of FilePaths and DirectoriesPaths. SetNewRootLocationToReferencedFiles(experiment, true); } } return success; }
private void Activated(object sender, EventArgs args) { //save the experiment of this application view model Experiment experiment = m_applicationContext.Application.Experiment; if (experiment != null) { string file = FileDialogs.ShowSaveAsDialog(m_applicationContext.MainWindow.WindowShell, experiment.ExperimentInfo.FilePath); if (file != null) { //remember old guid in case save fails Guid oldId = experiment.ExperimentInfo.GuidId; bool successfulSave = false; try { experiment.ExperimentInfo.GuidId = Guid.NewGuid(); //TODO: allow user to set whether referenced files should be copied or not ReferencedFiles referencedFilesProcessing = ReferencedFiles.IGNORE; //try save successfulSave = ExperimentManager.SaveAs(experiment, file, referencedFilesProcessing); } catch (System.IO.IOException e) { FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file); } catch (UnauthorizedAccessException e) { FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file); } catch (TraceLab.Core.Exceptions.FilesCopyFailuresException e) { //some referenced files failed to be copied... note the experiment still might have been saved as correctly NLog.LogManager.GetCurrentClassLogger().Warn(String.Format("Failed to Save File {0}. {1}", file, e.Message)); //TODO //DisplayCopyErrorsWindow(e); } catch (Exception e) { FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file); } if (successfulSave == true) { //reset the workspace view and logView to the new experiment id //so that both workspace and log view shows the data of the experiment with new id ApplicationViewModel.CreateNewApplicationViewModel(m_applicationContext.Application, experiment); //create new workspace view for the new experiment id m_applicationContext.Application.WorkspaceViewModel = new WorkspaceViewModel((TraceLab.Core.Workspaces.Workspace)m_applicationContext.Application.WorkspaceViewModel, experiment.ExperimentInfo.Id); m_applicationContext.Application.LogViewModel = new LogViewModel(experiment.ExperimentInfo.Id, m_applicationContext.Application.LogViewModel); } else { //otherwise don't change the views, but reset the experiment id back to old ID experiment.ExperimentInfo.GuidId = oldId; } } } }