Esempio n. 1
0
 public void AddPeripheral(IPeripheral peripheral)
 {
     if (Peripherals.Contains(peripheral))
     {
         // public const string ExistingPeripheral = "Peripheral {0} already exists in {1} with Id {2}.";
         throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.ExistingPeripheral, peripheral.GetType().Name, this.GetType().Name, this.Id));
     }
     else
     {
         peripherals.Add(peripheral);
         //public const string AddedPeripheral = "Peripheral {0} with id {1} added successfully in computer with id {2}.";
         //Console.WriteLine(string.Format(Common.Constants.SuccessMessages.AddedComponent, peripheral.GetType(), peripheral.Id, this.Id));
     }
 }
Esempio n. 2
0
            private void ScanPeripheral(XElement node, RegisterSettings defaultRegisterSettings)
            {
                var name = GetMandatoryField(node, "name");
                var newRegisterSettings = GetRegisterSettings(node, defaultRegisterSettings);
                var peripheral          = new SVDPeripheral(name, this);

                Peripherals.Add(peripheral);

                var registersElement = node.Element("registers");

                if (registersElement != null)
                {
                    ScanRegistersAndClusters(registersElement, newRegisterSettings, peripheral);
                }
            }
Esempio n. 3
0
 private void Peripherals_ScrollWheelUp(object sender, EventArgs e)
 {
     if (MainGame.IsActive == true)
     {
         if (Peripherals.KeyPressed(Keys.LeftControl) && World.Zoom < 5)
         {
             World.Zoom++;
             if (MainGame.Camera.CurrentMode == CameraMode.Drag)
             {
                 MainGame.Camera.DragTransform = MainGame.Camera.CreateDragTransform();
             }
         }
         else if (!Peripherals.KeyPressed(Keys.LeftControl) && Authorization == Authorization.Builder)
         {
             Altitude++;
         }
     }
 }
        public Form1()
        {
            InitializeComponent();

            ArrayList pList = null;

            string[] lStatistic = null;
            try
            {
                pList = Peripherals.EnumerateAdapters();
            }
            catch (Exception ex)
            {
                MessageBox.Show("failed with\r\n" + ex.Message, "EnumerateAdapters()");
                Close();
                return;
            }

            listBox1.Items.Clear();

            foreach (string AdapterName in pList)
            {
                try
                {
                    listBox1.Items.Add(AdapterName + (Peripherals.IsAdapterPresent(AdapterName) ? " is present" : " is NOT present") + (Peripherals.IsWirelessAdapter(AdapterName) ? " [wireless adapter] " : ""));
                    lStatistic = Peripherals.GetAdapterStatistics(AdapterName);     // See Note 1
                    foreach (string StatInfo in lStatistic)
                    {
                        if (StatInfo.StartsWith("Local MAC Address"))
                        {
                            listBox1.Items.Add("» " + StatInfo);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    Close();
                    return;
                }
            }
        }
        void GetConnectedDevices()
        {
            _connectedDisposable = _centralManager.GetConnectedPeripherals().Subscribe(scanResult =>
            {
                scanResult.ToList().ForEach(
                    item =>
                {
                    if (!string.IsNullOrEmpty(item.Name))
                    {
                        Peripherals.Add(item);
                    }
                });

                _connectedDisposable?.Dispose();
            });

            if (_centralManager.IsScanning)
            {
                _centralManager.StopScan();
            }
        }
 void GetDeviceList()
 {
     if (_centralManager.IsScanning)
     {
         _scanDisposable?.Dispose();
     }
     else
     {
         if (_centralManager.Status == Shiny.AccessState.Available && !_centralManager.IsScanning)
         {
             _scanDisposable = _centralManager.ScanForUniquePeripherals().Subscribe(scanResult =>
             {
                 if (!string.IsNullOrEmpty(scanResult.Name) && !Peripherals.Contains(scanResult))
                 {
                     Peripherals.Add(scanResult);
                 }
             });
         }
     }
     IsScanning = _centralManager.IsScanning;
 }
Esempio n. 7
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(base.ToString());

            sb.AppendLine($" Components ({Components.Count}):");
            foreach (var component in Components)
            {
                sb.AppendLine($"  {component.ToString()}");
            }
            string averagePeripheralsOverallPerformance = Peripherals.Count == 0 ? "0.00" :
                                                          Peripherals.Average(p => p.OverallPerformance).ToString("F2");

            sb.AppendLine($" Peripherals ({Peripherals.Count}); Average Overall Performance ({averagePeripheralsOverallPerformance}):");
            foreach (var peripheral in Peripherals)
            {
                sb.AppendLine($"  {peripheral.ToString()}");
            }
            return(sb.ToString().TrimEnd());
        }
Esempio n. 8
0
        public override string ToString()
        {
            StringBuilder bb = new StringBuilder();

            bb.AppendLine($"Overall Performance: {OverallPerformance:f2}. Price: {Price:f2} - {GetType().Name}: {Manufacturer} {Model} (Id: {Id})");
            bb.AppendLine($" Components ({Components.Count}):");
            foreach (var component in components)
            {
                bb.AppendLine($"  {component}");
            }

            string averageResult = Peripherals.Count == 0 ? "0.00" : Peripherals.Average(x => x.OverallPerformance).ToString("f2");

            bb.AppendLine($" Peripherals ({Peripherals.Count}); Average Overall Performance ({averageResult:f2}):");

            foreach (var peripheral in peripherals)
            {
                bb.AppendLine($"  {peripheral}");
            }

            return(bb.ToString().TrimEnd());
        }
Esempio n. 9
0
        public override string ToString()
        {
            double peripheralsAvg = Peripherals.Count > 0 ? Peripherals.Average(x => x.OverallPerformance) : 0;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($" Components ({Components.Count}):");

            foreach (var component in Components)
            {
                sb.AppendLine($"  {component}");
            }

            sb.AppendLine($" Peripherals ({Peripherals.Count}); " +
                          $"Average Overall Performance ({peripheralsAvg:F2}):");

            foreach (var peripheral in Peripherals)
            {
                sb.AppendLine($"  {peripheral}");
            }

            return(base.ToString() + $"\n{sb.ToString().TrimEnd()}");
        }
Esempio n. 10
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(base.ToString());

            sb.AppendLine($" Components ({Components.Count}):");
            foreach (var component in Components)
            {
                sb.AppendLine($"  {component}");
            }

            double avgPerformance = Peripherals.Sum(p => p.OverallPerformance) / Peripherals.Count;

            string avgPerfString = Peripherals.Count == 0 ? $"{Peripherals.Count:F2}" : $"{avgPerformance:F2}";

            sb.AppendLine($" Peripherals ({Peripherals.Count}); Average Overall Performance ({avgPerfString}):");
            foreach (var peripherial in Peripherals)
            {
                sb.AppendLine($"  {peripherial}");
            }

            return(sb.ToString().Trim());
        }
 public Computer(Peripherals peripherals, Case c)
 {
 }
