private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (object checkVersionSender, DoWorkEventArgs checkVersionE) =>
            {
                VersionHandler.Instance.GetOnlineVersion(App.ApplicationName, App.LocalVersion);
            };
            worker.RunWorkerCompleted += (object checkVersionSender, RunWorkerCompletedEventArgs echeckVersionE) =>
            {
                VersionResult versionResult = VersionHandler.Instance.VersionResult;

                if (versionResult.Exception != null)
                {
                    App.Instance.ShowError($"Error retrieving version number for '{App.ApplicationName}'", versionResult.Exception.Message, versionResult.Exception.InnerException);
                }

                if (versionResult.IsUpToDate.HasValue && !versionResult.IsUpToDate.Value)
                {
                    UpdateRecommendedWindow updateRecommendedWindow = new UpdateRecommendedWindow();
                    updateRecommendedWindow.ShowDialog();
                }
            };
            worker.RunWorkerAsync();
        }
示例#2
0
        private void Update_Click(object sender, RoutedEventArgs e)
        {
            CheckingForUpdatesWindow window = new CheckingForUpdatesWindow();

            window.ShowDialog();

            VersionResult versionResult = VersionHandler.Instance.VersionResult;

            if (versionResult.IsUpToDate.HasValue)
            {
                if (!versionResult.IsUpToDate.Value)
                {
                    UpdateRecommendedWindow updateRecommendedWindow = new UpdateRecommendedWindow();
                    updateRecommendedWindow.ShowDialog();
                }
                else
                {
                    App.Instance.ShowMessage("Up to date", $"{App.ApplicationDisplayName} {App.LocalVersion} is up to date.");
                }
            }
            else
            {
                App.Instance.ShowError($"Error retrieving version number for '{App.ApplicationName}'", versionResult.Exception.Message, versionResult.Exception.InnerException);
            }
        }
示例#3
0
        /**
         * Verifica si existe una nueva version en la tienda disponible para
         * realizar la actualizacion de la aplicacion.
         * y cambia la bandera allowLogin para que se permita el login
         * en caso que sea necesario.
         */
        public async Task VerifyStoreVersion()
        {
            IAppInfo appInfo = DependencyService.Get <IAppInfo>();

            VersionResult result = await appInfo.NeedUpdateApp();

            if (result.isSuccess)
            {
                // si no es necesario actualizar permitimos el
                // login de manera tradicional
                // en caso contrario mostramos mensaje de error.
                if (!result.needUpdate)
                {
                    AllowNavigate = true;
                    return;
                }

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await page.DisplayAlert("Nueva versión disponible",
                                            "Es necesario actualizar su aplicación para disfrutar de las nuevas características.",
                                            "Actualizar");

                    await Xamarin.Essentials.Launcher.TryOpenAsync(new Uri(appInfo.GotoStore()));
                    appInfo.CloseApp();
                });
            }
            else
            {
                await page.DisplayAlert("Error", result.error, "Cerrar");
            }
        }
示例#4
0
        private static async Task Main()
        {
            ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
                                                                builder.AddConsole(opt => opt.Format = ConsoleLoggerFormat.Systemd)
                                                                .SetMinimumLevel(LogLevel.Trace));

            ILogger logger = loggerFactory.CreateLogger <Program>();

            const string connectionString = "tcp://127.0.0.1:3310";
            const string eicarAvTest      = @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*";

            //Create a client
            IClamAvClient clamAvClient = ClamAvClient.Create(new Uri(connectionString), loggerFactory);

            //Send PING command to ClamAV
            await clamAvClient.PingAsync().ConfigureAwait(false);

            //Get ClamAV engine and virus database version
            VersionResult result = await clamAvClient.GetVersionAsync().ConfigureAwait(false);

            logger.LogInformation((
                                      $"ClamAV version - {result.ProgramVersion} , virus database version {result.VirusDbVersion}"));

            await using MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(eicarAvTest));

            //Send a stream to ClamAV scan
            ScanResult res = await clamAvClient.ScanDataAsync(memoryStream).ConfigureAwait(false);

            logger
            .LogInformation(($"Scan result : Infected - {res.Infected} , Virus name {res.VirusName}"));
        }
