Exemplo n.º 1
0
        public string Validate(IDictionaryAdapter dictionaryAdapter)
        {
            List <string> errors      = new List <string>();
            var           globalRules = AttributesUtil.GetTypeAttributes <ValidationRuleAttribute>(
                dictionaryAdapter.Meta.Type
                );

            foreach (var property in dictionaryAdapter.This.Properties.Values)
            {
                var propertyRules = AttributesUtil
                                    .GetAttributes <ValidationRuleAttribute>(property.Property)
                                    .Select(x => (IValidationRule)x);
                var propertyValue = dictionaryAdapter.GetProperty(property.PropertyName, true);
                ApplyValidationRules(
                    dictionaryAdapter,
                    propertyRules,
                    property,
                    propertyValue,
                    errors
                    );
                ApplyValidationRules(
                    dictionaryAdapter,
                    globalRules,
                    property,
                    propertyValue,
                    errors
                    );
            }

            return(string.Join(Environment.NewLine, errors.ToArray()));
        }
Exemplo n.º 2
0
        private static PropertyInfo[] GetManagedProperties(object mobInstance)
        {
            var properties = mobInstance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
                             .Where(property => AttributesUtil.HasAttribute <ManagedPropertyAttribute>(property))
                             .ToArray();

            return(properties);
        }
Exemplo n.º 3
0
        private void ObtainTypeConverter()
        {
            var converterType = AttributesUtil.GetTypeConverter(Property);

            TypeConverter = (converterType != null)
                                ? (TypeConverter)Activator.CreateInstance(converterType)
                                : TypeDescriptor.GetConverter(PropertyType);
        }
Exemplo n.º 4
0
        public void ProcessModel(IKernel kernel, ComponentModel model)
        {
            var cachedMethods = model.Implementation.GetMethods().Where(m => AttributesUtil.GetAttribute <LoggingAttribute>(m) != null).ToList();

            if (cachedMethods.Any())
            {
                model.Interceptors.AddIfNotInCollection(InterceptorReference.ForType <LoggingInterceptor>());
            }
        }
Exemplo n.º 5
0
        public string Validate(IDictionaryAdapter dictionaryAdapter, PropertyDescriptor property)
        {
            List <String> errors      = new List <string>();
            var           globalRules = AttributesUtil.GetTypeAttributes <IValidationRule>(dictionaryAdapter.Meta.Type);

            var propertyRules = AttributesUtil.GetAttributes <IValidationRule>(property.Property);
            var propertyValue = dictionaryAdapter.GetProperty(property.PropertyName, true);

            ApplyValidationRules(dictionaryAdapter, propertyRules, property, propertyValue, errors);
            ApplyValidationRules(dictionaryAdapter, globalRules, property, propertyValue, errors);

            return(String.Join(Environment.NewLine, errors.ToArray()));
        }
Exemplo n.º 6
0
            public IEnumerable <ServiceInfo> GetServicesFrom(Type type)
            {
                ServiceAttribute atr = AttributesUtil.GetAttribute <ServiceAttribute>(type);

                if (atr.ContractName == this.annotation)
                {
                    return new[] { new ServiceInfo(typeof(IService), type, Lifetime.Instance) }
                }
                ;

                return(new ServiceInfo[] {});
            }
        }
        public EventEditorFactoryImp()
        {
            this.eventEditors = new List <EventEditor> ();

            var methods = AttributesUtil.GetMethodsWith <GameEventAttribute>(typeof(EventedEventManager), true);

            foreach (var m in methods)
            {
                this.eventEditors.Add(new AttributeEventEditor(new GameEventConfig(m.Key, m.Value)));
            }

            /*this.eventEditors.Add (new ChangeSwitchEventEditor ());
             * this.eventEditors.Add (new AddItemEditor ());
             * this.eventEditors.Add(new MoveEventEditor());
             */

            this.defaultEventEditor = new DefaultEventEditor();
        }
