コード例 #1
0
ファイル: Stack.cs プロジェクト: pand5461/KOS-1
        private void dumpItem(int index, bool isSP, object item, StringBuilder builder)
        {
            builder.AppendLine(string.Format("{0:000} {1,4} {2} (type: {3})", index, (isSP ? "SP->" : ""),
                                             (item == null ? "<null>" : item.ToString()),
                                             (item == null ? "<n/a>" : KOSNomenclature.GetKOSName(item.GetType()))));
            builder.AppendLine();
            VariableScope dict = item as VariableScope;

            if (dict != null)
            {
                Int16 parentScopeId = -1;
                if (dict.ParentScope != null)
                {
                    parentScopeId = dict.ParentScope.ScopeId;
                }

                builder.AppendFormat("          ScopeId={0}, ParentScopeId={1}, IsClosure={2}",
                                     dict.ScopeId, parentScopeId, dict.IsClosure);
                builder.AppendLine();
                // Dump the local variable context stored here on the stack:
                foreach (var entry in dict.Locals)
                {
                    builder.AppendFormat("            local var {0} is {1} with value = {2}", entry.Key, KOSNomenclature.GetKOSName(entry.Value.GetType()), entry.Value);
                    builder.AppendLine();
                }
            }
        }
コード例 #2
0
ファイル: Structure.cs プロジェクト: stephengeorgewest/KOS-1
        public virtual BooleanValue GetKOSIsType(StringValue queryTypeName)
        {
            // We can't use Reflection's IsAssignableFrom because of the annoying way Generics work under Reflection.

            for (Type t = GetType(); t != null; t = t.BaseType)
            {
                // Our KOSNomenclature mapping can't store a Dictionary mapping for all
                // the new generics types that get made on the fly and weren't present when the static constructor was made.
                // So instead we ask Reflection to get the base from which it came so we can look that up instead.
                if (t.IsGenericType)
                {
                    t = t.GetGenericTypeDefinition();
                }

                if (KOSNomenclature.HasKOSName(t))
                {
                    string kOSname = KOSNomenclature.GetKOSName(t);
                    if (kOSname == queryTypeName)
                    {
                        return(true);
                    }
                    if (t == typeof(Structure))
                    {
                        break; // don't bother walking further up - there won't be any more KOS types above this.
                    }
                }
            }
            return(false);
        }
コード例 #3
0
        private static string GetMessage(string op, OperandPair pair)
        {
            string t1 = pair.Left == null ? "<null>" : KOSNomenclature.GetKOSName(pair.Left.GetType());
            string t2 = pair.Right == null ? "<null>" : KOSNomenclature.GetKOSName(pair.Right.GetType());

            return(string.Format("Cannot perform the operation: {0} On Structures {1} and {2}", op, t1, t2));
        }
コード例 #4
0
        public string Dump()
        {
            var builder = new StringBuilder();

            builder.AppendLine("Stack dump: stackPointer = " + stackPointer);

            // Print in reverse order so the top of the stack is on top of the printout:
            // (actually given the double nature of the stack, one of the two sub-stacks
            // inside it will always be backwardly printed):
            for (int index = stack.Count - 1; index >= 0; --index)
            {
                object item = stack[index];
                builder.AppendLine(string.Format("{0:000} {1,4} {2} (type: {3})", index, (index == stackPointer ? "SP->" : ""),
                                                 (item == null ? "<null>" : item.ToString()),
                                                 (item == null ? "<n/a>" : KOSNomenclature.GetKOSName(item.GetType()))));
                VariableScope dict = item as VariableScope;
                if (dict != null)
                {
                    builder.AppendFormat("          ScopeId={0}, ParentScopeId={1}, ParentSkipLevels={2} IsClosure={3}",
                                         dict.ScopeId, dict.ParentScopeId, dict.ParentSkipLevels, dict.IsClosure);
                    builder.AppendLine();
                    // Dump the local variable context stored here on the stack:
                    foreach (string varName in dict.Variables.Keys)
                    {
                        var value = dict.Variables[varName].Value;
                        builder.AppendFormat("            local var {0} is {1} with value = {2}", varName, KOSNomenclature.GetKOSName(value.GetType()), dict.Variables[varName].Value);
                        builder.AppendLine();
                    }
                }
            }

            return(builder.ToString());
        }
コード例 #5
0
ファイル: Bootstrapper.cs プロジェクト: dewiniaid/KOS
        public void Start()
        {
            BuildEnvironment();
            BuildLogger();

            CheckForLegacyArchive();

            KOSNomenclature.PopulateMapping(typeof(kOS.Safe.Encapsulation.Structure).Assembly, this.GetType().Assembly);
        }
コード例 #6
0
 public void SetNavMode(object navMode)
 {
     navMode = Safe.Encapsulation.Structure.FromPrimitiveWithAssert(navMode);
     if (!(navMode is Safe.Encapsulation.StringValue))
     {
         throw new KOSWrongControlValueTypeException(
                   "NAVMODE", KOSNomenclature.GetKOSName(navMode.GetType()), "string (\"ORBIT\", \"SURFACE\" or \"TARGET\")");
     }
     SetNavMode(navMode.ToString());
 }
