Save() public méthode

Save the contents of the current PwDatabase to a KDBX file.
public Save ( Stream sSaveTo, PwGroup pgDataSource, Kdb4Format format, IStatusLogger slLogger ) : void
sSaveTo Stream Stream to write the KDBX file into.
pgDataSource PwGroup Group containing all groups and /// entries to write. If null, the complete database will /// be written.
format Kdb4Format Format of the file to create.
slLogger IStatusLogger Logger that recieves status information.
Résultat void
Exemple #1
0
		public override bool Export(PwExportInfo pwExportInfo, Stream sOutput,
			IStatusLogger slLogger)
		{
			Kdb4File kdb4 = new Kdb4File(pwExportInfo.ContextDatabase);
			kdb4.Save(sOutput, pwExportInfo.DataGroup, Kdb4Format.Default, slLogger);
			return true;
		}
		public override bool Export(PwExportInfo pwExportInfo, Stream sOutput,
			IStatusLogger slLogger)
		{
			string strFilter = UIUtil.CreateFileTypeFilter("xsl", KPRes.XslFileType, true);
			OpenFileDialog dlgXsl = UIUtil.CreateOpenFileDialog(KPRes.XslSelectFile,
				strFilter, 1, "xsl", false, false);

			if(dlgXsl.ShowDialog() != DialogResult.OK) return false;

			string strXslFile = dlgXsl.FileName;
			XslCompiledTransform xsl = new XslCompiledTransform();

			try { xsl.Load(strXslFile); }
			catch(Exception exXsl)
			{
				throw new NotSupportedException(strXslFile + MessageService.NewParagraph +
					KPRes.NoXslFile + MessageService.NewParagraph + exXsl.Message);
			}

			MemoryStream msDataXml = new MemoryStream();

			PwDatabase pd = (pwExportInfo.ContextDatabase ?? new PwDatabase());
			Kdb4File kdb = new Kdb4File(pd);
			kdb.Save(msDataXml, pwExportInfo.DataGroup, Kdb4Format.PlainXml, slLogger);

			byte[] pbData = msDataXml.ToArray();
			MemoryStream msDataRead = new MemoryStream(pbData, false);
			XmlReader xmlDataReader = XmlReader.Create(msDataRead);

			XmlWriterSettings xws = new XmlWriterSettings();
			xws.CheckCharacters = false;
			xws.Encoding = new UTF8Encoding(false);
			xws.NewLineChars = MessageService.NewLine;
			xws.NewLineHandling = NewLineHandling.None;
			xws.OmitXmlDeclaration = true;
			xws.ConformanceLevel = ConformanceLevel.Auto;

			XmlWriter xmlWriter = XmlWriter.Create(sOutput, xws);
			xsl.Transform(xmlDataReader, xmlWriter);
			xmlWriter.Close();

			Array.Clear(pbData, 0, pbData.Length);
			return true;
		}
Exemple #3
0
        /// <summary>
        /// Write entries to a stream.
        /// </summary>
        /// <param name="msOutput">Output stream to which the entries will be written.</param>
        /// <param name="vEntries">Entries to serialize.</param>
        /// <returns>Returns <c>true</c>, if the entries were written successfully
        /// to the stream.</returns>
        public static bool WriteEntries(Stream msOutput, PwEntry[] vEntries)
        {
            /* Kdb4File f = new Kdb4File(pwDatabase);
             *             f.m_format = Kdb4Format.PlainXml;
             *
             *             XmlTextWriter xtw = null;
             *             try { xtw = new XmlTextWriter(msOutput, StrUtil.Utf8); }
             *             catch(Exception) { Debug.Assert(false); return false; }
             *             if(xtw == null) { Debug.Assert(false); return false; }
             *
             *             f.m_xmlWriter = xtw;
             *
             *             xtw.Formatting = Formatting.Indented;
             *             xtw.IndentChar = '\t';
             *             xtw.Indentation = 1;
             *
             *             xtw.WriteStartDocument(true);
             *             xtw.WriteStartElement(ElemRoot);
             *
             *             foreach(PwEntry pe in vEntries)
             *                     f.WriteEntry(pe, false);
             *
             *             xtw.WriteEndElement();
             *             xtw.WriteEndDocument();
             *
             *             xtw.Flush();
             *             xtw.Close();
             *             return true; */

            PwDatabase pd = new PwDatabase();

            pd.New(new IOConnectionInfo(), new CompositeKey());

            foreach (PwEntry peCopy in vEntries)
            {
                pd.RootGroup.AddEntry(peCopy.CloneDeep(), true);
            }

            Kdb4File f = new Kdb4File(pd);

            f.Save(msOutput, null, Kdb4Format.PlainXml, null);
            return(true);
        }
