aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/SecondsToGraphPointsConverter.cs
blob: 17df7b9d5e15460a20892532076c4b49b4ddd6c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Tango.MachineStudio.Common.Converters
{
    /// <summary>
    /// Converts number of seconds to graph FIFO capacity.
    /// </summary>
    /// <seealso cref="System.Windows.Data.IValueConverter" />
    public class SecondsToGraphPointsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double arrLength = double.Parse(parameter.ToString());
            return Helpers.GraphsHelper.GetMaxPoints(arrLength);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }
}
private set; } private InstallerBuilder() { double latestVersion = 0.0; //Extract the latest advanced installer version... foreach (var folder in Directory.GetDirectories(ADVANCED_INSTALLER_BASE_FOLDER)) { try { var versionString = Regex.Match(Path.GetFileName(folder), @"\d+\.*\d+").Value; double version = double.Parse(versionString); if (version > latestVersion) { latestVersion = version; } } catch { } } AdvancedInstallerPath = $@"{ADVANCED_INSTALLER_BASE_FOLDER}\Advanced Installer {latestVersion}\bin\x86\AdvancedInstaller.com"; } public InstallerBuilder(String projectFile) : this() { ProjectFile = projectFile; } public InstallerBuilder(String advancedInstallerPath, String projectFile) : this(projectFile) { AdvancedInstallerPath = advancedInstallerPath; } public Task<String> GetProperty(ProjectProperty property) { return Task.Factory.StartNew<String>(() => { CmdCommand command = new CmdCommand(AdvancedInstallerPath, $"/edit \"{ProjectFile}\" /GetProperty {property.ToString()}"); var result = command.Run().Result; return result.StandardOutput.Replace("\r", "").Replace("\n", ""); }); } public Task SetProperty(ProjectProperty property, String value) { return Task.Factory.StartNew(() => { CmdCommand command = new CmdCommand(AdvancedInstallerPath, $"/edit \"{ProjectFile}\" /SetProperty {property.ToString()}=\"{value}\""); command.Run().Wait(); String propValue = GetProperty(property).Result; if (propValue != value) { throw new ArgumentException("The property set command had succeeded but the property value validation has failed."); } }); } public Task Build(String productVersion, String outputFile) { return Task.Factory.StartNew(() => { CmdCommand command = new CmdCommand(AdvancedInstallerPath, $"/edit \"{ProjectFile}\" /SetVersion {productVersion}"); command.Run().Wait(); command = new CmdCommand(AdvancedInstallerPath, $"/edit \"{ProjectFile}\" /SetPackageName \"{outputFile}\" -buildname DefaultBuild"); command.Run().Wait(); command = new CmdCommand(AdvancedInstallerPath, $"/rebuild \"{ProjectFile}\""); command.Timeout = TimeSpan.FromMinutes(2); command.Run().Wait(); }); } public Task Uninstall() { return Task.Factory.StartNew(() => { String productName = GetProperty(ProjectProperty.ProductName).Result; CmdCommand command = new CmdCommand("wmic", $"product where name=\"{productName}\" call uninstall /nointeractive"); command.ExitStrategy = CmdCommand.ExitStrategies.StandardOutput; command.Run().Wait(); }); } public Task<bool> IsInstalled() { return Task.Factory.StartNew<bool>(() => { String productName = GetProperty(ProjectProperty.ProductName).Result; CmdCommand command = new CmdCommand("wmic", $"product get name"); command.ExitStrategy = CmdCommand.ExitStrategies.StandardOutput; var result = command.Run().Result; List<String> list = result.StandardOutput.Split(new[] { '\r', '\n' }).ToList(); bool found = list.Any(x => x.Trim() == productName); return found; }); } } }