Esempio n. 1
0
        public static bool Export(PwExportInfo pwExportInfo, FileFormatProvider
                                  fileFormat, IOConnectionInfo iocOutput, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }
            if (fileFormat == null)
            {
                throw new ArgumentNullException("fileFormat");
            }
            if (fileFormat.RequiresFile && (iocOutput == null))
            {
                throw new ArgumentNullException("iocOutput");
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }
            if (!fileFormat.SupportsExport)
            {
                return(false);
            }
            if (!fileFormat.TryBeginExport())
            {
                return(false);
            }

            bool bExistedAlready = true;             // No deletion by default
            bool bResult         = false;

            try
            {
                bExistedAlready = (fileFormat.RequiresFile ? IOConnection.FileExists(
                                       iocOutput) : false);
                Stream s = (fileFormat.RequiresFile ? IOConnection.OpenWrite(
                                iocOutput) : null);

                try { bResult = fileFormat.Export(pwExportInfo, s, slLogger); }
                finally { if (s != null)
                          {
                              s.Close();
                          }
                }
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }

            if (fileFormat.RequiresFile && !bResult && !bExistedAlready)
            {
                try { IOConnection.DeleteFile(iocOutput); }
                catch (Exception) { }
            }

            return(bResult);
        }
Esempio n. 2
0
        private static void PerformExport(PwExportInfo pwExportInfo,
                                          FileFormatProvider fileFormat, string strOutputFile, IStatusLogger slLogger)
        {
            if (!fileFormat.SupportsExport)
            {
                return;
            }
            if (fileFormat.TryBeginExport() == false)
            {
                return;
            }

            bool bExistedAlready = File.Exists(strOutputFile);

            FileStream fsOut = new FileStream(strOutputFile, FileMode.Create,
                                              FileAccess.Write, FileShare.None);

            bool bResult = fileFormat.Export(pwExportInfo, fsOut, slLogger);

            fsOut.Close();
            fsOut.Dispose();

            if ((bResult == false) && (bExistedAlready == false))
            {
                try { File.Delete(strOutputFile); }
                catch (Exception) { }
            }
        }
Esempio n. 3
0
		public static bool Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
		{
			if(pwExportInfo == null) throw new ArgumentNullException("pwExportInfo");
			if(pwExportInfo.DataGroup == null) throw new ArgumentException();

			if(!AppPolicy.Try(AppPolicyId.Export)) return false;

			ExchangeDataForm dlg = new ExchangeDataForm();
			dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);

			if(dlg.ShowDialog() == DialogResult.OK)
			{
				FileFormatProvider ffp = dlg.ResultFormat;
				if(ffp == null) { Debug.Assert(false); return false; }
				if(ffp.RequiresFile)
				{
					if(dlg.ResultFiles.Length != 1) { Debug.Assert(false); return false; }
					if(dlg.ResultFiles[0] == null) { Debug.Assert(false); return false; }
					if(dlg.ResultFiles[0].Length == 0) { Debug.Assert(false); return false; }
				}

				Application.DoEvents(); // Redraw parent window

				IOConnectionInfo iocOutput = (ffp.RequiresFile ? IOConnectionInfo.FromPath(
					dlg.ResultFiles[0]) : null);

				try
				{
					return Export(pwExportInfo, dlg.ResultFormat, iocOutput, slLogger);
				}
				catch(Exception ex) { MessageService.ShowWarning(ex); }
			}

			return false;
		}