Exemple #4
0
		public override bool Export(PwExportInfo pwExportInfo, Stream sOutput,
			IStatusLogger slLogger)
		{
			PwDatabase pd = (pwExportInfo.ContextDatabase ?? new PwDatabase());

			PwObjectList<PwDeletedObject> vDel = null;
			if(pwExportInfo.ExportDeletedObjects == false)
			{
				vDel = pd.DeletedObjects.CloneShallow();
				pd.DeletedObjects.Clear();
			}

			Kdb4File kdb = new Kdb4File(pd);
			kdb.Save(sOutput, pwExportInfo.DataGroup, Kdb4Format.PlainXml, slLogger);

			// Restore deleted objects list
			if(vDel != null) pd.DeletedObjects.Add(vDel);

			return true;
		}
Exemple #5
0
        /// <summary>
        /// Save the currently opened database. The file is written to the location
        /// it has been opened from.
        /// </summary>
        /// <param name="slLogger">Logger that recieves status information.</param>
        public void Save(IStatusLogger slLogger)
        {
            bool bMadeUnhidden = UrlUtil.UnhideFile(m_ioSource.Path);

            Stream s = IOConnection.OpenWrite(m_ioSource);

            Kdb4File kdb = new Kdb4File(this);
            kdb.Save(s, null, Kdb4Format.Default, slLogger);

            if(bMadeUnhidden) UrlUtil.HideFile(m_ioSource.Path, true); // Hide again

            m_pbHashOfLastIO = kdb.HashOfFileOnDisk;
            m_pbHashOfFileOnDisk = kdb.HashOfFileOnDisk;
            Debug.Assert(m_pbHashOfFileOnDisk != null);

            m_bModified = false;
        }
Exemple #6
0
        /// <summary>
        /// Write entries to a stream.
        /// </summary>
        /// <param name="msOutput">Output stream to which the entries will be written.</param>
        /// <param name="vEntries">Entries to serialize.</param>
        /// <returns>Returns <c>true</c>, if the entries were written successfully
        /// to the stream.</returns>
        public static bool WriteEntries(Stream msOutput, PwEntry[] vEntries)
        {
            /* Kdb4File f = new Kdb4File(pwDatabase);
            f.m_format = Kdb4Format.PlainXml;

            XmlTextWriter xtw = null;
            try { xtw = new XmlTextWriter(msOutput, StrUtil.Utf8); }
            catch(Exception) { Debug.Assert(false); return false; }
            if(xtw == null) { Debug.Assert(false); return false; }

            f.m_xmlWriter = xtw;

            xtw.Formatting = Formatting.Indented;
            xtw.IndentChar = '\t';
            xtw.Indentation = 1;

            xtw.WriteStartDocument(true);
            xtw.WriteStartElement(ElemRoot);

            foreach(PwEntry pe in vEntries)
                f.WriteEntry(pe, false);

            xtw.WriteEndElement();
            xtw.WriteEndDocument();

            xtw.Flush();
            xtw.Close();
            return true; */

            PwDatabase pd = new PwDatabase();
            pd.New(new IOConnectionInfo(), new CompositeKey());

            foreach(PwEntry peCopy in vEntries)
                pd.RootGroup.AddEntry(peCopy.CloneDeep(), true);

            Kdb4File f = new Kdb4File(pd);
            f.Save(msOutput, null, Kdb4Format.PlainXml, null);
            return true;
        }