BioImager  5.0.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
BioImager.Automation.AutomationHelpers Class Reference

Static Public Member Functions

static List< AutomationElement > GetChildren (AutomationElement parent)
 
static List< AutomationElement > GetAllChildren (AutomationElement parent)
 
static List< AutomationElement > GetName (AutomationElement parent, string name)
 
static List< AutomationElement > GetAutomationID (AutomationElement parent, string id)
 
static List< AutomationElement > GetClassName (AutomationElement parent, string name)
 
static AutomationElement GetElementByProcess (string process, string title, string id, string name, string classname, int index)
 
static int GetIndex (string process, string title, string id, string name, string classname, Point p)
 
static int[] StringToRuntimeID (string s)
 
static List< AutomationElement > GetElement (string id, string name)
 
static List< AutomationElement > GetLocalizedControlType (AutomationElement parent, TreeScope scope, string type)
 
static AutomationElement[] GetRawChildren (AutomationElement parent)
 
static List< AutomationElement > GetRawAutomationID (AutomationElement parent, string auto)
 
static List< AutomationElement > GetRawLocalizedControlType (AutomationElement parent, string auto)
 
static AutomationElement[] GetRaw (AutomationElement parent)
 
static string GetValue (AutomationElement control)
 
static string GetSelection (AutomationElement control)
 
static string GetText (AutomationElement control)
 
static void SetValue (AutomationElement targetControl, string value)
 
static int GetCount (AutomationElement parent)
 
static bool GetToggle (AutomationElement element)
 
static Bitmap GetImage (AutomationElement el)
 

Detailed Description

Definition at line 612 of file Automation.cs.

Member Function Documentation

◆ GetAllChildren()

static List< AutomationElement > BioImager.Automation.AutomationHelpers.GetAllChildren ( AutomationElement parent)
static

Definition at line 633 of file Automation.cs.

634 {
635 if (parent == null)
636 {
637 // null parameter
638 throw new ArgumentException();
639 }
640 try
641 {
642 AutomationElement[] collection = automation.GetDesktop().FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
643 if (collection != null)
644 {
645 List<AutomationElement> result = new List<AutomationElement>(collection.Cast<AutomationElement>());
646 return result;
647 }
648 else
649 {
650 // some error occured
651 return null;
652 }
653 }
654 catch (Exception)
655 {
656 return null;
657 }
658 }
static UIA3Automation automation
Definition Automation.cs:16

◆ GetAutomationID()

static List< AutomationElement > BioImager.Automation.AutomationHelpers.GetAutomationID ( AutomationElement parent,
string id )
static

Definition at line 685 of file Automation.cs.

686 {
687 if (parent == null)
688 {
689 // null parameter
690 throw new ArgumentException();
691 }
692 AutomationElement[] collection = automation.GetDesktop().FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
693 if (collection != null)
694 {
695 List<AutomationElement> result = new List<AutomationElement>();
696 foreach (AutomationElement item in collection)
697 {
698 if (item.AutomationId == id)
699 {
700 result.Add(item);
701 }
702 }
703 return result;
704 }
705 else
706 {
707 // some error occured
708 return null;
709 }
710 }

◆ GetChildren()

static List< AutomationElement > BioImager.Automation.AutomationHelpers.GetChildren ( AutomationElement parent)
static

Definition at line 614 of file Automation.cs.

615 {
616 if (parent == null)
617 {
618 // null parameter
619 throw new ArgumentException();
620 }
621 AutomationElement[] collection = automation.GetDesktop().FindAll(TreeScope.Children, FlaUI.Core.Conditions.TrueCondition.Default);
622 if (collection != null)
623 {
624 List<AutomationElement> result = new List<AutomationElement>(collection.Cast<AutomationElement>());
625 return result;
626 }
627 else
628 {
629 // some error occured
630 return null;
631 }
632 }

◆ GetClassName()

static List< AutomationElement > BioImager.Automation.AutomationHelpers.GetClassName ( AutomationElement parent,
string name )
static

Definition at line 711 of file Automation.cs.