Esempio n. 12
0
 public bool Contains(IPeripheral peripheral)
 {
     return(Peripherals.Contains(peripheral));
 }
Esempio n. 13
0
        public override void Update(GameTime gameTime)
        {
            if (!IsLoading)
            {
                // Defined with respect to current mouse position.
                Coord2D mouseIsoFlatCoord = World.MousePositionToIsoFlatCoord(MainGame);
                Coord2D mouseIsoCoord     = World.MousePositionToIsoCoord(MainGame, Altitude);

                // User input actions.
                if (Peripherals.KeyTapped(Keys.Q) && MainGame.IsActive)
                {
                    var i = (int)Authorization + 1;
                    if (i >= Enum.GetNames(typeof(Authorization)).Length)
                    {
                        i = 0;
                    }
                    Authorization = (Authorization)(i);
                }

                if (Peripherals.KeyTapped(Keys.L) && MainGame.IsActive)
                {
                    $"Altitude = {Altitude}".Log();
                    mouseIsoCoord.ToString().Log();
                }

                if (Authorization == Authorization.Builder)
                {
                    if (Peripherals.LeftButtonPressed() && MainGame.IsActive)
                    {
                        BuildWorldObject(mouseIsoFlatCoord, mouseIsoCoord);
                    }

                    if (Peripherals.RightButtonPressed() && MainGame.IsActive)
                    {
                        RemoveWorldObject(mouseIsoFlatCoord, mouseIsoCoord);
                    }
                }

                // Ghost marker management.
                if (Authorization == Authorization.Builder)
                {
                    GhostMarker.Altitude = Altitude;
                    GhostMarker.Coords   = mouseIsoCoord;
                }
                else if (Authorization == Authorization.None)
                {
                    // Top down look.
                    for (int i = 30; i > -30; i--)
                    {
                        var targetedCoord = World.GetIsoCoord(mouseIsoFlatCoord, i);
                        if (LayerMap.ContainsKey(new Coord3D(targetedCoord, i)) && !(LayerMap[new Coord3D(targetedCoord, i)] is Deco))
                        {
                            Altitude             = i;
                            GhostMarker.Altitude = Altitude;
                            break;
                        }
                    }
                    GhostMarker.Coords = World.MousePositionToIsoCoord(MainGame, Altitude);
                }

                // Test
                GhostMarker.Position = World.IsoFlatCoordToWorldPosition(mouseIsoFlatCoord);

                if (LayerMap.ContainsKey(new Coord3D(mouseIsoCoord, Altitude)) || Authorization == Authorization.None)
                {
                    GhostMarker.DrawDefaultMarker = true;
                }
                else if (Authorization == Authorization.Builder)
                {
                    GhostMarker.DrawDefaultMarker = false;
                }

                if (LayerMap.ContainsKey(new Coord3D(mouseIsoCoord, Altitude)))
                {
                    GhostMarker.DrawPriority = 1;
                }
                else if (Authorization == Authorization.Builder)
                {
                    GhostMarker.DrawPriority = 0;
                }
                else if (Authorization == Authorization.None)
                {
                    // If !LayerMap[Altitude].OccupiedCoords.Contains(mouseIsoCoord), we are in empty space
                    // and always draw last.
                    GhostMarker.DrawPriority = -1000;
                }

                GhostMarker.IsHidden = !MainGame.IsMouseOver;


                if (Authorization == Authorization.None)
                {
                    if (Peripherals.LeftButtonTapped())
                    {
                        ClickAnimation.Position     = GhostMarker.Position;
                        ClickAnimation.Coords       = GhostMarker.Coords;
                        ClickAnimation.Altitude     = GhostMarker.Altitude;
                        ClickAnimation.DrawPriority = GhostMarker.DrawPriority;
                        ClickAnimation.Animator.AnimationFinished = false;
                        ClickAnimation.Animator.Reconfigure(new AnimArgs(1, 7, 0.066f, AnimationState.Once));
                    }
                }
                ClickAnimation.Update(gameTime);

                // Player management.
                //Player.Altitude = 1;

                #region Pre Loop

                // Rearrange sprites into their correct altitude layer.
                //var altitudeList = LayerMap.Keys.ToList();
                //altitudeList.Sort();

                //foreach (var altitude in altitudeList)
                //{
                //    for (int i = 0; i < LayerMap[altitude].Count(); i++)
                //    {
                //        var sprite = LayerMap[altitude][i];
                //        if (sprite.Altitude != altitude)
                //        {
                //            LayerMap[altitude].Remove(sprite); i--;
                //            if (!LayerMap.ContainsKey(sprite.Altitude))
                //            {
                //                LayerMap.Add(sprite.Altitude, new SpriteList<Sprite>() { sprite });
                //            }
                //            else
                //            {
                //                if (!(sprite is IWorldObject))
                //                {
                //                    LayerMap[sprite.Altitude].Add(sprite);
                //                }
                //                else
                //                {
                //                    throw new NotImplementedException("Cube/Deco trying to move between layers, is this correct? Use AddCheck if so.");
                //                }
                //            }
                //        }
                //    }
                //}

                #endregion

                #region Main Loop

                Sort();
                foreach (var sprite in OrderedLayerMap)
                {
                    sprite.Update(gameTime);
                }

                #endregion
            }
        }
