示例#1
0
 public Engine()
 {
     this.hardwareComponents = new List <IComponentHardware>();
     hardwareFactory         = new HardwareFactory();
     softwareFactory         = new SoftwareFactory();
     newMachine = new Machine();
 }
示例#2
0
文件: Form1.cs 项目: Adman1724/VIS
        private void backupHardwareToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XDocument xDoc  = new XDocument();
            XElement  xRoot = new XElement("Database");

            HardwareFactory            hardwareFactory = new HardwareFactory();
            HardwareGateway <Hardware> hg = (HardwareGateway <Hardware>)hardwareFactory.GetHardware();

            Collection <Hardware> hardwares = hg.Select();
            XElement xHardwares             = new XElement("Hardware");

            foreach (var hardware in hardwares)
            {
                xHardwares.Add(HardwareXMLGateway <Hardware> .Instance.Insert(hardware));
            }

            xRoot.Add(xHardwares);


            xDoc.Add(xRoot);
            if (!Directory.Exists(Connective.XMLGateway.Paths.FolderPath))
            {
                Directory.CreateDirectory(Connective.XMLGateway.Paths.FolderPath);
            }

            using (StreamWriter sw = new StreamWriter(Connective.XMLGateway.Paths.FilePath))
            {
                sw.Write(xDoc.ToString());
            }

            MessageBox.Show("Backed up!");
        }