Esempio n. 4
0
        public static bool Export(PwExportInfo pwExportInfo, FileFormatProvider
                                  fileFormat, IOConnectionInfo iocOutput, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }
            if (fileFormat == null)
            {
                throw new ArgumentNullException("fileFormat");
            }
            if (fileFormat.RequiresFile && (iocOutput == null))
            {
                throw new ArgumentNullException("iocOutput");
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }
            if (!fileFormat.SupportsExport)
            {
                return(false);
            }
            if (!fileFormat.TryBeginExport())
            {
                return(false);
            }

            // bool bExistedAlready = File.Exists(strOutputFile);
            bool bExistedAlready = (fileFormat.RequiresFile ? IOConnection.FileExists(
                                        iocOutput) : false);

            // FileStream fsOut = new FileStream(strOutputFile, FileMode.Create,
            //	FileAccess.Write, FileShare.None);
            Stream sOut = (fileFormat.RequiresFile ? IOConnection.OpenWrite(
                               iocOutput) : null);

            bool bResult = false;

            try { bResult = fileFormat.Export(pwExportInfo, sOut, slLogger); }
            catch (Exception ex) { MessageService.ShowWarning(ex); }

            if (sOut != null)
            {
                sOut.Close();
            }

            if (fileFormat.RequiresFile && (bResult == false) && (bExistedAlready == false))
            {
                try { IOConnection.DeleteFile(iocOutput); }
                catch (Exception) { }
            }

            return(bResult);
        }
Esempio n. 5
0
        public static void Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
        {
            if(pwExportInfo == null) throw new ArgumentNullException("pwExportInfo");
            if(pwExportInfo.DataGroup == null) throw new ArgumentException();

            if(!AppPolicy.Try(AppPolicyId.Export)) return;

            ExchangeDataForm dlg = new ExchangeDataForm();
            dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);

            if(dlg.ShowDialog() == DialogResult.OK)
            {
                if(dlg.ResultFormat == null) { Debug.Assert(false); return; }
                if(dlg.ResultFiles.Length != 1) { Debug.Assert(false); return; }
                if(dlg.ResultFiles[0] == null) { Debug.Assert(false); return; }
                if(dlg.ResultFiles[0].Length == 0) { Debug.Assert(false); return; }

                Application.DoEvents(); // Redraw parent window

                try
                {
                    PerformExport(pwExportInfo, dlg.ResultFormat, dlg.ResultFiles[0],
                        slLogger);
                }
                catch(Exception ex)
                {
                    MessageService.ShowWarning(ex);
                }
            }
        }
Esempio n. 6
0
        public static bool Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }

            ExchangeDataForm dlg = new ExchangeDataForm();

            dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                FileFormatProvider ffp = dlg.ResultFormat;
                if (ffp == null)
                {
                    Debug.Assert(false); return(false);
                }
                if (ffp.RequiresFile)
                {
                    if (dlg.ResultFiles.Length != 1)
                    {
                        Debug.Assert(false); return(false);
                    }
                    if (dlg.ResultFiles[0] == null)
                    {
                        Debug.Assert(false); return(false);
                    }
                    if (dlg.ResultFiles[0].Length == 0)
                    {
                        Debug.Assert(false); return(false);
                    }
                }

                Application.DoEvents();                 // Redraw parent window

                IOConnectionInfo iocOutput = (ffp.RequiresFile ? IOConnectionInfo.FromPath(
                                                  dlg.ResultFiles[0]) : null);

                try
                {
                    return(Export(pwExportInfo, dlg.ResultFormat, iocOutput, slLogger));
                }
                catch (Exception ex) { MessageService.ShowWarning(ex); }
            }

            return(false);
        }
Esempio n. 7
0
        public static bool Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }

            ExchangeDataForm dlg = new ExchangeDataForm();

            dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);

            bool bResult = false;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                FileFormatProvider ffp = dlg.ResultFormat;
                if (ffp == null)
                {
                    Debug.Assert(false); goto ExpZRet;
                }
                if (ffp.RequiresFile)
                {
                    if (dlg.ResultFiles.Length != 1)
                    {
                        Debug.Assert(false); goto ExpZRet;
                    }
                    if (dlg.ResultFiles[0] == null)
                    {
                        Debug.Assert(false); goto ExpZRet;
                    }
                    if (dlg.ResultFiles[0].Length == 0)
                    {
                        Debug.Assert(false); goto ExpZRet;
                    }
                }

                IOConnectionInfo iocOutput = (ffp.RequiresFile ? IOConnectionInfo.FromPath(
                                                  dlg.ResultFiles[0]) : null);

                Application.DoEvents();                 // Redraw parent window
                bResult = Export(pwExportInfo, ffp, iocOutput, slLogger);
            }

