public static bool camposEstanLlenos(System.Windows.Forms.Control.ControlCollection controles)
        {
            foreach (TextBox txtbox in controles.OfType<TextBox>())
            {
                if (txtbox.Text == String.Empty) return false;
            }
            foreach (ComboBox cBox in controles.OfType<ComboBox>())
            {
                if (cBox.SelectedItem == null) return false;
            }

            foreach (NumericUpDown nud in controles.OfType<NumericUpDown>())
            {
                if (nud.Value == 0) return false;
            }

            return true;
        }
        public void Collide()
        {
            if (!this._movingItem1.IsExtant || !this._movingItem2.IsExtant)
                return;

            var items = new[] { this._movingItem1, this._movingItem2 };
            var shot = items.OfType<Shot>().FirstOrDefault();
            if (shot != null)
                {
                var otherItem = items.Single(item => item != shot);
                if (InteractionInvolvingShot(this._world, shot, otherItem))
                    return;
                }

            var mine = items.OfType<Mine>().FirstOrDefault();
            if (mine != null)
                {
                var otherItem = items.Single(item => item != mine);
                mine.SteppedOnBy(otherItem);
                return;
                }

            var player = items.OfType<Player>().SingleOrDefault();
            if (player != null)
                {
                var monster = items.Single(item => item != player) as Monster.Monster;
                if (monster != null)
                    {
                    int monsterEnergy = monster.InstantlyExpire();
                    player.ReduceEnergy(monsterEnergy);
                    this._world.AddBang(monster.Position, BangType.Long);
                    this._world.Game.SoundPlayer.Play(GameSound.PlayerCollidesWithMonster);
                    return;
                    }
                }

            var moveableObject = items.FirstOrDefault(item => item.Solidity == ObjectSolidity.Moveable);
            var movingObject = items.FirstOrDefault(item => item != moveableObject && (item.Capability == ObjectCapability.CanPushOthers || item.Capability == ObjectCapability.CanPushOrCauseBounceBack));
            if (moveableObject != null && movingObject != null)
                {
                if (PushOrBounceObject(moveableObject, movingObject))
                    return;
                }
        }
 protected override ModelMetadata CreateMetadata(System.Collections.Generic.IEnumerable<System.Attribute> attributes, System.Type containerType, System.Func<object> modelAccessor, System.Type modelType, string propertyName)
 {
     var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
     var additionalValues = attributes.OfType<NonEditableAttribute>().FirstOrDefault();
     if (additionalValues != null)
     {
         metadata.AdditionalValues.Add("NonEditable", true);
     }
     return metadata;
 }
		public override IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
		{
			if (string.IsNullOrWhiteSpace(searchText))
			{
				return items.OfType<object>().Where(x => !escapedItems.Contains(x));
			}
			else
			{
				return base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode);
			}
		}
 public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
 {
     if (AssemblyResourceManager.IsEmbeddedViewResourcePath(virtualPath))
     {
         return null;
     }
     else
     {
         string[] dependencies = virtualPathDependencies.OfType<string>().Where(s => !s.ToLower().Contains("/views/inputbuilders")).ToArray();
         return base.GetCacheDependency(virtualPath, dependencies, utcStart);
     }
 }
        public static void limpiarControles(System.Windows.Forms.Control.ControlCollection controles)
        {
            foreach (TextBox txtbox in controles.OfType<TextBox>())
            {
                txtbox.Text = String.Empty;
            }
            foreach (ComboBox cBox in controles.OfType<ComboBox>())
            {
                cBox.SelectedItem = null;
            }

            foreach (NumericUpDown nud in controles.OfType<NumericUpDown>())
            {
                nud.Value = nud.Minimum;
            }

            foreach (CheckBox chk in controles.OfType<CheckBox>())
            {
                chk.Checked = false;
            }

            foreach (CheckedListBox chk in controles.OfType<CheckedListBox>())
            {
                chk.Items.Clear();
            }

            foreach (DataGridView dg in controles.OfType<DataGridView>())
            {
                SQL_Library.limpiarDataGrid(dg);
            }
        }