Exemplo n.º 8
0
 private Dictionary <string, Type> GetPossibleCreations()
 {
     if (possibleCreationsCache == null)
     {
         possibleCreationsCache = new Dictionary <string, Type>();
         // Make sure is a DOMWriter
         var contents = AttributesUtil.GetTypesWith <NodeContentAttribute>(true).Where(t => (typeof(Checkable)).IsAssignableFrom(t));
         foreach (var content in contents)
         {
             foreach (var attr in content.GetCustomAttributes(typeof(NodeContentAttribute), true))
             {
                 var nodeContent = attr as NodeContentAttribute;
                 var name        = nodeContent.Name == string.Empty ? content.ToString() : nodeContent.Name;
                 possibleCreationsCache.Add(name, content);
             }
         }
     }
     return(possibleCreationsCache);
 }
 private static IEnumerable <T> GetPropertyBehaviors <T>(MemberInfo member) where T : class
 {
     return(AttributesUtil.GetAttributes <T>(member));
 }
 private static IEnumerable <T> GetInterfaceBehaviors <T>(Type type) where T : class
 {
     return(AttributesUtil.GetTypeAttributes <T>(type));
 }
        static int Main(string[] args)
        {
            bool   shouldShowHelp    = false;
            string robot_info_file   = null;
            string robot_name        = null;
            bool   wait_signal       = false;
            bool   electric_gripper  = false;
            bool   vacuum_gripper    = false;
            string gripper_info_file = null;
            string gripper_name      = null;

            var options = new OptionSet {
                { "robot-info-file=", "the robot info YAML file", n => robot_info_file = n },
                { "robot-name=", "override the robot device name", n => robot_name = n },
                { "h|help", "show this message and exit", h => shouldShowHelp = h != null },
                { "electric-gripper", "rethink electric gripper is attached", n => electric_gripper = n != null },
                { "vacuum-gripper", "rethink vacuum gripper is attached", n => vacuum_gripper = n != null },
                { "gripper-info-file=", "gripper info file", n => gripper_info_file = n },
                { "gripper-name=", "override the gripper device name", n => gripper_name = n },
                { "wait-signal", "wait for POSIX sigint or sigkill to exit", n => wait_signal = n != null }
            };

            List <string> extra;

            try
            {
                // parse the command line
                extra = options.Parse(args);
            }
            catch (OptionException e)
            {
                // output some error message
                Console.Write("SawyerRobotRaconteurDriver: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `SawyerRobotRaconteurDriver --help' for more information.");
                return(1);
            }

            if (shouldShowHelp)
            {
                Console.WriteLine("Usage: SawyerRobotRaconteurDriver [Options+]");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return(0);
            }

            if (robot_info_file == null)
            {
                Console.WriteLine("error: robot-info-file must be specified");
                return(1);
            }

            if (vacuum_gripper && electric_gripper)
            {
                throw new ArgumentException("--vacuum-gripper and --electric-gripper are mutually exclusive");
            }

            Tuple <RobotInfo, LocalIdentifierLocks> robot_info = null;
            Tuple <ToolInfo, LocalIdentifierLocks>  tool_info  = null;
            SawyerRobot    robot   = null;
            ISawyerGripper gripper = null;


            try
            {
                robot_info = RobotInfoParser.LoadRobotInfoYamlWithIdentifierLocks(robot_info_file, robot_name);

                ros_csharp_interop.ros_csharp_interop.init_ros(args, "sawyer_robotraconteur_driver", false);

                if (electric_gripper || vacuum_gripper)
                {
                    tool_info = ToolInfoParser.LoadToolInfoYamlWithIdentifierLocks(gripper_info_file, gripper_name);
                    tool_info.Item1.device_info.parent_device      = robot_info.Item1.device_info.device;
                    tool_info.Item1.device_info.device_origin_pose = new NamedPose
                    {
                        parent_frame = new Identifier {
                            name = "right_hand", uuid = new com.robotraconteur.uuid.UUID
                            {
                                uuid_bytes = new byte[16]
                            }
                        },
                        pose = new Pose {
                            orientation = new Quaternion {
                                w = 1
                            }
                        }
                    };
                }

                robot = new SawyerRobot(robot_info.Item1, "");
                if (electric_gripper)
                {
                    gripper = new SawyerElectricGripper(tool_info.Item1, "right_gripper", "");
                    gripper._start_tool();
                }
                else if (vacuum_gripper)
                {
                    gripper = new SawyerVacuumGripper(tool_info.Item1, "right_vacuum_gripper", "");
                    gripper._start_tool();
                }

                robot._start_robot();
                using (var node_setup = new ServerNodeSetup("sawyer_robot", 58653, args))
                {
                    var robot_service_ctx = RobotRaconteurNode.s.RegisterService("robot", "com.robotraconteur.robotics.robot", robot);
                    robot_service_ctx.SetServiceAttributes(AttributesUtil.GetDefaultServiceAtributesFromDeviceInfo(robot_info.Item1.device_info));
                    if (gripper != null)
                    {
                        var tool_service_ctx = RobotRaconteurNode.s.RegisterService("gripper", "com.robotraconteur.robotics.tool", gripper);
                        tool_service_ctx.SetServiceAttributes(AttributesUtil.GetDefaultServiceAtributesFromDeviceInfo(tool_info.Item1.device_info));
                    }

                    if (!wait_signal)
                    {
                        Console.WriteLine("Press enter to exit");
                        Console.ReadKey();
                    }
                    else
                    {
                        UnixSignal[] signals = new UnixSignal[] {
                            new UnixSignal(Mono.Unix.Native.Signum.SIGINT),
                            new UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
                        };

                        Console.WriteLine("Press Ctrl-C to exit");
                        // block until a SIGINT or SIGTERM signal is generated.
                        int which = UnixSignal.WaitAny(signals, -1);

                        Console.WriteLine("Got a {0} signal, exiting", signals[which].Signum);
                    }
                }
            }
            finally
            {
                robot_info?.Item2?.Dispose();
                tool_info?.Item2?.Dispose();
                robot?.Dispose();
                gripper?.Dispose();
            }

            return(0);
        }
        private static Dictionary <String, PropertyDescriptor> GetPropertyDescriptors(Type type, PropertyDescriptor initializers, out object[] typeBehaviors)
        {
            var propertyMap        = new Dictionary <String, PropertyDescriptor>();
            var interfaceBehaviors = typeBehaviors = ExpandBehaviors(AttributesUtil.GetInterfaceAttributes(type)).ToArray();
            var defaultFetch       = typeBehaviors.OfType <FetchAttribute>().Select(b => (bool?)b.Fetch).FirstOrDefault().GetValueOrDefault();

#if DOTNET40
            initializers.AddBehaviors(typeBehaviors.OfType <IDictionaryMetaInitializer>())
            .AddBehaviors(typeBehaviors.OfType <IDictionaryInitializer>());
#else
            initializers.AddBehaviors(typeBehaviors.OfType <IDictionaryMetaInitializer>().Cast <IDictionaryBehavior>())
            .AddBehaviors(typeBehaviors.OfType <IDictionaryInitializer>    ().Cast <IDictionaryBehavior>());
#endif

            CollectProperties(type, property =>
            {
                var propertyBehaviors  = ExpandBehaviors(AttributesUtil.GetAttributes <object>(property)).ToArray();
                var propertyDescriptor = new PropertyDescriptor(property, propertyBehaviors)
                                         .AddBehaviors(propertyBehaviors.OfType <IDictionaryBehavior>())
                                         .AddBehaviors(interfaceBehaviors.OfType <IDictionaryBehavior>().Where(b => b is IDictionaryKeyBuilder == false))
#if DOTNET40
                                         .AddBehaviors(ExpandBehaviors(AttributesUtil
                                                                       .GetInterfaceAttributes(property.ReflectedType))
                                                       .OfType <IDictionaryKeyBuilder>());
#else
                                         .AddBehaviors(ExpandBehaviors(AttributesUtil
                                                                       .GetInterfaceAttributes(property.ReflectedType))
                                                       .OfType <IDictionaryKeyBuilder>()
                                                       .Cast <IDictionaryBehavior>());
#endif

                AddDefaultGetter(propertyDescriptor);

                var propertyFetch           = propertyBehaviors.OfType <FetchAttribute>().Select(b => (bool?)b.Fetch).FirstOrDefault();
                propertyDescriptor.IfExists = propertyBehaviors.OfType <IfExistsAttribute>().Any();
                propertyDescriptor.Fetch    = propertyFetch.GetValueOrDefault(defaultFetch);

                foreach (var descriptorInitializer in propertyDescriptor.Behaviors.OfType <IPropertyDescriptorInitializer>())
                {
                    descriptorInitializer.Initialize(propertyDescriptor, propertyBehaviors);
                }

#if DOTNET40
                initializers.AddBehaviors(propertyBehaviors.OfType <IDictionaryMetaInitializer>());
#else
                initializers.AddBehaviors(propertyBehaviors.OfType <IDictionaryMetaInitializer>().Cast <IDictionaryBehavior>());
#endif

                PropertyDescriptor existingDescriptor;
                if (propertyMap.TryGetValue(property.Name, out existingDescriptor))
                {
                    var existingProperty = existingDescriptor.Property;
                    if (existingProperty.PropertyType == property.PropertyType)
                    {
                        if (property.CanRead && property.CanWrite)
                        {
                            propertyMap[property.Name] = propertyDescriptor;
                        }
                        return;
                    }
                }

                propertyMap.Add(property.Name, propertyDescriptor);
            });
 /// <inheritdoc />
 public override IEnumerable <Type> BuildSerializableTypes()
 {
     //Then we want to register DTOs for unknown
     return(GamePacketStubMetadataMarker.GamePacketPayloadStubTypes
            .Where(t => GamePacketMetadataMarker.UnimplementedOperationCodes.Value.Contains(AttributesUtil.GetAttribute <GamePayloadOperationCodeAttribute>((Type)t).OperationCode))
            .Concat(GamePacketMetadataMarker.SerializableTypes)
            .ToArray());
 }
Exemplo n.º 14
0
        static int Main(string[] args)
        {
            bool   shouldShowHelp  = false;
            string robot_info_file = null;
            string robot_name      = null;
            ushort tcp_port        = 58653;
            string node_name       = "gazebo_robot";
            string model_name      = null;
            string gazebo_url      = null;

            var options = new OptionSet {
                { "robot-info-file=", n => robot_info_file = n },
                { "robot-name=", "override the robot device name", n => robot_name = n },
                { "model-name=", "the gazebo model to control", n => model_name = n },
                { "gazebo-url=", "url for the Robot Raconteur Gazebo plugin", n => gazebo_url = n },
                { "h|help", "show this message and exit", h => shouldShowHelp = h != null }
            };

            List <string> extra;

            try
            {
                // parse the command line
                extra = options.Parse(args);
            }
            catch (OptionException e)
            {
                // output some error message
                Console.Write("GazeboModelRobotRaconteurDriver: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `GazeboModelRobotRaconteurDriver --help' for more information.");
                return(1);
            }

            if (shouldShowHelp)
            {
                Console.WriteLine("Usage: GazeboModelRobotRaconteurDriver [Options+]");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return(0);
            }

            if (robot_info_file == null)
            {
                Console.WriteLine("error: robot-info-file must be specified");
                return(1);
            }

            if (model_name == null)
            {
                Console.WriteLine("error: model-name must be specified");
                return(1);
            }

            if (gazebo_url == null)
            {
                Console.WriteLine("error: gazebo_url must be specified");
                return(1);
            }

            var robot_info = RobotInfoParser.LoadRobotInfoYamlWithIdentifierLocks(robot_info_file, robot_name);

            robot_info.Item1.robot_capabilities &= (uint)(RobotCapabilities.jog_command | RobotCapabilities.position_command | RobotCapabilities.trajectory_command);

            RobotOperationalMode robot_op_mode = RobotOperationalMode.auto;
            var robot_class = robot_info.Item1?.device_info?.device_classes?.Find(x => x?.class_identifier?.name == "robot");

            if (robot_class?.subclasses != null)
            {
                if (robot_class.subclasses.Contains("cobot"))
                {
                    robot_op_mode = RobotOperationalMode.cobot;
                }
            }


            using (robot_info.Item2)
            {
                using (var node_setup = new ServerNodeSetup(node_name, tcp_port, args))
                {
                    using (var robot = new GazeboRobot(robot_info.Item1, gazebo_url, model_name, robot_op_mode))
                    {
                        robot._start_robot();
                        var robot_service_ctx = RobotRaconteurNode.s.RegisterService("robot", "com.robotraconteur.robotics.robot", robot);
                        robot_service_ctx.SetServiceAttributes(AttributesUtil.GetDefaultServiceAtributesFromDeviceInfo(robot_info.Item1.device_info));

                        Console.WriteLine("Press enter to exit");
                        Console.ReadKey();
                    }
                }
            }

            return(0);
        }
Exemplo n.º 15
0
        private static Dictionary <String, PropertyDescriptor> GetPropertyDescriptors(
            Type type, out IDictionaryInitializer[] typeInitializers,
            out IDictionaryMetaInitializer[] metaInitializers, out object[] typeBehaviors)
        {
            var propertyMap        = new Dictionary <String, PropertyDescriptor>();
            var interfaceBehaviors = typeBehaviors = ExpandBehaviors(AttributesUtil.GetTypeAttributes <object>(type)).ToArray();

            typeInitializers = typeBehaviors.OfType <IDictionaryInitializer>().Prioritize().ToArray();
            metaInitializers = typeBehaviors.OfType <IDictionaryMetaInitializer>().Prioritize().ToArray();
            var defaultFetch = typeBehaviors.OfType <FetchAttribute>().Select(b => b.Fetch).FirstOrDefault();

            CollectProperties(type, property =>
            {
                var propertyBehaviors  = ExpandBehaviors(AttributesUtil.GetAttributes <object>(property)).ToArray();
                var propertyDescriptor = new PropertyDescriptor(property, propertyBehaviors);

                var descriptorInitializers = propertyBehaviors.OfType <IPropertyDescriptorInitializer>();
                foreach (var descriptorInitializer in descriptorInitializers.OrderBy(b => b.ExecutionOrder))
                {
                    descriptorInitializer.Initialize(propertyDescriptor, propertyBehaviors);
                }

                propertyDescriptor.AddKeyBuilders(
                    propertyBehaviors.OfType <IDictionaryKeyBuilder>().Prioritize(
                        ExpandBehaviors(AttributesUtil.GetTypeAttributes <object>(property.ReflectedType)).OfType <IDictionaryKeyBuilder>())
                    );

                propertyDescriptor.AddGetters(
                    propertyBehaviors.OfType <IDictionaryPropertyGetter>().Prioritize(
                        interfaceBehaviors.OfType <IDictionaryPropertyGetter>())
                    );
                AddDefaultGetter(propertyDescriptor);

                propertyDescriptor.AddSetters(
                    propertyBehaviors.OfType <IDictionaryPropertySetter>().Prioritize(
                        interfaceBehaviors.OfType <IDictionaryPropertySetter>())
                    );

                bool?propertyFetch          = (from b in propertyBehaviors.OfType <FetchAttribute>() select b.Fetch).FirstOrDefault();
                propertyDescriptor.IfExists = propertyBehaviors.OfType <IfExistsAttribute>().Any();
                propertyDescriptor.Fetch    = propertyFetch.GetValueOrDefault(defaultFetch);

                PropertyDescriptor existingDescriptor;
                if (propertyMap.TryGetValue(property.Name, out existingDescriptor))
                {
                    var existingProperty = existingDescriptor.Property;
                    if (existingProperty.PropertyType == property.PropertyType)
                    {
                        if (property.CanRead && property.CanWrite)
                        {
                            propertyMap[property.Name] = propertyDescriptor;
                        }
                        return;
                    }
                }

                propertyMap.Add(property.Name, propertyDescriptor);
            });

            return(propertyMap);
        }
        static int Main(string[] args)
        {
            bool   shouldShowHelp = false;
            string tool_info_file = null;
            string robot_url      = null;
            bool   wait_signal    = false;

            var options = new OptionSet {
                { "tool-info-file=", n => tool_info_file = n },
                { "robot-url=", "url for the robot with signals", n => robot_url = n },
                { "wait-signal", "wait for POSIX sigint or sigkill to exit", n => wait_signal = n != null },
                { "h|help", "show this message and exit", h => shouldShowHelp = h != null }
            };

            List <string> extra;

            try
            {
                // parse the command line
                extra = options.Parse(args);
            }
            catch (OptionException e)
            {
                // output some error message
                Console.Write("RobotSignalToolRobotRaconteurDriver: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `RobotSignalToolRobotRaconteurDriver --help' for more information.");
                return(1);
            }

            if (shouldShowHelp)
            {
                Console.WriteLine("Usage: RobotSignalToolRobotRaconteurDriver [Options+]");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                Console.WriteLine("Also supports standard --robotraconteur- node options");
                return(0);
            }

            if (tool_info_file == null)
            {
                Console.WriteLine("error: robot-info-file must be specified");
                return(1);
            }

            if (robot_url == null)
            {
                Console.WriteLine("error: robot-url must be specified");
                return(1);
            }


            Tuple <ToolInfo, LocalIdentifierLocks> tool_info = null;

            tool_info = ToolInfoParser.LoadToolInfoYamlWithIdentifierLocks(tool_info_file);

            using (tool_info.Item2)
                using (var node_setup = new ServerNodeSetup("robot_signal_tool", 58323, args))
                {
                    using (var tool = new UR_CB2_SoftGripper(robot_url, tool_info.Item1))
                    {
                        var tool_service_ctx = RobotRaconteurNode.s.RegisterService("tool", "com.robotraconteur.robotics.tool", tool);
                        tool_service_ctx.SetServiceAttributes(AttributesUtil.GetDefaultServiceAtributesFromDeviceInfo(tool_info.Item1.device_info));

                        if (!wait_signal)
                        {
                            Console.WriteLine("Press enter to exit");
                            Console.ReadKey();
                        }
                        else
                        {
                            UnixSignal[] signals = new UnixSignal[] {
                                new UnixSignal(Mono.Unix.Native.Signum.SIGINT),
                                new UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
                            };

                            Console.WriteLine("Press Ctrl-C to exit");
                            // block until a SIGINT or SIGTERM signal is generated.
                            int which = UnixSignal.WaitAny(signals, -1);

                            Console.WriteLine("Got a {0} signal, exiting", signals[which].Signum);
                        }
                    }
                }

            return(0);
        }