示例#5
0
        private void HandleVersion(Action <GithubReleaseResponse> updateCallback = null)
        {
            LocalVersion = LoadLocalVersion(VERSION_FILE_NAME);
            if (LocalVersion == null)
            {
                VersionResult = VersionResult.Error;
                return;
            }

            var remoteVersionTask = Task.Run(() => LoadLatestVersion());

            remoteVersionTask.Wait();
            var remoteVersionResponse = remoteVersionTask.Result;

            if (remoteVersionResponse == null)
            {
                return;
            }

            LatestVersion = ConvertStringToVersionJson(remoteVersionResponse.Value.VersionString);
            if (LatestVersion == null)
            {
                VersionResult = VersionResult.Error;
                DebugWindow.LogError($"VersionChecker -> String from remote version cant be converted: {remoteVersionResponse.Value.VersionString}");
                return;
            }

            VersionResult = VersionComparison(LocalVersion.Value, LatestVersion.Value);
            if (VersionResult.IsUpdateAvailable())
            {
                DebugWindow.LogMsg($"VersionChecker -> Update Available");
                updateCallback?.Invoke(remoteVersionResponse.Value);
            }
        }
示例#6
0
        public HttpResponseMessage GetLatestVersion()
        {
#if DEBUG
            virtualPackageAdress = @"http://172.18.9.211/Package/";
            packageUrl           = @"E:\SMZDM\VersionManagementCenter\VersionManagementCenter\Package";
#endif
            VersionResult versionResult = new VersionResult();
            try
            {
                OperationDocument fileServies = new OperationDocument(packageUrl);
                var latestVersion             = fileServies.GetLatestVersion();
                var fullPackAgeAdress         = Path.Combine(virtualPackageAdress, latestVersion);
                versionResult.DownLoadUrl   = fullPackAgeAdress;
                versionResult.FullFileName  = latestVersion;
                versionResult.VersionNumber = OperationDocument.VersionNumber(latestVersion);
                versionResult.ErrCode       = 200;
            }
            catch (Exception ex)
            {
                versionResult.ErrCode = 417;
                versionResult.ErrMsg  = ex.Message;
            }
            string result = JsonConvert.SerializeObject(versionResult);
            return(JsonTool.Instance.toJson(result));
        }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VersionContext"/> class.
 /// </summary>
 /// <param name="environment">The <see cref="IVersionEnvironment"/> for the invocation.</param>
 /// <param name="configuration">The <see cref="VersionConfiguration"/> for the current branch.</param>
 /// <param name="result">The <see cref="VersionResult"/> to collect final version details.</param>
 public VersionContext(
     IVersionEnvironment environment,
     VersionConfiguration configuration,
     VersionResult result)
 {
     Environment   = environment ?? throw new ArgumentNullException(nameof(environment));
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     Result        = result ?? throw new ArgumentNullException(nameof(result));
 }
示例#8
0
        private static bool TryParseVersion(string version, ref VersionResult result)
        {
            if (version == null)
            {
                result.SetFailure(ParseFailureKind.ArgumentNullException);
                return(false);
            }

            string[] array = version.Split(SeparatorsArray);
            int      num   = array.Length;

            if (num < 2 || num > 4)
            {
                result.SetFailure(ParseFailureKind.ArgumentException);
                return(false);
            }

            if (!TryParseComponent(array[0], "version", ref result, out int parsedComponent))
            {
                return(false);
            }

            if (!TryParseComponent(array[1], "version", ref result, out int parsedComponent2))
            {
                return(false);
            }

            num -= 2;
            if (num > 0)
            {
                if (!TryParseComponent(array[2], "build", ref result, out int parsedComponent3))
                {
                    return(false);
                }

                num--;
                if (num > 0)
                {
                    if (!TryParseComponent(array[3], "revision", ref result, out int parsedComponent4))
                    {
                        return(false);
                    }

                    result.m_parsedVersion = new VersionEx(parsedComponent, parsedComponent2, parsedComponent3, parsedComponent4);
                }
                else
                {
                    result.m_parsedVersion = new VersionEx(parsedComponent, parsedComponent2, parsedComponent3);
                }
            }
            else
            {
                result.m_parsedVersion = new VersionEx(parsedComponent, parsedComponent2);
            }

            return(true);
        }
示例#9
0
 public void SetConfig(Config config)
 {
     this.config           = config;
     cached_version_result = new VersionResult
     {
         SemverId    = config.GameVersion,
         BuildNumber = config.GameBuildNumber
     };
 }
示例#10
0
        public static bool TryParse(string input, out Version result)
        {
            VersionResult result2 = new VersionResult();

            result2.Init("input", false);
            bool flag = TryParseVersion(input, ref result2);

            result = result2.m_parsedVersion;
            return(flag);
        }
        public void HeightPadded_Pads_Height()
        {
            // Arrange / Act
            var sut = new VersionResult {
                Height = 40
            };

            // Assert
            sut.HeightPadded.Should().Be("0040");
        }
