Beispiel #1
0
        public TAutomation GetAutomation <TAutomation>(AutomationId id) where TAutomation : IAutomation
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            return(_automations.Get <TAutomation>(id));
        }
Beispiel #2
0
        protected AutomationBase(AutomationId id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            Id = id;
        }
Beispiel #3
0
        public static string From(AutomationId automationId)
        {
            if (automationId == null)
            {
                throw new ArgumentNullException(nameof(automationId));
            }

            return("Automation/" + automationId);
        }
        public BathroomFanAutomation(AutomationId id, IHomeAutomationTimer timer)
            : base(id)
        {
            if (timer == null)
            {
                throw new ArgumentNullException(nameof(timer));
            }

            _timer = timer;
        }
        public BathroomFanAutomation(AutomationId id, ISchedulerService schedulerService, ISettingsService settingsService)
            : base(id)
        {
            if (schedulerService == null) throw new ArgumentNullException(nameof(schedulerService));
            if (settingsService == null) throw new ArgumentNullException(nameof(settingsService));

            _schedulerService = schedulerService;

            settingsService.CreateSettingsMonitor<BathroomFanAutomationSettings>(Id, s => Settings = s);
        }
        public BathroomFanAutomation(AutomationId id, ISchedulerService schedulerService)
            : base(id)
        {
            if (schedulerService == null)
            {
                throw new ArgumentNullException(nameof(schedulerService));
            }

            _schedulerService = schedulerService;
        }
        protected AutomationBase(AutomationId id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            Id       = id;
            Settings = new SettingsContainer(StoragePath.WithFilename("Automations", id.Value, "Settings.json"));
            GeneralSettingsWrapper = new AutomationSettingsWrapper(Settings);
        }
Beispiel #8
0
        public TurnOnAndOffAutomation(AutomationId id, IHomeAutomationTimer timer)
            : base(id)
        {
            if (timer == null)
            {
                throw new ArgumentNullException(nameof(timer));
            }

            _timer           = timer;
            _wrappedSettings = new TurnOnAndOffAutomationSettingsWrapper(Settings);
        }
        public ConditionalOnAutomation(AutomationId id, ISchedulerService schedulerService, IDateTimeService dateTimeService, IDaylightService daylightService)
            : base(id)
        {
            if (dateTimeService == null) throw new ArgumentNullException(nameof(dateTimeService));
            if (daylightService == null) throw new ArgumentNullException(nameof(daylightService));

            _dateTimeService = dateTimeService;
            _daylightService = daylightService;

            WithTrigger(new IntervalTrigger(TimeSpan.FromMinutes(1), schedulerService));
        }
        public Automation(AutomationId id, IHomeAutomationTimer timer, IHttpRequestController httpApiController, ILogger logger)
            : base(id)
        {
            if (timer == null)
            {
                throw new ArgumentNullException(nameof(timer));
            }

            Timer = timer;
            _conditionsValidator = new ConditionsValidator(Conditions);

            Settings = new AutomationSettings(id, httpApiController, logger);
        }
Beispiel #11
0
        public AutomationSettings(AutomationId automationId, IHttpRequestController httpApiController, ILogger logger)
            : base(GenerateFilename(automationId), logger)
        {
            if (httpApiController == null)
            {
                throw new ArgumentNullException(nameof(httpApiController));
            }

            AutomationId = automationId;
            IsEnabled    = new Setting <bool>(true);
            AppSettings  = new Setting <JsonObject>(new JsonObject());

            new AutomationSettingsHttpApiDispatcher(this, httpApiController).ExposeToApi();
        }
        public TurnOnAndOffAutomation(AutomationId id, IDateTimeService dateTimeService, ISchedulerService schedulerService, ISettingsService settingsService, IDaylightService daylightService)
            : base(id)
        {
            if (dateTimeService == null) throw new ArgumentNullException(nameof(dateTimeService));
            if (schedulerService == null) throw new ArgumentNullException(nameof(schedulerService));
            if (settingsService == null) throw new ArgumentNullException(nameof(settingsService));
            if (daylightService == null) throw new ArgumentNullException(nameof(daylightService));

            _dateTimeService = dateTimeService;
            _schedulerService = schedulerService;
            _daylightService = daylightService;

            settingsService.CreateSettingsMonitor<TurnOnAndOffAutomationSettings>(Id, s => Settings = s);
        }
