コード例 #1
0
        public List <Software> GetSoftwareGreaterThanInput(string input)
        {
            var results = new List <Software>();

            //TODO: Add front-end validation and error handling for invalid inputs
            input = ValidateInput(input);

            Version.TryParse(input, out Version inputVersion);

            if (inputVersion != null)
            {
                var existingSoftware = SoftwareManager.GetAllSoftware();

                foreach (var software in existingSoftware)
                {
                    if (Version.TryParse(software.Version, out Version ver))
                    {
                        if (ver > inputVersion)
                        {
                            results.Add(software);
                        }
                    }
                    else
                    {
                        //TODO: handle bad versions in existingSoftware
                    }
                }

                return(results);
            }

            return(results);
            //TODO: Handle bad version input
        }
コード例 #2
0
 public VersionHelper()
 {
     foreach (var software in SoftwareManager.GetAllSoftware())
     {
         AllSoftware.Add(software);
     }
 }
コード例 #3
0
        public void GetAllSoftwareTest()
        {
            var manager = new SoftwareManager();

            var allSoftware = manager.GetSoftware().ToList();

            // This is true because the data manager is fixed/hard-coded.
            Assert.IsTrue(allSoftware.Count == 9);
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: troylar/aws-configurator
        public void UninstallSoftware(string displayName)
        {
            var softwareManager = new SoftwareManager();

            if (softwareManager.IsSoftwareInstalled("AWS Command Line Interface"))
            {
                softwareManager.UninstallSoftware("AWS Command Line Interface");
            }
            Task.Run(() => RefreshVersions());
        }
コード例 #5
0
        public void GetAllSoftwareTest()
        {
            var allSoftware = SoftwareManager.GetAllSoftware().ToList();

            // Fixed/hard-coded software manager so the data is consistent for the unit test.
            Assert.IsTrue(allSoftware.Count == 9);

            allSoftware.ForEach(o => Assert.IsFalse(string.IsNullOrWhiteSpace(o.Name)));
            allSoftware.ForEach(o => Assert.IsFalse(string.IsNullOrWhiteSpace(o.Version)));
        }
コード例 #6
0
        public void GetSoftwareExceptionTests()
        {
            var manager = new SoftwareManager();

            Assert.ThrowsException <FormatException>(() =>
            {
                manager
                .GetSoftware(
                    versionFilter: "A.B",
                    versionComparision: VersionComparison.GreaterThanOrEqualTo)
                .ToList();
            });
        }
コード例 #7
0
        public JsonResult GreaterSoftware([FromUri] SearchRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult(new List <Software>
                {
                    new Software {
                        Name = "Invalid", Version = "Input was not in correct format."
                    }
                }
                                      ));
            }

            var inputVersion = software.GetInputVersion(request.Input);

            return(new JsonResult(software.GetSoftwareGreaterThan(inputVersion, SoftwareManager.GetAllSoftware())));
        }
