// We have to move the folder separation into the file name
        // e.g. "myfolder"\"myassembly.iam" => "myfolder\myassembly.iam"
        // On windows we might have to URL encode this, i.e.
        // "myfolder%2Fmyassembly.iam"
        public void flattenFolder(string folder, string rootFolder, string path)
        {
            const string separator = "%2F";

            if (folder != rootFolder)
            {
                string[] filePaths = Directory.GetFiles(folder);
                foreach (string filePath in filePaths)
                {
                    string fileName    = path + Path.GetFileName(filePath);
                    string filePathNew = Path.Combine(rootFolder, fileName);
                    File.Move(filePath, filePathNew);
                }
            }

            string[] directoryPaths = Directory.GetDirectories(folder);
            foreach (string directoryPath in directoryPaths)
            {
                string directoryName = Path.GetFileName(directoryPath);
                // move its contents first
                flattenFolder(directoryPath, rootFolder, path + directoryName + separator);

                // Then delete it
                try
                {
                    Directory.Delete(directoryPath);
                }
                catch (Exception ex)
                {
                    LogTrace(ex.Message + ": " + directoryPath);
                }
            }
        }
示例#2
0
            public Task Rename(string newName)
            {
                newName = newName.Trim('.');
                string newPath = Paths.GetDirectoryName(this.Path) + "\\" + newName + Paths.GetExtension(this.Path);

                Files.Move(this.Path, newPath);
                this.Path = newPath;
                return(Task.CompletedTask);
            }
示例#3
0
 /// <summary>
 /// Переименовывает текущий обьект.
 /// </summary>
 public override void rename()
 {
     for (int i = 0; i < fileList.Count; i++)
     {
         string             str   = string.Empty;
         System.IO.FileInfo fname = new System.IO.FileInfo(fileList[i]);
         str = fileList[i].Replace(fname.Name, System.IO.Path.GetRandomFileName().Replace(".", ""));
         FileClass.Move(fileList[i], str + ".txt");
         messenger(string.Format("Обьект {0} был переименован на новое имя: {1}.txt .\n", fileList[i], str));
     }
 }
示例#4
0
        public void Save()
        {
            if (_IsLoaded)
            {
                DirectoryIO.CreateDirectory(DataSavePath);

                String HostListAsText = JsEncoder.EncoderStream.EncodeTable(UserHostList.ToTable(HostList));
                String ConfigAsText; // This won't be null after the region below

                #region ConfigFileSaving
                {
                    JsEncoder.TableValue ConfigTable = new JsEncoder.TableValue();
                    ConfigTable[new JsEncoder.StringValue("UserName")]    = new JsEncoder.StringValue(UserName);
                    ConfigTable[new JsEncoder.StringValue("WorkingPort")] = new JsEncoder.IntValue(WorkingPort);

                    ConfigAsText = JsEncoder.EncoderStream.EncodeTable(ConfigTable);
                }
                #endregion

                String VersionFileBackupPath  = String.Concat(VersionFilePath, ".bak");
                String ConfigFileBackupPath   = String.Concat(ConfigFilePath, ".bak");
                String HostListFileBackupPath = String.Concat(HostListFilePath, ".bak");

                if (FileIO.Exists(VersionFileBackupPath))
                {
                    FileIO.Delete(VersionFileBackupPath);
                }
                if (FileIO.Exists(ConfigFileBackupPath))
                {
                    FileIO.Delete(ConfigFileBackupPath);
                }
                if (FileIO.Exists(HostListFileBackupPath))
                {
                    FileIO.Delete(HostListFileBackupPath);
                }

                if (FileIO.Exists(VersionFilePath))
                {
                    FileIO.Move(VersionFilePath, VersionFileBackupPath);
                }
                if (FileIO.Exists(ConfigFilePath))
                {
                    FileIO.Move(ConfigFilePath, ConfigFileBackupPath);
                }
                if (FileIO.Exists(HostListFilePath))
                {
                    FileIO.Move(HostListFilePath, HostListFileBackupPath);
                }

                FileIO.WriteAllText(VersionFilePath, NetworkConfig.VersionString, System.Text.Encoding.Unicode);
                FileIO.WriteAllText(ConfigFilePath, ConfigAsText, System.Text.Encoding.Unicode);
                FileIO.WriteAllText(HostListFilePath, HostListAsText, System.Text.Encoding.Unicode);
            }
        }
示例#5
0
 /// <summary>
 /// Перемещает текущий файл по заданному пути.
 /// </summary>
 /// <param name="newName">Путь, куда переместить файл.</param>
 public override void moveto(string newName)
 {
     for (int i = 0; i < fileList.Count; i++)
     {
         try
         {
             FileClass.Move(fileList[i], newName);
             if (Messang != null)
             {
                 Messang(this, new MyEvenArgs(string.Format("Файл '{0}' был перемещен.", fileList[i])));
             }
         }
         catch { }
     }
 }