Beispiel #13
0
        public RollerShutterAutomationSettings(AutomationId automationId, IHttpRequestController httpApiController, ILogger logger)
            : base(automationId, httpApiController, logger)
        {
            DoNotOpenBeforeIsEnabled = new Setting <bool>(false);
            DoNotOpenBeforeTime      = new Setting <TimeSpan>(TimeSpan.Parse("07:15"));

            AutoCloseIfTooHotIsEnabled  = new Setting <bool>(false);
            AutoCloseIfTooHotTemperaure = new Setting <float>(25);

            DoNotOpenIfTooColdIsEnabled   = new Setting <bool>(false);
            DoNotOpenIfTooColdTemperature = new Setting <float>(2);

            OpenOnSunriseOffset = new Setting <TimeSpan>(TimeSpan.FromMinutes(-30));
            CloseOnSunsetOffset = new Setting <TimeSpan>(TimeSpan.FromMinutes(30));
        }
        public static JObject GetRawSettings(this ISettingsService settingsService, AutomationId automationId)
        {
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }
            if (automationId == null)
            {
                throw new ArgumentNullException(nameof(automationId));
            }

            var uri = SettingsUriGenerator.From(automationId);

            return(settingsService.GetSettings(uri));
        }
        public override int GetHashCode()
        {
            // It does not metter int overflow
            unchecked
            {
                // Choose large primes to avoid hashing collisions
                const int HASHING_BASE       = (int)2166136261;
                const int HASHING_MULTIPLIER = 16777619;

                int hash = HASHING_BASE;
                hash *= HASHING_MULTIPLIER + ((Title is null) ? 0 : Title.GetHashCode());
                hash *= HASHING_MULTIPLIER + ((AutomationId is null) ? 0 : AutomationId.GetHashCode());
                hash *= HASHING_MULTIPLIER + ((IconImageSource is null) ? 0 : IconImageSource.GetHashCode());
                return(hash);
            }
        }
Beispiel #16
0
        public BathroomFanAutomation(AutomationId id, ISchedulerService schedulerService, ISettingsService settingsService)
            : base(id)
        {
            if (schedulerService == null)
            {
                throw new ArgumentNullException(nameof(schedulerService));
            }
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }

            _schedulerService = schedulerService;

            settingsService.CreateSettingsMonitor <BathroomFanAutomationSettings>(Id, s => Settings = s);
        }
        public TurnOnAndOffAutomation(AutomationId id, IDateTimeService dateTimeService, ISchedulerService schedulerService)
            : base(id)
        {
            if (dateTimeService == null)
            {
                throw new ArgumentNullException(nameof(dateTimeService));
            }
            if (schedulerService == null)
            {
                throw new ArgumentNullException(nameof(schedulerService));
            }

            _dateTimeService  = dateTimeService;
            _schedulerService = schedulerService;

            _wrappedSettings = new TurnOnAndOffAutomationSettingsWrapper(Settings);
        }
Beispiel #18
0
        public ConditionalOnAutomation(AutomationId id, ISchedulerService schedulerService, IDateTimeService dateTimeService, IDaylightService daylightService)
            : base(id)
        {
            if (dateTimeService == null)
            {
                throw new ArgumentNullException(nameof(dateTimeService));
            }
            if (daylightService == null)
            {
                throw new ArgumentNullException(nameof(daylightService));
            }

            _dateTimeService = dateTimeService;
            _daylightService = daylightService;

            WithTrigger(new IntervalTrigger(TimeSpan.FromMinutes(1), schedulerService));
        }
Beispiel #19
0
        public RollerShutterAutomation(
            AutomationId id,
            ISchedulerService schedulerService,
            IDateTimeService dateTimeService,
            IDaylightService daylightService,
            IOutdoorTemperatureService outdoorTemperatureService,
            IComponentController componentController)
            : base(id)
        {
            if (schedulerService == null)
            {
                throw new ArgumentNullException(nameof(schedulerService));
            }
            if (dateTimeService == null)
            {
                throw new ArgumentNullException(nameof(dateTimeService));
            }
            if (daylightService == null)
            {
                throw new ArgumentNullException(nameof(daylightService));
            }
            if (outdoorTemperatureService == null)
            {
                throw new ArgumentNullException(nameof(outdoorTemperatureService));
            }
            if (componentController == null)
            {
                throw new ArgumentNullException(nameof(componentController));
            }

            _schedulerService          = schedulerService;
            _dateTimeService           = dateTimeService;
            _daylightService           = daylightService;
            _outdoorTemperatureService = outdoorTemperatureService;
            _componentController       = componentController;

            SpecialSettingsWrapper = new RollerShutterAutomationSettingsWrapper(Settings);
        }
        public RollerShutterAutomation(
            AutomationId id, 
            INotificationService notificationService,
            ISchedulerService schedulerService,
            IDateTimeService dateTimeService,
            IDaylightService daylightService,
            IOutdoorTemperatureService outdoorTemperatureService,
            IComponentService componentService,
            ISettingsService settingsService,
            IResourceService resourceService)
            : base(id)
        {
            if (notificationService == null) throw new ArgumentNullException(nameof(notificationService));
            if (dateTimeService == null) throw new ArgumentNullException(nameof(dateTimeService));
            if (daylightService == null) throw new ArgumentNullException(nameof(daylightService));
            if (outdoorTemperatureService == null) throw new ArgumentNullException(nameof(outdoorTemperatureService));
            if (componentService == null) throw new ArgumentNullException(nameof(componentService));
            if (settingsService == null) throw new ArgumentNullException(nameof(settingsService));
            if (resourceService == null) throw new ArgumentNullException(nameof(resourceService));

            _notificationService = notificationService;
            _dateTimeService = dateTimeService;
            _daylightService = daylightService;
            _outdoorTemperatureService = outdoorTemperatureService;
            _componentService = componentService;
            _settingsService = settingsService;
            _componentService = componentService;

            resourceService.RegisterText(
                RollerShutterAutomationNotification.AutoClosingDueToHighOutsideTemperature,
                "Closing roller shutter because outside temperature reaches {AutoCloseIfTooHotTemperaure}°C.");

            settingsService.CreateSettingsMonitor<RollerShutterAutomationSettings>(Id, s => Settings = s);

            // TODO: Consider timer service here.
            schedulerService.RegisterSchedule("RollerShutterAutomation-" + Guid.NewGuid(), TimeSpan.FromMinutes(1), PerformPendingActions);
        }