コード例 #7
0
        void IFlightControlParameter.UpdateValue(object value, SharedObjects shared)
        {
            if (!Enabled)
            {
                ((IFlightControlParameter)this).EnableControl(shared);
            }

            float bearing = 0;

            if (value is VesselTarget)
            {
                bearing = VesselUtils.GetTargetBearing(controlShared.Vessel, ((VesselTarget)value).Vessel);
            }
            else if (value is GeoCoordinates)
            {
                bearing = ((GeoCoordinates)value).GetBearing();
            }
            else
            {
                try
                {
                    double doubleValue = Convert.ToDouble(value);
                    if (Utils.IsValidNumber(doubleValue))
                    {
                        bearing = (float)(Math.Round(doubleValue) - Mathf.Round(FlightGlobals.ship_heading));
                        if (bearing < -180)
                        {
                            bearing += 360; // i.e. 359 degrees to the left is really 1 degree to the right.
                        }
                        else if (bearing > 180)
                        {
                            bearing -= 360; // i.e. 359 degrees to the right is really 1 degree to the left
                        }
                    }
                }
                catch
                {
                    throw new KOSWrongControlValueTypeException(
                              "WHEELSTEERING",
                              KOSNomenclature.GetKOSName(value.GetType()),
                              string.Format(
                                  "{0}, {1}, or {2} (compass heading)",
                                  KOSNomenclature.GetKOSName(typeof(VesselTarget)),
                                  KOSNomenclature.GetKOSName(typeof(GeoCoordinates)),
                                  KOSNomenclature.GetKOSName(typeof(ScalarValue))
                                  )
                              );
                }
            }
            Value = bearing;
        }
コード例 #8
0
 public void SelectAutopilotMode(object autopilotMode)
 {
     autopilotMode = Safe.Encapsulation.Structure.FromPrimitiveWithAssert(autopilotMode);
     if ((autopilotMode is Safe.Encapsulation.StringValue))
     {
         SelectAutopilotMode(autopilotMode.ToString());
     }
     else if (autopilotMode is Direction)
     {
         //TODO: implment use of direction subclasses.
         throw new KOSException(
                   string.Format("Cannot set SAS mode to a direction. Should use the name of the mode (as string, e.g. \"PROGRADE\", not PROGRADE) for SASMODE. Alternatively, can use LOCK STEERING TO Direction instead of using SAS"));
     }
     else
     {
         throw new KOSWrongControlValueTypeException(
                   "SASMODE", KOSNomenclature.GetKOSName(autopilotMode.GetType()), "name of the SAS mode (as string)");
     }
 }
コード例 #9
0
ファイル: ThrottleManager.cs プロジェクト: pand5461/KOS-1
        void IFlightControlParameter.UpdateValue(object value, SharedObjects shared)
        {
            if (!Enabled)
            {
                ((IFlightControlParameter)this).EnableControl(shared);
            }

            try
            {
                Value = KOSMath.Clamp(Convert.ToDouble(value), 0, 1);
            }
            catch
            {
                throw new KOSWrongControlValueTypeException(
                          "THROTTLE",
                          KOSNomenclature.GetKOSName(value.GetType()),
                          string.Format("{0} in the range [0..1]", KOSNomenclature.GetKOSName(typeof(ScalarValue)))
                          );
            }
        }
コード例 #10
0
ファイル: Structure.cs プロジェクト: stephengeorgewest/KOS-1
        public virtual StringValue GetKOSInheritance()
        {
            StringBuilder sb = new StringBuilder();

            string prevKosName = "";

            for (Type t = GetType(); t != null; t = t.BaseType)
            {
                // Our KOSNomenclature mapping can't store a Dictionary mapping for all
                // the new generics types that get made on the fly and weren't present when the static constructor was made.
                // So instead we ask Reflection to get the base from which it came so we can look that up instead.
                if (t.IsGenericType)
                {
                    t = t.GetGenericTypeDefinition();
                }

                if (KOSNomenclature.HasKOSName(t))
                {
                    string kOSname = KOSNomenclature.GetKOSName(t);
                    if (kOSname != prevKosName) // skip extra iterations where we mash parent C# types and child C# types into the same KOS type.
                    {
                        if (prevKosName != "")
                        {
                            sb.Append(" derived from ");
                        }
                        sb.Append(kOSname);
                    }
                    prevKosName = kOSname;
                    if (t == typeof(Structure))
                    {
                        break; // don't bother walking further up - there won't be any more KOS types above this.
                    }
                }
            }
            return(sb.ToString());
        }
コード例 #11
0
ファイル: Structure.cs プロジェクト: stephengeorgewest/KOS-1
 public override string ToString()
 {
     return(KOSNomenclature.GetKOSName(GetType()) + ": \"\""); // print as the KOSNomenclature string name, will look like: Structure: ""
 }
コード例 #12
0
 /// <summary>
 /// Make an exception when an attempt to convert from one type to another failed.
 /// </summary>
 public KOSCastException(Type typeFrom, Type typeTo)
     : this(KOSNomenclature.GetKOSName(typeFrom), KOSNomenclature.GetKOSName(typeTo))
 {
 }