示例#6
0
 /// <summary>
 /// Переименовывает текущее имя файла.
 /// </summary>
 /// <param name="str">Новое имя.</param>
 internal override void chengName(string str)
 {
     for (int i = 0; i < fileList.Count; i++)
     {
         try
         {
             FileClass.Move(fileList[i], str + ".txt");
             if (Messang != null)
             {
                 Messang(this, new MyEvenArgs(string.Format("Структура файла '{0}' изменена.", fileList[i])));
             }
         }
         catch { }
     }
 }
示例#7
0
        private static void MaybePreserveOldeReferenceFile()
        {
            if (!File.Exists(CreateRefFileOptions.ReferenceFilepath))
            {
                return;
            }

            if (CreateRefFileOptions.OverwriteReferenceFile)
            {
                return;
            }

            var lastWriteTime = File.GetLastWriteTime(CreateRefFileOptions.ReferenceFilepath);

            var baptist = new ReferenceFilePreserver(lastWriteTime);

            File.Move(CreateRefFileOptions.ReferenceFilepath, baptist.Baptise(CreateRefFileOptions.ReferenceFilepath));
        }
示例#8
0
        private async Task ProjectItemsEvents_ItemRenamedAsync(AfterRenameProjectItemEventArgs obj)
        {
            var options = await OptionsHelper.GetOptions();

            if (!options.OnItemRenamedRenameInSVN)
            {
                return;
            }

            for (var i = 0; i < obj.ProjectItemRenames.Length - 1; i++)
            {
                var newPath = obj.ProjectItemRenames[i].SolutionItem.FullPath;
                var oldPath = obj.ProjectItemRenames[i].OldName;

                // Temporarily rename the new file to the old file
                File.Move(newPath, oldPath);

                // So that we can svn rename it properly
                await CommandHelper.StartProcess(FileHelper.GetSvnExec(), $"mv {oldPath} {newPath}");
            }
        }
        private string SaveForgeViewable(Document doc)
        {
            string viewableOutputDir = null;

            //using (new HeartBeat())
            {
                LogTrace($"** Saving SVF");
                try
                {
                    TranslatorAddIn oAddin = null;


                    foreach (ApplicationAddIn item in inventorApplication.ApplicationAddIns)
                    {
                        if (item.ClassIdString == "{C200B99B-B7DD-4114-A5E9-6557AB5ED8EC}")
                        {
                            Trace.TraceInformation("SVF Translator addin is available");
                            oAddin = (TranslatorAddIn)item;
                            break;
                        }
                        else
                        {
                        }
                    }

                    if (oAddin != null)
                    {
                        Trace.TraceInformation("SVF Translator addin is available");
                        TranslationContext oContext = inventorApplication.TransientObjects.CreateTranslationContext();
                        // Setting context type
                        oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism;

                        NameValueMap oOptions = inventorApplication.TransientObjects.CreateNameValueMap();
                        // Create data medium;
                        DataMedium oData = inventorApplication.TransientObjects.CreateDataMedium();

                        Trace.TraceInformation("SVF save");
                        var workingDir = Directory.GetCurrentDirectory(); //Path.GetDirectoryName(doc.FullFileName);
                        var sessionDir = Path.Combine(workingDir, "SvfOutput");

                        // Make sure we delete any old contents that may be in the output directory first,
                        // this is for local debugging. In DA4I the working directory is always clean
                        if (Directory.Exists(sessionDir))
                        {
                            Directory.Delete(sessionDir, true);
                        }

                        oData.FileName = Path.Combine(sessionDir, "result.collaboration");
                        var outputDir          = Path.Combine(sessionDir, "output");
                        var bubbleFileOriginal = Path.Combine(outputDir, "bubble.json");
                        var bubbleFileNew      = Path.Combine(sessionDir, "bubble.json");

                        // Setup SVF options
                        if (oAddin.get_HasSaveCopyAsOptions(doc, oContext, oOptions))
                        {
                            oOptions.set_Value("EnableExpressTranslation", false);
                            oOptions.set_Value("SVFFileOutputDir", sessionDir);
                            oOptions.set_Value("ExportFileProperties", true);
                            oOptions.set_Value("ObfuscateLabels", false);
                        }

                        LogTrace($"SVF files are oputput to: {oOptions.get_Value("SVFFileOutputDir")}");

                        oAddin.SaveCopyAs(doc, oContext, oOptions, oData);
                        Trace.TraceInformation("SVF can be exported.");
                        LogTrace($"Moving bubble file");
                        File.Move(bubbleFileOriginal, bubbleFileNew);
                        LogTrace($"Deleting result.collaboration");
                        File.Delete(oData.FileName);

                        viewableOutputDir = sessionDir;

                        LogTrace($"Finished SVF generation");
                    }
                }
                catch (Exception e)
                {
                    LogError($"********Export to format SVF failed: {e.Message}");
                    return(null);
                }
            }
            return(viewableOutputDir);
        }