Beispiel #21
0
 public TAutomation GetAutomation <TAutomation>(AutomationId id) where TAutomation : IAutomation
 {
     return(_automations.Get <TAutomation>(id));
 }
Beispiel #22
0
        public string Get(string propertyName)
        {
            switch (propertyName)
            {
            //ELEMENT
            case nameof(ClassId):
                return(ClassId.ToString());

            case nameof(AutomationId):
                return(AutomationId.ToString());

            case nameof(Id):
                return(Id.ToString());

            case nameof(StyleId):
                return(StyleId.ToString());

            //VISUAL ELEMENT
            case nameof(AnchorX):
                return(AnchorX.ToString());

            case nameof(AnchorY):
                return(AnchorY.ToString());

            case nameof(BackgroundColor):
                return(BackgroundColor.ToHex());

            case nameof(Width):
                return(this.Width.ToString());

            case nameof(Height):
                return(this.Height.ToString());

            case nameof(IsEnabled):
                return(IsEnabled.ToString());

            case nameof(WidthRequest):
                return(this.WidthRequest.ToString());

            case nameof(HeightRequest):
                return(this.HeightRequest.ToString());

            case nameof(IsFocused):
                return(IsFocused.ToString());

            case nameof(IsVisible):
                return(IsVisible.ToString());

            case nameof(InputTransparent):
                return(InputTransparent.ToString());

            case nameof(X):
                return(this.X.ToString());

            case nameof(Y):
                return(this.Y.ToString());

            case nameof(Opacity):
                return(this.Opacity.ToString());

            case nameof(TranslationX):
                return(this.TranslationX.ToString());

            case nameof(TranslationY):
                return(this.TranslationY.ToString());

            case nameof(Rotation):
                return(this.Rotation.ToString());

            case nameof(RotationX):
                return(this.RotationX.ToString());

            case nameof(RotationY):
                return(this.RotationY.ToString());

            case nameof(Scale):
                return(this.Scale.ToString());

            //VIEW
            case nameof(Margin):
                return(this.Margin.ToString());

            case nameof(VerticalOptions):
                return(this.VerticalOptions.ToString());

            case nameof(HorizontalOptions):
                return(this.HorizontalOptions.ToString());

            //STEPPER
            case nameof(Maximum):
                return(Maximum.ToString());

            case nameof(Minimum):
                return(Minimum.ToString());

            case nameof(Value):
                return(Value.ToString());

            case nameof(Increment):
                return(Increment.ToString());

            default:
                return(string.Empty);
            }
        }
        public static void SetSettings <TSettings>(this ISettingsService settingsService, AutomationId automationId, TSettings settings) where TSettings : IAutomationSettings
        {
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }
            if (automationId == null)
            {
                throw new ArgumentNullException(nameof(automationId));
            }

            var uri = SettingsUriGenerator.From(automationId);

            settingsService.ImportSettings(uri, settings);
        }
        public static TSettings GetSettings <TSettings>(this ISettingsService settingsService, AutomationId automationId) where TSettings : IAutomationSettings
        {
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }
            if (automationId == null)
            {
                throw new ArgumentNullException(nameof(automationId));
            }

            var uri = SettingsUriGenerator.From(automationId);

            return(settingsService.GetSettings <TSettings>(uri));
        }
        protected AutomationBase(AutomationId id)
        {
            if (id == null) throw new ArgumentNullException(nameof(id));

            Id = id;
        }
        public static void CreateSettingsMonitor <TSettings>(this ISettingsService settingsService, AutomationId automationId, Action <TSettings> callback) where TSettings : IAutomationSettings
        {
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }

            var uri = SettingsUriGenerator.From(automationId);

            settingsService.CreateSettingsMonitor(uri, callback);
        }
 public Automation(AutomationId id)
     : base(id)
 {
     _conditionsValidator = new ConditionsValidator(Conditions);
 }
            public void ShouldReturnTypedViewWithSameAutomationIdFoundInPageHierarchy()
            {
                var screen = new Renderer <App>().Render <MainPage>();

                screen.QueryByAutomationId <Label>(singleLabelAutomationId) !.AutomationId.Should().Be(singleLabelAutomationId);
            }