712 {
713 if (parent == null)
714 {
715 // null parameter
716 throw new ArgumentException();
717 }
718 AutomationElement[] collection = automation.GetDesktop().FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
719 if (collection != null)
720 {
721 List<AutomationElement> result = new List<AutomationElement>();
722 foreach (AutomationElement item in collection)
723 {
724 if (item.ClassName == name)
725 {
726 result.Add(item);
727 }
728 }
729 return result;
730 }
731 else
732 {
733 // some error occured
734 return null;
735 }
736 }

◆ GetCount()

static int BioImager.Automation.AutomationHelpers.GetCount ( AutomationElement parent)
static

Definition at line 1007 of file Automation.cs.

1008 {
1009 if (parent == null)
1010 {
1011 // null parameter
1012 throw new ArgumentException();
1013 }
1014 int i = 0;
1015 return parent.FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default).Length;
1016 }

◆ GetElement()

static List< AutomationElement > BioImager.Automation.AutomationHelpers.GetElement ( string id,
string name )
static

Definition at line 858 of file Automation.cs.

859 {
860 AutomationElement parent = automation.GetDesktop();
861 AutomationElement[] collection = automation.GetDesktop().FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
862 if (collection != null)
863 {
864 List<AutomationElement> result = new List<AutomationElement>();
865 foreach (AutomationElement item in collection)
866 {
867 if (item.AutomationId == id && item.Name == name)
868 {
869 result.Add(item);
870 }
871 }
872 return result;
873 }
874 else
875 {
876 // some error occured
877 return null;
878 }
879 }

◆ GetElementByProcess()

static AutomationElement BioImager.Automation.AutomationHelpers.GetElementByProcess ( string process,
string title,
string id,
string name,
string classname,
int index )
static

Definition at line 737 of file Automation.cs.

738 {
739 Process[] procs = Process.GetProcessesByName(process);
740 string ti = title;
741 if (ti == "")
742 ti = procs[0].MainWindowTitle;
743 AutomationElement root = automation.GetDesktop();
744 AutomationElement[] prs = automation.GetDesktop().FindAll(TreeScope.Children, FlaUI.Core.Conditions.TrueCondition.Default);
745 AutomationElement window = null;
746 List<AutomationElement> ats = new List<AutomationElement>();
747 foreach (AutomationElement item in prs)
748 {
749 try
750 {
751 if (item.Name.Contains(ti))
752 {
753 window = item;
754 }
755 }
756 catch (Exception)
757 {
758
759 }
760
761 }
762 if (window == null)
763 throw new ArgumentException("Window " + title + " not found.");
764 AutomationElement[] items = window.FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
765 List<AutomationElement> result = new List<AutomationElement>();
766 foreach (AutomationElement item in items)
767 {
768 try
769 {
770 if (item.Properties.LocalizedControlType == classname && item.Name == name)
771 {
772 result.Add(item);
773 }
774 }
775 catch (Exception)
776 {
777
778 }
779
780 }
781 if (index == -1)
782 return result[0];
783 return result[index];
784 }

◆ GetImage()

static Bitmap BioImager.Automation.AutomationHelpers.GetImage ( AutomationElement el)
static

Definition at line 1029 of file Automation.cs.

1030 {
1031 System.Drawing.Graphics g;
1032 Rectangle r = el.BoundingRectangle;
1033 Bitmap b = new Bitmap((int)r.Width, (int)r.Height);
1034 g = System.Drawing.Graphics.FromImage(b);
1035 g.CopyFromScreen(new Point((int)r.X,(int)r.Y), new Point(0, 0),new Size(r.Width,r.Height));
1036 return b;
1037 }
AForge.Bitmap Bitmap
AForge.Point Point
AForge.Rectangle Rectangle
System.Drawing.Size Size

◆ GetIndex()

static int BioImager.Automation.AutomationHelpers.GetIndex ( string process,
string title,
string id,
string name,
string classname,
Point p )
static

Definition at line 785 of file Automation.cs.

