コード例 #1
0
        private object[] MakeArgs(Type[] types, string[] text, out string error)
        {
            int expected = 0;

            VarConverter[] converters = new VarConverter[types.Length];
            for (int i = 0; i < types.Length; i++)
            {
                var c = GameVar.GetConverter(types[i]);
                if (c == null)
                {
                    error = $"Could not find parser for type '{types[i].FullName}'.";
                    return(null);
                }

                converters[i] = c;
                expected     += c.ExpectedArgCount;
            }

            if (expected != text.Length)
            {
                error = $"Incorrect number of input parts.\nExpected: {expected} parts from {types.Length} parameters, got {text.Length} parts.";
                return(null);
            }

            object[] output    = new object[types.Length];
            int      readIndex = 0;

            for (int i = 0; i < types.Length; i++)
            {
                var      c    = converters[i];
                string[] args = new string[c.ExpectedArgCount];
                System.Array.Copy(text, readIndex, args, 0, c.ExpectedArgCount);
                readIndex += c.ExpectedArgCount;

                object obj = c.Convert(args, out string oops);
                if (oops != null)
                {
                    error = $"Failed to parse argument #{i} ({types[i].Name}):\n{oops}";;
                    return(null);
                }

                output[i] = obj;
            }

            error = null;
            return(output);
        }
コード例 #2
0
        public GameVar(GameVarAttribute atr, FieldInfo field, PropertyInfo prop)
        {
            if (string.IsNullOrWhiteSpace(atr.Name))
            {
                if (prop != null)
                {
                    Name = prop.Name.ToLowerInvariant();
                }
                else
                {
                    Name = field.Name.ToLowerInvariant();
                }
            }
            else
            {
                Name = atr.Name.Trim().ToLowerInvariant();
            }

            Attribute = atr;

            if (prop != null)
            {
                FInfo = new FInfo(prop);
            }
            else
            {
                FInfo = new FInfo(field);
            }

            Converter = GetConverter(FInfo.MemberType);

            if (Converter == null)
            {
                Debug.LogError($"Failed to find converter for GameVar of type: {FInfo.MemberType}. Bad stuff is about to happen.");
                IsValid = false;
            }
            else
            {
                IsValid = true;
            }
        }
コード例 #3
0
ファイル: MainDlg.cs プロジェクト: dh1df/AirScout
        public MainDlg()
        {
            // save current local LocalCulture
            LocalCulture = Application.CurrentCulture;

            // force culture invariant language for GUI
            Application.CurrentCulture = CultureInfo.InvariantCulture;

            // Initailize variables
            VC = new VarConverter();
            VC.AddVar("APPDIR", AppDirectory);
            VC.AddVar("DATADIR", AppDataDirectory);
            VC.AddVar("LOGDIR", LogDirectory);
            VC.AddVar("DATABASEDIR", DatabaseDirectory);
            VC.AddVar("MINLAT", Properties.Settings.Default.Planes_MinLat);
            VC.AddVar("MAXLAT", Properties.Settings.Default.Planes_MaxLat);
            VC.AddVar("MINLON", Properties.Settings.Default.Planes_MinLon);
            VC.AddVar("MAXLON", Properties.Settings.Default.Planes_MaxLon);
            VC.AddVar("MINALTM", Properties.Settings.Default.Planes_MinAlt);
            VC.AddVar("MAXALTM", Properties.Settings.Default.Planes_MaxAlt);
            VC.AddVar("MINALTFT", (int)UnitConverter.m_ft((double)Properties.Settings.Default.Planes_MinAlt));
            VC.AddVar("MAXALTFT", (int)UnitConverter.m_ft((double)Properties.Settings.Default.Planes_MaxAlt));

            // initilaize web feeds selection boxes and background workers
            InitializeWebFeeds();

            InitializeComponent();

            // uprade settings from previous versions on first run (if not Linux)
            if (Properties.Settings.Default.Application_FirstRun && !SupportFunctions.IsMono)
            {
                Console.WriteLine("First run...");
                Properties.Settings.Default.Upgrade();
                foreach (SettingsPropertyValue p in Properties.Settings.Default.PropertyValues)
                {
                    Console.WriteLine(p.Name + ":" + p.PropertyValue.ToString());
                }
            }

            // open database
            if (Properties.Settings.Default.WebFeed1_Settings != null)
            {
                Console.WriteLine("WebFeed1 Settings:" + Properties.Settings.Default.WebFeed1_Settings.URL);
            }
            if (Properties.Settings.Default.WebFeed2_Settings != null)
            {
                Console.WriteLine("WebFeed2 Settings:" + Properties.Settings.Default.WebFeed2_Settings.URL);
            }
            if (Properties.Settings.Default.WebFeed3_Settings != null)
            {
                Console.WriteLine("WebFeed3 Settings:" + Properties.Settings.Default.WebFeed3_Settings.URL);
            }
            // load application icon here
            Icon = new Icon(IconPath);
            // load notifictaion icon here (if not Linux)
            if (!SupportFunctions.IsMono)
            {
                ni_Main.Icon = new Icon(IconPath);
            }

            // check for all necessary directories
            CheckDirectories();
            // implement an Idle procedure
//             Application.Idle += new EventHandler(OnIdle);

            // configure LogWriter
            ScoutBase.Core.Properties.Settings.Default.LogWriter_Directory     = LogDirectory;
            ScoutBase.Core.Properties.Settings.Default.LogWriter_FileFormat    = Application.ProductName + "_{0:yyyy-MM-dd}.log";
            ScoutBase.Core.Properties.Settings.Default.LogWriter_MessageFormat = "{0:u}: {1}";
            Log = LogWriter.Instance;
            Console.WriteLine("Initializing logfile in: " + LogDirectory);
            Log.WriteMessage(Application.ProductName + " is starting up.", 0, false);

            Model = ELEVATIONMODEL.GLOBE;

            // initialize database
            InitializeDatabase();
            // set initial settings for planes tab
            cb_WebFeed1.DisplayMember = "Name";
            cb_WebFeed2.DisplayMember = "Name";
            cb_WebFeed3.DisplayMember = "Name";
            cb_WebFeed1.Items.Clear();
            cb_WebFeed2.Items.Clear();
            cb_WebFeed3.Items.Clear();
            cb_WebFeed1.Items.Add("[none]");
            cb_WebFeed2.Items.Add("[none]");
            cb_WebFeed3.Items.Add("[none]");

            // get installed plane feeds
            ArrayList feeds = new PlaneFeedEnumeration().EnumFeeds();

            foreach (PlaneFeed feed in feeds)
            {
                cb_WebFeed1.Items.Add(feed);
                cb_WebFeed2.Items.Add(feed);
                cb_WebFeed3.Items.Add(feed);
            }
            cb_WebFeed1.SelectedIndex = cb_WebFeed1.FindStringExact(Properties.Settings.Default.Planes_WebFeed1);
            cb_WebFeed2.SelectedIndex = cb_WebFeed1.FindStringExact(Properties.Settings.Default.Planes_WebFeed2);
            cb_WebFeed3.SelectedIndex = cb_WebFeed1.FindStringExact(Properties.Settings.Default.Planes_WebFeed3);

            double d = ElevationData.Database[51, 10, Model];
        }