Beispiel #29
0
        public string Get(string propertyName)
        {
            switch (propertyName)
            {
            //ELEMENT
            case nameof(ClassId):
                return(ClassId.ToString());

            case nameof(AutomationId):
                return(AutomationId.ToString());

            case nameof(Id):
                return(Id.ToString());

            case nameof(StyleId):
                return(StyleId.ToString());

            //VISUAL ELEMENT
            case nameof(AnchorX):
                return(AnchorX.ToString());

            case nameof(AnchorY):
                return(AnchorY.ToString());

            case nameof(BackgroundColor):
                return(BackgroundColor.ToHex());

            case nameof(Width):
                return(this.Width.ToString());

            case nameof(Height):
                return(this.Height.ToString());

            case nameof(IsEnabled):
                return(IsEnabled.ToString());

            case nameof(WidthRequest):
                return(this.WidthRequest.ToString());

            case nameof(HeightRequest):
                return(this.HeightRequest.ToString());

            case nameof(IsFocused):
                return(IsFocused.ToString());

            case nameof(IsVisible):
                return(IsVisible.ToString());

            case nameof(InputTransparent):
                return(InputTransparent.ToString());

            case nameof(X):
                return(this.X.ToString());

            case nameof(Y):
                return(this.Y.ToString());

            case nameof(Opacity):
                return(this.Opacity.ToString());

            case nameof(TranslationX):
                return(this.TranslationX.ToString());

            case nameof(TranslationY):
                return(this.TranslationY.ToString());

            case nameof(Rotation):
                return(this.Rotation.ToString());

            case nameof(RotationX):
                return(this.RotationX.ToString());

            case nameof(RotationY):
                return(this.RotationY.ToString());

            case nameof(Scale):
                return(this.Scale.ToString());

            //VIEW
            case nameof(Margin):
                return(this.Margin.ToString());

            case nameof(VerticalOptions):
                return(this.VerticalOptions.ToString());

            case nameof(HorizontalOptions):
                return(this.HorizontalOptions.ToString());

            //IMAGE
            case nameof(Source):
                switch (Source)
                {
                case FileImageSource file:
                    return(file.File);

                case UriImageSource uri:
                    return(uri.Uri.ToString());

                default:
                    return(string.Empty);
                }

            case nameof(Aspect):
                return(this.Aspect.ToString());

            case nameof(IsOpaque):
                return(this.IsOpaque.ToString());

            default:
                return(string.Empty);
            }
        }
