public static bool WriteSessionArchive(string sFilename, Session[] arrSessions, string sPassword, bool bVerboseDialogs) { if (arrSessions == null || arrSessions.Length < 1) { if (bVerboseDialogs) { FiddlerApplication.DoNotifyUser("No sessions were provided to save to the archive.", "WriteSessionArchive - No Input"); } return(false); } if (FiddlerApplication.oSAZProvider == null) { throw new NotSupportedException("This application was compiled without .SAZ support."); } //FiddlerApplication.DoBeforeSaveSAZ(sFilename, arrSessions); bool result; try { if (File.Exists(sFilename)) { File.Delete(sFilename); } ISAZWriter iSAZWriter = FiddlerApplication.oSAZProvider.CreateSAZ(sFilename); if (!string.IsNullOrEmpty(sPassword)) { iSAZWriter.SetPassword(sPassword); } iSAZWriter.Comment = "Fiddler Session Archive. See http://fiddler2.com"; int num = 1; string sFileNumberFormat = "D" + arrSessions.Length.ToString().Length; for (int i = 0; i < arrSessions.Length; i++) { Session oSession = arrSessions[i]; WriteSessionToSAZ(oSession, iSAZWriter, num, sFileNumberFormat, null, bVerboseDialogs); num++; } iSAZWriter.CompleteArchive(); result = true; } catch (Exception ex) { if (bVerboseDialogs) { FiddlerApplication.DoNotifyUser("Failed to save Session Archive.\n\n" + ex.Message, "Save Failed"); } result = false; } return(result); }
internal static void WriteSessionToSAZ(Session oSession, ISAZWriter oISW, int iFileNumber, string sFileNumberFormat, StringBuilder sbHTML, bool bVerboseDialogs) { string text = "raw\\" + iFileNumber.ToString(sFileNumberFormat); string text2 = text + "_c.txt"; string text3 = text + "_s.txt"; string text4 = text + "_m.xml"; bool shouldicreatexmlfile = true; try { oISW.AddFile(text2, delegate(Stream oS) { oSession.WriteRequestToStream(false, true, oS); }); } catch (Exception eX) { if (bVerboseDialogs) { //FiddlerApplication.DoNotifyUser( + Utilities.DescribeExceptionWithStack(eX), "Archive Failure"); Console.Write(String.Format("Unable to add " + text2 + "\n\n")); } } try { oISW.AddFile(text3, delegate(Stream oS) { oSession.WriteResponseToStream(oS, false); }); } catch (Exception eX2) { if (bVerboseDialogs) { //FiddlerApplication.DoNotifyUser("Unable to add " + text3 + "\n\n" + Utilities.DescribeExceptionWithStack(eX2), "Archive Failure"); Console.Write(String.Format("Unable to add " + text3 + "\n\n")); } } if (shouldicreatexmlfile) { try { oISW.AddFile(text4, delegate(Stream oS) { oSession.WriteMetadataToStream(oS); }); } catch (Exception eX3) { if (bVerboseDialogs) { //FiddlerApplication.DoNotifyUser("Unable to add " + text4 + "\n\n" + Utilities.DescribeExceptionWithStack(eX3), "Archive Failure"); Console.Write(String.Format("Unable to add " + text4 + "\n\n")); } } } if (oSession.bHasWebSocketMessages) { Console.Write(String.Format("[INTERESTING]Skipping websocket sessions.\n\n")); /*string text5 = text + "_w.txt"; * try * { * oISW.AddFile(text5, delegate(Stream oS) * { * oSession.WriteWebSocketMessagesToStream(oS); * }); * } * catch (Exception eX4) * { * if (bVerboseDialogs) * { * FiddlerApplication.DoNotifyUser("Unable to add " + text5 + "\n\n" + Utilities.DescribeExceptionWithStack(eX4), "Archive Failure"); * } * }*/ } }