Ejemplo n.º 1
0
        public static async Task UpdateControls <T, R>(this ControlCollection controlCollection,
                                                       IList <T> editEntities,
                                                       R entityControlView,
                                                       CancellationToken token)
            where T : IEntity
            where R : IEntityControlView <T>
        {
            if (editEntities.Count == 0)
            {
                return;
            }

            var controls       = (Control[])null;
            var currentControl = (IEnumerable <IEntityControlView <T> >)null;

            await Task.Factory.StartNew(() =>
            {
                controls = editEntities.CreateControlCollection(entityControlView, token);

                currentControl = controlCollection?.Cast <IEntityControlView <T> >();
            }, TaskCreationOptions.AttachedToParent);

            foreach (IEntityControlView <T> control in controls)
            {
                currentControl.FirstOrDefault(c => c.Id == control.Id)?.SetCopy(control);
            }
        }
Ejemplo n.º 2
0
        public ListCell getFocusCell()
        {
            List <ListCell> total = new List <ListCell>();

            total.AddRange(leftNameControl.Cast <ListCell>());
            total.AddRange(leftControl.Cast <ListCell>());
            total.AddRange(rightControl.Cast <ListCell>());
            foreach (ListCell lc in total)
            {
                if (lc.focus)
                {
                    return(lc);
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static IList <TResult> TransformControlsToEntities <TResult>(this ControlCollection controlCollection)
            where TResult : class, IEntity
        {
            var entities = new List <TResult>(controlCollection.Count);

            entities.AddRange(controlCollection.Cast <IEntityControlView <TResult> >()
                              .Select(control => EFGenericRepository.Find <TResult>(control.Id)));

            return(entities);
        }
Ejemplo n.º 4
0
        private void SortThumbs()
        {
            IEnumerable <Thumb> sortedList = from thumb in myControls.Cast <Thumb>()
                                             orderby thumb.DisplayName, thumb.FullPath
            select thumb;
            int counter = 0;

            foreach (Thumb thumb in sortedList)
            {
                myControls.SetChildIndex(thumb, counter);
                counter++;
            }
        }
Ejemplo n.º 5
0
        public static async Task <IList <TResult> > TransformControlsToEntitiesAsync <TResult>(
            this ControlCollection controlCollection, CancellationToken token)
            where TResult : class, IEntity
        {
            return(await Task.Run(() =>
            {
                var entities = new List <TResult>(controlCollection.Count);

                entities.AddRange(controlCollection.Cast <IEntityControlView <TResult> >()
                                  .Select(control => EFGenericRepository.Find <TResult>(control.Id)));

                return entities;
            }, token));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Delete students from ControlCollection
        /// </summary>
        /// <param name="controlCollection"></param>
        /// <param name="changedEntities">Entities that was changed</param>
        /// <param name="storedEntities">Entities that store in DB </param>
        /// <param name="token">Cancellation token</param>
        public static async Task DeleteControls <T>(
            this ControlCollection controlCollection,
            IEnumerable <T> changedEntities,
            IEnumerable <T> storedEntities,
            CancellationToken token)
            where T : IEntity
        {
            var controls = new List <Control>();

            Console.WriteLine($"DeleteControls: changedEntities - {changedEntities.Count()}");

            await Task.Factory.StartNew(() =>
            {
                foreach (var entity in changedEntities)
                {
                    var control = controlCollection
                                  .Cast <IEntity>()
                                  .FirstOrDefault(c => c.Id == entity.Id);
                    controls.Add((Control)control);
                }

                //entity that doesnt store in db and was deleted
                var entityIDs = controlCollection
                                .Cast <IEntity>()
                                .Select(sv => sv.Id);

                var storedEntityIDs = storedEntities.Select(s => s.Id);

                entityIDs.Except(storedEntityIDs)
                .Select(id => controlCollection
                        .Cast <IEntity>()
                        .First(st => st.Id == id)).ToList()
                .ForEach(c => controls.Add((Control)c));
            }, token);

            controls.ForEach(controlCollection.Remove);
        }
Ejemplo n.º 7
0
        public static async void DeleteControls <T>(
            this ControlCollection controlCollection,
            IEnumerable <T> changedEntities,
            CancellationToken token)
            where T : IEntity
        {
            var controls = new List <Control>();

            await Task.Factory.StartNew(() =>
            {
                foreach (var entity in changedEntities)
                {
                    var control = controlCollection
                                  .Cast <IEntity>()
                                  .FirstOrDefault(c => c.Id == entity.Id);
                    controls.Add((Control)control);
                }
            }, token);

            controls.ForEach(controlCollection.Remove);
        }
Ejemplo n.º 8
0
 public static bool IsContainControl <T>(this ControlCollection controlCollection, int id) where T : class, IEntity
 {
     return(controlCollection.Cast <IEntityControlView <T> >().FirstOrDefault(c => c.Id == id) != null);
 }
Ejemplo n.º 9
0
 public Control this[string name] {
     get { return(_formContainer.Cast <Control>().FirstOrDefault(control => control.ID == name)); }
 }