ExpZRet:
            UIUtil.DestroyForm(dlg);
            return(bResult);
        }
Esempio n. 8
0
        public static bool Export(PwExportInfo pwExportInfo, string strFormatName,
            IOConnectionInfo iocOutput)
        {
            if(strFormatName == null) throw new ArgumentNullException("strFormatName");
            // iocOutput may be null

            FileFormatProvider prov = Program.FileFormatPool.Find(strFormatName);
            if(prov == null) return false;

            NullStatusLogger slLogger = new NullStatusLogger();
            return Export(pwExportInfo, prov, iocOutput, slLogger);
        }
Esempio n. 9
0
        public static void Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return;
            }

            ExchangeDataForm dlg = new ExchangeDataForm();

            dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (dlg.ResultFormat == null)
                {
                    Debug.Assert(false); return;
                }
                if (dlg.ResultFiles.Length != 1)
                {
                    Debug.Assert(false); return;
                }
                if (dlg.ResultFiles[0] == null)
                {
                    Debug.Assert(false); return;
                }
                if (dlg.ResultFiles[0].Length == 0)
                {
                    Debug.Assert(false); return;
                }

                Application.DoEvents();                 // Redraw parent window

                try
                {
                    PerformExport(pwExportInfo, dlg.ResultFormat, dlg.ResultFiles[0],
                                  slLogger);
                }
                catch (Exception ex)
                {
                    MessageService.ShowWarning(ex);
                }
            }
        }
Esempio n. 10
0
        public static bool Export(PwExportInfo pwExportInfo, string strFormatName,
                                  IOConnectionInfo iocOutput)
        {
            if (strFormatName == null)
            {
                throw new ArgumentNullException("strFormatName");
            }
            // iocOutput may be null

            FileFormatProvider prov = Program.FileFormatPool.Find(strFormatName);

            if (prov == null)
            {
                return(false);
            }

            NullStatusLogger slLogger = new NullStatusLogger();

            return(Export(pwExportInfo, prov, iocOutput, slLogger));
        }
