示例#1
0
 public void Update()
 {
     while (AddComponents.Count > 0)
     {
         AllComponents.Add(AddComponents[0]);
         AddComponents.RemoveAt(0);
     }
     foreach (var item in AllComponents)
     {
         if (item.IsDisposed)
         {
             RemoveComponents.Add(item);
             continue;
         }
         item.Update();
     }
     if (RemoveComponents.Count > 0)
     {
         foreach (var item in RemoveComponents)
         {
             AllComponents.Remove(item);
         }
         RemoveComponents.Clear();
     }
 }
示例#2
0
        public void FillList()
        {
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString()))
            {
                SqlCommand query = new SqlCommand(@"exec Get_AllComponents", conn);
                conn.Open();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(query);
                DataTable      dataTable      = new DataTable();
                sqlDataAdapter.Fill(dataTable);

                if (AllComponents == null)
                {
                    AllComponents = new ObservableCollection <Components>();
                }

                foreach (DataRow row in dataTable.Rows)
                {
                    Components r = new Components
                    {
                        ComponentId     = int.Parse(row[0].ToString()),
                        ReceptId        = int.Parse(row[1].ToString()),
                        ComponentName   = row[2].ToString(),
                        ComponentAmount = int.Parse(row[3].ToString()),
                    };

                    AllComponents.Add(r);
                }
            }
        }
        private void CreateCurrentComponent()
        {
            if (Current == null)
            {
                return;
            }

            AllComponents.Add(new List <T>());
        }
示例#4
0
        public Player(Point position, int fovRadius = 10)
            : base(position, 1, false)
        {
            // Set FOV radius we will use for calculating FOV
            FOVRadius = fovRadius;

            // Set hook so that FOV is recalculated when the player moves
            Moved += OnMoved;

            // Add component for controlling player movement via keyboard
            var motionControl = new PlayerControlsComponent();

            AllComponents.Add(motionControl);
        }
示例#5
0
 public void AddComponent(DrawableComponent dc)
 {
     AllComponents.Add(dc);
 }
        /// <summary>
        /// Registers all components with the component manager
        /// </summary>
        private void RegisterComponents()
        {
            //use reflection to find all available components
            string      componentNamespace = WizardComponentNamespace;
            List <Type> componentObjects   = (from type in Assembly.GetExecutingAssembly().GetTypes()
                                              where
                                              type.GetInterfaces().Contains(typeof(IWizardBaseController))
                                              &&
                                              !type.IsAbstract
                                              &&
                                              type.Namespace.CompareTo(componentNamespace) == 0
                                              select type).ToList();

            foreach (Type component in componentObjects)
            {
                IWizardBaseController controller = Activator.CreateInstance(component) as IWizardBaseController;
                AllComponents.Add(controller);
            }

            //pull from the cache if possible
            FileCache cache           = FileCacheHelper.GetGlobalCacheInstance();
            bool      loadedFromCache = false;

            string[] sorted = (string[])cache.Get(componentsCacheString, CacheRegion);
            if (sorted != null)
            {
                //set loaded to true for now
                loadedFromCache = true;

                //make sure that the sizes match up
                if (sorted.Length != AllComponents.Count)
                {
                    loadedFromCache = false;
                }

                //make sure all components are represented in the cache
                foreach (IWizardBaseController component in AllComponents)
                {
                    if (!sorted.Contains(component.ControllerName))
                    {
                        loadedFromCache = false;
                        break;
                    }
                }

                //if we're still clear to load from the cache, then do so
                if (loadedFromCache)
                {
                    IWizardBaseController[] tempComponentList = new IWizardBaseController[sorted.Length];
                    for (int i = 0; i < sorted.Length; i++)
                    {
                        IWizardBaseController component = AllComponents.Find(c => c.ControllerName == sorted[i]);
                        if (component != null)
                        {
                            tempComponentList[i] = component;
                        }
                    }

                    //reassign the sorted list
                    AllComponents = tempComponentList.ToList();
                }
            }

            //if caching failed, do it the long way
            if (!loadedFromCache)
            {
                List <IWizardBaseController> components = SortComponents(AllComponents);
                AllComponents = components;

                //save sorted component information to cache
                string[] sortedComponents = new string[AllComponents.Count];
                for (int i = 0; i < sortedComponents.Length; i++)
                {
                    sortedComponents[i] = AllComponents[i].ControllerName;
                }
                cache.Add(componentsCacheString, sortedComponents, cache.DefaultPolicy, CacheRegion);
            }

            //attach event listeners to selection change
            //and apply a sort order for faster sorting in the future
            int counter = 1;

            foreach (IWizardBaseController component in AllComponents)
            {
                component.SortOrder        = counter;
                component.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ComponentPropertyChanged);
                counter++;
            }
        }