/// <summary> /// The process record. /// </summary> protected override void ProcessRecord() { base.ProcessRecord(); try { Status status = Connection.ApiClient.CreateRealServer(Network.id, Name, Server.id, InService).Result; if (status != null && PassThru.IsPresent) { // Regex to extract the Id from the status result detail: Real-Server (id:b1a3aea6-37) created var regexObj = new Regex(@"\x28id\x3A([-\w]*)\x29"); Match match = regexObj.Match(status.resultDetail); if (match.Success && match.Groups.Count > 1) { var rserver = new RealServer { id = match.Groups[1].Value, name = Name, inService = InService.ToString().ToLower(), serverName = Server.name, serverId = Server.id, serverIp = Server.privateIp }; WriteObject(rserver); } else { WriteError(new ErrorRecord(new CloudComputePsException("object Id not returned from API"), "-1", ErrorCategory.InvalidData, status)); } } WriteDebug( string.Format( "{0} resulted in {1} ({2}): {3}", status.operation, status.result, status.resultCode, status.resultDetail)); } catch (AggregateException ae) { ae.Handle( e => { if (e is ComputeApiException) { WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection)); } else { // if (e is HttpRequestException) ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); } return(true); }); } }
/// <inheritdoc cref="CommandBase.PrepareArguments"/> protected override string[] PrepareArguments() { var arguments = new List <string>(); AddOptions(arguments); arguments.AddConditionally( !InService.Equals(Default.InService, StringComparison.OrdinalIgnoreCase), InService); AddCommandAndArguments(arguments); return(arguments.ToArray()); }
// NEXTVERSION // public Country[][] LiveriesPriority { get; private set; } = new Country[2][]; // public string[][] Liveries { get; private set; } = new string[HQTools.EnumCount<Country>()][]; /// <summary> /// Loads data required by this definition. /// </summary> /// <param name="ini">The ini file to load from.</param> /// <returns>True is successful, false if an error happened.</returns> protected override bool OnLoad(INIFile ini) { // -------------- // [Unit] section // -------------- ID = ini.GetValue <string>("Unit", "ID"); if (string.IsNullOrEmpty(ID)) { return(false); } DCSID = ini.GetValue <string>("Unit", "DCSID"); if (string.IsNullOrEmpty(DCSID)) { DCSID = ID; } DisplayName = ini.GetValue <string>("Unit", "DisplayName"); Families = ini.GetValueArray <UnitFamily>("Unit", "Families"); if (Families.Length == 0) { return(false); } Category = HQTools.GetUnitCategoryFromUnitFamily(Families[0]); // All families must belong to the same category. If that's not the case, remove all "wrong" families. Families = (from UnitFamily f in Families where f.ToString().StartsWith(Category.ToString()) select f).ToArray(); if (Families.Length == 0) { return(false); } InService = HQTools.ParseEnumString <TimePeriod>(ini.GetValue <string>("Unit", "InService"), '-', "Decade"); if (InService.Length < 2) { return(false); } InService = InService.Take(2).OrderBy(x => x).ToArray(); ExtraLua = ini.GetValue <string>("Unit", "ExtraLua"); // --------------- // [Comms] section // --------------- CommsRadioFrequency = ini.GetValue <float>("Comms", "RadioFrequency"); CommsRadioFrequency = (CommsRadioFrequency <= 0) ? DEFAULT_RADIO_FREQUENCY : CommsRadioFrequency; CommsTACANChannel = HQTools.Clamp(ini.GetValue <int>("Comms", "TACAN.Channel"), 0, 99); CommsTACANChannelMode = ini.GetValue <string>("Comms", "TACAN.ChannelMode").ToUpperInvariant(); CommsTACANChannelMode = (CommsTACANChannelMode == "Y") ? "Y" : "X"; CommsTACANCallsign = ini.GetValue <string>("Comms", "TACAN.Callsign").ToUpperInvariant(); CommsILSChannel = HQTools.Clamp(ini.GetValue <int>("Comms", "ILS.Channel"), 0, 99); // ---------------------------------------------------- // [Aircraft] section (only for planes and helicopters) // ---------------------------------------------------- if ((Category == UnitCategory.Helicopter) || (Category == UnitCategory.Plane)) { AircraftDefaultTask = ini.GetValue <DCSFlightGroupTask>("Aircraft", "DefaultTask"); AircraftAirToAirRating[0] = ini.GetValue <int>("Aircraft", "AirToAirRating.A2APayload"); AircraftAirToAirRating[1] = ini.GetValue <int>("Aircraft", "AirToAirRating.A2GPayload"); AircraftCruiseAltitude = ini.GetValue <int>("Aircraft", "CruiseAltitude") * HQTools.FEET_TO_METERS; if (AircraftCruiseAltitude <= 0) { AircraftCruiseAltitude = Category == UnitCategory.Helicopter ? 350 : 6000; } AircraftCruiseSpeed = ini.GetValue <int>("Aircraft", "CruiseSpeed") * HQTools.KNOTS_TO_METERSPERSECOND; if (AircraftCruiseSpeed <= 0) { AircraftCruiseSpeed = Category == UnitCategory.Helicopter ? 50 : 130; } AircraftPlayerControllable = ini.GetValue <bool>("Aircraft", "PlayerControllable"); AircraftCarrierShipType = ini.GetValueArray <CarrierGroupShipType>("Aircraft", "CarrierShipType"); // ----------------------------------------------------------- // [AircraftPayload] section (only for planes and helicopters) // ----------------------------------------------------------- int i, j; AircraftPayloadCommon = ini.GetValue <string>("AircraftPayload", "Common"); List <PlayerFlightGroupPayloadType> payloadsList = new List <PlayerFlightGroupPayloadType>(); for (i = 0; i < AircraftPayloadPylons.GetLength(0); i++) { for (j = 0; j < AircraftPayloadPylons.GetLength(1); j++) { AircraftPayloadPylons[i, j] = ini.GetValue <string>("AircraftPayload", $"Pylons.{((PlayerFlightGroupPayloadType)i).ToString()}.Pylon{HQTools.ValToString(j + 1, "00")}"); // Each payload with at least one pylon not empty is a valid payload if (!payloadsList.Contains((PlayerFlightGroupPayloadType)i) && !string.IsNullOrEmpty(AircraftPayloadPylons[i, j])) { payloadsList.Add((PlayerFlightGroupPayloadType)i); } } } AircraftAvailablePayloads = payloadsList.ToArray(); } // ------------------ // [Liveries] section // ------------------ // NEXT VERSION //LiveriesPriority[0] = ini.GetValueArray<Country>("Liveries", "Priority.Real"); //LiveriesPriority[1] = ini.GetValueArray<Country>("Liveries", "Priority.Fictional"); //Liveries = new string[HQTools.EnumCount<Country>()][]; //for (int i = 0; i < Liveries.Length; i++) // Liveries[i] = ini.GetValueArray<string>("Liveries", $"Country.{(Country)i}", '|'); return(true); }
private void AddService(IList <string> arguments) { arguments.AddConditionally(!InService.Equals(Default.InService, StringComparison.OrdinalIgnoreCase), InService); }