コード例 #8
0
        public void GetSoftwareByNameAndVersionFilterTests()
        {
            var manager = new SoftwareManager();

            var filteredSoftware = manager
                                   .GetSoftware("Visual Studio", "2017.0.1", VersionComparison.EqualTo)
                                   .ToList();

            Assert.IsTrue(filteredSoftware.Count == 1);


            filteredSoftware = manager
                               .GetSoftware("Visual Studio INVALID", "2017.0.1", VersionComparison.EqualTo)
                               .ToList();

            Assert.IsTrue(filteredSoftware.Count == 0);
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: troylar/aws-configurator
        private void RefreshVersions()
        {
            var softwareManager = new SoftwareManager();

            latestVersionLabel.Text    = "Checking . . . ";
            installedVersionLabel.Text = "Checking . . . ";
            string latestVersion;

            var installFile = softwareManager.DownloadSoftware(System.Configuration.ConfigurationManager.AppSettings["AWSCliX64"]);

            try
            {
                latestVersion = softwareManager.GetMsiProperty(installFile, "ProductVersion").Replace(":", ".");
            }
            finally
            {
                File.Delete(installFile);
            }

            var installedVersion = softwareManager.GetInstalledSoftwareProperty("AWS Command Line Interface", "DisplayVersion");

            latestVersionLabel.Text    = latestVersion;
            installedVersionLabel.Text = string.IsNullOrEmpty(installedVersion) ? "Not installed" : installedVersion;
            installButton.Enabled      = false;
            if (string.IsNullOrEmpty(installedVersion))
            {
                installButton.Enabled   = true;
                installButton.Text      = Resources.Resources.Install;
                uninstallButton.Enabled = false;
            }
            else if (new Version(latestVersion) > new Version(installedVersion))
            {
                installButton.Enabled   = true;
                installButton.Text      = Resources.Resources.Upgrade;
                uninstallButton.Enabled = false;
            }
            else if (new Version(latestVersion) == new Version(installedVersion))
            {
                installButton.Text      = Resources.Resources.Upgrade;
                installButton.Enabled   = false;
                uninstallButton.Enabled = false;
            }

            lastCheckedLabel.Text = $@"Last checked: {DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}";
        }
コード例 #10
0
        public void GetAllSoftwareFromFactoryManagerTest()
        {
            var dataManager = new SoftwareDataManagerFactory().CreateSoftwareDataManager();

            var allSoftware = dataManager.GetAllSoftware().ToList();

            // now get all software from static to compare
            var allSoftware2 = SoftwareManager.GetAllSoftware().ToList();

            Assert.IsTrue(allSoftware.Count == allSoftware2.Count);

            allSoftware.ForEach(o =>
                                Assert.IsTrue(allSoftware2.Any(x =>
            {
                return(o.Name == x.Name &&
                       o.Version == x.Version);
            })));
        }
コード例 #11
0
        public void OnPost()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (!this.Version.Contains("."))
                    {
                        this.Version += ".0"; // System.Version does not treat "2" as a valid version so convert to equivalent "2.0"
                    }
                    Version ver = new Version(this.Version);

                    var software = SoftwareManager.GetAllSoftware();
                    this.Results = software.Where(s => s.VersionObj > ver).OrderBy(o => o.VersionObj).ToList();
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("Version", e.Message);
                }
            }
        }
コード例 #12
0
ファイル: Form1.cs プロジェクト: troylar/aws-configurator
        private void installButton_Click(object sender, EventArgs e)
        {
            var softwareManager = new SoftwareManager();

            if (softwareManager.IsSoftwareInstalled("AWS Command Line Interface"))
            {
                UninstallSoftware("AWS Command Line Interface");
            }

            var installPath = softwareManager.DownloadSoftware(System.Configuration.ConfigurationManager.AppSettings["AWSCliX64"]);

            try
            {
                softwareManager.InstallSoftware(installPath);
            }
            finally
            {
                File.Delete(installPath);
            }

            Task.Run(() => RefreshVersions());
        }
コード例 #13
0
    private void Awake()
    {
        if (Instance != null)
        {
            Debug.LogWarning("Multiple SoftwareManager exist. Destroying the last one registered.", gameObject);
            Destroy(this);
        }
        else
        {
            Instance = this;

            mainThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;

            ThreadPool.GetMaxThreads(out defaultMaximumNumberOfThreads, out int _);
            ThreadPool.GetMinThreads(out defaultMinimumNumberOfThreads, out int _);

            if (!ThreadPool.SetMaxThreads(realDesiredMaximumNumberOfThreads, realDesiredMaximumNumberOfThreads))
            {
                Debug.LogWarning("Error setting maximum number of threads. The value can not be below " + lowestAcceptableValueForMaximumNumberOfThreads);
            }
        }
    }
コード例 #14
0
        public IEnumerable <Software> GetSoftwareWithGreaterVersion(SemVersion version)
        {
            var softwareResult = new List <Software>();

            var allSoftware = SoftwareManager.GetAllSoftware();

            foreach (var software in allSoftware)
            {
                if (!SemVersion.TryParse(software.Version, out var parsedVersion))
                {
                    _logger.LogWarning($"Unable to parse version from source date.{Environment.NewLine}\tName: {software.Name};{Environment.NewLine}\tVersion: {software.Version}");
                    continue;
                }

                if (parsedVersion > version)
                {
                    softwareResult.Add(software);
                }
            }

            return(softwareResult);
        }
コード例 #15
0
        public void OnPost()
        {
            if (!(ModelState.IsValid))
            {
                return;
            }

            try
            {
                NewerSoftware = SoftwareManager.GetNewerSoftware(Version).ToList();
            }
            catch (InvalidSoftwareVersionException exception)
            {
                ErrorMessage  = exception.Message;
                NewerSoftware = new List <Software>();
            }
            catch
            {
                ErrorMessage  = "An error occurred while processing your request";
                NewerSoftware = new List <Software>();
                // would log this error
            }
        }