Esempio n. 11
0
        private static void PerformExport(PwExportInfo pwExportInfo,
            FileFormatProvider fileFormat, string strOutputFile, IStatusLogger slLogger)
        {
            if(!fileFormat.SupportsExport) return;
            if(fileFormat.TryBeginExport() == false) return;

            bool bExistedAlready = File.Exists(strOutputFile);

            FileStream fsOut = new FileStream(strOutputFile, FileMode.Create,
                FileAccess.Write, FileShare.None);

            bool bResult = fileFormat.Export(pwExportInfo, fsOut, slLogger);

            fsOut.Close();
            fsOut.Dispose();

            if((bResult == false) && (bExistedAlready == false))
            {
                try { File.Delete(strOutputFile); }
                catch(Exception) { }
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Export data into a stream. Throws an exception if an error
 /// occurs (like writing to stream fails, etc.). Returns <c>true</c>,
 /// if the export was successful.
 /// </summary>
 /// <param name="pwExportInfo">Contains the data source and detailed
 /// information about which entries should be exported.</param>
 /// <param name="sOutput">Output stream to write the data to.</param>
 /// <param name="slLogger">Status logger. May be <c>null</c>.</param>
 /// <returns>Returns <c>false</c>, if the user has aborted the export
 /// process (like clicking Cancel in an additional export settings
 /// dialog).</returns>
 public virtual bool Export(PwExportInfo pwExportInfo, Stream sOutput,
                            IStatusLogger slLogger)
 {
     throw new NotSupportedException();
 }
Esempio n. 13
0
        public static bool Export(PwExportInfo pwExportInfo, FileFormatProvider fileFormat,
                                  IOConnectionInfo iocOutput, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }
            if (fileFormat == null)
            {
                throw new ArgumentNullException("fileFormat");
            }

            bool bFileReq = fileFormat.RequiresFile;

            if (bFileReq && (iocOutput == null))
            {
                throw new ArgumentNullException("iocOutput");
            }
            if (bFileReq && (iocOutput.Path.Length == 0))
            {
                throw new ArgumentException();
            }

            PwDatabase pd = pwExportInfo.ContextDatabase;

            Debug.Assert(pd != null);

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }
            if (!AppPolicy.Current.ExportNoKey && (pd != null))
            {
                if (!KeyUtil.ReAskKey(pd, true))
                {
                    return(false);
                }
            }

            if (!fileFormat.SupportsExport)
            {
                return(false);
            }
            if (!fileFormat.TryBeginExport())
            {
                return(false);
            }

            CompositeKey ckOrgMasterKey = null;
            DateTime     dtOrgMasterKey = PwDefs.DtDefaultNow;

            PwGroup pgOrgData     = pwExportInfo.DataGroup;
            PwGroup pgOrgRoot     = ((pd != null) ? pd.RootGroup : null);
            bool    bParentGroups = (pwExportInfo.ExportParentGroups && (pd != null) &&
                                     (pgOrgData != pgOrgRoot));

            bool bExistedAlready = true;             // No deletion by default
            bool bResult         = false;

            try
            {
                if (pwExportInfo.ExportMasterKeySpec && fileFormat.RequiresKey &&
                    (pd != null))
                {
                    KeyCreationForm kcf = new KeyCreationForm();
                    kcf.InitEx((iocOutput ?? new IOConnectionInfo()), true);

                    if (UIUtil.ShowDialogNotValue(kcf, DialogResult.OK))
                    {
                        return(false);
                    }

                    ckOrgMasterKey = pd.MasterKey;
                    dtOrgMasterKey = pd.MasterKeyChanged;

                    pd.MasterKey        = kcf.CompositeKey;
                    pd.MasterKeyChanged = DateTime.UtcNow;

                    UIUtil.DestroyForm(kcf);
                }

                if (bParentGroups)
                {
                    PwGroup pgNew = WithParentGroups(pgOrgData, pd);
                    pwExportInfo.DataGroup = pgNew;
                    pd.RootGroup           = pgNew;
                }

                if (bFileReq)
                {
                    bExistedAlready = IOConnection.FileExists(iocOutput);
                }

                Stream s = (bFileReq ? IOConnection.OpenWrite(iocOutput) : null);
                try { bResult = fileFormat.Export(pwExportInfo, s, slLogger); }
                finally { if (s != null)
                          {
                              s.Close();
                          }
                }

                if (bFileReq && bResult)
                {
                    if (pwExportInfo.ExportPostOpen)
                    {
                        NativeLib.StartProcess(iocOutput.Path);
                    }
                    if (pwExportInfo.ExportPostShow)
                    {
                        WinUtil.ShowFileInFileManager(iocOutput.Path, true);
                    }
                }
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }
            finally
            {
                if (ckOrgMasterKey != null)
                {
                    pd.MasterKey        = ckOrgMasterKey;
                    pd.MasterKeyChanged = dtOrgMasterKey;
                }

                if (bParentGroups)
                {
                    pwExportInfo.DataGroup = pgOrgData;
                    pd.RootGroup           = pgOrgRoot;
                }
            }

            if (bFileReq && !bResult && !bExistedAlready)
            {
                try { IOConnection.DeleteFile(iocOutput); }
                catch (Exception) { }
            }

            return(bResult);
        }
Esempio n. 14
0
        public static bool Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }

            ExchangeDataForm dlg = new ExchangeDataForm();

            dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);
            dlg.ExportInfo = pwExportInfo;

            bool bStatusActive = false;

            try
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    FileFormatProvider ffp = dlg.ResultFormat;
                    if (ffp == null)
                    {
                        Debug.Assert(false); return(false);
                    }

                    IOConnectionInfo ioc = null;
                    if (ffp.RequiresFile)
                    {
                        string[] vFiles = dlg.ResultFiles;
                        if (vFiles == null)
                        {
                            Debug.Assert(false); return(false);
                        }
                        if (vFiles.Length == 0)
                        {
                            Debug.Assert(false); return(false);
                        }
                        Debug.Assert(vFiles.Length == 1);

                        string strFile = vFiles[0];
                        if (string.IsNullOrEmpty(strFile))
                        {
                            Debug.Assert(false); return(false);
                        }

                        ioc = IOConnectionInfo.FromPath(strFile);
                    }

                    if (slLogger != null)
                    {
                        slLogger.StartLogging(KPRes.ExportingStatusMsg, true);
                        bStatusActive = true;
                    }

                    Application.DoEvents();                     // Redraw parent window
                    return(Export(pwExportInfo, ffp, ioc, slLogger));
                }
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }
            finally
            {
                UIUtil.DestroyForm(dlg);
                if (bStatusActive)
                {
                    slLogger.EndLogging();
                }
            }

            return(false);
        }