Beispiel #30
0
        public string Get(string propertyName)
        {
            switch (propertyName)
            {
            //ELEMENT
            case nameof(ClassId):
                return(ClassId.ToString());

            case nameof(AutomationId):
                return(AutomationId.ToString());

            case nameof(Id):
                return(Id.ToString());

            case nameof(StyleId):
                return(StyleId.ToString());

            //VISUAL ELEMENT
            case nameof(AnchorX):
                return(AnchorX.ToString());

            case nameof(AnchorY):
                return(AnchorY.ToString());

            case nameof(BackgroundColor):
                return(BackgroundColor.ToHex());

            case nameof(Width):
                return(this.Width.ToString());

            case nameof(Height):
                return(this.Height.ToString());

            case nameof(IsEnabled):
                return(IsEnabled.ToString());

            case nameof(WidthRequest):
                return(this.WidthRequest.ToString());

            case nameof(HeightRequest):
                return(this.HeightRequest.ToString());

            case nameof(IsFocused):
                return(IsFocused.ToString());

            case nameof(IsVisible):
                return(IsVisible.ToString());

            case nameof(InputTransparent):
                return(InputTransparent.ToString());

            case nameof(X):
                return(this.X.ToString());

            case nameof(Y):
                return(this.Y.ToString());

            case nameof(Opacity):
                return(this.Opacity.ToString());

            case nameof(TranslationX):
                return(this.TranslationX.ToString());

            case nameof(TranslationY):
                return(this.TranslationY.ToString());

            case nameof(Rotation):
                return(this.Rotation.ToString());

            case nameof(RotationX):
                return(this.RotationX.ToString());

            case nameof(RotationY):
                return(this.RotationY.ToString());

            case nameof(Scale):
                return(this.Scale.ToString());

            //VIEW
            case nameof(Margin):
                return(this.Margin.ToString());

            case nameof(VerticalOptions):
                return(this.VerticalOptions.ToString());

            case nameof(HorizontalOptions):
                return(this.HorizontalOptions.ToString());

            //ITEMSVIEW
            case nameof(ItemsSource):
                return(ItemsSource.OfType <object>().Select(x => x.ToString()).Aggregate((x, y) => x + "," + y));

            //LISTVIEW
            case nameof(HasUnevenRows):
                return(HasUnevenRows.ToString());

            case nameof(IsGroupingEnabled):
                return(IsGroupingEnabled.ToString());

            case nameof(RowHeight):
                return(RowHeight.ToString());

            case nameof(Footer):
                return(Footer.ToString());

            case nameof(Header):
                return(Header.ToString());

            case nameof(IsPullToRefreshEnabled):
                return(IsPullToRefreshEnabled.ToString());

            case nameof(IsRefreshing):
                return(IsRefreshing.ToString());

            case nameof(SelectedItem):
                return(SelectedItem.ToString());

            case nameof(SeparatorColor):
                return(SeparatorColor.ToHex());

            case nameof(this.SeparatorVisibility):
                return(SeparatorVisibility.ToString());

            default:
                return(string.Empty);
            }
        }
        public static string GetAutomationIdOfUiElement(RecordedUiTask recordedUiTask, List <string> pathNodes, ref UiTreeNode rootRet)
        {
            string lastValidAutomationId = string.Empty;

            rootRet = null;

            string tag, ClassName, Name, AutomationId, Pos;
            string xPath = "";

            UiTreeNode parent = null;

            for (int i = 0; i < pathNodes.Count; i++)
            {
                var nodePath = pathNodes[i];

                bool bStartsWithName   = false;
                bool bStartsWithClass  = false;
                bool bStartsWithAutoId = false;

                var tagAttrs = GetTagAttributes(nodePath);

                tag = tagAttrs.ContainsKey("Tag") ? tagAttrs["Tag"] : "Unknown";

                AutomationId = tagAttrs.ContainsKey("AutomationId") ? tagAttrs["AutomationId"] : null;

                Name = tagAttrs.ContainsKey("Name") ? tagAttrs["Name"] : null;

                ClassName = tagAttrs.ContainsKey("ClassName") ? tagAttrs["ClassName"] : null;
                ClassName = CheckAndFixNoneStaticValue(ClassName);

                Pos = tagAttrs.ContainsKey("position()") ? tagAttrs["position()"] : null;

                string xPathNode = $"/{tag}";

                // Set AutomationId to null if it is a GUID which is very likely generated at runtime
                AutomationId = CheckAndFixNoneStaticValue(AutomationId);

                // AutomationId (like UIs on Cortana search result list) created at runtime may end with digits
                if (!string.IsNullOrEmpty(AutomationId) && !AutomationId.StartsWith("starts-with:"))
                {
                    string patAutoIdEndsWithDigits = @"^([^\d]*)[_\.\-\d]+$";
                    System.Text.RegularExpressions.Regex regAutoId = new System.Text.RegularExpressions.Regex(patAutoIdEndsWithDigits, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    if (regAutoId != null)
                    {
                        System.Text.RegularExpressions.Match matchAutoId = regAutoId.Match(AutomationId);
                        if (matchAutoId.Success && matchAutoId.Groups.Count > 1)
                        {
                            if (matchAutoId.Groups[1].Length > 0)
                            {
                                AutomationId      = "starts-with:" + matchAutoId.Groups[1].ToString();
                                bStartsWithAutoId = true;
                            }
                            else
                            {
                                AutomationId = null;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(ClassName) && string.IsNullOrEmpty(AutomationId))
                {
                    if (ClassName.StartsWith("starts-with:"))
                    {
                        ClassName        = ClassName.Remove(0, "starts-with:".Length);
                        xPathNode       += string.Format(sNameStartsWithValue, "ClassName", ClassName);
                        bStartsWithClass = true;
                    }
                    else
                    {
                        xPathNode += string.Format(sNameValue, "ClassName", ClassName);
                    }
                }

                if (!string.IsNullOrEmpty(Name))
                {
                    if (Name.StartsWith("starts-with:"))
                    {
                        Name            = Name.Remove(0, "starts-with:".Length);
                        xPathNode      += string.Format(sNameStartsWithValue, "Name", Name);
                        bStartsWithName = true;
                    }
                    else
                    {
                        xPathNode += string.Format(sNameValue, "Name", Name);
                    }
                }

                if (!string.IsNullOrEmpty(AutomationId))
                {
                    if (AutomationId.StartsWith("starts-with:"))
                    {
                        AutomationId      = AutomationId.Remove(0, "starts-with:".Length);
                        xPathNode        += string.Format(sNameStartsWithValue, "AutomationId", AutomationId);
                        bStartsWithAutoId = true;
                    }
                    else
                    {
                        xPathNode += string.Format(sNameValue, "AutomationId", AutomationId);
                    }
                }

                if (!string.IsNullOrEmpty(Pos) && string.IsNullOrEmpty(AutomationId) && string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(ClassName))
                {
                    xPathNode += $"[position()={Pos}]";
                }

                // UiTreeNode
                var left      = tagAttrs.ContainsKey("x") ? tagAttrs["x"] : null;
                var top       = tagAttrs.ContainsKey("y") ? tagAttrs["y"] : null;
                var leftLocal = tagAttrs.ContainsKey("lx") ? tagAttrs["lx"] : null;
                var topLocal  = tagAttrs.ContainsKey("ly") ? tagAttrs["ly"] : null;
                var width     = tagAttrs.ContainsKey("width") ? tagAttrs["width"] : null;
                var height    = tagAttrs.ContainsKey("height") ? tagAttrs["height"] : null;
                var runtimeId = tagAttrs.ContainsKey("RuntimeId") ? tagAttrs["RuntimeId"] : null;

                xPath += xPathNode;

                var uiTreeNode = new UiTreeNode(parent)
                {
                    Title = $"{tag}, \"{Name}\", {ClassName}"
                };

                uiTreeNode.NodePath                  = xPathNode;
                uiTreeNode.Tag                       = tag;
                uiTreeNode.ClassName                 = ClassName;
                uiTreeNode.Name                      = Name;
                uiTreeNode.AutomationId              = AutomationId;
                uiTreeNode.Left                      = left;
                uiTreeNode.Top                       = left;
                uiTreeNode.Width                     = width;
                uiTreeNode.Height                    = height;
                uiTreeNode.RuntimeId                 = runtimeId;
                uiTreeNode.Position                  = Pos;
                uiTreeNode.NameCompareMethod         = bStartsWithName ? UiTreeNode.CompareMethod.StartsWith : UiTreeNode.CompareMethod.Equal;
                uiTreeNode.ClassNameCompareMethod    = bStartsWithClass ? UiTreeNode.CompareMethod.StartsWith : UiTreeNode.CompareMethod.Equal;
                uiTreeNode.AutomationIdCompareMethod = bStartsWithAutoId ? UiTreeNode.CompareMethod.StartsWith : UiTreeNode.CompareMethod.Equal;

                if (i == pathNodes.Count - 1)
                {
                    uiTreeNode.UiTask        = recordedUiTask;
                    recordedUiTask.Left      = left;
                    recordedUiTask.Top       = top;
                    recordedUiTask.LeftLocal = leftLocal;
                    recordedUiTask.TopLocal  = topLocal;
                    recordedUiTask.Name      = Name;
                    recordedUiTask.Tag       = tag;
                }

                if (rootRet == null)
                {
                    rootRet = uiTreeNode;
                }

                if (parent != null)
                {
                    parent.Items.Add(uiTreeNode);
                }

                parent = uiTreeNode;

                lastValidAutomationId = string.IsNullOrEmpty(AutomationId) ? lastValidAutomationId : AutomationId;
            }

            return(lastValidAutomationId);
        }
Beispiel #32
0
        static string GetXPathFromUiTaskNode(XmlElement uiTaskNode)
        {
            if (uiTaskNode == null || uiTaskNode.ChildNodes.Count < 1)
            {
                return("");
            }

            string tag, ClassName, Name, AutomationId, Pos;
            string xPath = "";

            for (int i = 0; i < uiTaskNode.ChildNodes.Count; i++)
            {
                XmlNode childNode = uiTaskNode.ChildNodes[i];

                tag          = childNode.Name != "Unknown" ? childNode.Name : "*";
                AutomationId = XmlEncode(childNode.Attributes[ConstVariables.AutomationId].Value);
                AutomationId = CheckAndFixNoneStaticValue(AutomationId);

                Name = XmlEncode(childNode.Attributes[ConstVariables.Name].Value);

                ClassName = childNode.Attributes[ConstVariables.ClassName].Value;
                ClassName = CheckAndFixNoneStaticValue(ClassName);
                Pos       = childNode.Attributes[ConstVariables.Pos].Value;

                xPath += $"/{tag}";
                int nPos = xPath.Length;

                // AutomationId (like UIs on Cortana search result list) created at runtime may end with digits
                if (!string.IsNullOrEmpty(AutomationId) && !AutomationId.StartsWith("starts-with:"))
                {
                    string patAutoIdEndsWithDigits = @"^([^\d]*)[\d]+$";
                    System.Text.RegularExpressions.Regex regAutoId = new System.Text.RegularExpressions.Regex(patAutoIdEndsWithDigits, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    if (regAutoId != null)
                    {
                        System.Text.RegularExpressions.Match matchAutoId = regAutoId.Match(AutomationId);
                        if (matchAutoId.Success && matchAutoId.Groups.Count > 1)
                        {
                            if (matchAutoId.Groups[1].Length > 0)
                            {
                                AutomationId = "starts-with:" + matchAutoId.Groups[1].ToString();
                            }
                            else
                            {
                                AutomationId = null;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(AutomationId))
                {
                    if (AutomationId.StartsWith("starts-with:"))
                    {
                        AutomationId = AutomationId.Remove(0, "starts-with:".Length);
                        xPath       += string.Format(sNameStartsWithValue, ConstVariables.AutomationId, AutomationId);
                    }
                    else
                    {
                        xPath += string.Format(sNameValue, ConstVariables.AutomationId, AutomationId);
                    }
                }

                if (!string.IsNullOrEmpty(Name))
                {
                    if (Name.StartsWith("starts-with:"))
                    {
                        Name   = Name.Remove(0, "starts-with:".Length);
                        xPath += string.Format(sNameStartsWithValue, ConstVariables.Name, Name);
                    }
                    else
                    {
                        xPath += string.Format(sNameValue, ConstVariables.Name, Name);
                    }
                }

                if (!string.IsNullOrEmpty(ClassName) && string.IsNullOrEmpty(AutomationId))
                {
                    if (ClassName.StartsWith("starts-with:"))
                    {
                        ClassName = ClassName.Remove(0, "starts-with:".Length);
                        xPath    += string.Format(sNameStartsWithValue, ConstVariables.ClassName, ClassName);
                    }
                    else
                    {
                        xPath += string.Format(sNameValue, ConstVariables.ClassName, ClassName);
                    }
                }

                if (!string.IsNullOrEmpty(Pos) && string.IsNullOrEmpty(AutomationId) && string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(ClassName))
                {
                    //TODO: verify
                    xPath = xPath.Insert(nPos, $"[position()={Pos}]");
                }
            }

            return("\"" + xPath + "\",\n");
        }
Beispiel #33
0
        public string Get(string propertyName)
        {
            switch (propertyName)
            {
            //ELEMENT
            case nameof(ClassId):
                return(ClassId.ToString());

            case nameof(AutomationId):
                return(AutomationId.ToString());

            case nameof(Id):
                return(Id.ToString());

            case nameof(StyleId):
                return(StyleId.ToString());

            //VISUAL ELEMENT
            case nameof(AnchorX):
                return(AnchorX.ToString());

            case nameof(AnchorY):
                return(AnchorY.ToString());

            case nameof(BackgroundColor):
                return(BackgroundColor.ToHex());

            case nameof(Width):
                return(this.Width.ToString());

            case nameof(Height):
                return(this.Height.ToString());

            case nameof(IsEnabled):
                return(IsEnabled.ToString());

            case nameof(WidthRequest):
                return(this.WidthRequest.ToString());

            case nameof(HeightRequest):
                return(this.HeightRequest.ToString());

            case nameof(IsFocused):
                return(IsFocused.ToString());

            case nameof(IsVisible):
                return(IsVisible.ToString());

            case nameof(InputTransparent):
                return(InputTransparent.ToString());

            case nameof(X):
                return(this.X.ToString());

            case nameof(Y):
                return(this.Y.ToString());

            case nameof(Opacity):
                return(this.Opacity.ToString());

            case nameof(TranslationX):
                return(this.TranslationX.ToString());

            case nameof(TranslationY):
                return(this.TranslationY.ToString());

            case nameof(Rotation):
                return(this.Rotation.ToString());

            case nameof(RotationX):
                return(this.RotationX.ToString());

            case nameof(RotationY):
                return(this.RotationY.ToString());

            case nameof(Scale):
                return(this.Scale.ToString());

            //VIEW
            case nameof(Margin):
                return(this.Margin.ToString());

            case nameof(VerticalOptions):
                return(this.VerticalOptions.ToString());

            case nameof(HorizontalOptions):
                return(this.HorizontalOptions.ToString());

            //INPUTVIEW
            case nameof(Keyboard):
                return(this.Keyboard.ToString());

            //EDITOR
            case nameof(FontAttributes):
                return(this.FontAttributes.ToString());

            case nameof(FontFamily):
                return(this.FontFamily);

            case nameof(FontSize):
                return(this.FontSize.ToString());

            case nameof(Text):
                return(this.Text);

            case nameof(TextColor):
                return(this.TextColor.ToHex());

            default:
                return(string.Empty);
            }
        }
Beispiel #34
0
        public string Get(string propertyName)
        {
            switch (propertyName)
            {
            //ELEMENT
            case nameof(ClassId):
                return(ClassId.ToString());

            case nameof(AutomationId):
                return(AutomationId.ToString());

            case nameof(Id):
                return(Id.ToString());

            case nameof(StyleId):
                return(StyleId.ToString());

            //VISUAL ELEMENT
            case nameof(AnchorX):
                return(AnchorX.ToString());

            case nameof(AnchorY):
                return(AnchorY.ToString());

            case nameof(BackgroundColor):
                return(BackgroundColor.ToHex());

            case nameof(Width):
                return(this.Width.ToString());

            case nameof(Height):
                return(this.Height.ToString());

            case nameof(IsEnabled):
                return(IsEnabled.ToString());

            case nameof(WidthRequest):
                return(this.WidthRequest.ToString());

            case nameof(HeightRequest):
                return(this.HeightRequest.ToString());

            case nameof(IsFocused):
                return(IsFocused.ToString());

            case nameof(IsVisible):
                return(IsVisible.ToString());

            case nameof(InputTransparent):
                return(InputTransparent.ToString());

            case nameof(X):
                return(this.X.ToString());

            case nameof(Y):
                return(this.Y.ToString());

            case nameof(Opacity):
                return(this.Opacity.ToString());

            case nameof(TranslationX):
                return(this.TranslationX.ToString());

            case nameof(TranslationY):
                return(this.TranslationY.ToString());

            case nameof(Rotation):
                return(this.Rotation.ToString());

            case nameof(RotationX):
                return(this.RotationX.ToString());

            case nameof(RotationY):
                return(this.RotationY.ToString());

            case nameof(Scale):
                return(this.Scale.ToString());

            //VIEW
            case nameof(Margin):
                return(this.Margin.ToString());

            case nameof(VerticalOptions):
                return(this.VerticalOptions.ToString());

            case nameof(HorizontalOptions):
                return(this.HorizontalOptions.ToString());

            //PICKER
            case nameof(ItemsSource):
                return(ItemsSource.OfType <object>().Select(x => x.ToString()).Aggregate((x, y) => x + "," + y));

            case nameof(SelectedItem):
                return(SelectedItem.ToString());

            case nameof(SelectedIndex):
                return(SelectedIndex.ToString());

            case nameof(Items):
                return(Items.Aggregate((x, y) => x + "," + y));

            case nameof(Title):
                return(Title);

            default:
                return(string.Empty);
            }
        }
            public void ShouldFilterElementsWithSameAutomationIdButDifferentTypesFoundInPageHierarchy()
            {
                var screen = new Renderer <App>().Render <MainPage>();

                screen.GetByAutomationId <Label>("Other Label Automation") !.AutomationId.Should().Be("Other Label Automation");
            }
Beispiel #36
0
        public string Get(string propertyName)
        {
            switch (propertyName)
            {
            //ELEMENT
            case nameof(ClassId):
                return(ClassId.ToString());

            case nameof(AutomationId):
                return(AutomationId.ToString());

            case nameof(Id):
                return(Id.ToString());

            case nameof(StyleId):
                return(StyleId.ToString());

            //VISUAL ELEMENT
            case nameof(AnchorX):
                return(AnchorX.ToString());

            case nameof(AnchorY):
                return(AnchorY.ToString());

            case nameof(BackgroundColor):
                return(BackgroundColor.ToHex());

            case nameof(Width):
                return(this.Width.ToString());

            case nameof(Height):
                return(this.Height.ToString());

            case nameof(IsEnabled):
                return(IsEnabled.ToString());

            case nameof(WidthRequest):
                return(this.WidthRequest.ToString());

            case nameof(HeightRequest):
                return(this.HeightRequest.ToString());

            case nameof(IsFocused):
                return(IsFocused.ToString());

            case nameof(IsVisible):
                return(IsVisible.ToString());

            case nameof(InputTransparent):
                return(InputTransparent.ToString());

            case nameof(X):
                return(this.X.ToString());

            case nameof(Y):
                return(this.Y.ToString());

            case nameof(Opacity):
                return(this.Opacity.ToString());

            case nameof(TranslationX):
                return(this.TranslationX.ToString());

            case nameof(TranslationY):
                return(this.TranslationY.ToString());

            case nameof(Rotation):
                return(this.Rotation.ToString());

            case nameof(RotationX):
                return(this.RotationX.ToString());

            case nameof(RotationY):
                return(this.RotationY.ToString());

            case nameof(Scale):
                return(this.Scale.ToString());

            //VIEW
            case nameof(Margin):
                return(this.Margin.ToString());

            case nameof(VerticalOptions):
                return(this.VerticalOptions.ToString());

            case nameof(HorizontalOptions):
                return(this.HorizontalOptions.ToString());

            //SEARCHBAR
            case nameof(CancelButtonColor):
                return(this.CancelButtonColor.ToHex());

            case nameof(Placeholder):
                return(this.Placeholder);

            case nameof(SearchCommandParameter):
                return(SearchCommandParameter.ToString());

            case nameof(Text):
                return(Text);

            default:
                return(string.Empty);
            }
        }