Example #7
0
        public void Add(Type serviceType, Type requestType, Type responseType)
        {
            this.ServiceTypes.Add(serviceType);
            this.RequestTypes.Add(requestType);

            var restrictTo = requestType.FirstAttribute<RestrictAttribute>()
                          ?? serviceType.FirstAttribute<RestrictAttribute>();


            var reqFilterAttrs = new[] { requestType, serviceType }
                .SelectMany(x => x.AllAttributes<IHasRequestFilter>()).ToList();
            var resFilterAttrs = (responseType != null ? new[] { responseType, serviceType } : new[] { serviceType })
                .SelectMany(x => x.AllAttributes<IHasResponseFilter>()).ToList();

            var authAttrs = reqFilterAttrs.OfType<AuthenticateAttribute>().ToList();
            var actions = GetImplementedActions(serviceType, requestType);
            authAttrs.AddRange(actions.SelectMany(x => x.AllAttributes<AuthenticateAttribute>()));

            var operation = new Operation
            {
                ServiceType = serviceType,
                RequestType = requestType,
                ResponseType = responseType,
                RestrictTo = restrictTo,
                Actions = actions.Map(x => x.Name.ToUpper()),
                Routes = new List<RestPath>(),
                RequestFilterAttributes = reqFilterAttrs,
                ResponseFilterAttributes = resFilterAttrs,
                RequiresAuthentication = authAttrs.Count > 0,
                RequiredRoles = authAttrs.OfType<RequiredRoleAttribute>().SelectMany(x => x.RequiredRoles).ToList(),
                RequiresAnyRole = authAttrs.OfType<RequiresAnyRoleAttribute>().SelectMany(x => x.RequiredRoles).ToList(),
                RequiredPermissions = authAttrs.OfType<RequiredPermissionAttribute>().SelectMany(x => x.RequiredPermissions).ToList(),
                RequiresAnyPermission = authAttrs.OfType<RequiresAnyPermissionAttribute>().SelectMany(x => x.RequiredPermissions).ToList(),
            };

            this.OperationsMap[requestType] = operation;
            this.OperationNamesMap[operation.Name.ToLower()] = operation;
            if (responseType != null)
            {
                this.ResponseTypes.Add(responseType);
                this.OperationsResponseMap[responseType] = operation;
            }

            //Only count non-core ServiceStack Services, i.e. defined outside of ServiceStack.dll or Swagger
            var nonCoreServicesCount = OperationsMap.Values
                .Count(x => x.ServiceType.Assembly != typeof(Service).Assembly
                && x.ServiceType.FullName != "ServiceStack.Api.Swagger.SwaggerApiService"
                && x.ServiceType.FullName != "ServiceStack.Api.Swagger.SwaggerResourcesService"
                && x.ServiceType.Name != "__AutoQueryServices");

            LicenseUtils.AssertValidUsage(LicenseFeature.ServiceStack, QuotaType.Operations, nonCoreServicesCount);
        }
 public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath,
                        System.Collections.IEnumerable virtualPathDependencies,
                        DateTime utcStart)
 {
     if (IsAppResourcePath(virtualPath))
     {
         return null;
     }
     else
     {
         var dependencies = virtualPathDependencies.OfType<string>().Where(s => !s.Contains("/Views/InputBuilders")).ToArray();
         return base.GetCacheDependency(virtualPath,
                                        dependencies, utcStart);
     }
 }
        /// <summary>
        /// Attempts to drink the item from the given container
        /// </summary>
        /// <param name="beverageContainer">The container from which to drink the beverage</param>
        public void From(IBeverageContainer beverageContainer)
        {
            IBeverageContainer[] beverageContainers = new[] {beverageContainer};

            IEnumerable<Guid> idsForObjectsBeingHeld = _avatar.Contents.Select(x => x.ObjectId);
            IEnumerable<Guid> beverageContainerObjectIds = beverageContainers.OfType<WorldObject>().Select(x => x.ObjectId);
            bool tryingToUseContainerNotBeingHeld = beverageContainerObjectIds.Except(idsForObjectsBeingHeld).Any();

            if (tryingToUseContainerNotBeingHeld)
            {
                throw new LawsOfPhysicsViolationException("You do not have telekinesis! You need to pick the item(s) up first.");
            }

            _beverage.Drink();
        }
        public MovingItemAndMovingItemInteraction(World world, MovingItem movingItem1, MovingItem movingItem2)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (movingItem1 == null)
                throw new ArgumentNullException("movingItem1");
            if (movingItem2 == null)
                throw new ArgumentNullException("movingItem2");
            if (movingItem1 is Shot)
                throw new ArgumentOutOfRangeException("movingItem1");
            if (movingItem2 is Shot)
                throw new ArgumentOutOfRangeException("movingItem2");

            this._world = world;
            var items = new[] {movingItem1, movingItem2};
            this._player = items.OfType<Player>().SingleOrDefault();
            this._boulder = items.OfType<Boulder>().SingleOrDefault();
            this._mine = items.OfType<Mine>().SingleOrDefault();
            this._monster1 = items.OfType<Monster.Monster>().FirstOrDefault();
            this._monster2 = items.OfType<Monster.Monster>().Skip(1).FirstOrDefault();

            this._moveableObject = items.FirstOrDefault(item => item.Solidity == ObjectSolidity.Moveable);
            this._insubstantialObject = items.FirstOrDefault(item => item.Solidity == ObjectSolidity.Insubstantial);
        }