786 {
787 //For elements which have the same name, tittle, & id we also find the index of the item.
788 Process[] procs = Process.GetProcessesByName(process);
789 string ti = title;
790 if (ti == "")
791 ti = procs[0].MainWindowTitle;
792 AutomationElement[] prs = automation.GetDesktop().FindAll(TreeScope.Children, FlaUI.Core.Conditions.TrueCondition.Default);
793 AutomationElement window = null;
794 List<AutomationElement> ats = new List<AutomationElement>();
795 foreach (AutomationElement item in prs)
796 {
797 try
798 {
799 if (item.Name.Contains(title))
800 {
801 window = item;
802 }
803 }
804 catch (Exception)
805 {
806
807 }
808
809 }
810 if (window == null)
811 return 0;
812 AutomationElement[] items = null;
813 try
814 {
815 items = window.FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
816 }
817 catch (Exception)
818 {
819
820 }
821 List<AutomationElement> result = new List<AutomationElement>();
822
823 int index = 0;
824 /*
825 if (items != null)
826 foreach (AutomationElement item in items)
827 {
828 try
829 {
830 int[] r = item.Properties.RuntimeId;
831 if (item.ClassName == classname && item.AutomationId == id && item.Name == name)
832 {
833 result.Add(item);
834 }
835 if (item.BoundingRectangle.IntersectsWith(new Rectangle(p.X, p.Y, 1, 1)) && result.Count > 0)
836 {
837 index = result.Count - 1;
838 }
839 }
840 catch (Exception)
841 {
842
843 }
844 }
845 */
846 return index;
847 }

◆ GetLocalizedControlType()

static List< AutomationElement > BioImager.Automation.AutomationHelpers.GetLocalizedControlType ( AutomationElement parent,
TreeScope scope,
string type )
static

Definition at line 880 of file Automation.cs.

881 {
882 if (parent == null)
883 {
884 // null parameter
885 throw new ArgumentException();
886 }
887 AutomationElement[] collection = automation.GetDesktop().FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
888 if (collection != null)
889 {
890 List<AutomationElement> result = new List<AutomationElement>();
891 foreach (AutomationElement item in collection)
892 {
893 if (item.Properties.LocalizedControlType == type)
894 {
895 result.Add(item);
896 }
897 }
898 return result;
899 }
900 else
901 {
902 // some error occured
903 return null;
904 }
905 }

◆ GetName()

static List< AutomationElement > BioImager.Automation.AutomationHelpers.GetName ( AutomationElement parent,
string name )
static

Definition at line 659 of file Automation.cs.

660 {
661 if (parent == null)
662 {
663 // null parameter
664 throw new ArgumentException();
665 }
666 AutomationElement[] collection = automation.GetDesktop().FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
667 if (collection != null)
668 {
669 List<AutomationElement> result = new List<AutomationElement>();
670 foreach (AutomationElement item in collection)
671 {
672 if (item.Name == name)
673 {
674 result.Add(item);
675 }
676 }
677 return result;
678 }
679 else
680 {
681 // some error occured
682 return null;
683 }
684 }

◆ GetRaw()

static AutomationElement[] BioImager.Automation.AutomationHelpers.GetRaw ( AutomationElement parent)
static

Definition at line 951 of file Automation.cs.

952 {
953 if (parent == null)
954 {
955 // null parameter
956 throw new ArgumentException();
957 }
958 List<AutomationElement> ress = new List<AutomationElement>();
959 return parent.FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
960 }

◆ GetRawAutomationID()

static List< AutomationElement > BioImager.Automation.AutomationHelpers.GetRawAutomationID ( AutomationElement parent,
string auto )
static

Definition at line 915 of file Automation.cs.

916 {
917 if (parent == null)
918 {
919 // null parameter
920 throw new ArgumentException();
921 }
922 List<AutomationElement> ress = new List<AutomationElement>();
923 AutomationElement[] all = parent.FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
924 foreach (AutomationElement item in all)
925 {
926 if (item.AutomationId == auto)
927 {
928 ress.Add(item);
929 }
930 }
931 return ress;
932 }

◆ GetRawChildren()

