public string ExpandMacroUsingNetwork(string str, MCN network) { // replace strings with their macros, using the network context if required. if (string.IsNullOrEmpty(str)) { return(string.Empty); } str = ExpandMacro(str); foreach (ReservedNetworkMacroKeys macro in Enum.GetValues(typeof(ReservedNetworkMacroKeys))) { string macroString = Prefix + Enum.GetName(typeof(ReservedNetworkMacroKeys), macro) + Suffix; var regex = new Regex(Regex.Escape(macroString), RegexOptions.IgnoreCase); if (regex.IsMatch(str)) { switch (macro) { case ReservedNetworkMacroKeys.MCP_PATH: { FileInfo fileInfo = new FileInfo(network.GetMCPPathAbsoluteExpanded()); str = regex.Replace(str, fileInfo.DirectoryName); break; } case ReservedNetworkMacroKeys.MCN_NAME: { FileInfo fileInfo = new FileInfo(network.GetMCNPathAbsoluteExpanded()); str = regex.Replace(str, Path.GetFileNameWithoutExtension(fileInfo.Name)); break; } case ReservedNetworkMacroKeys.MCN_PATH: { FileInfo fileInfo = new FileInfo(network.GetMCNPathAbsoluteExpanded()); str = fileInfo.Directory.FullName; break; } case ReservedNetworkMacroKeys.MCN_DIR: { FileInfo fileInfo = new FileInfo(network.GetMCNPathAbsoluteExpanded()); str = regex.Replace(str, fileInfo.Directory.Name); break; } } } } return(str); }
public static void GetFilePathsFromNetwork(MCN network, string exportRootPath, out string mcpFile, out string mcnFile, out string intermediateFile) { // build the xml file FileInfo mcnfileInfo = new FileInfo(network.GetMCNPathAbsoluteExpanded()); string exportFileName = mcnfileInfo.Name.Replace(MCN.MCNExtension, MCN.MCNIntermediateExtension); string exportFileFullName = Path.Combine(exportRootPath, exportFileName); // format the paths to work with connect mcnFile = network.GetMCNPathAbsoluteExpanded().Replace("\\", "/"); mcpFile = network.GetMCPPathAbsoluteExpanded().Replace("\\", "/"); intermediateFile = exportFileFullName.Replace("\\", "/"); }