コード例 #16
0
        public Task <IEnumerable <Software> > Handle(SearchVersionCommand request, CancellationToken cancellationToken)
        {
            try
            {
                _logger.LogTrace("Processing request '{request}' ...", request);
                var watch = Stopwatch.StartNew();

                var matched = SoftwareManager
                              .GetAllSoftware()
                              .Where(software => _versionMatcher.IsGreaterThan(software.Version, request.Version))
                              .ToList();

                watch.Stop();
                _logger.LogTrace("Processed request '{requestName}': {elapsed} ms", request, watch.ElapsedMilliseconds);

                return(Task.FromResult <IEnumerable <Software> >(matched));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error processing request '{requestName}': {errorMessage}", request, ex.Message);
                throw;
            }
        }
コード例 #17
0
        public void GetSoftwareByNameFilterTests()
        {
            var manager = new SoftwareManager();

            var filteredSoftware = manager
                                   .GetSoftware("Visual Studio")
                                   .ToList();

            Assert.IsTrue(filteredSoftware.Count == 3);


            filteredSoftware = manager
                               .GetSoftware("Visual Studio Code")
                               .ToList();

            Assert.IsTrue(filteredSoftware.Count == 1);


            filteredSoftware = manager
                               .GetSoftware("INVALID TITLE")
                               .ToList();

            Assert.IsTrue(filteredSoftware.Count == 0);
        }
コード例 #18
0
 public IEnumerable <Software> ByVersion(string versionNumber)
 {
     return(new List <Software>(SoftwareManager.GetAllSoftwareWithHigherVersion(versionNumber)));
 }
コード例 #19
0
 public IEnumerable <Software> GetAllSoftware()
 {
     return(SoftwareManager.GetAllSoftware());
 }
コード例 #20
0
 public void OnGet()
 {
     this.Version = "";
     this.Results = SoftwareManager.GetAllSoftware();
 }
コード例 #21
0
        public IEnumerable <Software> Get()
        {
            var softwareList = SoftwareManager.GetAllSoftware();

            return(softwareList);
        }
コード例 #22
0
        private void SetSoftwareDataList(string filter)
        {
            Tuple <bool, IEnumerable <SoftwareSearch> > filteredSoftwareSearchReturn = SoftwareManager.GetFilteredSoftwareSearch(filter);

            if (!filteredSoftwareSearchReturn.Item1)
            {
                SetFilterMessage("Invalid filter.  Format:<br>[Number].[Number].[Number]");
            }
            else
            {
                ClearFilterMessage();
            }

            dlSoftware.DataSource = filteredSoftwareSearchReturn.Item2;
            dlSoftware.DataBind();
        }
コード例 #23
0
        public void GetSoftwareByVersionFilterTests()
        {
            var manager = new SoftwareManager();

            var filteredSoftware = manager
                                   .GetSoftware(
                versionFilter: "2016.0",
                versionComparision: VersionComparison.GreaterThanOrEqualTo)
                                   .ToList();

            // This is true because the data manager is fixed/hard-coded.
            Assert.IsTrue(filteredSoftware.Count == 2);


            filteredSoftware = manager
                               .GetSoftware(
                versionFilter: "2019.0",
                versionComparision: VersionComparison.GreaterThanOrEqualTo)
                               .ToList();

            Assert.IsTrue(filteredSoftware.Count == 1);


            filteredSoftware = manager
                               .GetSoftware(
                versionFilter: "2017.0.1",
                versionComparision: VersionComparison.EqualTo)
                               .ToList();

            Assert.IsTrue(filteredSoftware.Count == 1);

            filteredSoftware = manager
                               .GetSoftware(
                versionFilter: "1",
                versionComparision: VersionComparison.GreaterThanOrEqualTo)
                               .ToList();

            Assert.IsTrue(filteredSoftware.Count == 7);


            filteredSoftware = manager
                               .GetSoftware(
                versionFilter: "9999",
                versionComparision: VersionComparison.LessThan)
                               .ToList();

            Assert.IsTrue(filteredSoftware.Count == 9);


            filteredSoftware = manager
                               .GetSoftware(
                versionFilter: "2017.0.1",
                versionComparision: VersionComparison.LessThan)
                               .ToList();

            Assert.IsTrue(filteredSoftware.Count == 7);


            filteredSoftware = manager
                               .GetSoftware(
                versionFilter: "2017.0.1",
                versionComparision: VersionComparison.LessThanOrEqualTo)
                               .ToList();

            Assert.IsTrue(filteredSoftware.Count == 8);
        }
コード例 #24
0
 public void Init()
 {
     logger          = new LoggerFactory().CreateLogger <SoftwareController>();
     softwareManager = new SoftwareManager();
 }