private static bool IsMatchCustomTbButton(EcasEvent e, EcasContext ctx)
        {
            string strIdRef = EcasUtil.GetParamString(e.Parameters, 0, true);
            if(string.IsNullOrEmpty(strIdRef)) return true;

            string strIdCur = EcasUtil.GetParamString(ctx.Event.Parameters, 0);
            if(string.IsNullOrEmpty(strIdCur)) return false;

            return strIdRef.Equals(strIdCur, StrUtil.CaseIgnoreCmp);
        }
        public bool Evaluate(EcasCondition c, EcasContext ctx)
        {
            if(c == null) throw new ArgumentNullException("c");

            foreach(EcasConditionType t in m_conditions)
            {
                if(t.Type.EqualsValue(c.Type))
                    return t.EvaluateMethod(c, ctx);
            }

            throw new NotSupportedException();
        }
        public void Execute(EcasAction a, EcasContext ctx)
        {
            if(a == null) throw new ArgumentNullException("a");

            foreach(EcasActionType t in m_actions)
            {
                if(t.Type.EqualsValue(a.Type))
                {
                    t.ExecuteMethod(a, ctx);
                    return;
                }
            }

            throw new NotSupportedException();
        }
		public bool Compare(EcasEvent e, EcasContext ctx)
		{
			if(e == null) throw new ArgumentNullException("e");
			if(ctx == null) throw new ArgumentNullException("ctx");

			Debug.Assert(e.Type.Equals(ctx.Event.Type));

			foreach(EcasEventType t in m_events)
			{
				if(t.Type.Equals(e.Type))
					return t.CompareMethod(e, ctx);
			}

			throw new NotSupportedException();
		}
		private static bool IsMatchEnvironmentVar(EcasCondition c, EcasContext ctx)
		{
			string strName = EcasUtil.GetParamString(c.Parameters, 0, true);
			uint uCompareType = EcasUtil.GetParamEnum(c.Parameters, 1,
				EcasUtil.StdStringCompareEquals, EcasUtil.StdStringCompare);
			string strValue = EcasUtil.GetParamString(c.Parameters, 2, true);

			if(string.IsNullOrEmpty(strName) || (strValue == null))
				return false;

			try
			{
				string strVar = Environment.GetEnvironmentVariable(strName);
				if(strVar == null) return false;

				return EcasUtil.CompareStrings(strVar, strValue, uCompareType);
			}
			catch(Exception) { Debug.Assert(false); }

			return false;
		}
 private static void ShowEntriesByTag(EcasAction a, EcasContext ctx)
 {
     string strTag = EcasUtil.GetParamString(a.Parameters, 0, true);
     Program.MainForm.ShowEntriesByTag(strTag);
 }
        private static void ImportIntoCurrentDatabase(EcasAction a, EcasContext ctx)
        {
            PwDatabase pd = Program.MainForm.ActiveDatabase;
            if((pd == null) || !pd.IsOpen) return;

            string strPath = EcasUtil.GetParamString(a.Parameters, 0, true);
            if(string.IsNullOrEmpty(strPath)) return;
            IOConnectionInfo ioc = IOConnectionInfo.FromPath(strPath);

            string strFormat = EcasUtil.GetParamString(a.Parameters, 1, true);
            if(string.IsNullOrEmpty(strFormat)) return;
            FileFormatProvider ff = Program.FileFormatPool.Find(strFormat);
            if(ff == null)
                throw new Exception(KPRes.Unknown + ": " + strFormat);

            uint uMethod = EcasUtil.GetParamUInt(a.Parameters, 2);
            Type tMM = Enum.GetUnderlyingType(typeof(PwMergeMethod));
            object oMethod = Convert.ChangeType(uMethod, tMM);
            PwMergeMethod mm = PwMergeMethod.None;
            if(Enum.IsDefined(typeof(PwMergeMethod), oMethod))
                mm = (PwMergeMethod)oMethod;
            else { Debug.Assert(false); }
            if(mm == PwMergeMethod.None) mm = PwMergeMethod.CreateNewUuids;

            CompositeKey cmpKey = KeyFromParams(a, 3, 4, 5);
            if((cmpKey == null) && ff.RequiresKey)
            {
                KeyPromptForm kpf = new KeyPromptForm();
                kpf.InitEx(ioc, false, true);

                if(UIUtil.ShowDialogNotValue(kpf, DialogResult.OK)) return;

                cmpKey = kpf.CompositeKey;
                UIUtil.DestroyForm(kpf);
            }

            bool? b = true;
            try { b = ImportUtil.Import(pd, ff, ioc, mm, cmpKey); }
            finally
            {
                if(b.GetValueOrDefault(false))
                    Program.MainForm.UpdateUI(false, null, true, null, true, null, true);
            }
        }
 private static void RemoveToolBarButton(EcasAction a, EcasContext ctx)
 {
     string strID = EcasUtil.GetParamString(a.Parameters, 0, true);
     Program.MainForm.RemoveCustomToolBarButton(strID);
 }
        private static void ExecuteSelectedAutoType(EcasAction a, EcasContext ctx)
        {
            try
            {
                // Do not Spr-compile the sequence here; it'll be compiled by
                // the auto-type engine (and this expects an auto-type sequence
                // as input, not a data string; compiling it here would e.g.
                // result in broken '%' characters in passwords)
                string strSeq = EcasUtil.GetParamString(a.Parameters, 0, false);
                if(string.IsNullOrEmpty(strSeq)) strSeq = null;

                PwEntry pe = Program.MainForm.GetSelectedEntry(true);
                if(pe == null) return;
                PwDatabase pd = Program.MainForm.DocumentManager.SafeFindContainerOf(pe);

                IntPtr hFg = NativeMethods.GetForegroundWindowHandle();
                if(AutoType.IsOwnWindow(hFg))
                    AutoType.PerformIntoPreviousWindow(Program.MainForm, pe,
                        pd, strSeq);
                else AutoType.PerformIntoCurrentWindow(pe, pd, strSeq);
            }
            catch(Exception) { Debug.Assert(false); }
        }
        private static void ExecuteSleep(EcasAction a, EcasContext ctx)
        {
            uint uTimeSpan = EcasUtil.GetParamUInt(a.Parameters, 0);

            if((uTimeSpan != 0) && (uTimeSpan <= (uint)int.MaxValue))
                Thread.Sleep((int)uTimeSpan);
        }
 private static void ExecuteGlobalAutoType(EcasAction a, EcasContext ctx)
 {
     Program.MainForm.ExecuteGlobalAutoType();
 }
 private static void CloseDatabaseFile(EcasAction a, EcasContext ctx)
 {
     Program.MainForm.CloseDocument(null, false, false, true);
 }
        private static void ImportIntoCurrentDatabase(EcasAction a, EcasContext ctx)
        {
            PwDatabase pd = Program.MainForm.ActiveDatabase;

            if ((pd == null) || !pd.IsOpen)
            {
                return;
            }

            string strPath = EcasUtil.GetParamString(a.Parameters, 0, true);

            if (string.IsNullOrEmpty(strPath))
            {
                return;
            }
            IOConnectionInfo ioc = IOConnectionInfo.FromPath(strPath);

            string strFormat = EcasUtil.GetParamString(a.Parameters, 1, true);

            if (string.IsNullOrEmpty(strFormat))
            {
                return;
            }
            FileFormatProvider ff = Program.FileFormatPool.Find(strFormat);

            if (ff == null)
            {
                throw new Exception(KPRes.Unknown + ": " + strFormat);
            }

            uint          uMethod = EcasUtil.GetParamUInt(a.Parameters, 2);
            Type          tMM     = Enum.GetUnderlyingType(typeof(PwMergeMethod));
            object        oMethod = Convert.ChangeType(uMethod, tMM);
            PwMergeMethod mm      = PwMergeMethod.None;

            if (Enum.IsDefined(typeof(PwMergeMethod), oMethod))
            {
                mm = (PwMergeMethod)oMethod;
            }
            else
            {
                Debug.Assert(false);
            }
            if (mm == PwMergeMethod.None)
            {
                mm = PwMergeMethod.CreateNewUuids;
            }

            CompositeKey cmpKey = KeyFromParams(a, 3, 4, 5);

            if ((cmpKey == null) && ff.RequiresKey)
            {
                KeyPromptForm kpf = new KeyPromptForm();
                kpf.InitEx(ioc, false, true);

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

                cmpKey = kpf.CompositeKey;
                UIUtil.DestroyForm(kpf);
            }

            bool?b = true;

            try { b = ImportUtil.Import(pd, ff, ioc, mm, cmpKey); }
            finally
            {
                if (b.GetValueOrDefault(false))
                {
                    Program.MainForm.UpdateUI(false, null, true, null, true, null, true);
                }
            }
        }
		private static void ShowMessageBox(EcasAction a, EcasContext ctx)
		{
			VistaTaskDialog vtd = new VistaTaskDialog();

			string strMain = EcasUtil.GetParamString(a.Parameters, 0, true);
			if(!string.IsNullOrEmpty(strMain)) vtd.MainInstruction = strMain;

			string strText = EcasUtil.GetParamString(a.Parameters, 1, true);
			if(!string.IsNullOrEmpty(strText)) vtd.Content = strText;

			uint uIcon = EcasUtil.GetParamUInt(a.Parameters, 2, 0);
			if(uIcon == (uint)MessageBoxIcon.Information)
				vtd.SetIcon(VtdIcon.Information);
			else if(uIcon == (uint)MessageBoxIcon.Question)
				vtd.SetIcon(VtdCustomIcon.Question);
			else if(uIcon == (uint)MessageBoxIcon.Warning)
				vtd.SetIcon(VtdIcon.Warning);
			else if(uIcon == (uint)MessageBoxIcon.Error)
				vtd.SetIcon(VtdIcon.Error);
			else { Debug.Assert(uIcon == (uint)MessageBoxIcon.None); }

			vtd.CommandLinks = false;

			uint uBtns = EcasUtil.GetParamUInt(a.Parameters, 3, 0);
			bool bCanCancel = false;
			if(uBtns == (uint)MessageBoxButtons.OKCancel)
			{
				vtd.AddButton((int)DialogResult.OK, KPRes.Ok, null);
				vtd.AddButton((int)DialogResult.Cancel, KPRes.Cancel, null);
				bCanCancel = true;
			}
			else if(uBtns == (uint)MessageBoxButtons.YesNo)
			{
				vtd.AddButton((int)DialogResult.OK, KPRes.YesCmd, null);
				vtd.AddButton((int)DialogResult.Cancel, KPRes.NoCmd, null);
				bCanCancel = true;
			}
			else vtd.AddButton((int)DialogResult.OK, KPRes.Ok, null);

			uint uDef = EcasUtil.GetParamUInt(a.Parameters, 4, 0);
			ReadOnlyCollection<VtdButton> lButtons = vtd.Buttons;
			if(uDef < (uint)lButtons.Count)
				vtd.DefaultButtonID = lButtons[(int)uDef].ID;

			vtd.WindowTitle = PwDefs.ShortProductName;

			string strTrg = ctx.Trigger.Name;
			if(!string.IsNullOrEmpty(strTrg))
			{
				vtd.FooterText = KPRes.Trigger + @": '" + strTrg + @"'.";
				vtd.SetFooterIcon(VtdIcon.Information);
			}

			int dr;
			if(vtd.ShowDialog()) dr = vtd.Result;
			else
			{
				string str = (strMain ?? string.Empty);
				if(!string.IsNullOrEmpty(strText))
				{
					if(str.Length > 0) str += MessageService.NewParagraph;
					str += strText;
				}

				MessageBoxDefaultButton mbdb = MessageBoxDefaultButton.Button1;
				if(uDef == 1) mbdb = MessageBoxDefaultButton.Button2;
				else if(uDef == 2) mbdb = MessageBoxDefaultButton.Button3;

				MessageService.ExternalIncrementMessageCount();
				try
				{
					dr = (int)MessageService.SafeShowMessageBox(str,
						PwDefs.ShortProductName, (MessageBoxButtons)uBtns,
						(MessageBoxIcon)uIcon, mbdb);
				}
				finally { MessageService.ExternalDecrementMessageCount(); }
			}

			uint uActCondID = EcasUtil.GetParamUInt(a.Parameters, 5, 0);

			bool bDrY = ((dr == (int)DialogResult.OK) ||
				(dr == (int)DialogResult.Yes));
			bool bDrN = ((dr == (int)DialogResult.Cancel) ||
				(dr == (int)DialogResult.No));

			bool bPerformAction = (((uActCondID == IdMbcY) && bDrY) ||
				((uActCondID == IdMbcN) && bDrN));
			if(!bPerformAction) return;

			uint uActID = EcasUtil.GetParamUInt(a.Parameters, 6, 0);
			string strActionParam = EcasUtil.GetParamString(a.Parameters, 7, true);

			if(uActID == IdMbaNone) { }
			else if(uActID == IdMbaAbort)
			{
				if(bCanCancel) ctx.Cancel = true;
			}
			else if(uActID == IdMbaCmd)
			{
				if(!string.IsNullOrEmpty(strActionParam))
					WinUtil.OpenUrl(strActionParam, null);
			}
			else { Debug.Assert(false); }
		}
        private static void ExecuteShellCmd(EcasAction a, EcasContext ctx)
        {
            string strCmd  = EcasUtil.GetParamString(a.Parameters, 0, true, true);
            string strArgs = EcasUtil.GetParamString(a.Parameters, 1, true, true);
            bool   bWait   = StrUtil.StringToBool(EcasUtil.GetParamString(a.Parameters,
                                                                          2, string.Empty));
            uint   uWindowStyle = EcasUtil.GetParamUInt(a.Parameters, 3);
            string strVerb      = EcasUtil.GetParamString(a.Parameters, 4, true);

            if (string.IsNullOrEmpty(strCmd))
            {
                return;
            }

            try
            {
                ProcessStartInfo psi = new ProcessStartInfo(strCmd);
                if (!string.IsNullOrEmpty(strArgs))
                {
                    psi.Arguments = strArgs;
                }

                bool bShEx = true;
                if (!string.IsNullOrEmpty(strVerb))
                {
                }                                                      // Need ShellExecute
                else if ((uWindowStyle == IdWindowMin) ||
                         (uWindowStyle == IdWindowMax))
                {
                }                                                          // Need ShellExecute
                else
                {
                    string strCmdFlt = strCmd.TrimEnd(new char[] { '\"', '\'',
                                                                   ' ', '\t', '\r', '\n' });
                    if (strCmdFlt.EndsWith(".exe", StrUtil.CaseIgnoreCmp) ||
                        strCmdFlt.EndsWith(".com", StrUtil.CaseIgnoreCmp))
                    {
                        bShEx = false;
                    }
                }
                psi.UseShellExecute = bShEx;

                if (uWindowStyle == IdWindowHidden)
                {
                    psi.CreateNoWindow = true;
                    psi.WindowStyle    = ProcessWindowStyle.Hidden;
                }
                else if (uWindowStyle == IdWindowMin)
                {
                    psi.WindowStyle = ProcessWindowStyle.Minimized;
                }
                else if (uWindowStyle == IdWindowMax)
                {
                    psi.WindowStyle = ProcessWindowStyle.Maximized;
                }

                if (!string.IsNullOrEmpty(strVerb))
                {
                    psi.Verb = strVerb;
                }

                Process p = Process.Start(psi);

                if ((p != null) && bWait)
                {
                    Program.MainForm.UIBlockInteraction(true);
                    MessageService.ExternalIncrementMessageCount();

                    try { p.WaitForExit(); }
                    catch (Exception) { Debug.Assert(false); }

                    MessageService.ExternalDecrementMessageCount();
                    Program.MainForm.UIBlockInteraction(false);
                }
            }
            catch (Exception e)
            {
                throw new Exception(strCmd + MessageService.NewParagraph + e.Message);
            }
        }
 private static void SaveDatabaseFile(EcasAction a, EcasContext ctx)
 {
     Program.MainForm.UIFileSave(false);
 }
        private static void ShowMessageBox(EcasAction a, EcasContext ctx)
        {
            VistaTaskDialog vtd = new VistaTaskDialog();

            string strMain = EcasUtil.GetParamString(a.Parameters, 0, true);

            if (!string.IsNullOrEmpty(strMain))
            {
                vtd.MainInstruction = strMain;
            }

            string strText = EcasUtil.GetParamString(a.Parameters, 1, true);

            if (!string.IsNullOrEmpty(strText))
            {
                vtd.Content = strText;
            }

            uint uIcon = EcasUtil.GetParamUInt(a.Parameters, 2, 0);

            if (uIcon == (uint)MessageBoxIcon.Information)
            {
                vtd.SetIcon(VtdIcon.Information);
            }
            else if (uIcon == (uint)MessageBoxIcon.Question)
            {
                vtd.SetIcon(VtdCustomIcon.Question);
            }
            else if (uIcon == (uint)MessageBoxIcon.Warning)
            {
                vtd.SetIcon(VtdIcon.Warning);
            }
            else if (uIcon == (uint)MessageBoxIcon.Error)
            {
                vtd.SetIcon(VtdIcon.Error);
            }
            else
            {
                Debug.Assert(uIcon == (uint)MessageBoxIcon.None);
            }

            vtd.CommandLinks = false;

            uint uBtns      = EcasUtil.GetParamUInt(a.Parameters, 3, 0);
            bool bCanCancel = false;

            if (uBtns == (uint)MessageBoxButtons.OKCancel)
            {
                vtd.AddButton((int)DialogResult.OK, KPRes.Ok, null);
                vtd.AddButton((int)DialogResult.Cancel, KPRes.Cancel, null);
                bCanCancel = true;
            }
            else if (uBtns == (uint)MessageBoxButtons.YesNo)
            {
                vtd.AddButton((int)DialogResult.OK, KPRes.YesCmd, null);
                vtd.AddButton((int)DialogResult.Cancel, KPRes.NoCmd, null);
                bCanCancel = true;
            }
            else
            {
                vtd.AddButton((int)DialogResult.OK, KPRes.Ok, null);
            }

            uint uDef = EcasUtil.GetParamUInt(a.Parameters, 4, 0);
            ReadOnlyCollection <VtdButton> lButtons = vtd.Buttons;

            if (uDef < (uint)lButtons.Count)
            {
                vtd.DefaultButtonID = lButtons[(int)uDef].ID;
            }

            vtd.WindowTitle = PwDefs.ShortProductName;

            string strTrg = ctx.Trigger.Name;

            if (!string.IsNullOrEmpty(strTrg))
            {
                vtd.FooterText = KPRes.Trigger + @": '" + strTrg + @"'.";
                vtd.SetFooterIcon(VtdIcon.Information);
            }

            int dr;

            if (vtd.ShowDialog())
            {
                dr = vtd.Result;
            }
            else
            {
                string str = (strMain ?? string.Empty);
                if (!string.IsNullOrEmpty(strText))
                {
                    if (str.Length > 0)
                    {
                        str += MessageService.NewParagraph;
                    }
                    str += strText;
                }

                MessageBoxDefaultButton mbdb = MessageBoxDefaultButton.Button1;
                if (uDef == 1)
                {
                    mbdb = MessageBoxDefaultButton.Button2;
                }
                else if (uDef == 2)
                {
                    mbdb = MessageBoxDefaultButton.Button3;
                }

                MessageService.ExternalIncrementMessageCount();
                try
                {
                    dr = (int)MessageService.SafeShowMessageBox(str,
                                                                PwDefs.ShortProductName, (MessageBoxButtons)uBtns,
                                                                (MessageBoxIcon)uIcon, mbdb);
                }
                finally { MessageService.ExternalDecrementMessageCount(); }
            }

            uint uActCondID = EcasUtil.GetParamUInt(a.Parameters, 5, 0);

            bool bDrY = ((dr == (int)DialogResult.OK) ||
                         (dr == (int)DialogResult.Yes));
            bool bDrN = ((dr == (int)DialogResult.Cancel) ||
                         (dr == (int)DialogResult.No));

            bool bPerformAction = (((uActCondID == IdMbcY) && bDrY) ||
                                   ((uActCondID == IdMbcN) && bDrN));

            if (!bPerformAction)
            {
                return;
            }

            uint   uActID         = EcasUtil.GetParamUInt(a.Parameters, 6, 0);
            string strActionParam = EcasUtil.GetParamString(a.Parameters, 7, true);

            if (uActID == IdMbaNone)
            {
            }
            else if (uActID == IdMbaAbort)
            {
                if (bCanCancel)
                {
                    ctx.Cancel = true;
                }
            }
            else if (uActID == IdMbaCmd)
            {
                if (!string.IsNullOrEmpty(strActionParam))
                {
                    WinUtil.OpenUrl(strActionParam, null);
                }
            }
            else
            {
                Debug.Assert(false);
            }
        }
        private static void RemoveToolBarButton(EcasAction a, EcasContext ctx)
        {
            string strID = EcasUtil.GetParamString(a.Parameters, 0, true);

            Program.MainForm.RemoveCustomToolBarButton(strID);
        }
        private static void ShowEntriesByTag(EcasAction a, EcasContext ctx)
        {
            string strTag = EcasUtil.GetParamString(a.Parameters, 0, true);

            Program.MainForm.ShowEntriesByTag(strTag);
        }
        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);
        }
        private static void AddToolBarButton(EcasAction a, EcasContext ctx)
        {
            string strID = EcasUtil.GetParamString(a.Parameters, 0, true);
            string strName = EcasUtil.GetParamString(a.Parameters, 1, true);
            string strDesc = EcasUtil.GetParamString(a.Parameters, 2, true);

            Program.MainForm.AddCustomToolBarButton(strID, strName, strDesc);
        }
		private static void ActivateDatabaseTab(EcasAction a, EcasContext ctx)
		{
			string strName = EcasUtil.GetParamString(a.Parameters, 0, true);
			bool bEmptyName = string.IsNullOrEmpty(strName);

			uint uSel = EcasUtil.GetParamUInt(a.Parameters, 1, 0);
			PwDatabase pdSel = ctx.Properties.Get<PwDatabase>(EcasProperty.Database);

			DocumentManagerEx dm = Program.MainForm.DocumentManager;
			foreach(PwDocument doc in dm.Documents)
			{
				if(doc.Database == null) { Debug.Assert(false); continue; }

				if(uSel == 0) // Select from all
				{
					if(bEmptyName) continue; // Name required in this case
				}
				else if(uSel == 1) // Triggering only
				{
					if(!object.ReferenceEquals(doc.Database, pdSel)) continue;
				}
				else { Debug.Assert(false); continue; }

				IOConnectionInfo ioc = null;
				if((doc.LockedIoc != null) && !string.IsNullOrEmpty(doc.LockedIoc.Path))
					ioc = doc.LockedIoc;
				else if((doc.Database.IOConnectionInfo != null) &&
					!string.IsNullOrEmpty(doc.Database.IOConnectionInfo.Path))
					ioc = doc.Database.IOConnectionInfo;

				if(bEmptyName || ((ioc != null) && (ioc.Path.IndexOf(strName,
					StrUtil.CaseIgnoreCmp) >= 0)))
				{
					Program.MainForm.MakeDocumentActive(doc);
					break;
				}
			}
		}
 private static void CloseDatabaseFile(EcasAction a, EcasContext ctx)
 {
     Program.MainForm.CloseDocument(null, false, false, true, true);
 }
        private static void ActivateDatabaseTab(EcasAction a, EcasContext ctx)
        {
            string strName = EcasUtil.GetParamString(a.Parameters, 0, true);
            if(string.IsNullOrEmpty(strName)) return;

            DocumentManagerEx dm = Program.MainForm.DocumentManager;
            foreach(PwDocument doc in dm.Documents)
            {
                if(doc.Database == null) { Debug.Assert(false); continue; }

                IOConnectionInfo ioc = null;
                if((doc.LockedIoc != null) && !string.IsNullOrEmpty(doc.LockedIoc.Path))
                    ioc = doc.LockedIoc;
                else if((doc.Database.IOConnectionInfo != null) &&
                    !string.IsNullOrEmpty(doc.Database.IOConnectionInfo.Path))
                    ioc = doc.Database.IOConnectionInfo;

                if((ioc != null) && (ioc.Path.IndexOf(strName, StrUtil.CaseIgnoreCmp) >= 0))
                {
                    Program.MainForm.MakeDocumentActive(doc);
                    break;
                }
            }
        }
        private static bool IsMatchFile(EcasCondition c, EcasContext ctx)
        {
            string strFile = EcasUtil.GetParamString(c.Parameters, 0, true);
            if(string.IsNullOrEmpty(strFile)) return true;

            try { return File.Exists(strFile); }
            catch(Exception) { }

            return false;
        }
        private static void ChangeTriggerOnOff(EcasAction a, EcasContext ctx)
        {
            string strName = EcasUtil.GetParamString(a.Parameters, 0, true);
            uint uState = EcasUtil.GetParamUInt(a.Parameters, 1);

            EcasTrigger t = null;
            if(strName.Length == 0) t = ctx.Trigger;
            else
            {
                foreach(EcasTrigger trg in ctx.TriggerSystem.TriggerCollection)
                {
                    if(trg.Name == strName) { t = trg; break; }
                }
            }

            if(t == null) throw new Exception(KPRes.ObjectNotFound +
                MessageService.NewParagraph + KPRes.TriggerName + ": " + strName + ".");

            if(uState == IdTriggerOn) t.On = true;
            else if(uState == IdTriggerOff) t.On = false;
            else if(uState == IdTriggerToggle) t.On = !t.On;
            else { Debug.Assert(false); }
        }