Example #11
0
		private static void Main()
		{
			//BasicConfigurator.Configure(new ConsoleAppender
			//{
			//    Layout = new PatternLayout("%logger - %message%newline")
			//});

			var learners = new[]
			{
				new Learner(acceptorsCount: 3),
				new Learner(acceptorsCount: 3),
				new Learner(acceptorsCount: 3),
			};
			var acceptors = new[]
			{
				new Acceptor(learners),
				new Acceptor(learners),
				new Acceptor(learners)
			};
			var proposers = new[]
			{
				new Proposer(acceptors[0], acceptors, 1),
				new Proposer(acceptors[1], acceptors, 2),
				new Proposer(acceptors[2], acceptors, 3),
			};

			var agents = acceptors.OfType<Agent>().Union(proposers).Union(learners).ToArray();

			foreach (var agent in agents)
			{
				new Thread(agent.ExecuteMultiThreaded)
				{
					Name = agent.ToString(),
					IsBackground = true
				}.Start();
			}

			proposers[0].Propose(new Add {Value = 5});
			proposers[1].Propose(new Multiply {Value = 3});
			proposers[2].Propose(new Add {Value = 2});

			WaitForNewValues(learners);

			proposers[2].Propose(new Multiply {Value = 3});
			proposers[1].Propose(new Add {Value = 4});

			WaitForNewValues(learners);
		}