Esempio n. 15
0
 /// <summary>
 /// Export data into a stream. Throws an exception if an error
 /// occurs (like writing to stream fails, etc.). Returns <c>true</c>,
 /// if the export was successful.
 /// </summary>
 /// <param name="pwExportInfo">Contains the data source and detailed
 /// information about which entries should be exported.</param>
 /// <param name="sOutput">Output stream to write the data to.</param>
 /// <param name="slLogger">Status logger. May be <c>null</c>.</param>
 /// <returns>Returns <c>false</c>, if the user has aborted the export
 /// process (like clicking Cancel in an additional export settings
 /// dialog).</returns>
 public virtual bool Export(PwExportInfo pwExportInfo, Stream sOutput,
     IStatusLogger slLogger)
 {
     throw new NotSupportedException();
 }
        private static void ExportDatabaseFile(EcasAction a, EcasContext ctx)
        {
            string strPath = EcasUtil.GetParamString(a.Parameters, 0, true);
            // if(string.IsNullOrEmpty(strPath)) return; // Allow no-file exports
            string strFormat = EcasUtil.GetParamString(a.Parameters, 1, true);
            if(string.IsNullOrEmpty(strFormat)) return;
            string strGroup = EcasUtil.GetParamString(a.Parameters, 2, true);
            string strTag = EcasUtil.GetParamString(a.Parameters, 3, true);

            PwDatabase pd = Program.MainForm.ActiveDatabase;
            if((pd == null) || !pd.IsOpen) return;

            PwGroup pg = pd.RootGroup;
            if(!string.IsNullOrEmpty(strGroup))
            {
                char chSep = strGroup[0];
                PwGroup pgSub = pg.FindCreateSubTree(strGroup.Substring(1),
                    new char[] { chSep }, false);
                pg = (pgSub ?? (new PwGroup(true, true, KPRes.Group, PwIcon.Folder)));
            }

            if(!string.IsNullOrEmpty(strTag))
            {
                // Do not use pg.Duplicate, because this method
                // creates new UUIDs
                pg = pg.CloneDeep();
                pg.TakeOwnership(true, true, true);

                GroupHandler gh = delegate(PwGroup pgSub)
                {
                    PwObjectList<PwEntry> l = pgSub.Entries;
                    long n = (long)l.UCount;
                    for(long i = n - 1; i >= 0; --i)
                    {
                        if(!l.GetAt((uint)i).HasTag(strTag))
                            l.RemoveAt((uint)i);
                    }

                    return true;
                };

                gh(pg);
                pg.TraverseTree(TraversalMethod.PreOrder, gh, null);
            }

            PwExportInfo pei = new PwExportInfo(pg, pd, true);
            IOConnectionInfo ioc = (!string.IsNullOrEmpty(strPath) ?
                IOConnectionInfo.FromPath(strPath) : null);
            ExportUtil.Export(pei, strFormat, ioc);
        }