static AutomationElement[] BioImager.Automation.AutomationHelpers.GetRawChildren ( AutomationElement parent)
static

Definition at line 906 of file Automation.cs.

907 {
908 if (parent == null)
909 {
910 // null parameter
911 throw new ArgumentException();
912 }
913 return parent.FindAll(TreeScope.Children, FlaUI.Core.Conditions.TrueCondition.Default);
914 }

◆ GetRawLocalizedControlType()

static List< AutomationElement > BioImager.Automation.AutomationHelpers.GetRawLocalizedControlType ( AutomationElement parent,
string auto )
static

Definition at line 933 of file Automation.cs.

934 {
935 if (parent == null)
936 {
937 // null parameter
938 throw new ArgumentException();
939 }
940 List<AutomationElement> ress = new List<AutomationElement>();
941 AutomationElement[] all = parent.FindAll(TreeScope.Subtree, FlaUI.Core.Conditions.TrueCondition.Default);
942 foreach (AutomationElement item in all)
943 {
944 if (item.Properties.LocalizedControlType == auto)
945 {
946 ress.Add(item);
947 }
948 }
949 return ress;
950 }

◆ GetSelection()

static string BioImager.Automation.AutomationHelpers.GetSelection ( AutomationElement control)
static

Definition at line 974 of file Automation.cs.

975 {
976 object patternProvider;
977 FlaUI.Core.AutomationElements.ListBox lb = control.AsListBox();
978 return lb.SelectedItem.Name;
979 }

◆ GetText()

static string BioImager.Automation.AutomationHelpers.GetText ( AutomationElement control)
static

Definition at line 980 of file Automation.cs.

981 {
982 return control.AsLabel().Text;
983 }

◆ GetToggle()

static bool BioImager.Automation.AutomationHelpers.GetToggle ( AutomationElement element)
static

Definition at line 1017 of file Automation.cs.

1018 {
1019 if (element == null)
1020 {
1021 return false;
1022 }
1023 ToggleButton tb = element.AsToggleButton();
1024 if (tb.TogglePattern.ToggleState.ValueOrDefault.HasFlag(ToggleState.On))
1025 return true;
1026 else
1027 return false;
1028 }

◆ GetValue()

static string BioImager.Automation.AutomationHelpers.GetValue ( AutomationElement control)
static

Definition at line 961 of file Automation.cs.

962 {
963 if(control.ControlType == ControlType.Edit)
964 {
965 FlaUI.Core.AutomationElements.TextBox tb = control.AsTextBox();
966 return tb.Text;
967 }
968 else if(control.ControlType == ControlType.Text)
969 {
970 return control.AsLabel().Text;
971 }
972 return control.Name;
973 }

◆ SetValue()

static void BioImager.Automation.AutomationHelpers.SetValue ( AutomationElement targetControl,
string value )
static

Definition at line 984 of file Automation.cs.

985 {
986 // Validate arguments / initial setup
987 if (value == null)
988 throw new ArgumentNullException(
989 "String parameter must not be null.");
990 if (targetControl == null)
991 throw new ArgumentNullException(
992 "AutomationElement parameter must not be null");
993 // A series of basic checks prior to attempting an insertion.
994 //
995 // Check #1: Is control enabled?
996 // An alternative to testing for static or read-only controls
997 // is to filter using
998 // PropertyCondition(AutomationElement.IsEnabledProperty, true)
999 // and exclude all read-only text controls from the collection.
1000 if (!targetControl.IsEnabled)
1001 {
1002 throw new InvalidOperationException(
1003 "The control is not enabled.\n\n");
1004 }
1005 targetControl.AsTextBox().Text = value;
1006 }

◆ StringToRuntimeID()

static int[] BioImager.Automation.AutomationHelpers.StringToRuntimeID ( string s)
static

Definition at line 848 of file Automation.cs.

849 {
850 int[] r = new int[3];
851 string[] sts = s.Split(',');
852 for (int i = 0; i < 3; i++)
853 {
854 r[i] = int.Parse(sts[i]);
855 }
856 return r;
857 }

The documentation for this class was generated from the following file: