Ejemplo n.º 1
0
        private static async Task DownloadUpdater(Uri address, string updaterDirectory, string zipFileName,
                                                  Action <DownloadProgressChangedEventArgs> eventHandler)
        {
            Directory.CreateDirectory(updaterDirectory);

            var sequence = new Sequence();
            var previousEventTimestamp = 0;

            using (var webClient = new WebClient())
            {
                webClient.DownloadProgressChanged += (sender, args) =>
                {
                    if (sequence.Next() == 0)
                    {
                        previousEventTimestamp = UniversalTime.GetTickCount();
                        eventHandler(args);
                    }
                    else
                    {
                        var current = UniversalTime.GetTickCount();
                        var elapsed = current - previousEventTimestamp;
                        if (elapsed >= 1000)
                        {
                            previousEventTimestamp = current;
                            eventHandler(args);
                        }
                    }
                };
                await webClient.DownloadFileTaskAsync(address, zipFileName);
            }
        }
Ejemplo n.º 2
0
        public static string GetEnvironmentInfo()
        {
            var tickCount              = UniversalTime.GetTickCount();
            var totalDays              = (double)tickCount / DateTimeConstants.MillisecondsPerDay;
            var zeroDateTime           = LocalTime.Default.Now.AddDays(-totalDays);
            var tickCountString        = $"{tickCount} ({totalDays:N2} days(s) from {zeroDateTime:yyyy.MM.dd HH:mm:ss})";
            var workingSet             = Environment.WorkingSet;
            var dotNetFrameworkRelease = GetDotNetFrameworkRelease();
            var dotNetFrameworkVersion = GetDotNetFrameworkVersion(dotNetFrameworkRelease);
            var windowsVersionInfo     = GetWindowsVersionInfo();

            var message = $@"Environment information
MachineName:            {Environment.MachineName}
ProcessorCount:         {Environment.ProcessorCount}
OSVersion:              {Environment.OSVersion}
Windows ProductName:    {windowsVersionInfo.ProductName}
Windows ReleaseId:      {windowsVersionInfo.ReleaseId}
Windows CurrentBuild:   {windowsVersionInfo.CurrentBuild}
Is64BitOperatingSystem: {Environment.Is64BitOperatingSystem}
Is64BitProcess:         {Environment.Is64BitProcess}
IntPtr.Size:            {IntPtr.Size} ({IntPtr.Size * 8} bit)
CLR version:            {Environment.Version}
.NET Framework release: {dotNetFrameworkRelease}
.NET Framework version: {dotNetFrameworkVersion}
UserDomainName:         {Environment.UserDomainName}
UserName:               {Environment.UserName}
UserInteractive:        {Environment.UserInteractive}
CurrentDirectory:       {Environment.CurrentDirectory}
CommandLine:            {Environment.CommandLine},
GC IsServerGC:          {GCSettings.IsServerGC}
GC LargeObjectHeapCompactionMode: {GCSettings.LargeObjectHeapCompactionMode}
GC LatencyMode:         {GCSettings.LatencyMode}
WorkingSet:             {(double) workingSet / (1024 * 1024):N} MB ({workingSet} bytes)
TickCount:              {tickCountString}
Stopwatch.Frequency:    {Stopwatch.Frequency}";

            return(message);
        }