Exemple #27
0
 private static bool EcasEventCompareTrue(EcasEvent e, EcasContext ctx)
 {
     return true;
 }
 private static void ExecuteGlobalAutoType(EcasAction a, EcasContext ctx)
 {
     Program.MainForm.ExecuteGlobalAutoType();
 }
Exemple #29
0
 private static bool EcasEventCompareTrue(EcasEvent e, EcasContext ctx)
 {
     return(true);
 }
        private static void ExecuteShellCmd(EcasAction a, EcasContext ctx)
        {
            string strCmd = EcasUtil.GetParamString(a.Parameters, 0, true, true);
            string strArgs = EcasUtil.GetParamString(a.Parameters, 1, true, true);
            bool bWait = StrUtil.StringToBool(EcasUtil.GetParamString(a.Parameters,
                2, string.Empty));

            if(string.IsNullOrEmpty(strCmd)) return;

            try
            {
                Process p;
                if(string.IsNullOrEmpty(strArgs)) p = Process.Start(strCmd);
                else p = Process.Start(strCmd, strArgs);

                if((p != null) && bWait)
                {
                    Program.MainForm.UIBlockInteraction(true);
                    MessageService.ExternalIncrementMessageCount();

                    try { p.WaitForExit(); }
                    catch(Exception) { Debug.Assert(false); }

                    MessageService.ExternalDecrementMessageCount();
                    Program.MainForm.UIBlockInteraction(false);
                }
            }
            catch(Exception e)
            {
                throw new Exception(strCmd + MessageService.NewParagraph + e.Message);
            }
        }
		private static bool EcasConditionEvaluateTrue(EcasCondition c, EcasContext ctx)
		{
			return true;
		}
        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);
        }
        private static bool IsMatchFileExists(EcasCondition c, EcasContext ctx)
        {
            string strFile = EcasUtil.GetParamString(c.Parameters, 0, true);
            if(string.IsNullOrEmpty(strFile)) return true;

            try
            {
                // return File.Exists(strFile);

                IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
                return IOConnection.FileExists(ioc);
            }
            catch(Exception) { }

            return false;
        }
        private static void OpenDatabaseFile(EcasAction a, EcasContext ctx)
        {
            string strPath = EcasUtil.GetParamString(a.Parameters, 0, true);
            if(string.IsNullOrEmpty(strPath)) return;

            string strIOUserName = EcasUtil.GetParamString(a.Parameters, 1, true);
            string strIOPassword = EcasUtil.GetParamString(a.Parameters, 2, true);

            IOConnectionInfo ioc = IOFromParameters(strPath, strIOUserName, strIOPassword);
            if(ioc == null) return;

            CompositeKey cmpKey = KeyFromParams(a, 3, 4, 5);

            Program.MainForm.OpenDatabase(ioc, cmpKey, ioc.IsLocalFile());
        }
 private static bool IsDatabaseModified(EcasCondition c, EcasContext ctx)
 {
     PwDatabase pd = Program.MainForm.ActiveDatabase;
     if((pd == null) || !pd.IsOpen) return false;
     return pd.Modified;
 }
 private static void SaveDatabaseFile(EcasAction a, EcasContext ctx)
 {
     Program.MainForm.UIFileSave(false);
 }
