public void ImportIdocFiles(RepositoryItem repositoryItem, IEnumerable <string> filePaths) { #region Argument Check if (repositoryItem == null) { throw new ArgumentNullException("repositoryItem"); } if (filePaths == null) { throw new ArgumentNullException("filePaths"); } #endregion var definition = SapIDocDefinition.LoadHeader(repositoryItem.DefinitionFilePath); foreach (var filePath in filePaths) { var contents = File.ReadAllText(filePath); var doc = new SapIDoc(definition, contents); var resultingFileContents = doc.GetXml().ToString(SaveOptions.None); var resultingFilePath = Path.Combine( this.RepositoryPath, repositoryItem.Folder, string.Format(CultureInfo.InvariantCulture, "{0}.txt", doc.Number)); File.WriteAllText(resultingFilePath, resultingFileContents); } }
private void UpdateActionFiles( IActionScriptItem initActionItem, IActionScriptItem mainActionItem, IActionScriptItem endActionItem) { Logger.InfoFormat( "Updating action files '{0}' and '{1}'.", mainActionItem.FullFileName, initActionItem.FullFileName); var definition = SapIDocDefinition.LoadHeader(this.DefinitionFilePath); var idocText = File.ReadAllText(this.ExampleFilePath); var doc = new SapIDoc(definition, idocText); var generatedActions = doc.GetVuGenActionContents().EnsureNotNull(); //// TODO [vmaklai] Open and modify files in editor rather than directly on disk #region In-editor Load //// In-editor Load approach does not work: //// VuGen throws ObjectDisposedException with the message: //// Cannot access a disposed object. //// Object name: 'the instance has been already disposed and cannot be used'. //////(!)var initActionContentsData = Encoding.Default.GetBytes(generatedActions.InitActionContents); ////var actionContentsData = Encoding.Default.GetBytes(generatedActions.MainActionContents); //////(!)var endActionContentsData = Encoding.Default.GetBytes(generatedActions.EndActionContents); ////using (var actionContentsStream = new MemoryStream(actionContentsData, false)) ////{ //// var viewContent = FileService.OpenFile(mainActionItem.FullFileName, true); //// if (viewContent == null) //// { //// throw new InvalidOperationException( //// string.Format( //// CultureInfo.InvariantCulture, //// "Unable to open file \"{0}\".", //// mainActionItem.FullFileName)); //// } //// viewContent.Load(viewContent.PrimaryFile, actionContentsStream); ////} #endregion File.WriteAllText(initActionItem.FullFileName, generatedActions.InitActionContents, Encoding.Default); File.WriteAllText(mainActionItem.FullFileName, generatedActions.MainActionContents, Encoding.Default); File.WriteAllText(endActionItem.FullFileName, generatedActions.EndActionContents, Encoding.Default); }
public void CreateNewType(string filePath) { #region Argument Check if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentException( @"The value can be neither empty or whitespace-only string nor null.", "filePath"); } #endregion var definition = SapIDocDefinition.LoadHeader(filePath); var path = Path.Combine(this.RepositoryPath, definition.Name); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var destinationFilePath = Path.Combine(path, Path.GetFileName(filePath).EnsureNotNull()); File.Copy(filePath, destinationFilePath, true); }
private static void Main(string[] args) { var p = new OptionSet { { "idoc=", "the flat-text IDoc file", v => _idocFile = v }, // Mandatory { "header=", "the exported C-header for the IDoc (from WE60)", v => _headerFile = v }, // Mandatory { "?|help", "display this help and exit", v => _showHelp = true }, // Optional }; // Process the command-line arguments List <string> options; try { options = p.Parse(args); } catch (OptionException e) { Console.Write("test: "); Console.WriteLine(e.Message); Console.WriteLine("Try `test --help' for more information."); return; } foreach (var option in options) { Console.WriteLine("Option: {0}", option); } // Command line option "--help" if (_showHelp) { ShowHelp(p); return; } // Check that the mandatory input arguments were specified. if (string.IsNullOrEmpty(_idocFile) || string.IsNullOrEmpty(_headerFile)) { Console.WriteLine("You did not specify all the arguments. Try `test --help' for more information."); return; } // Check that both of the input files exist. if (!File.Exists(_idocFile) || !File.Exists(_headerFile)) { Console.WriteLine("One of the input files does not exist. Please double check the file name and path."); return; } // Read the IDoc and IDoc Definition Console.WriteLine("Reading IDoc Definition from C-header file: {0}", _headerFile); var def = SapIDocDefinition.LoadHeader(_headerFile); Console.WriteLine("Reading IDoc data text file: {0}", _idocFile); var idocContents = File.ReadAllText(_idocFile); var idoc = new SapIDoc(def, idocContents); //// ========================================== //// Example for spec: ////// Import IDoc Definition from C header file (*.h) ////string headerFileName = "example.h"; ////SapIDocDefinition def = SapIDocDefinition.LoadHeader(headerFileName); ////Console.WriteLine("IDoc type: {0}", def.Name); ////// Import IDoc file ////string idocFileName = "example.txt"; ////string idocTxt = File.ReadAllText(idocFileName); ; ////IDoc idoc = new IDoc(def, idocTxt); ////Console.WriteLine("IDoc Number: {0}", idoc.Number); ////// Output Action.c file ////Console.WriteLine("Action.c: {0}", idoc.GetVuGenActionContents()); //// ========================================== ////// Import IDoc Definition from C header file (*.h) ////string headerFileName = "example.h"; ////SapIDocDefinition def = SapIDocDefinition.LoadHeader(headerFileName); ////// Bulk Import IDoc files and save them as XML ////foreach (string file in files) { //// string idocTxt = File.ReadAllText(idocFileName); ; //// IDoc idoc = new IDoc(def, idocTxt); //// Console.WriteLine("IDoc Number: {0}", idoc.Number); //// string path = repositoryPath + "\\" + idoc.Type + "\\" + idoc.Number + ".xml"; //// using (StreamWriter writer = new StreamWriter(filepath)) { //// writer.WriteLine(idoc.GetXml.ToString()); //// } ////} // Output Action.c file var generatedActions = idoc.GetVuGenActionContents(); Console.WriteLine("Action.c: {0}", generatedActions.MainActionContents); // Save IDoc for input parameter Console.WriteLine("IDoc XML to save for Parameter input: {0}", idoc.GetXml()); // Create output files _xmlFile = idoc.Number + ".xml"; Console.WriteLine("Creating XML IDoc output file: {0}", _xmlFile); File.WriteAllText(_xmlFile, idoc.GetXml().ToString()); Console.WriteLine("Creating VuGen output file: {0}", SourceFile); File.WriteAllText(SourceFile, generatedActions.MainActionContents); ////Console.WriteLine(idoc.GetXml().ToString()); ////Console.WriteLine(idoc.GetVuGenActionContents()); Console.Write("finished. Press any key to continue . . . "); Console.ReadKey(true); }