示例#12
0
        public static bool TryParse(string input, out VersionEx result)
        {
            VersionResult result2 = default(VersionResult);

            result2.Init("input", canThrow: false);
            bool result3 = TryParseVersion(input, ref result2);

            result = result2.m_parsedVersion;
            return(result3);
        }
示例#13
0
        public static bool TryParse(string input, out Version result)
        {
            VersionResult r = new VersionResult();

            r.Init("input", false);
            bool b = TryParseVersion(input, ref r);

            result = r.m_parsedVersion;
            return(b);
        }
示例#14
0
        private static bool TryParseVersion(string version, ref VersionResult result)
        {
            int num;
            int num2;

            if (version == null)
            {
                result.SetFailure(ParseFailureKind.ArgumentNullException);
                return(false);
            }
            string[] strArray = version.Split(new char[] { '.' });
            int      length   = strArray.Length;

            if ((length < 2) || (length > 4))
            {
                result.SetFailure(ParseFailureKind.ArgumentException);
                return(false);
            }
            if (!TryParseComponent(strArray[0], "version", ref result, out num))
            {
                return(false);
            }
            if (!TryParseComponent(strArray[1], "version", ref result, out num2))
            {
                return(false);
            }
            length -= 2;
            if (length > 0)
            {
                int num3;
                if (!TryParseComponent(strArray[2], "build", ref result, out num3))
                {
                    return(false);
                }
                length--;
                if (length > 0)
                {
                    int num4;
                    if (!TryParseComponent(strArray[3], "revision", ref result, out num4))
                    {
                        return(false);
                    }
                    result.m_parsedVersion = new Version(num, num2, num3, num4);
                }
                else
                {
                    result.m_parsedVersion = new Version(num, num2, num3);
                }
            }
            else
            {
                result.m_parsedVersion = new Version(num, num2);
            }
            return(true);
        }
        public void Sha7_IsSubstring_OfSha(string sha, string sha7)
        {
            // Arrange / Act
            var sut = new VersionResult
            {
                Sha = sha
            };

            // Assert
            sut.Sha7.Should().Be(sha7);
        }
        public void Non_PR_Branch_Does_Not_Set_PR_Properties()
        {
            // Arrange / Act
            var sut = new VersionResult {
                CanonicalBranchName = "refs/heads/master"
            };

            // Assert
            sut.IsPullRequest.Should().BeFalse();
            sut.PullRequestNumber.Should().Be(0);
        }
        public void PR_Branch_Sets_PR_Properties()
        {
            // Arrange / Act
            var sut = new VersionResult {
                CanonicalBranchName = "refs/pull/124876/merge"
            };

            // Assert
            sut.IsPullRequest.Should().BeTrue();
            sut.PullRequestNumber.Should().Be(124876);
        }
        private VersionResult MakeVersionResult(string[] versions, bool randomizeListing = false, bool listAll = true)
        {
            var versionResult1 = new VersionResult();

            foreach (var versionString in versions)
            {
                versionResult1.AllVersionDetails.Add(MakeVersionDetail(versionString, randomizeListing ? (randomizer.Next(100) >= 50 ? true : false) : listAll));
            }

            return(versionResult1);
        }
示例#19
0
 private void GetVersion(object sender, EventArgs e)
 {
     version = TaskHandlers.Version();
     if (version.Success)
     {
         CrcVersionLabel.Text = String.Format("{0}+{1}", version.CrcVersion, version.CommitSha);
         OcpVersion.Text      = version.OpenshiftVersion;
     }
     else
     {
         DisplayMessageBox.Warn("Unable to fetch version information from daemon");
     }
 }
示例#20
0
        public void ProcessRawResponseAsync_Valid_Raw_Data_Should_Return_PONG()
        {
            VersionCommand versionCommand = new VersionCommand();

            const string expectedProgramVersion = "ClamAv 1.17.219";
            string       expectedVirusDbVersion = (DateTime.Now.Ticks % 11177).ToString();

            byte[] rawBytes = Encoding.UTF8.GetBytes($"{expectedProgramVersion}/{expectedVirusDbVersion}/{DateTime.Now}");

            VersionResult actual = versionCommand.ProcessRawResponse(rawBytes);

            actual.ProgramVersion.Should().Be(expectedProgramVersion);
            actual.VirusDbVersion.Should().Be(expectedVirusDbVersion);
        }
