Esempio n. 1
0
 void Start()
 {
     loader      = FindObjectOfType <TrialLoader>();
     conductor   = FindObjectOfType <TrialConductor>();
     toggler     = FindObjectOfType <ToggleElement>();
     logger      = FindObjectOfType <TrialLogger>();
     targetCandM = FindObjectOfType <TargetChooserAndMarker>();
     suggester   = FindObjectOfType <TargetSuggester>();
     menuManager = FindObjectOfType <MenuManager>();
 }
 private void Clicked(ToggleElement el)
 {
     if (el.action != null)
     {
         el.action();
     }
     else
     {
         HandleChangeSelection(el);
     }
 }
Esempio n. 3
0
        public void Initialise()
        {
            for (int i = 0; i < ToggleConfigurations.toggles.Count; i++)
            {
                ToggleElement element = ToggleConfigurations.toggles[i];

                if (!toggles.ContainsKey(element.name))
                {
                    toggles.Add(element.name, ToggleConfigurations.toggles[i]);
                }
            }
        }
        public void ValidateIpAddressesTest()
        {
            ToggleConfigurationSection section = ConfigurationManager.GetSection("ToggleConfiguration") as ToggleConfigurationSection;

            ToggleElement toggle = section.Toggles[0];

            Assert.IsNotNull(toggle);

            Assert.AreEqual("CacheInheritableDatasource", toggle.Name);
            Assert.IsTrue(toggle.IpAddresses.Count > 0);

            Assert.AreEqual("127.0.0.1/28", toggle.IpAddresses[0].Value);
        }
        public void ValidateUsersTest()
        {
            ToggleConfigurationSection section = ConfigurationManager.GetSection("ToggleConfiguration") as ToggleConfigurationSection;

            ToggleElement toggle = section.Toggles[0];

            Assert.IsNotNull(toggle);

            Assert.AreEqual("CacheInheritableDatasource", toggle.Name);
            Assert.IsTrue(toggle.Users.Count > 0);

            Assert.AreEqual("abcd", toggle.Users[0].Name);
        }
Esempio n. 6
0
        public void ValidateIpAddressesTest()
        {
            IConfiguration configuration = InitConfiguration();

            ToggleConfigurationSection config = configuration.GetSection("ToggleConfiguration").Get <ToggleConfigurationSection>();

            ToggleElement toggle = config.toggles[0];

            Assert.IsNotNull(toggle);

            Assert.AreEqual("CacheInheritableDatasource", toggle.name);
            Assert.IsTrue(toggle.ipaddresses.Count > 0);

            Assert.AreEqual("127.0.0.1/28", toggle.ipaddresses[0].ipaddress.value);
        }
Esempio n. 7
0
        public void ValidateRolesTest()
        {
            IConfiguration configuration = InitConfiguration();

            ToggleConfigurationSection config = configuration.GetSection("ToggleConfiguration").Get <ToggleConfigurationSection>();

            ToggleElement toggle = config.toggles[0];

            Assert.IsNotNull(toggle);

            Assert.AreEqual("CacheInheritableDatasource", toggle.name);
            Assert.IsTrue(toggle.roles.Count > 0);

            Assert.AreEqual("Staff", toggle.roles[0].role.name);
        }
Esempio n. 8
0
        public Toggle GetFlag(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(Toggle.Empty);
            }

            if (!toggles.ContainsKey(name))
            {
                return(Toggle.Empty);
            }

            ToggleElement element = toggles[name];

            Toggle toggle = new Toggle(element.name, element.enabled);

            return(toggle);
        }
Esempio n. 9
0
        public Toggle GetFlag(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                Logger.Error("Fetching flag with no name provided");
                return(Toggle.Empty);
            }

            Logger.Debug("Fetching toggle: " + name);

            if (!toggles.ContainsKey(name))
            {
                return(Toggle.Empty);
            }

            ToggleElement element = toggles[name];

            Toggle toggle = new Toggle(element.Name, element.Enabled);

            return(toggle);
        }
        protected void HandleChangeSelection(ToggleElement el)
        {
            Func <float, float, float, float> incr = (current, add, snap) => {
                if (!float.IsNaN(add))
                {
                    current = Mathf.Round((current + add * snap) / snap) * snap;
                }
                return(current);
            };

            bend.x = incr(bend.x, el.bend.x * workDirection, snapAngle);
            bend.y = incr(bend.y, el.bend.y, snapAngle);
            bend.z = incr(bend.z, el.bend.z * workDirection, snapAngle);

            shim.x = incr(shim.x, el.shim.x, snapLength);
            shim.y = incr(shim.y, el.shim.y, snapLength);
            shim.z = incr(shim.z, el.shim.z, snapLength);
            if (shim.z < .5f)
            {
                shim.z = .5f;
            }

            Bend();
        }
Esempio n. 11
0
        public Toggle GetFlag(string name, ToggleData userData)
        {
            if (!toggles.ContainsKey(name))
            {
                return(Toggle.Empty);
            }

            ToggleElement element = toggles[name];

            if (!string.IsNullOrWhiteSpace(userData.UserRoles))
            {
                List <string> roles = element.roles.Select(x => x.role.name).ToList();
                bool          found = false;
                foreach (string role in userData.UserRoles.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (roles.Contains(role))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    return(new Toggle(name, false));
                }
            }

            if (!string.IsNullOrWhiteSpace(userData.UserId))
            {
                List <string> users = element.users.Select(x => x.user.name).ToList();

                if (!users.Contains(userData.UserId))
                {
                    return(new Toggle(name, false));
                }
            }

            if (!string.IsNullOrWhiteSpace(userData.IpAddress))
            {
                if (!IPAddress.TryParse(userData.IpAddress, out IPAddress candidate))
                {
                    return(new Toggle(name, false));
                }

                List <string> addresses = element.ipaddresses.Select(x => x.ipaddress.value).ToList();
                bool          found     = false;
                foreach (string address in addresses)
                {
                    if (string.IsNullOrWhiteSpace(address))
                    {
                        continue;
                    }

                    IPAddressRange range = IPAddressRange.FromCidrAddress(address);
                    if (range == IPAddressRange.Empty)
                    {
                        continue;
                    }

                    if (range.IPInRange(candidate))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    return(new Toggle(name, false));
                }
            }

            return(new Toggle(name, true));
        }