Esempio n. 17
0
        public static bool Export(PwExportInfo pwExportInfo, FileFormatProvider
            fileFormat, IOConnectionInfo iocOutput, IStatusLogger slLogger)
        {
            if(pwExportInfo == null) throw new ArgumentNullException("pwExportInfo");
            if(pwExportInfo.DataGroup == null) throw new ArgumentException();
            if(fileFormat == null) throw new ArgumentNullException("fileFormat");
            if(fileFormat.RequiresFile && (iocOutput == null))
                throw new ArgumentNullException("iocOutput");

            if(!AppPolicy.Try(AppPolicyId.Export)) return false;
            if(!fileFormat.SupportsExport) return false;
            if(!fileFormat.TryBeginExport()) return false;

            // bool bExistedAlready = File.Exists(strOutputFile);
            bool bExistedAlready = (fileFormat.RequiresFile ? IOConnection.FileExists(
                iocOutput) : false);

            // FileStream fsOut = new FileStream(strOutputFile, FileMode.Create,
            //	FileAccess.Write, FileShare.None);
            Stream sOut = (fileFormat.RequiresFile ? IOConnection.OpenWrite(
                iocOutput) : null);

            bool bResult = false;
            try { bResult = fileFormat.Export(pwExportInfo, sOut, slLogger); }
            catch(Exception ex) { MessageService.ShowWarning(ex); }

            if(sOut != null) sOut.Close();

            if(fileFormat.RequiresFile && (bResult == false) && (bExistedAlready == false))
            {
                try { IOConnection.DeleteFile(iocOutput); }
                catch(Exception) { }
            }

            return bResult;
        }
Esempio n. 18
0
            public override void Run()
            {
                StatusLogger.UpdateMessage(UiStringKey.exporting_database);
                var pd = _app.GetDb().KpDatabase;
                PwExportInfo pwInfo = new PwExportInfo(pd.RootGroup, pd, true);

                try
                {
                    using (var writeTransaction =_app.GetFileStorage(_targetIoc).OpenWriteTransaction(_targetIoc, _app.GetDb().KpDatabase.UseFileTransactions))
                    {
                        Stream sOut = writeTransaction.OpenFile();
                        _fileFormat.Export(pwInfo, sOut, new NullStatusLogger());

                        if (sOut != null) sOut.Close();

                        writeTransaction.CommitWrite();

                    }
                    Finish(true);

                }
                catch (Exception ex)
                {
                    Finish(false, ex.Message);
                }
            }
        private static void ExportDatabaseFile(EcasAction a, EcasContext ctx)
        {
            string strPath = EcasUtil.GetParamString(a.Parameters, 0, true);
            // if(string.IsNullOrEmpty(strPath)) return; // Allow no-file exports
            string strFormat = EcasUtil.GetParamString(a.Parameters, 1, true);
            if(string.IsNullOrEmpty(strFormat)) return;

            PwDatabase pd = Program.MainForm.ActiveDatabase;
            if((pd == null) || !pd.IsOpen) return;

            PwExportInfo pei = new PwExportInfo(pd.RootGroup, pd, true);
            IOConnectionInfo ioc = (!string.IsNullOrEmpty(strPath) ?
                IOConnectionInfo.FromPath(strPath) : null);
            ExportUtil.Export(pei, strFormat, ioc);
        }
Esempio n. 20
0
		public void PerformExport(PwGroup pgDataSource, bool bExportDeleted)
		{
			Debug.Assert(m_docMgr.ActiveDatabase.IsOpen); if(!m_docMgr.ActiveDatabase.IsOpen) return;

			if(!AppPolicy.Try(AppPolicyId.Export)) return;

			PwDatabase pd = m_docMgr.ActiveDatabase;
			if((pd == null) || !pd.IsOpen) return;
			if(!AppPolicy.Current.ExportNoKey)
			{
				if(!KeyUtil.ReAskKey(pd, true)) return;
			}

			PwGroup pg = (pgDataSource ?? pd.RootGroup);
			PwExportInfo pwInfo = new PwExportInfo(pg, pd, bExportDeleted);

			MessageService.ExternalIncrementMessageCount();
			ShowWarningsLogger swLogger = CreateShowWarningsLogger();
			swLogger.StartLogging(KPRes.ExportingStatusMsg, true);

			ExportUtil.Export(pwInfo, swLogger);

			swLogger.EndLogging();
			MessageService.ExternalDecrementMessageCount();
			UpdateUIState(false);
		}