Exemple #1
0
        public static Tuple <ConsoleColor?, ConsoleColor?> ConsoleColorBegin(ConsoleColor?p_foregroundColor, ConsoleColor?p_backgroundColor)
        {
            ConsoleColor?previousForeColor = null;
            ConsoleColor?previousBackColor = null;

            if (p_foregroundColor != null)
            {
                previousForeColor = Console.ForegroundColor;

                if (Utils.RunningPlatform() == Platform.Linux)
                {
                    Console.Write(GetLinuxVT100ForeColorCodes((ConsoleColor)p_foregroundColor));
                }
                else
                {
                    Console.ForegroundColor = (ConsoleColor)p_foregroundColor;
                }
            }

            if (p_backgroundColor != null)
            {
                if (Utils.RunningPlatform() == Platform.Linux)
                {
                    gLogger.Trace("Linux background colour is not yet implemented. The whole Linux implementation is temporary anyway, until DotNetCore is fixed on Linux.");
                }
                previousBackColor       = Console.BackgroundColor;
                Console.BackgroundColor = (ConsoleColor)p_backgroundColor;
            }
            return(new Tuple <ConsoleColor?, ConsoleColor?>(previousForeColor, previousBackColor));
        }
Exemple #2
0
 // Need different IP for different platforms, and different GwClientID for different developers (if they happen to code and connect to IbGateways at the same time)
 public static (string HostIp, GatewayClientID GwClientID) GetHostIpAndGatewayClientID(GatewayId p_gatewayId)
 {
     switch (Utils.RunningPlatform())
     {
     case Platform.Linux:
         return(p_gatewayId switch
         {
             GatewayId.CharmatMain => (ServerIp.LocalhostLoopbackWithIP, GatewayClientID.SqCoreToDcProd),
             GatewayId.DeBlanzacMain => (ServerIp.LocalhostLoopbackWithIP, GatewayClientID.SqCoreToDbProd),
             GatewayId.GyantalMain => (ServerIp.AtsVirtualBrokerServerPublicIpForClients, GatewayClientID.SqCoreToGaProd),
             _ => throw new NotImplementedException()
         });
Exemple #3
0
 public static void ConsoleColorRestore(Tuple <ConsoleColor?, ConsoleColor?> p_previousColors)
 {
     // Console.ResetColor(); is one option, but it is not that good than going back to previous
     if (p_previousColors.Item1 != null)
     {
         if (Utils.RunningPlatform() == Platform.Linux)
         {
             Console.Write(GetLinuxVT100ForeColorCodes((ConsoleColor)p_previousColors.Item1));
         }
         else
         {
             Console.ForegroundColor = (ConsoleColor)p_previousColors.Item1;
         }
     }
     if (p_previousColors.Item2 != null)
     {
         Console.BackgroundColor = (ConsoleColor)p_previousColors.Item2;
     }
 }
Exemple #4
0
        //http://www.mcnearney.net/blog/windows-timezoneinfo-olson-mapping/
        //http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml
        //string londonZoneId = "GMT Standard Time";      // Linux: "Europe/London"

        // http://mono.1490590.n4.nabble.com/Cross-platform-time-zones-td1507630.html
        //In windows the timezones have a descriptive name such as "Eastern
        //Standard Time" but in linux the same timezone has the name
        //"US/Eastern".
        //Is there a cross platform way of running
        //TimeZoneInfo.FindSystemTimeZoneById that can be used both in linux and
        //windows, or would i have to add additional code to check what platform
        //i am running before getting the time zone.
        //WINDOWS TIMEZONE ID DESCRIPTION                UNIX TIMEZONE ID
        //Eastern Standard Time => GMT - 5 w/DST             => US/Eastern
        //Central Standard Time => GMT - 6 w/DST             => US/Central
        //US Central Standard Time  => GMT-6 w/o DST(Indiana) => US / Indiana - Stark
        //Mountain Standard Time    => GMT-7 w/DST             => US/Mountain
        //US Mountain Standard Time => GMT-7 w/o DST(Arizona) => US / Arizona
        //Pacific Standard Time     => GMT-8 w/DST             => US/Pacific
        //Alaskan Standard Time => GMT - 9 w/DST             => US/Alaska
        //Hawaiian Standard Time => GMT - 10 w/DST            => US/Hawaii
        public static TimeZoneInfo FindSystemTimeZoneById(TimeZoneId p_tzType)
        {
            switch (p_tzType)
            {
            case TimeZoneId.UTC:
                return(TimeZoneInfo.Utc);

            default:
                if (g_tzi.TryGetValue(p_tzType, out TimeZoneInfo? tzi))
                {
                    return(tzi);
                }
                string zoneId;
                switch (p_tzType)
                {
                case TimeZoneId.London:
                    if (Utils.RunningPlatform() == Platform.Windows)
                    {
                        zoneId = "GMT Standard Time";
                    }
                    else
                    {
                        zoneId = "Europe/London";
                    }
                    break;

                case TimeZoneId.EST:
                    if (Utils.RunningPlatform() == Platform.Windows)
                    {
                        zoneId = "Eastern Standard Time";
                    }
                    else
                    {
                        zoneId = "America/New_York";                // or "US/Eastern". We have to test it.
                    }
                    break;

                case TimeZoneId.CET:
                    if (Utils.RunningPlatform() == Platform.Windows)
                    {
                        zoneId = "Central Europe Standard Time";
                    }
                    else
                    {
                        zoneId = "Europe/Budapest";
                    }
                    break;

                default:
                    throw new Exception($"TimeZoneType {p_tzType} is unexpected.");
                }
                try
                {
                    tzi = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
                }
                catch (Exception e)
                {
                    Utils.Logger.Error("ERROR: Unable to find the {0} zone in the registry. {1}", zoneId, e.Message);
                    throw;
                }
                g_tzi[p_tzType] = tzi;
                return(tzi);
            }
        }