Exemplo n.º 1
0
 protected AbstractSoftware(string name, int capacity, int memory, SoftwareTypes type, double capacityPercent, double memoryPercent)
 {
     this.Name = name;
     this.CapacityConsumption = capacity;
     this.MemoryConsumption = memory;
     this.Type = type;
     this.capacityPercent = capacityPercent;
     this.memoryPercent = memoryPercent;
 }
Exemplo n.º 2
0
        private void GetInstalledPrograms(Dictionary <string, SoftwareInfo> ProgramList, SoftwareTypes SoftwareType = SoftwareTypes.bit64)
        {
            if (ProgramList == null)
            {
                return;
            }

            string uninstallKey = "";

            switch (SoftwareType)
            {
            case SoftwareTypes.bit32:
                uninstallKey = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
                break;

            case SoftwareTypes.bit64:
            default:
                uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
                break;
            }

            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
            {
                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        SoftwareInfo softwareInfo = GetSoftwareInfoForKey(sk);

                        if (!string.IsNullOrEmpty(softwareInfo.DisplayName))
                        {
                            if (ProgramList.Keys.Contains(softwareInfo.DisplayName))
                            {
                                SoftwareInfo si = ProgramList[softwareInfo.DisplayName];

                                si.KeyCount++;

                                if (string.IsNullOrEmpty(si.DisplayVersion) && !string.IsNullOrEmpty(softwareInfo.DisplayVersion))
                                {
                                    si.DisplayVersion = softwareInfo.DisplayVersion;
                                }

                                if (string.IsNullOrEmpty(si.InstallDateRaw) && !string.IsNullOrEmpty(softwareInfo.InstallDateRaw))
                                {
                                    si.InstallDateRaw = softwareInfo.InstallDateRaw;
                                }

                                if (si.InstallDate < softwareInfo.InstallDate)
                                {
                                    si.InstallDate = softwareInfo.InstallDate;
                                }

                                if (string.IsNullOrEmpty(si.Publisher) && !string.IsNullOrEmpty(softwareInfo.Publisher))
                                {
                                    si.Publisher = softwareInfo.Publisher;
                                }

                                if (string.IsNullOrEmpty(si.URLInfoAbout) && !string.IsNullOrEmpty(softwareInfo.URLInfoAbout))
                                {
                                    si.URLInfoAbout = softwareInfo.URLInfoAbout;
                                }

                                ProgramList[softwareInfo.DisplayName] = si;
                            }
                            else
                            {
                                ProgramList.Add(softwareInfo.DisplayName, softwareInfo);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public AppsResult CreateAppSoftware(SoftwareTypes softwareType)
        {
            var result = new AppsResult();

            try
            {
                //1. Create new app object
                //2. Create new software object
                //3. Create "Software" folder under appfolders/app
                //4. Create "ID" folder under "Software"
                //5. Run new command

                var newApp         = new App();
                var newSoftware    = new Software();
                var appsTable      = _db.GetCollection <App>("Apps");
                var softwaresTable = _db.GetCollection <Software>("Softwares");


                appsTable.Upsert(newApp); //Creates primary id
                softwaresTable.Upsert(newSoftware);

                string appFoldersFolder = System.Environment.CurrentDirectory + "\\AppFolders";

                if (System.IO.Directory.Exists(appFoldersFolder))
                {
                    System.IO.Directory.CreateDirectory(appFoldersFolder + "\\App" + newApp.AppID.ToString());
                    System.IO.Directory.CreateDirectory(appFoldersFolder + "\\App" + newApp.AppID.ToString() + "\\Software");
                    System.IO.Directory.CreateDirectory(appFoldersFolder + "\\App" + newApp.AppID.ToString() + "\\Software\\Software" + newSoftware.SoftwareID.ToString());

                    new AppFlows.Create(newApp.AppID, "Created all folders.");

                    if (softwareType == SoftwareTypes.CoreWebService)
                    {
                        newApp.AppName       = "CoreWebService" + newApp.AppID.ToString();
                        newApp.MachineName   = System.Environment.MachineName;
                        newApp.WorkingFolder = appFoldersFolder + "\\App" + newApp.AppID.ToString() + "\\Software\\Software" + newSoftware.SoftwareID.ToString();
                        newApp.SoftwareType  = SoftwareTypes.CoreWebService;

                        appsTable.Upsert(newApp); //Uniquely identifies in apps

                        new AppFlows.Create(newApp.AppID, "Set app working folder.");

                        //Command.Exec("", "cd", new Dictionary<string, string> { { "", newApp.WorkingFolder } }, newApp.WorkingFolder, ref result);
                        //Create solution
                        Command.Exec("dotnet", "new sln", new Dictionary <string, string>
                        {
                            { "-o", newApp.WorkingFolder }
                        }, newApp.WorkingFolder, ref result);

                        new AppFlows.Create(newApp.AppID, "Created solution.");

                        //Create software
                        Command.Exec("dotnet", "new", new Dictionary <string, string> {
                            { "", "webapi" },
                            { "-o", "\"" + newApp.WorkingFolder + "\\" + newApp.AppName + "\"" },
                            { "-n", newApp.AppName }
                        }, newApp.WorkingFolder, ref result);

                        new AppFlows.Create(newApp.AppID, "Created app.");

                        //Add project to solution
                        Command.Exec("dotnet", "sln", new Dictionary <string, string>
                        {
                            { "add", newApp.AppName + "\\" + newApp.AppName + ".csproj" }
                        }, newApp.WorkingFolder, ref result);

                        new AppFlows.Create(newApp.AppID, "Added project to solution.");

                        //Create test project
                        Command.Exec("dotnet", "new", new Dictionary <string, string> {
                            { "", "xunit" },
                            { "-o", "\"" + newApp.WorkingFolder + "\\" + newApp.AppName + ".Tests" + "\"" },
                            { "-n", newApp.AppName + ".Tests" }
                        }, newApp.WorkingFolder, ref result);

                        new AppFlows.Create(newApp.AppID, "Created test app.");

                        //Add test app to solution
                        Command.Exec("dotnet", "sln", new Dictionary <string, string>
                        {
                            { "add", newApp.WorkingFolder + "\\" + newApp.AppName + ".Tests" + "\\" + newApp.AppName + ".Tests.csproj" }
                        }, newApp.WorkingFolder, ref result);

                        new AppFlows.Create(newApp.AppID, "Added test app to solution.");

                        //Add Brooksoft.Apps.Client nuget package
                        string projFileName = newApp.AppName + ".csproj";
                        string projFilePath = newApp.WorkingFolder + "\\" + newApp.AppName + "\\" + projFileName;

                        if (System.IO.File.Exists(projFilePath))
                        {
                            Command.Exec("dotnet", "add", new Dictionary <string, string>
                            {
                                { "", newApp.AppName + "\\" + projFileName },
                                { "package", "Brooksoft.Apps.Client" }
                            }, newApp.WorkingFolder, ref result);

                            new AppFlows.Create(newApp.AppID, "Added apps nuget package.");

                            newApp.ProjectFileFullName = projFilePath;
                            newApp.ProjectFileExists   = true;
                            appsTable.Upsert(newApp);

                            //Add Load
                            string startupCSPath = newApp.WorkingFolder + "\\" + newApp.AppName + "\\Startup.cs";
                            string startupFile   = System.IO.File.ReadAllText(startupCSPath);
                            string start         = startupFile.Substring(0, startupFile.Length - 22);
                            string end           = startupFile.Substring(startupFile.Length - 20);
                            string inserted      = "var appsClient = new AppsClient.AppsClientConfig();appsClient.Load(\"Software14\", Environment.MachineName, Environment.CurrentDirectory, Environment.Version, new List<string>(), new List<AppsClient.AppsCustomConfigItem>(), true, true, new Flows.AppFlow());";
                            string changed       = start + inserted + end;

                            new AppFlows.Create(newApp.AppID, "Added code to startup.");

                            //Parse
                            Microsoft.CodeAnalysis.SyntaxTree tree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(changed);
                            var diags = tree.GetDiagnostics().ToList();
                            foreach (var diag in diags)
                            {
                                result.FailMessages.Add("(Start: " + diag.Location.SourceSpan.Start.ToString() + ", End: " + diag.Location.SourceSpan.End.ToString() + ") " + diag.Severity.ToString() + " " + diag.Descriptor.Id.ToString() + " " + diag.Descriptor.MessageFormat);;
                            }
                            if (result.FailMessages.Count == 0)
                            {
                                System.IO.File.WriteAllText(startupCSPath, changed);
                                result.SuccessMessages.Add("CS file updated.");

                                new AppFlows.Create(newApp.AppID, "Written and parsed successfully!");
                            }
                            else
                            {
                                result.FailMessages.Add("CS file did not update.");
                            }


                            //Run
                            Command.Exec("dotnet", "run", new Dictionary <string, string>
                            {
                                { "", newApp.WorkingFolder + "\\" + newApp.AppName + "\\" + projFileName }
                            }, newApp.WorkingFolder, ref result);

                            new AppFlows.Create(newApp.AppID, "Started app.");

                            result.Success = true;
                        }
                        else
                        {
                            new AppFlows.Create.Fail("Project file not found for add package: " + projFilePath, ref result);
                        }
                    }
                    else
                    {
                        new AppFlows.Create.Fail("No software type found to create.", ref result);
                    }
                }
                else
                {
                    new AppFlows.Create.Fail("Apps folders folder not found.", ref result);
                }
            }
            catch (System.Exception ex)
            {
                new AppFlows.Create.Exception(ex, ref result);
            }

            return(result);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            ComponentFactory componentFactory = new ComponentFactory();
            ProductFactory   productFactory   = new ProductFactory();
            SoftwareTypes    softwareTypes    = new SoftwareTypes();

            bool exit = false;

            while (!exit)
            {
                Console.WriteLine("Welcome to Our E-shop");
                Console.WriteLine("What would you like to buy ?\n " +
                                  "press 'a' for  PC tower\n" +
                                  "press 'b' for a PC screen\n" +
                                  "press 'c' for a Personal Computer\n" +
                                  "press 'd' for a Workstation\n" +
                                  "press 'e' to exit\n");


                string answer = Console.ReadLine();

                if (answer.Equals("a"))
                {
                    PCTower pcTower = ConfigurePCTower(componentFactory, productFactory);
                    if (!pcTower.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    PrintReceiptInfo(pcTower);
                }
                else if (answer.Equals("b"))
                {
                    PCScreen pcScreen = ConfigurePCScreen(productFactory);
                    if (!pcScreen.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    PrintReceiptInfo(pcScreen);
                }
                else if (answer.Equals("c"))
                {
                    PersonalComputer personalComputer = ConfigurePersonalComputer(componentFactory, productFactory);
                    if (!personalComputer.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    PrintReceiptInfo(personalComputer);
                }
                else if (answer.Equals("d"))
                {
                    PersonalComputer personalComputer = ConfigurePersonalComputer(componentFactory, productFactory);
                    if (!personalComputer.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    Console.WriteLine("Please select one of the available softwares\n");
                    foreach (var type in softwareTypes.Types)
                    {
                        Console.WriteLine(type.Value + "\n");
                    }
                    answer = Console.ReadLine();
                    Software software = componentFactory.CreateComponent("Software") as Software;
                    if (!software.SetValue(answer))
                    {
                        WrongInput();
                        continue;
                    }

                    Workstation workstation = productFactory.CreateProduct("Workstation") as Workstation;
                    if (!workstation.SetPersonalComputer(personalComputer) || !workstation.SetSoftware(software))
                    {
                        continue;
                    }

                    if (!workstation.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }
                    PrintReceiptInfo(workstation);
                }
                else if (answer.Equals("e"))
                {
                    exit = true;
                }
                else
                {
                    WrongInput();
                }
            }
        }