Exemplo n.º 1
0
        internal static void WriteRecordingsToFile(TranscriptCmdletBase cmdlet, string fileName)
        {
            
//            System.IO.StreamWriter writer0001 = 
//                new System.IO.StreamWriter(@"C:\1\__writer0001__.txt");
//            for (int i = 0; i < Recorder.recordingCollection.Count; i++) {
//                for (int j = 0; j < Recorder.recordingCollection[i].Items.Count; j++) {
//                    
//                    RecordedWebElement webE = Recorder.recordingCollection[i].Items[j] as RecordedWebElement;
//                    RecordedAction actE = Recorder.recordingCollection[i].Items[j] as RecordedAction;
//                    RecordedData dataE = Recorder.recordingCollection[i].Items[j] as RecordedData;
//                    
//                    if (null != webE) {
//                        foreach (string webKey in webE.UserData.Keys) {
//                            writer0001.WriteLine("\r\n" + webKey + "\t" + webE.UserData[webKey]);
//                        }
//                        writer0001.Flush();
//                    } else if (null != actE) {
//                        foreach (string actKey in actE.UserData.Keys) {
//                            writer0001.WriteLine("\r\n" + actKey + "\t" + actE.UserData[actKey]);
//                        }
//                        writer0001.Flush();
//                    } else if (null != dataE) {
//                        foreach (string dataKey in dataE.UserData.Keys) {
//                            writer0001.WriteLine("\r\n" + dataKey + "\t" + dataE.UserData[dataKey]);
//                        }
//                        writer0001.Flush();
//                    } else {
//                        writer0001.WriteLine("\r\nother");
//                        writer0001.Flush();
//                    }
//                }
//            }
//            writer0001.Flush();
//            writer0001.Close();
            
            cmdlet.WriteVerbose(cmdlet, "WriteRecordingsToFile");

            string commonData = string.Empty;
                
            //foreach (IRecordedCodeSequence codeSequence in recordingCollection) {
            foreach (IRecordedCodeSequence codeSequence in Recorder.recordingCollection) {
                
                commonData =
                    Recorder.ConvertCodeSequenceToCode(codeSequence, (new PSLanguage()), commonData);
Console.WriteLine("<<<<<<<<<<<<<<<<<<< written >>>>>>>>>>>>>>>>>>>>>");
            }
            
            if (string.Empty != commonData) {
Console.WriteLine("<<<<<<<<<<<<<<<<<<< string.Empty != commonData >>>>>>>>>>>>>>>>>>>>>");
                try {
                    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fileName)) {
Console.WriteLine("<<<<<<<<<<<<<<<<<<< writing to the file >>>>>>>>>>>>>>>>>>>>>");
                        writer.WriteLine(commonData);
                        writer.Flush();
                        writer.Close();
Console.WriteLine("<<<<<<<<<<<<<<<<<<< written to the file >>>>>>>>>>>>>>>>>>>>>");
                    }
                }
                catch (Exception eOutputFileProblem) {
Console.WriteLine("<<<<<<<<<<<<<<<<<<< error >>>>>>>>>>>>>>>>>>>>>");
                    cmdlet.WriteError(
                        cmdlet,
                        "Couldn't save data to the file '" + 
                        fileName + 
                        "'. " +
                        eOutputFileProblem.Message,
                        "FailedToSaveData",
                        ErrorCategory.InvalidArgument,
                        true);
                }
            } else {
Console.WriteLine("<<<<<<<<<<<<<<<<<<< error2 >>>>>>>>>>>>>>>>>>>>>");
                cmdlet.WriteError(
                    cmdlet,
                    "Nothing was recorded",
                    "NoRecords",
                    ErrorCategory.InvalidData,
                    false);
            }
            
Console.WriteLine("FINISHED!!!!!!!!");

        }
Exemplo n.º 2
0
        internal static void WriteRecordingsToFile(TranscriptCmdletBase cmdlet, string fileName)
        {
//            System.IO.StreamWriter writer0001 =
//                new System.IO.StreamWriter(@"C:\1\__writer0001__.txt");
//            for (int i = 0; i < Recorder.recordingCollection.Count; i++) {
//                for (int j = 0; j < Recorder.recordingCollection[i].Items.Count; j++) {
//
//                    RecordedWebElement webE = Recorder.recordingCollection[i].Items[j] as RecordedWebElement;
//                    RecordedAction actE = Recorder.recordingCollection[i].Items[j] as RecordedAction;
//                    RecordedData dataE = Recorder.recordingCollection[i].Items[j] as RecordedData;
//
//                    if (null != webE) {
//                        foreach (string webKey in webE.UserData.Keys) {
//                            writer0001.WriteLine("\r\n" + webKey + "\t" + webE.UserData[webKey]);
//                        }
//                        writer0001.Flush();
//                    } else if (null != actE) {
//                        foreach (string actKey in actE.UserData.Keys) {
//                            writer0001.WriteLine("\r\n" + actKey + "\t" + actE.UserData[actKey]);
//                        }
//                        writer0001.Flush();
//                    } else if (null != dataE) {
//                        foreach (string dataKey in dataE.UserData.Keys) {
//                            writer0001.WriteLine("\r\n" + dataKey + "\t" + dataE.UserData[dataKey]);
//                        }
//                        writer0001.Flush();
//                    } else {
//                        writer0001.WriteLine("\r\nother");
//                        writer0001.Flush();
//                    }
//                }
//            }
//            writer0001.Flush();
//            writer0001.Close();

            cmdlet.WriteVerbose(cmdlet, "WriteRecordingsToFile");

            var commonData = string.Empty;

            //foreach (IRecordedCodeSequence codeSequence in recordingCollection) {
            foreach (var codeSequence in RecordingCollection)
            {
                commonData =
                    ConvertCodeSequenceToCode(codeSequence, (new PsLanguage()), commonData);
                Console.WriteLine("<<<<<<<<<<<<<<<<<<< written >>>>>>>>>>>>>>>>>>>>>");
            }

            if (string.Empty != commonData)
            {
                Console.WriteLine("<<<<<<<<<<<<<<<<<<< string.Empty != commonData >>>>>>>>>>>>>>>>>>>>>");
                try {
                    using (var writer = new System.IO.StreamWriter(fileName)) {
                        Console.WriteLine("<<<<<<<<<<<<<<<<<<< writing to the file >>>>>>>>>>>>>>>>>>>>>");
                        writer.WriteLine(commonData);
                        writer.Flush();
                        writer.Close();
                        Console.WriteLine("<<<<<<<<<<<<<<<<<<< written to the file >>>>>>>>>>>>>>>>>>>>>");
                    }
                }
                catch (Exception eOutputFileProblem) {
                    Console.WriteLine("<<<<<<<<<<<<<<<<<<< error >>>>>>>>>>>>>>>>>>>>>");
                    cmdlet.WriteError(
                        cmdlet,
                        "Couldn't save data to the file '" +
                        fileName +
                        "'. " +
                        eOutputFileProblem.Message,
                        "FailedToSaveData",
                        ErrorCategory.InvalidArgument,
                        true);
                }
            }
            else
            {
                Console.WriteLine("<<<<<<<<<<<<<<<<<<< error2 >>>>>>>>>>>>>>>>>>>>>");
                cmdlet.WriteError(
                    cmdlet,
                    "Nothing was recorded",
                    "NoRecords",
                    ErrorCategory.InvalidData,
                    false);
            }

            Console.WriteLine("FINISHED!!!!!!!!");
        }