示例#21
0
        /// <summary>
        /// Parse <paramref name="version"/> and return the result if it is a valid <see cref="SemanticVersion"/>, otherwise throws an exception.
        /// </summary>
        /// <param name="version">The string to parse</param>
        /// <returns></returns>
        /// <exception cref="PSArgumentException"></exception>
        /// <exception cref="ValidationMetadataException"></exception>
        /// <exception cref="FormatException"></exception>
        /// <exception cref="OverflowException"></exception>
        public static SemanticVersion Parse(string version)
        {
            if (version == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(version));
            }

            var r = new VersionResult();

            r.Init(true);
            TryParseVersion(version, ref r);

            return(r._parsedVersion);
        }
示例#22
0
        /**
         * busca en la tienda la version actual de la aplicacion y
         * la compara con la version actual y retorna un bandera que
         * indica si es necesario actualizar la aplicacion.
         */
        public Task <VersionResult> NeedUpdateApp()
        {
            return(Task.Run(async() =>
            {
                try
                {
                    // si es appCurrentVersion 1, significa que aun no hay version en la tienda.
                    double appCurrentVersion = GetVersion().RemoveAllOcurrenceToDouble(".");
                    //if (appCurrentVersion == 1002)
                    //{
                    //    return VersionResult.Done(false);
                    //}
                    var uri = new Uri(StoreUrl());
                    using (var client = new HttpClient())
                        using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
                        {
                            request.Headers.TryAddWithoutValidation("Accept", "text/html");
                            request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
                            request.Headers.TryAddWithoutValidation("Accept-Charset", "ISO-8859-1");
                            using (var response = await client.SendAsync(request).ConfigureAwait(false))
                            {
                                response.EnsureSuccessStatusCode();
                                var responseHTML = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                                var rx = new Regex(@"(?<=""htlgb"">)(\d{1,3}\.\d{1,3}\.\d{1,3}\.{0,1}\d{0,4})(?=<\/span>)", RegexOptions.Compiled);
                                MatchCollection matches = rx.Matches(responseHTML);

                                string storeVersion = matches.Count > 0 ? matches[0].Value : "Unknown";
                                if (storeVersion == "Unknown")
                                {
                                    return VersionResult.Done(false);
                                }
                                double appStoreVersion = storeVersion.RemoveAllOcurrenceToDouble(".");
                                //double appCurrentVersion = GetVersion().RemoveAllOcurrenceToDouble(".");

                                bool needUpdate = appCurrentVersion < appStoreVersion;

                                return VersionResult.Done(needUpdate);
                            }
                        }
                }
                catch (Exception e)
                {
                    var error = string.IsNullOrEmpty(e.Message) ?
                                "ha ocurrido un error inesperado" :
                                e.Message;
                    Console.WriteLine(error);
                    return VersionResult.Fail(error);
                }
            }));
        }
示例#23
0
        public static Version Parse(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            VersionResult result = new VersionResult();

            result.Init("input", true);
            if (!TryParseVersion(input, ref result))
            {
                throw result.GetVersionParseException();
            }
            return(result.m_parsedVersion);
        }
示例#24
0
        private void VersionReceived(VersionResult result)
        {
            if (result.Failed)
            {
                return;
            }

            try
            {
                var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;

                var previousDistributive = Path.Combine(Path.GetTempPath(), string.Format("livedc_update_{0}.exe", currentVersion));

                if (File.Exists(previousDistributive))
                {
                    File.Delete(previousDistributive);
                }

                if (result.Version > currentVersion)
                {
                    var wc = new WebClient();

                    _readyUpdateFile = Path.Combine(Path.GetTempPath(), string.Format("livedc_update_{0}.exe", result.Version));

                    if (File.Exists(_readyUpdateFile))
                    {
                        RequestUpdate();
                        return;
                    }

                    _updateTempFile = Path.GetTempFileName();
                    wc.DownloadFile(result.DownloadUri, _updateTempFile);

                    File.Move(_updateTempFile, _readyUpdateFile);

                    RequestUpdate();
                }
                else
                {
                    Logger.Info("No need to update the client");
                }
            }
            catch (Exception x)
            {
                Logger.Error("Update error: {0}", x.Message);
            }
        }
示例#25
0
        public static Version Parse(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            Contract.EndContractBlock();

            VersionResult r = new VersionResult();

            r.Init("input", true);
            if (!TryParseVersion(input, ref r))
            {
                throw r.GetVersionParseException();
            }
            return(r.m_parsedVersion);
        }