示例#3
0
 protected Command(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
 {
     this.input = input;
     this.data = data;
     this.hardwareFactory = hardwareFactory;
     this.softwareFactory = softwareFactory;
 }
示例#4
0
        public Command ParseCommand(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
        {
            switch (input[0])
            {
            case "RegisterPowerHardware": return(new RegisterPowerHardware(data, input, hardwareFactory, softwareFactory));

            case "RegisterHeavyHardware": return(new RegisterHeavyHardware(data, input, hardwareFactory, softwareFactory));

            case "RegisterExpressSoftware": return(new RegisterExpressSoftware(data, input, hardwareFactory, softwareFactory));

            case "RegisterLightSoftware": return(new RegisterLightSoftware(data, input, hardwareFactory, softwareFactory));

            case "Analyze": return(new Analyze(data, input, hardwareFactory, softwareFactory));

            case "ReleaseSoftwareComponent": return(new ReleaseSoftwareComponent(data, input, hardwareFactory, softwareFactory));

            case "System Split": return(new SystemSplit(data, input, hardwareFactory, softwareFactory));

            case "Dump": return(new Dump(data, input, hardwareFactory, softwareFactory));

            case "Restore": return(new Restore(data, input, hardwareFactory, softwareFactory));

            case "Destroy": return(new Destroy(data, input, hardwareFactory, softwareFactory));

            case "DumpAnalyze": return(new DumpAnalyze(data, input, hardwareFactory, softwareFactory));

            default: throw new ArgumentException(string.Format("Incorrect Comand {0}", input[0]));
            }
        }
    public void RegisterHardware(string[] tokens)
    {
        var hardFactory = new HardwareFactory();
        var hardware    = hardFactory.Create(tokens);

        allHardwares.Add(hardware);
    }
示例#6
0
 public SystemManager()
 {
     this.hardwareFactory = new HardwareFactory();
     this.softwareFactory = new SoftwareFactory();
     this.hardwares       = new Dictionary <string, Hardware>();
     this.dump            = new Dump();
 }
示例#7
0
 protected Command(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
 {
     this.input           = input;
     this.data            = data;
     this.hardwareFactory = hardwareFactory;
     this.softwareFactory = softwareFactory;
 }
示例#8
0
        public FormReportError()
        {
            HardwareFactory hardwareFactory = new HardwareFactory();

            h = hardwareFactory.GetHardware().Select();
            InitializeComponent();
        }
示例#9
0
 public CommandInterpreter
     (OutputWriter writer, SystemRepository systemRepository, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
 {
     this.writer           = writer;
     this.systemRepository = systemRepository;
     this.hardwareFactory  = hardwareFactory;
     this.softwareFactory  = softwareFactory;
 }
 public EnhancedCommandInterpreter
     (OutputWriter writer,
     SystemRepository systemRepository,
     DumpRepository dumpRepository,
     HardwareFactory hardwareFactory,
     SoftwareFactory softwareFactory)
     : base(writer, systemRepository, hardwareFactory, softwareFactory)
 {
     this.dumpRepository = dumpRepository;
 }
示例#11
0
        public void ProduceOneBundleOfHardware(HardwareFactory factory)
        {
            string serialNumber = DateTime.Now.Ticks.ToString(); //Dla uproszczenia - losowa liczba.
            var    keyboard     = factory.CreateKeyboard(serialNumber);
            var    mouse        = factory.CreateMouse(4000);
            var    microfon     = factory.CreateMicrophone("abc");

            keyboard.PrintSerialNumber();
            Console.WriteLine($"Mouse with {mouse.GetDPI()} DPI");
            Console.WriteLine($"Mic (model {microfon.Model})");
        }
示例#12
0
        static void Main()
        {
            InputReader      reader           = new InputReader();
            OutputWriter     writer           = new OutputWriter();
            SoftwareFactory  softwareFactory  = new SoftwareFactory();
            HardwareFactory  hardwareFactory  = new HardwareFactory();
            SystemRepository systemRepository = new SystemRepository();
            DumpRepository   dumpRepository   = new DumpRepository();
            Engine           engine           = new Engine(reader, writer, systemRepository, dumpRepository, hardwareFactory, softwareFactory);

            engine.Run();
        }
示例#13
0
 public Engine
     (InputReader reader,
     OutputWriter writer,
     SystemRepository systemRepository,
     DumpRepository dumpRepository,
     HardwareFactory hardwareFactory,
     SoftwareFactory softwareFactory)
 {
     this.reader           = reader;
     this.writer           = writer;
     this.systemRepository = systemRepository;
     this.dumpRepository   = dumpRepository;
     this.hardwareFactory  = hardwareFactory;
     this.softwareFactory  = softwareFactory;
     this.interpreter      =
         new EnhancedCommandInterpreter
             (this.writer, this.systemRepository, this.dumpRepository, this.hardwareFactory, this.softwareFactory);
 }
示例#14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HardwareFactory hardwareFactory = new HardwareFactory();


            hc = hardwareFactory.GetHardware().Select();
            Collection <string> hardwareStrings = new Collection <string>();

            foreach (Hardware h in hc)
            {
                hardwareStrings.Add(h.Name);
            }

            if (!IsPostBack)
            {
                hardwareElement.DataSource = hardwareStrings;
                hardwareElement.DataBind();
            }
        }
示例#15
0
    static void Main(string[] args)
    {
        IReader reader = new ConsoleReader();
        IWriter writer = new ConsoleWriter();

        var softwares = new List <ISoftware>();
        var hardwares = new List <IHardware>();

        var hadrwareFactory = new HardwareFactory();
        var softwareFactory = new SoftwareFactory();

        IController controller = new Controller(hardwares, softwares, hadrwareFactory, softwareFactory);

        ICommandInterpreter commandInterpreter = new CommandInterpreter(controller);

        IEngine engine = new Engine(reader, writer, commandInterpreter);

        engine.Run();
    }
        public Command ParseCommand(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
        {
            switch (input[0])
            {
                case "RegisterPowerHardware": return new RegisterPowerHardware(data,input,hardwareFactory,softwareFactory);
                case "RegisterHeavyHardware": return new RegisterHeavyHardware(data, input,hardwareFactory, softwareFactory);
                case "RegisterExpressSoftware": return new RegisterExpressSoftware(data, input, hardwareFactory, softwareFactory);
                case "RegisterLightSoftware": return  new RegisterLightSoftware(data, input,hardwareFactory,softwareFactory);
                case "Analyze": return new Analyze(data, input,hardwareFactory, softwareFactory);
                case "ReleaseSoftwareComponent": return  new ReleaseSoftwareComponent(data, input,hardwareFactory,softwareFactory);
                case "System Split": return new SystemSplit(data, input,hardwareFactory, softwareFactory);
                case "Dump": return new Dump(data, input, hardwareFactory, softwareFactory);
                case "Restore": return new Restore(data, input, hardwareFactory, softwareFactory);
                case "Destroy": return new Destroy(data, input, hardwareFactory, softwareFactory);
                case "DumpAnalyze": return new DumpAnalyze(data, input, hardwareFactory, softwareFactory);

                default: throw new ArgumentException(string.Format("Incorrect Comand {0}",input[0]));

            }
        }
示例#17
0
        static void Main()
        {
            string             input           = Console.ReadLine();
            Data               data            = new Data();
            CommandInterpreter commandHandler  = new CommandInterpreter();
            HardwareFactory    hardwareFactory = new HardwareFactory();
            SoftwareFactory    softwareFactory = new SoftwareFactory();

            while (true)
            {
                string[] inputParameters = input.Split(new[] { '(', ')', ',' }, StringSplitOptions.RemoveEmptyEntries);

                Command c = commandHandler.ParseCommand(data, inputParameters, hardwareFactory, softwareFactory);
                c.Execute();

                if (inputParameters[0].Equals("System Split"))
                {
                    break;
                }
                input = Console.ReadLine();
            }
        }
示例#18
0
        static void Main()
        {
            string input = Console.ReadLine();
            Data data=new Data();
            CommandInterpreter commandHandler=new CommandInterpreter();
            HardwareFactory hardwareFactory=new HardwareFactory();
            SoftwareFactory softwareFactory= new SoftwareFactory();

            while (true)
            {
                string[] inputParameters = input.Split(new[] {'(', ')', ','}, StringSplitOptions.RemoveEmptyEntries);

                Command c=commandHandler.ParseCommand(data, inputParameters, hardwareFactory, softwareFactory);
                c.Execute();

                if (inputParameters[0].Equals("System Split"))
                {
                    break;
                }
                input = Console.ReadLine();
            }
        }
 public RegisterExpressSoftware(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }
 public RegisterLightSoftware(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }
示例#21
0
 protected RegisterSoftware(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }
示例#22
0
 public ReleaseSoftwareComponent(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }
 public Manager()
 {
     this.createSoftware = new SoftwareFactory();
     this.createHardware = new HardwareFactory();
     this.system         = new TheSystem();
 }
示例#24
0
 public Restore(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }
 public ReleaseSoftwareComponent(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }
示例#26
0
    public void Execute()
    {
        while (true)
        {
            string[] commandArgs = GetCommand();

            string command = commandArgs[0];
            switch (command)
            {
            case "RegisterPowerHardware":
                Hardware hardware = HardwareFactory.CreateHardware("Power", commandArgs.Skip(1).ToArray());

                this.hardwares.Add(hardware);
                break;

            case "RegisterHeavyHardware":
                hardware = HardwareFactory.CreateHardware("Heavy", commandArgs.Skip(1).ToArray());

                this.hardwares.Add(hardware);
                break;

            case "RegisterExpressSoftware":
                string hardwareComponentName = commandArgs[1];

                try
                {
                    hardware = hardwares.FirstOrDefault(h => h.Name == hardwareComponentName);

                    Software software = SoftwareFactory.CreateSoftware("Express", commandArgs.Skip(2).ToArray());

                    hardware.AddSoftwareComponent(software);
                    softwares.Add(software);
                }
                catch (Exception)
                {
                    continue;
                }
                break;

            case "RegisterLightSoftware":
                hardwareComponentName = commandArgs[1];

                try
                {
                    hardware = hardwares.FirstOrDefault(h => h.Name == hardwareComponentName);

                    Software software = SoftwareFactory.CreateSoftware("Light", commandArgs.Skip(2).ToArray());

                    hardware.AddSoftwareComponent(software);
                    softwares.Add(software);
                }
                catch (Exception)
                {
                    continue;
                }
                break;

            case "ReleaseSoftwareComponent":
                hardwareComponentName = commandArgs[1];
                string softwareComponentName = commandArgs[2];

                try
                {
                    hardware = hardwares.FirstOrDefault(h => h.Name == hardwareComponentName);
                    Software software = hardware.ReleaseSoftwareComponent(softwareComponentName);
                    softwares.Remove(software);
                }
                catch (Exception)
                {
                    continue;
                }
                break;

            case "Dump":
                hardwareComponentName = commandArgs[1];

                if (!hardwares.Exists(h => h.Name == hardwareComponentName))
                {
                    continue;
                }
                try
                {
                    hardware = hardwares.FirstOrDefault(h => h.Name == hardwareComponentName);

                    hardwares.Remove(hardware);

                    dump.Add(hardware);
                }
                catch (Exception)
                {
                    continue;
                }
                break;

            case "Restore":
                hardwareComponentName = commandArgs[1];

                if (!dump.Exists(h => h.Name == hardwareComponentName))
                {
                    continue;
                }

                try
                {
                    hardware = dump.FirstOrDefault(h => h.Name == hardwareComponentName);

                    dump.Remove(hardware);

                    hardwares.Add(hardware);
                }
                catch (Exception)
                {
                    continue;
                }
                break;

            case "Destroy":
                hardwareComponentName = commandArgs[1];

                if (!hardwares.Exists(h => h.Name == hardwareComponentName))
                {
                    continue;
                }

                try
                {
                    hardware = dump.FirstOrDefault(h => h.Name == hardwareComponentName);

                    dump.Remove(hardware);
                }
                catch (Exception)
                {
                    continue;
                }
                break;

            case "DumpAnalyze":
                StringBuilder sb = new StringBuilder();

                sb.Append($"Dump Analysis{Environment.NewLine}");

                int countOfPowerHardwareComponents   = dump.Where(c => c.GetType().Name == "Power").Count();
                int countOfHeavyHardwareComponents   = dump.Where(c => c.GetType().Name == "Heavy").Count();
                int countOfExpressSoftwareComponents = dump.Sum(c => c.Softwares.Where(s => s.GetType().Name == "Express").Count());
                int countOfLightSoftwareComponents   = dump.Sum(c => c.Softwares.Where(s => s.GetType().Name == "Light").Count());;
                int totalDumpedMemory   = dump.Sum(c => c.TotalOperationalMemoryInUse);
                int totalDumpedCapacity = dump.Sum(c => c.TotalCapacityTaken);

                sb.Append($"Power Hardware Components: {countOfPowerHardwareComponents}{Environment.NewLine}");
                sb.Append($"Heavy Hardware Components: {countOfHeavyHardwareComponents}{Environment.NewLine}");
                sb.Append($"Express Software Components: {countOfExpressSoftwareComponents}{Environment.NewLine}");
                sb.Append($"Light Software Components: {countOfLightSoftwareComponents}{Environment.NewLine}");
                sb.Append($"Total Dumped Memory: {totalDumpedMemory}{Environment.NewLine}");
                sb.Append($"Total Dumped Capacity: {totalDumpedCapacity}{Environment.NewLine}");

                Console.Write(sb.ToString());
                break;

            case "Analyze":
                sb = new StringBuilder();

                sb.Append($"System Analysis{Environment.NewLine}");

                sb.Append($"Hardware Components: {hardwares.Count}{Environment.NewLine}");
                sb.Append($"Software Components: {hardwares.Sum(s => s.Softwares.Count)}{Environment.NewLine}");

                int TotalOperationalMemoryInUse = hardwares.Sum(h => h.TotalOperationalMemoryInUse);
                int TotalMemory = hardwares.Sum(h => h.MaximumMemory);
                sb.Append($"Total Operational Memory: {TotalOperationalMemoryInUse} / {TotalMemory}{Environment.NewLine}");

                int TotalCapacityTaken = hardwares.Sum(h => h.TotalCapacityTaken);
                int TotalCapacity      = hardwares.Sum(h => h.MaximumCapacity);
                sb.Append($"Total Capacity Taken: {TotalCapacityTaken} / {TotalCapacity}");
                Console.WriteLine(sb.ToString());
                break;

            case "System":
                Console.Write(SystemInformation());
                return;
            }
        }
    }
 protected RegisterSoftware(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }
示例#28
0
 public SystemSplit(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }
示例#29
0
 public Dump(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }
示例#30
0
 public DumpAnalyze(Data data, string[] input, HardwareFactory hardwareFactory, SoftwareFactory softwareFactory)
     : base(data, input, hardwareFactory, softwareFactory)
 {
 }