Example #12
0
        public override int FindHighlightedIndex(string searchText, System.Collections.IList filteredItems, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
        {
            var items = filteredItems.OfType<Item>().ToList<Item>();

            if (items != null)
            {
                if (items.Any(x => x.Name == searchText))
                {
                    // there is an exact match
                    var matchedItem = items.First(x => x.Name == searchText);
                    // return the index of the matched item
                    return items.IndexOf(matchedItem);
                }
            }

            // there isn't exact match
            // return the index of the last item from the filtered items 
            return items.Count - 1;
        }
Example #13
0
 public override System.Collections.Generic.IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, System.Collections.Generic.IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
 {
     var dependencies = new List<Dependency>();
     var toRemove = escapedItems.OfType<Dependency>();
     for (int i = 0; i < items.Count; i++)
     {
         dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.FinishFinish });
         dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.FinishStart });
         dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.StartFinish });
         dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.StartStart });
     }
     var searchTexts = searchText.Split(new char[] { '-' });
     var titleToUpper = searchTexts.First().Trim().ToUpper();
     var typeToUpper = searchTexts.Length > 1 ? searchTexts[1].Trim().ToUpper() : string.Empty;
     
     var result = dependencies.Where(x => !toRemove.Any(y => y.FromTask == x.FromTask && y.Type == x.Type));
     result = result.Where(x => x.FromTask.Title.ToUpper().StartsWith(titleToUpper.ToUpper()) && x.Type.ToString().ToUpper().StartsWith(typeToUpper));
     return result;
 }
        // This solution doesnt work in hackerrank but it should, this is a more efficient solution. If you call this function with N = 40 it works.
        private static long solution2(int N)
        {
            int[] prime = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 };
            List<int> primeList = prime.OfType<int>().ToList();
            int[][] primeFactorizationPerValue = new int[N][];
            //primeFactorizationPerValue[0] = new int[prime.Length]; // Factorization of 0 is not needed
            //primeFactorizationPerValue[1] = new int[prime.Length]; // Factorization of 1 is not needed
            for (int i = 2; i < N; i++)
                primeFactorizationPerValue[i] = getPrimeFactorization(i, primeList);

            long result = 1;
            for (int j = 0; j < prime.Length; j++)
            {
                long maxOfTheColumn = primeFactorizationPerValue[2][j];
                for (int i = 2; i < N; i++)
                    if (maxOfTheColumn < primeFactorizationPerValue[i][j])
                        maxOfTheColumn = primeFactorizationPerValue[i][j];
                result *= (long)Math.Pow(prime[j], maxOfTheColumn);
            }
            return result;
        }
        public void Handler_ShouldReturnIpInfo_IfNoException()
        {
            // Arrange
            var ipAddresses = new[] {IPAddress.Any, IPAddress.Broadcast, IPAddress.Parse("1.2.3.4")};
            _sut.Stub(x => x.GetHostAddesses()).Return(ipAddresses);

            // Act
            dynamic answer = _sut.Handler(_question);

            // Assert
            Assert.IsNotInstanceOfType(answer, typeof (string));

            Assert.AreEqual(string.Join(", ", ipAddresses.OfType<object>()), answer.IpAddresses);
        }
 public string ShowPeopleNameAfterSeleted(System.Collections.IList people)
 {
     if (people == null)
     {
         return string.Empty;
     }
     return (from p in people.OfType<PeopleProfile>() select p.Name).ToStringLine<string>(",");
 }
        private static bool InteractionInvolvingShot(World world, Shot shot, MovingItem movingItem)
        {
            if (movingItem is Player)
                {
                movingItem.ReduceEnergy(shot.Energy);
                if (movingItem.IsAlive())
                    world.Game.SoundPlayer.Play(GameSound.PlayerInjured);
                world.ConvertShotToBang(shot);
                return true;
                }

            var monster = movingItem as Monster.Monster;
            if (monster != null)
                {
                var result = ShotHitsMonster(world, shot, monster);
                return result;
                }

            var items = new[] { shot, movingItem };
            var explosion = items.OfType<Explosion>().FirstOrDefault();
            if (explosion != null)
                {
                var otherItem = items.Single(item => item != explosion);
                if (otherItem is Shot)
                    {
                    shot.ReduceEnergy(explosion.Energy);
                    return true;
                    }
                }

            var standardShot1 = shot as StandardShot;
            var standardShot2 = movingItem as StandardShot;
            if (standardShot1 != null && standardShot2 != null)
                {
                var result = ShotHitsShot(world, standardShot1, standardShot2);
                return result;
                }

            return false;
        }
 private void ProcessDescriptors(System.ComponentModel.PropertyDescriptor[] descriptors)
 {
     foreach (var attributeDesc in descriptors.OfType<AttributePropertyDescriptor>())
     {
         var args = attributeDesc.AttributeInfo.GetTagLocal<PropertyChangedEventArgsCollection>();
         if (args == null)
         {
             args = new PropertyChangedEventArgsCollection();
             attributeDesc.AttributeInfo.SetTag<PropertyChangedEventArgsCollection>(args);
         }
         args.Add(new PropertyChangedEventArgs(attributeDesc.DisplayName));
     }
 }