Ejemplo n.º 1
0
        public async Task DownloadApp(AppInformation appInfo)
        {
            if (appInfo is null)
            {
                throw new ArgumentNullException(nameof(appInfo));
            }

            //if (Directory.Exists(AppInformation.AppFolderPath) == false)
            //{
            //    Directory.CreateDirectory(AppInformation.AppFolderPath);

            //    // Wait untill download.
            //    await DownloadAppTask(appInfo, new Version()).ConfigureAwait(false);
            //    return;
            //}

            var maxVesion = GetAppInstalledMaxVersion(appInfo);

            if (maxVesion is null)
            {
                // Wait untill download.
                await DownloadAppTask(appInfo, maxVesion).ConfigureAwait(false);
            }
            else
            {
                // Don't wait, run exising app, Download new version if exist for next time.
                DownloadApp(appInfo, maxVesion);
            }
        }
Ejemplo n.º 2
0
        private static Version GetAppInstalledMaxVersion(AppInformation appInfo)
        {
            var appVersionFolderPathList = Directory.GetDirectories(AppInformation.AppFolderPath, $"{appInfo.AppVersionFolderNamePrefix}*", SearchOption.TopDirectoryOnly).ToList();

            if (appVersionFolderPathList.Any() == false)
            {
                return(null);
            }
            var maxVesion = appVersionFolderPathList.Select(p => new Version(p.Split(appInfo.AppVersionFolderNamePrefix).LastOrDefault())).Max();

            return(maxVesion);
        }
Ejemplo n.º 3
0
        public static void RunApp(ProcessStartInfo process, AppInformation appInfo)
        {
            if (process is null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            if (appInfo is null)
            {
                throw new ArgumentNullException(nameof(appInfo));
            }

            var appVersionExePath = GetAppMaxVersionExePath(appInfo);

            process.FileName = appVersionExePath;
            Process.Start(process);
        }
Ejemplo n.º 4
0
        private static string GetAppMaxVersionExePath(AppInformation appInfo)
        {
            var maxVesion = GetAppInstalledMaxVersion(appInfo);

            if (maxVesion is null)
            {
                throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.NotFound, nameof(maxVesion)));
            }
            var appVersionExePath = Path.Combine(AppInformation.AppFolderPath, $"{appInfo.AppVersionFolderNamePrefix}{maxVesion}", appInfo.AppExecutableName);

            if (File.Exists(appVersionExePath) == false)
            {
                throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.NotFound, nameof(appVersionExePath)));
            }
            return(appVersionExePath);
        }
Ejemplo n.º 5
0
 private async void DownloadApp(AppInformation appInfo, Version installedMaxVersion)
 {
     await DownloadAppTask(appInfo, installedMaxVersion).ConfigureAwait(false);
 }