示例#26
0
        /// <summary>
        /// Parse <paramref name="version"/> and return true if it is a valid <see cref="SemanticVersion"/>, otherwise return false.
        /// No exceptions are raised.
        /// </summary>
        /// <param name="version">The string to parse</param>
        /// <param name="result">The return value when the string is a valid <see cref="SemanticVersion"/></param>
        public static bool TryParse(string version, out SemanticVersion result)
        {
            if (version != null)
            {
                var r = new VersionResult();
                r.Init(false);

                if (TryParseVersion(version, ref r))
                {
                    result = r._parsedVersion;
                    return(true);
                }
            }

            result = null;
            return(false);
        }
示例#27
0
        static void CheckForUpdates()
        {
            VersionResult vr = Updater.CheckUpdates(true);

            Console.WriteLine("Checking for GemsCraft updates...");
            try
            {
                //update is available, prompt for a download

                if (vr != VersionResult.Current)
                {
                    string premier = vr == VersionResult.Outdated
                        ? "Server.Run: Your GemsCraft version is out of date. A GemsCraft Update is available!"
                        : "Server.Run: You are using an unreleased version of GemsCraft.";
                    Console.WriteLine(vr);
                    Console.WriteLine("Download the latest GemsCraft version and restart the server? (Y/N)");
                    string answer = Console.ReadLine();
                    if (answer.ToLower() == "y" || answer.ToLower() == "yes" || answer.ToLower() == "yup" ||
                        answer.ToLower() == "yeah") //preparedness at its finest
                    {
                        Process.Start("Updater.exe");
                    }
                    else
                    {
                        Console.WriteLine(
                            "Update ignored. To ignore future GemsCraft update requests, uncheck the box in configGUI.");
                    }
                }
                else
                {
                    Console.WriteLine("Your GemsCraft version is up to date!");
                }
            }

            catch (WebException error)
            {
                Console.WriteLine(
                    "There was an internet connection error. Server was unable to check for updates. Error: \n\r" +
                    error);
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error in trying to check for updates:\n\r " + e);
            }
        }
        public void Ctor_SetsDefaults()
        {
            // Arrange / Act
            var sut = new VersionResult();

            // Assert
            sut.Version.Should().BeNull();
            sut.Major.Should().Be(0);
            sut.Minor.Should().Be(0);
            sut.Patch.Should().Be(0);
            sut.Revision.Should().Be(0);
            sut.Height.Should().Be(0);
            sut.HeightPadded.Should().Be("0000");
            sut.Sha.Should().BeNull();
            sut.BranchName.Should().BeNull();
            sut.CanonicalBranchName.Should().BeNull();
            sut.Formats.Should().BeEmpty();
        }
示例#29
0
        /// <summary>
        /// Parse <paramref name="version"/> and return the result if it is a valid <see cref="SemanticVersion"/>, otherwise throws an exception.
        /// </summary>
        /// <param name="version">The string to parse.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="FormatException"></exception>
        /// <exception cref="OverflowException"></exception>
        public static SemanticVersion Parse(string version)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }
            if (version == string.Empty)
            {
                throw new FormatException(nameof(version));
            }

            var r = new VersionResult();

            r.Init(true);
            TryParseVersion(version, ref r);

            return(r._parsedVersion);
        }
示例#30
0
        private static bool TryParseVersion(string version, ref VersionResult result)
        {
            var dashIndex = version.IndexOf('-');

            // Empty label?
            if (dashIndex == version.Length - 1)
            {
                result.SetFailure(ParseFailureKind.ArgumentException);
                return(false);
            }

            var versionSansLabel = (dashIndex < 0) ? version : version.Substring(0, dashIndex);

            string[] parsedComponents = versionSansLabel.Split(Utils.Separators.Dot);
            if (parsedComponents.Length != 3)
            {
                result.SetFailure(ParseFailureKind.ArgumentException);
                return(false);
            }

            int major, minor, patch;

            if (!TryParseComponent(parsedComponents[0], "major", ref result, out major))
            {
                return(false);
            }

            if (!TryParseComponent(parsedComponents[1], "minor", ref result, out minor))
            {
                return(false);
            }

            if (!TryParseComponent(parsedComponents[2], "patch", ref result, out patch))
            {
                return(false);
            }

            result._parsedVersion = dashIndex < 0
                ? new SemanticVersion(major, minor, patch)
                : new SemanticVersion(major, minor, patch, version.Substring(dashIndex + 1));
            return(true);
        }