Beispiel #1
0
        public static void PrintAvailableInstanceLayers()
        {
            var availableLayers = Commands.EnumerateInstanceLayerProperties();

            _logger.LogDebug("Available instance layers:");
            foreach (var layer in availableLayers)
            {
                _logger.LogDebug("\t" + layer.LayerName);
            }
        }
Beispiel #2
0
        public static bool InitSections(ControllerMap _controllerMap)
        {
            //MyLogger.LogDebug("InitSections");
            // Loop through our custom actions we added via Rewired
            foreach (int myActionId in CustomKeybindings.myCustomActionIds.Keys)
            {
                // The info that the user specified for this action
                CustomKeybindings.InputActionDescription myActionDescription = CustomKeybindings.myCustomActionIds[myActionId];

                // There are separate keybinding maps for keyboard, mouse, & controllers
                // We only add our action-to-element mappings to the keybind maps that make sense
                // For example, if you are adding a key that doesn't make sense to have on a controller,
                // then skip when _controllerMap is JoystickMap
                //
                // (Optional)
                // You can check if this method is being called for the Keyboard/Mouse bindings panel or
                // the Controller bindings panel, but I prefer to check the class of the _controllerMap
                //   if (self.ControllerType == ControlMappingPanel.ControlType.Keyboard) {
                //

                bool shouldLog = false;
                if (shouldLog)
                {
                    MyLogger.LogDebug("_controllerMap is keyboard or mouse: " + (_controllerMap is KeyboardMap || _controllerMap is MouseMap));
                    MyLogger.LogDebug("_controllerMap is joystick: " + (_controllerMap is JoystickMap));
                    MyLogger.LogDebug("_controllerMap.categoryId: " + _controllerMap.categoryId);
                    MyLogger.LogDebug("action is keyboard: " + (myActionDescription.controlType == ControlType.Keyboard));
                    MyLogger.LogDebug("action is gamepad: " + (myActionDescription.controlType == ControlType.Gamepad));
                    MyLogger.LogDebug("action is both: " + (myActionDescription.controlType == ControlType.Both));
                    MyLogger.LogDebug("action.sectionId: " + myActionDescription.sectionId);
                }

                // If the controller map's control type does not match our action
                if (!(myActionDescription.controlType == ControlType.Keyboard && (_controllerMap is KeyboardMap || _controllerMap is MouseMap) ||
                      myActionDescription.controlType == ControlType.Gamepad && (_controllerMap is JoystickMap) ||
                      myActionDescription.controlType == ControlType.Both))
                {
                    // Then skip to next action
                    continue;
                }

                // If the categoryId of this controller map does not match our action's
                if (_controllerMap.categoryId != myActionDescription.sectionId)
                {
                    // Skip to next action
                    continue;
                }

                // If we pass the tests, create & add the action-to-element map for this particular action
                _controllerMap.CreateElementMap(myActionId, Pole.Positive, KeyCode.None, ModifierKeyFlags.None);

                // Continue the loop...
            }

            // We're done here. Call original implementation
            return(true);
        }
        /// <summary>
        ///     Convert Csv file by metadata description
        ///           use only properties ( get; set; ) field
        ///
        ///    Metadata File as :
        ///        [
        ///          {
        ///         "Column":0,
        ///         "Field":"FL_ID"
        ///             },
        ///         {
        ///         "Column":1,
        ///         "Field":"FL_Dep_Hour"
        ///             },
        ///         {
        ///         "Column":2,
        ///         "Field":"FL_Arrv_Hour"
        ///             }
        ///         ]
        ///
        ///    run as :
        ///            CsvConverter convert = new CsvConverter();
        ///            List<FlightDetail> flight = convert.CsvConvert<FlightDetail>(@"FlList.txt", @"FlList.json");
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="CsvFileName"></param>
        /// <param name="jsonMetoDataFileName"></param>
        /// <returns></returns>
        public List <T> CsvConvert <T>(String CsvFileName, String jsonMetoDataFileName)
        {
            String   jsonString = File.ReadAllText(jsonMetoDataFileName, Encoding.UTF8);
            dynamic  metoData   = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString, typeof(List <MetodataItem>));
            List <T> ret        = new List <T>();


            var bindingFlags = BindingFlags.Public |
                               BindingFlags.Instance;
            var fields = typeof(T).GetFields(bindingFlags);

            var properties = typeof(T).GetProperties();

            T t = (T)Activator.CreateInstance(typeof(T), new object[] { });

            String line = "";

            using (var fs = new FileStream(CsvFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (StreamReader fileReader = new System.IO.StreamReader(fs, System.Text.Encoding.UTF8, false))
                {
                    while ((line = fileReader.ReadLine()) != null)
                    {
                        String[] fieldsItem = line.Split(";");
                        T        Obj        = (T)Activator.CreateInstance(typeof(T), new object[] { });

                        if (properties.Length > 0)
                        {
                            foreach (var item in metoData)
                            {
                                if (item.Column < fieldsItem.Length)
                                {
                                    String       value        = fieldsItem[item.Column];
                                    PropertyInfo propertyInfo = Obj.GetType().GetProperty(item.Field);
                                    if (propertyInfo != null)
                                    {
                                        try
                                        {
                                            object safeValue = MyConvert.ChangeType(value, propertyInfo.PropertyType);
                                            propertyInfo.SetValue(Obj, safeValue, null);
                                        }
                                        catch (Exception ex)
                                        {
                                            // TODO - Exception - check field type
                                            MyLogger.LogDebug($"Error: File - {CsvFileName} {item} field - {propertyInfo.Name} {ex.Message} ");
                                        }
                                    }
                                }
                            }
                        }


                        ret.Add(Obj);
                    }
                }
            }



            return(ret);
        }