Esempio n. 14
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(base.ToString());
            sb.AppendLine($" Components ({Components.Count}):");
            foreach (var item in Components)
            {
                sb.AppendLine($"  {item}");
            }

            if (Peripherals.Any())
            {
                sb.AppendLine($" Peripherals ({Peripherals.Count}); Average Overall Performance ({Peripherals.Average(p => p.OverallPerformance):f2}):");
            }
            else
            {
                sb.AppendLine($" Peripherals ({Peripherals.Count}); Average Overall Performance (0):");
            }

            foreach (var item in Peripherals)
            {
                sb.AppendLine($"  {item}");
            }
            return(sb.ToString().TrimEnd());
        }
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            result.AppendLine(base.ToString());
            result.AppendLine($" Components ({Components.Count}):");

            if (Components.Count > 0)
            {
                foreach (var item in components)
                {
                    result.AppendLine($"  {item.ToString()}");
                }
            }

            result.AppendLine($" Peripherals ({Peripherals.Count}); Average Overall Performance ({Peripherals.Average(x => x.OverallPerformance)}):");

            if (Peripherals.Count > 0)
            {
                foreach (var item in peripherals)
                {
                    result.AppendLine($"  {item.ToString()}");
                }
            }

            return(result.ToString().TrimEnd());
        }