Exemple #37
0
 private static bool EcasConditionEvaluateTrue(EcasCondition c, EcasContext ctx)
 {
     return(true);
 }
        private static void SyncDatabaseFile(EcasAction a, EcasContext ctx)
        {
            string strPath = EcasUtil.GetParamString(a.Parameters, 0, true);
            if(string.IsNullOrEmpty(strPath)) return;

            string strIOUserName = EcasUtil.GetParamString(a.Parameters, 1, true);
            string strIOPassword = EcasUtil.GetParamString(a.Parameters, 2, true);

            IOConnectionInfo ioc = IOFromParameters(strPath, strIOUserName, strIOPassword);
            if(ioc == null) return;

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

            bool? b = ImportUtil.Synchronize(pd, Program.MainForm, ioc, false,
                Program.MainForm);
            Program.MainForm.UpdateUI(false, null, true, null, true, null, false);
            if(b.HasValue) Program.MainForm.SetStatusEx(b.Value ? KPRes.SyncSuccess : KPRes.SyncFailed);
        }
        private static void ExecuteShellCmd(EcasAction a, EcasContext ctx)
        {
            string strCmd       = EcasUtil.GetParamString(a.Parameters, 0);
            string strArgs      = EcasUtil.GetParamString(a.Parameters, 1, true, true);
            bool   bWait        = EcasUtil.GetParamBool(a.Parameters, 2);
            uint   uWindowStyle = EcasUtil.GetParamUInt(a.Parameters, 3);
            string strVerb      = EcasUtil.GetParamString(a.Parameters, 4, true);

            if (string.IsNullOrEmpty(strCmd))
            {
                return;
            }

            Process p = null;

            try
            {
                PwEntry pe = null;
                try { pe = Program.MainForm.GetSelectedEntry(false); }
                catch (Exception) { Debug.Assert(false); }

                strCmd = WinUtil.CompileUrl(strCmd, pe, true, null, false);
                if (string.IsNullOrEmpty(strCmd))
                {
                    return;                                              // Might be placeholder only
                }
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = strCmd;
                if (!string.IsNullOrEmpty(strArgs))
                {
                    psi.Arguments = strArgs;
                }

                bool bShEx = true;
                if (!string.IsNullOrEmpty(strVerb))
                {
                }                                                      // Need ShellExecute
                else if ((uWindowStyle == IdWindowMin) ||
                         (uWindowStyle == IdWindowMax))
                {
                }                                                          // Need ShellExecute
                else
                {
                    string strCmdFlt = strCmd.TrimEnd(new char[] { '\"', '\'',
                                                                   ' ', '\t', '\r', '\n' });
                    if (strCmdFlt.EndsWith(".exe", StrUtil.CaseIgnoreCmp) ||
                        strCmdFlt.EndsWith(".com", StrUtil.CaseIgnoreCmp))
                    {
                        bShEx = false;
                    }
                }
                psi.UseShellExecute = bShEx;

                if (uWindowStyle == IdWindowHidden)
                {
                    psi.CreateNoWindow = true;
                    psi.WindowStyle    = ProcessWindowStyle.Hidden;
                }
                else if (uWindowStyle == IdWindowMin)
                {
                    psi.WindowStyle = ProcessWindowStyle.Minimized;
                }
                else if (uWindowStyle == IdWindowMax)
                {
                    psi.WindowStyle = ProcessWindowStyle.Maximized;
                }

                if (!string.IsNullOrEmpty(strVerb))
                {
                    psi.Verb = strVerb;
                }

                p = NativeLib.StartProcessEx(psi);

                if ((p != null) && bWait)
                {
                    Program.MainForm.UIBlockInteraction(true);
                    MessageService.ExternalIncrementMessageCount();

                    try { p.WaitForExit(); }
                    catch (Exception) { Debug.Assert(false); }

                    MessageService.ExternalDecrementMessageCount();
                    Program.MainForm.UIBlockInteraction(false);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(strCmd + MessageService.NewParagraph + ex.Message);
            }
            finally
            {
                try { if (p != null)
                      {
                          p.Dispose();
                      }
                }
                catch (Exception) { Debug.Assert(false); }
            }
        }
        private static bool IsMatchString(EcasCondition c, EcasContext ctx)
        {
            string str = EcasUtil.GetParamString(c.Parameters, 0, true);
            uint uCompareType = EcasUtil.GetParamEnum(c.Parameters, 1,
                EcasUtil.StdStringCompareEquals, EcasUtil.StdStringCompare);
            string strValue = EcasUtil.GetParamString(c.Parameters, 2, true);

            if((str == null) || (strValue == null)) return false;

            return EcasUtil.CompareStrings(str, strValue, uCompareType);
        }
        private static bool IsMatchTextEvent(EcasEvent e, EcasContext ctx)
        {
            uint uCompareType = EcasUtil.GetParamEnum(e.Parameters, 0,
                EcasUtil.StdStringCompareEquals, EcasUtil.StdStringCompare);

            string strFilter = EcasUtil.GetParamString(e.Parameters, 1, true);
            if(string.IsNullOrEmpty(strFilter)) return true;

            string strCurFile = EcasUtil.GetParamString(ctx.Event.Parameters, 0);
            if(string.IsNullOrEmpty(strCurFile)) return false;

            return EcasUtil.CompareStrings(strCurFile, strFilter, uCompareType);
        }
        private static bool IsHostReachable(EcasCondition c, EcasContext ctx)
        {
            string strHost = EcasUtil.GetParamString(c.Parameters, 0, true);
            if(string.IsNullOrEmpty(strHost)) return true;

            int[] vTimeOuts = { 250, 1250 };
            const string strBuffer = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] pbBuffer = Encoding.ASCII.GetBytes(strBuffer);

            try
            {
                Ping ping = new Ping(); // We have sufficient privileges?
                PingOptions options = new PingOptions(64, true);

                foreach(int nTimeOut in vTimeOuts)
                {
                    PingReply reply = ping.Send(strHost, nTimeOut, pbBuffer, options);
                    if(reply.Status == IPStatus.Success) return true;
                }

                return false;
            }
            catch(Exception) { }

            return false;
        }
Exemple #43
0
 private static void EcasActionExecuteNull(EcasAction a, EcasContext ctx)
 {
 }