コード例 #1
0
        public override MatchContext Match(TypeDeclaration typeDeclaration, MatchContext context)
        {
            MatchContext newContext = Modifiers.MatchSubset(typeDeclaration.Modifiers, context);

            if (!newContext.Success)
            {
                return(newContext);
            }

            if (Name != null)
            {
                newContext = Name.MatchUst(typeDeclaration.Name, newContext);
                if (!newContext.Success)
                {
                    return(newContext);
                }
            }

            newContext = BaseTypes.MatchSubset(typeDeclaration.BaseTypes, newContext);

            if (!newContext.Success)
            {
                return(newContext);
            }

            if (Body != null)
            {
                if (!typeDeclaration.TypeMembers.Any(m => Body.Match(m, newContext).Success))
                {
                    return(newContext.Fail());
                }
            }

            return(newContext.AddUstIfSuccess(typeDeclaration));
        }
コード例 #2
0
        private Type GetSchemaType(
            IDescriptorContext context,
            MemberInfo member)
        {
            Type?          type       = SchemaType;
            ITypeReference returnType = context.Inspector.GetReturnType(
                member, TypeContext.Output);

            if (type is null &&
                returnType is ClrTypeReference clr &&
                TypeInspector.Default.TryCreate(clr.Type, out var typeInfo))
            {
                if (BaseTypes.IsSchemaType(typeInfo.ClrType))
                {
                    type = typeInfo.ClrType;
                }
                else if (SchemaTypeResolver.TryInferSchemaType(
                             clr.WithType(typeInfo.ClrType),
                             out ClrTypeReference schemaType))
                {
                    type = schemaType.Type;
                }
            }

            if (type is null || !typeof(IType).IsAssignableFrom(type))
            {
                throw new SchemaException(
                          SchemaErrorBuilder.New()
                          .SetMessage("The UsePaging attribute needs a valid node schema type.")
                          .SetCode("ATTR_USEPAGING_SCHEMATYPE_INVALID")
                          .Build());
            }

            return(type);
        }
コード例 #3
0
        public DelegateDeclaration(TypeContainer parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, ParametersCompiled param_list,
                                   VSharpAttributes attrs, CompilationSourceFile file)
            : base(parent, mod_flags | Modifiers.SEALED, AllowedModifiers, name, attrs, name.Location, TypeKind.Delegate, file)

        {
            BaseTypes.Add(KnownTypeReference.MulticastDelegate);
            this.ReturnType = type;
            parameters      = param_list;
            List <IUnresolvedParameter> uparameters = new List <IUnresolvedParameter>();

            foreach (Parameter p in param_list.parameters)
            {
                uparameters.Add(p);
            }


            AddDefaultMethodsToDelegate(type as ITypeReference, uparameters);


            if (attrs != null)
            {
                IUnresolvedMethod invokeMethod = (IUnresolvedMethod)Members.Single(m => m.Name == "Invoke");
                foreach (IUnresolvedAttribute attr in attrs.Attrs.Where(x => x.ExplicitTarget == "ret").ToList())
                {
                    invokeMethod.ReturnTypeAttributes.Add(attr);
                }
            }
        }
コード例 #4
0
ファイル: BaseTypesTest.cs プロジェクト: mjul/diesel
        public void ApplyOverrides_Null_ShouldReturnSameInstance()
        {
            var instance = new BaseTypes(new TypeName[0]);
            var actual   = instance.ApplyOverridesFrom(null);

            Assert.That(actual, Is.SameAs(instance));
        }
コード例 #5
0
        public void Register(
            ITypeRegistrar typeRegistrar,
            IEnumerable <ITypeReference> typeReferences)
        {
            foreach (ClrTypeReference typeReference in typeReferences.OfType <ClrTypeReference>())
            {
                if (!BaseTypes.IsNonGenericBaseType(typeReference.Type) &&
                    _typeInspector.TryCreate(typeReference.Type, out TypeInfo typeInfo))
                {
                    Type type = typeInfo.ClrType;

                    if (IsTypeSystemObject(type))
                    {
                        ClrTypeReference namedTypeReference = typeReference.With(type);

                        if (!typeRegistrar.IsResolved(namedTypeReference))
                        {
                            typeRegistrar.Register(
                                typeRegistrar.CreateInstance(type),
                                typeReference.Scope,
                                BaseTypes.IsGenericBaseType(type));
                        }
                    }
                    else
                    {
                        TryMapToExistingRegistration(
                            typeRegistrar,
                            typeInfo,
                            typeReference.Context,
                            typeReference.Scope);
                    }
                }
            }
        }
コード例 #6
0
        public static Base GetBaseConfiguration(BaseTypes controller)
        {
            Base result = new Base();

            switch (controller)
            {
            case BaseTypes.ATMega128RFA1_V1:
            case BaseTypes.ATMega128RFA1_V2:
                result.UController     = controller;
                result.DeviceSignature = 128;
                result.NumPorts        = 7;
                result.NumPins         = 8;

                result.AnalogPorts      = new string[] { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7" };
                result.PWMPorts         = new string[] { "B4", "B5", "B6", "B7", "E3", "E4", "E5", "G5" }; //VERSION MINOLO:{ "B4", "B7", "G5" } el B7 y el G5 estan compartidos con el mismo timer
                result.UnavailablePorts = new string[] { "G3", "G4" };                                     //TODO: de momento estos pero hay que chequear

                result.LittleEndian = true;
                break;

            default:
                throw new Exception();
            }

            return(result);
        }
コード例 #7
0
    public static bool IsCLSSafe(BaseTypes type)
    {
        var fieldInfo  = typeof(BaseTypes).GetField(typeof(BaseTypes).GetEnumName(type));
        var attributes = fieldInfo.GetCustomAttributes(typeof(CLSASafeAttribute), false);

        return((attributes.Length > 0) && ((CLSASafeAttribute)attributes[0]).CLSSafe);
    }
コード例 #8
0
        protected ITypeReference RewriteTypeListType()
        {
            ITypeReference reference = Definition.Type;

            if (reference is IClrTypeReference clrRef)
            {
                if (BaseTypes.IsSchemaType(clrRef.Type))
                {
                    return(clrRef.WithType(
                               typeof(ListType <>).MakeGenericType(clrRef.Type)));
                }
                else
                {
                    return(clrRef.WithType(
                               typeof(List <>).MakeGenericType(clrRef.Type)));
                }
            }

            if (reference is ISchemaTypeReference schemaRef)
            {
                return(schemaRef.WithType(new ListType((IType)schemaRef.Type)));
            }

            if (reference is ISyntaxTypeReference syntaxRef)
            {
                return(syntaxRef.WithType(new ListTypeNode(syntaxRef.Type)));
            }

            throw new NotSupportedException();
        }
コード例 #9
0
ファイル: NodeManager.cs プロジェクト: zaguarman/SUCC
        internal static object GetNodeData(Node node, Type type)
        {
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle);

            try
            {
                if (type == typeof(string) && node.Value == MultiLineStringNode.Terminator && node.ChildLines.Count > 0)
                {
                    return(BaseTypes.ParseSpecialStringCase(node));
                }

                if (BaseTypes.IsBaseType(type))
                {
                    return(BaseTypes.ParseBaseType(node.Value, type));
                }

                var collection = CollectionTypes.TryGetCollection(node, type);
                if (collection != null)
                {
                    return(collection);
                }

                if (!String.IsNullOrEmpty(node.Value))
                {
                    return(ComplexTypeShortcuts.GetFromShortcut(node.Value, type));
                }

                return(ComplexTypes.RetrieveComplexType(node, type));
            }
            catch (Exception e)
            {
                throw new Exception($"Error getting data of type {type} from node: {e.InnerException}");
            }
        }
コード例 #10
0
ファイル: NodeManager.cs プロジェクト: zaguarman/SUCC
        internal static void SetNodeData(Node node, object data, Type type, FileStyle style)
        {
            if (data == null)
            {
                throw new Exception("you can't serialize null");
            }

            // ensure the type is initialized. This is especially important if it's added as
            // a base type in the type's static constructor.
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle);

            string dataAsString = data as string;

            if (type == typeof(string) && (dataAsString.ContainsNewLine() || node.ChildNodes.Count > 0))
            {
                BaseTypes.SetStringSpecialCase(node, dataAsString, style);
            }

            else if (BaseTypes.IsBaseType(type))
            {
                BaseTypes.SetBaseTypeNode(node, data, type, style);
            }

            else if (CollectionTypes.TrySetCollection(node, data, type, style))
            {
                return;
            }

            else
            {
                ComplexTypes.SetComplexNode(node, data, type, style);
            }
        }
コード例 #11
0
        private static Type GetType(BaseTypes baseType)
        {
            switch (baseType)
            {
            case BaseTypes.Null: return(null);

            case BaseTypes.Boolean: return(typeof(bool));

            case BaseTypes.Byte: return(typeof(byte));

            case BaseTypes.DateTime: return(typeof(DateTime));

            case BaseTypes.Decimal: return(typeof(decimal));

            case BaseTypes.Double: return(typeof(double));

            case BaseTypes.Int32: return(typeof(int));

            case BaseTypes.Int64: return(typeof(long));

            case BaseTypes.Single: return(typeof(float));

            case BaseTypes.String: return(typeof(string));

            case BaseTypes.TimeSpan: return(typeof(TimeSpan));
            }

            throw new Exception($"Type {baseType} was not expected. Cannot Serialize.");
        }
コード例 #12
0
        /// <summary>
        /// To be merged with another type definition, <see cref="Kind"/> and <see cref="TypeName.Key"/> must be the same
        /// otherwise an <see cref="InvalidOperationException"/> is thrown.
        /// </summary>
        /// <param name="other">The other type definition.</param>
        /// <returns>The merged definition.</returns>
        public void MergeWith(TypeDefinition other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }
            if (Kind != other.Kind)
            {
                throw new InvalidOperationException($"Unable to merge type '{ToString()}' with '{other}': Kind differ {Kind} vs. {other.Kind}.");
            }
            if (Name.Key != other.Name.Key)
            {
                throw new InvalidOperationException($"Unable to merge type '{ToString()}' with '{other}': TypeDefinitionKey differ {Name.Key} vs. {other.Name.Key}.");
            }

            Attributes.MergeWith(other.Attributes);
            Modifiers |= other.Modifiers;

            var baseTypes = new HashSet <ExtendedTypeName>(BaseTypes.Concat(other.BaseTypes));

            BaseTypes.Clear();
            BaseTypes.AddRange(baseTypes);

            var constraints = new HashSet <TypeParameterConstraint>(Constraints.Concat(other.Constraints));

            Constraints.Clear();
            Constraints.AddRange(constraints);
        }
コード例 #13
0
 /// <include file='doc\CodeTypeDelegate.uex' path='docs/doc[@for="CodeTypeDelegate.CodeTypeDelegate"]/*' />
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of <see cref='System.CodeDom.CodeTypeDelegate'/>.
 ///    </para>
 /// </devdoc>
 public CodeTypeDelegate()
 {
     TypeAttributes &= ~TypeAttributes.ClassSemanticsMask;
     TypeAttributes |= TypeAttributes.Class;
     BaseTypes.Clear();
     BaseTypes.Add(new CodeTypeReference("System.Delegate"));
 }
コード例 #14
0
ファイル: SDType.cs プロジェクト: llenroc/sharpDox
        private string GetInheritText(bool linked)
        {
            var inheritedText = ImplementedInterfaces.Count > 0 ?
                                string.Join(", ", ImplementedInterfaces.Select(i => linked ? i.LinkedNameWithArguments :
                                                                               i.NameWithTypeArguments).ToList()) : string.Empty;

            var baseText = string.Empty;

            if (BaseTypes.Any())
            {
                baseText = linked ? BaseTypes.First().LinkedNameWithArguments : BaseTypes.First().NameWithTypeArguments;
            }

            if (inheritedText != string.Empty && baseText != string.Empty)
            {
                inheritedText += ", " + baseText;
                inheritedText  = " : " + inheritedText;
            }
            else if (inheritedText != string.Empty)
            {
                inheritedText = " : " + inheritedText;
            }
            else if (baseText != string.Empty)
            {
                inheritedText = " : " + baseText;
            }

            return(inheritedText);
        }
コード例 #15
0
        private void SaveNewItem(Match item, Types itemType, BaseTypes itemBaseType)
        {
            ItemDB newItem = new ItemDB();

            newItem.Name = item.Groups["name"].Value;

            if (item.Groups["level"].Value != "")
            {
                newItem.Level = byte.Parse(item.Groups["level"].Value);
            }

            string baseType = itemBaseType.BaseTypeToString();

            newItem.BaseType = _context.BaseTypes.SingleOrDefault(i => i.Name == baseType);

            string type = itemType.TypeToString();

            newItem.Type = _context.Types.SingleOrDefault(i => i.Name == type);

            bool isItemInDb = _context.ItemsDB.Select(i => i.Name).Contains(newItem.Name);

            if (!isItemInDb)
            {
                try
                {
                    _context.ItemsDB.Add(newItem);
                    LogNewItem(newItem);
                }
                catch (Exception e)
                {
                    LogError(e);
                }
            }
        }
コード例 #16
0
        public ISchemaBuilder BindClrType(Type clrType, Type schemaType)
        {
            if (clrType == null)
            {
                throw new ArgumentNullException(nameof(clrType));
            }

            if (schemaType == null)
            {
                throw new ArgumentNullException(nameof(schemaType));
            }

            if (!BaseTypes.IsSchemaType(schemaType))
            {
                // TODO : resources
                throw new ArgumentException(
                          TypeResources.SchemaBuilder_MustBeSchemaType,
                          nameof(schemaType));
            }

            TypeContext context =
                SchemaTypeReference.InferTypeContext(schemaType);

            _clrTypes[new ClrTypeReference(clrType, context)] =
                new ClrTypeReference(schemaType, context);

            return(this);
        }
コード例 #17
0
        internal static Type?GetNamedType(Type type)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (BaseTypes.IsNamedType(type))
            {
                return(type);
            }

            if (type.IsGenericType)
            {
                Type definition = type.GetGenericTypeDefinition();
                if (typeof(ListType <>) == definition ||
                    typeof(NonNullType <>) == definition ||
                    typeof(NativeType <>) == definition)
                {
                    return(GetNamedType(type.GetGenericArguments()[0]));
                }
            }

            return(null);
        }
コード例 #18
0
        private static Dictionary <TKey, TValue> RetrieveDictionaryGeneric <TKey, TValue>(Node node)
        {
            bool keyIsBase = BaseTypes.IsBaseType(typeof(TKey));

            var dictionary = new Dictionary <TKey, TValue>(capacity: node.ChildNodes.Count);

            if (keyIsBase && node.ChildNodeType == NodeChildrenType.key)
            {
                foreach (var child in node.ChildNodes)
                {
                    string childKey = (child as KeyNode).Key;
                    var    key      = BaseTypes.ParseBaseType <TKey>(childKey);
                    var    value    = NodeManager.GetNodeData <TValue>(child);
                    dictionary.Add(key, value);
                }
            }
            else
            {
                var array = NodeManager.GetNodeData <WritableKeyValuePair <TKey, TValue>[]>(node);
                foreach (var kvp in array)
                {
                    dictionary.Add(kvp.key, kvp.value);
                }
            }

            return(dictionary);
        }
コード例 #19
0
        public IObjectFieldDescriptor Resolver(
            FieldResolverDelegate fieldResolver,
            Type resultType)
        {
            if (fieldResolver == null)
            {
                throw new ArgumentNullException(nameof(fieldResolver));
            }

            Definition.Resolver = fieldResolver;

            if (resultType != null)
            {
                Definition.SetMoreSpecificType(resultType, TypeContext.Output);

                Type resultTypeDef = resultType.GetGenericTypeDefinition();
                Type clrResultType = resultType.IsGenericType &&
                                     resultTypeDef == typeof(NativeType <>)
                        ? resultType.GetGenericArguments()[0]
                        : resultType;
                if (!BaseTypes.IsSchemaType(clrResultType))
                {
                    Definition.ResultType = clrResultType;
                }
            }
            return(this);
        }
コード例 #20
0
        public override AstNode?VisitBaseTypeList(BaseTypeListContext context)
        {
            _currentMessage !.BaseTypes.AddRange(
                context.GetRuleContexts <TypeNameContext>()
                .Select(typeContext => new TypeName(typeContext.GetText())));

            return(null);
        }
コード例 #21
0
        public FakeClass AddBaseClass(string name)
        {
            var baseClass  = new FakeClass(name);
            var returnType = new DefaultReturnType(baseClass);

            BaseTypes.Add(returnType);
            return(baseClass);
        }
コード例 #22
0
 public static ValueObjectSpecification CreateClass(
     NamespaceName namespaceName, string name,
     PropertyDeclaration[] properties,
     BaseTypes baseTypes,
     bool isDataContract, bool isSealed)
 {
     return(new ValueObjectSpecification(false, namespaceName, name, properties, baseTypes, isDataContract, isSealed));
 }
コード例 #23
0
 public static ValueObjectSpecification CreateStruct(
     NamespaceName namespaceName, string name,
     PropertyDeclaration[] properties,
     BaseTypes baseTypes,
     bool isDataContract)
 {
     return(new ValueObjectSpecification(true, namespaceName, name, properties, baseTypes, isDataContract, true));
 }
コード例 #24
0
        internal static bool IsNonGenericBaseType(Type type)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            return(BaseTypes.IsNonGenericBaseType(type));
        }
コード例 #25
0
        internal override void MergePartialType(CustomTypeNode partialTypeNode)
        {
            base.MergePartialType(partialTypeNode);

            if (partialTypeNode.BaseTypes.Count > 0)
            {
                BaseTypes.Append(GetParentedNodeList(partialTypeNode.BaseTypes));
            }
        }
コード例 #26
0
        private RegisteredType InitializeType(
            TypeSystemObjectBase typeSystemObject,
            string?scope,
            bool isInferred)
        {
            try
            {
                var discoveryContext = new TypeDiscoveryContext(
                    typeSystemObject,
                    scope,
                    _serviceFactory.Services,
                    _descriptorContext,
                    _interceptor);

                typeSystemObject.Initialize(discoveryContext);

                var references = new List <ITypeReference>();

                if (!isInferred)
                {
                    references.Add(TypeReference.Create(
                                       typeSystemObject,
                                       scope: scope));
                }

                if (!BaseTypes.IsNonGenericBaseType(typeSystemObject.GetType()))
                {
                    references.Add(TypeReference.Create(
                                       typeSystemObject.GetType(),
                                       SchemaTypeReference.InferTypeContext(typeSystemObject),
                                       scope: scope));
                }

                if (typeSystemObject is IHasTypeIdentity hasTypeIdentity &&
                    hasTypeIdentity.TypeIdentity is { })
                {
                    var reference = TypeReference.Create(
                        hasTypeIdentity.TypeIdentity,
                        SchemaTypeReference.InferTypeContext(typeSystemObject),
                        scope: scope);

                    if (!references.Contains(reference))
                    {
                        references.Add(reference);
                    }
                }

                var registeredType = new RegisteredType(
                    references,
                    typeSystemObject,
                    discoveryContext,
                    CollectDependencies(discoveryContext),
                    isInferred);

                return(registeredType);
            }
コード例 #27
0
ファイル: KittyHighNIL.cs プロジェクト: freezernick/kitty
        public KittyHighNIL()
        {
            // Not complete yet, but for now this will do!
            BaseTypes.Add("table");
            BaseTypes.Add("void");
            BaseTypes.Add("string");
            BaseTypes.Add("int");
            BaseTypes.Add("bool");
            BaseTypes.Add("var");
            KeyWords.Add("not");
            KeyWords.Add("class");
            KeyWords.Add("group");
            KeyWords.Add("module");
            KeyWords.Add("global");
            KeyWords.Add("private");
            KeyWords.Add("end");
            KeyWords.Add("and");
            KeyWords.Add("or");
            KeyWords.Add("quickmeta");
            KeyWords.Add("switch");
            KeyWords.Add("case");
            KeyWords.Add("default");
            // KeyWords.Add("goto"); // EEEEW!
            KeyWords.Add("if");
            KeyWords.Add("else");
            KeyWords.Add("elseif");
            KeyWords.Add("do");
            KeyWords.Add("while");
            KeyWords.Add("true");
            KeyWords.Add("false");
            KeyWords.Add("abstract");
            KeyWords.Add("override");
            KeyWords.Add("self");
            KeyWords.Add("get");
            KeyWords.Add("set");
            KeyWords.Add("try");
            KeyWords.Add("catch");
            KeyWords.Add("finally");
            KeyWords.Add("static");
            KeyWords.Add("return");
            KeyWords.Add("for");
            KeyWords.Add("in");
            KeyWords.Add("delegate");
            KeyWords.Add("readonly");
            KeyWords.Add("new");
            KeyWords.Add("break");
            KeyWords.Add("nil");
            KeyWords.Add("extends");

            KeyWords.Add("CONSTRUCTOR");
            KeyWords.Add("DESTRUCTOR");

            //KeyWords.Add("foreach");
            Langs["nil"] = this;
            Language     = "NIL isn't Lua";
        }
コード例 #28
0
        protected ITypeReference RewriteTypeToNullableType()
        {
            ITypeReference reference = Definition.Type;

            if (reference is IClrTypeReference clrRef &&
                TypeInspector.Default.TryCreate(
                    clrRef.Type,
                    out Utilities.TypeInfo typeInfo))
            {
                if (BaseTypes.IsSchemaType(typeInfo.ClrType))
                {
                    if (clrRef.Type.IsGenericType &&
                        clrRef.Type.GetGenericTypeDefinition() ==
                        typeof(NonNullType <>))
                    {
                        return(clrRef.WithType(typeInfo.Components[1]));
                    }
                    return(clrRef);
                }
                else
                {
                    if (clrRef.Type.IsValueType)
                    {
                        if (Nullable.GetUnderlyingType(clrRef.Type) == null)
                        {
                            return(clrRef.WithType(
                                       typeof(Nullable <>).MakeGenericType(clrRef.Type)));
                        }
                        return(clrRef);
                    }
                    else if (clrRef.Type.IsGenericType &&
                             clrRef.Type.GetGenericTypeDefinition() ==
                             typeof(NonNullType <>))
                    {
                        return(clrRef.WithType(typeInfo.Components[1]));
                    }
                    return(clrRef);
                }
            }

            if (reference is ISchemaTypeReference schemaRef)
            {
                return(schemaRef.Type is NonNullType nnt
                    ? schemaRef.WithType(nnt)
                    : schemaRef);
            }

            if (reference is ISyntaxTypeReference syntaxRef)
            {
                return(syntaxRef.Type is NonNullTypeNode nnt
                    ? syntaxRef.WithType(nnt)
                    : syntaxRef);
            }

            throw new NotSupportedException();
        }
コード例 #29
0
ファイル: Nodes.cs プロジェクト: presscad/BaseLayer
        internal static BaseType BaseType(BaseTypes typeid, Symbol s)
        {
            BaseType res = new BaseType();

            res.kind   = Kind.BaseType;
            res.start  = s.pos;
            res.end    = s.endpos;
            res.typeid = typeid;
            return(res);
        }
コード例 #30
0
ファイル: TypeInfo.cs プロジェクト: GeorgeR/GameArchitect
        public override bool IsValid(ILogger <IValidatable> logger)
        {
            var result = base.IsValid(logger);

            return(result &&
                   BaseTypes.All(t => t.IsValid(logger)) &&
                   Properties.All(p => p.IsValid(logger)) &&
                   Events.All(e => e.IsValid(logger)) &&
                   Functions.All(f => f.IsValid(logger)));
        }
コード例 #31
0
        public preferencesForm(BaseTypes.Settings settings)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            localSettingsInstance=new FinalApp1.BaseTypes.Settings();
            InitializeValues(settings);

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
コード例 #32
0
        public trackedPointsViewer(BaseTypes.trackingHistory TrackingHistory)
        {
            //
            // Required for Windows Form Designer support
            //
            this.TrackingHistory=new BaseTypes.trackingHistory();
            this.TrackingHistory=TrackingHistory;
            InitializeComponent();
            refreshData();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
コード例 #33
0
        public static Node CreateNode(BaseTypes baseType, ShieldTypes shieldType)
        {
            Node node = new Node
            {
                Base = baseType,
                Shield = shieldType,
                NetworkRetries = 3,
            };

            foreach (var item in ProductConfiguration.GetShieldDictionary(shieldType))
            {
                if(item.Value.Item1 != DataLayer.Entities.Enums.ConnectorTypes.DimmerPassZero)
                    node.Connectors.Add(BusinessConnector.CreateConnector(item.Key, item.Value.Item1));
            }

            return node;
        }
コード例 #34
0
        public static Base GetBaseConfiguration(BaseTypes controller)
        {
            Base result = new Base();
            switch (controller)
            {
                case BaseTypes.ATMega128RFA1_V1:
                case BaseTypes.ATMega128RFA1_V2:
                    result.UController = controller;
                    result.DeviceSignature = 128;
                    result.NumPorts = 7;
                    result.NumPins = 8;

                    result.AnalogPorts = new string[] { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7" };
                    result.PWMPorts = new string[] { "B4", "B5", "B6", "B7", "E3", "E4", "E5", "G5" };  //VERSION MINOLO:{ "B4", "B7", "G5" } el B7 y el G5 estan compartidos con el mismo timer
                    result.UnavailablePorts = new string[] { "G3", "G4" };  //TODO: de momento estos pero hay que chequear

                    result.LittleEndian = true;
                    break;
                default:
                    throw new Exception();
            }

            return result;
        }
コード例 #35
0
        //OK
        //Event handling
        private void InitializeValues(BaseTypes.Settings settings)
        {
            localSettingsInstance = settings;
            this.neuralNetworksInitialLearningDurationTB.Text=Convert.ToString(settings.neuralNetworkTrainingIterations);
            this.trainingRateTB.Text=Convert.ToString(settings.neuralNetworkTrainingRate);
            this.maxWeightTB.Text=Convert.ToString(settings.neuralNetworkMaximumWeight);
            this.minWeightTB.Text=Convert.ToString(settings.neuralNetworkMinimumWeight);
            this.hiddenLayersCountTB.Text=Convert.ToString(settings.neuralNetworkHiddenLayersCount);
            this.hiddenLayersSizeTB.Text=Convert.ToString(settings.neuralNetworkHiddenLayersSize);
            this.scalingFactorTB.Text=Convert.ToString(settings.viewportXYScalingFactor);
            this.horizontalResTB.Text=Convert.ToString(settings.viewportXYHorizontalRes);
            this.verticalResTB.Text=Convert.ToString(settings.viewportXYVerticalRes);
            this.scanAreaOffsetTB.Text=Convert.ToString(settings.scanAreaOffset);
            this.preciseAcceptanceThresholdTB.Text=Convert.ToString(settings.preciseAcceptanceThreshold);
            this.frameIteratorTB.Text=Convert.ToString(settings.frameIterator);
            this.minimumTrackingPointRadiusTB.Text=Convert.ToString(settings.minimumOrientPointRadius);
            this.maximumTrackingPointRadiusTB.Text=Convert.ToString(settings.maximumOrientPointRadius);

            if (settings.viewportXYScalingType==BaseTypes.scalingType.Native)
                this.keepNativeSizeRB.Checked=true; else if
               (settings.viewportXYScalingType==BaseTypes.scalingType.ScaleBy)
                this.scaleByRB.Checked=true; else this.customResolutionRB.Checked=true;
        }
コード例 #36
0
 public static IVertex StoreVertexType(
     IVertexStore myStore,
     VertexInformation myVertex,
     BaseTypes myType,
     String myComment,
     Int64 myCreationDate,
     bool myIsAbstract,
     bool myIsSealed,
     bool myIsUserDefined,
     VertexInformation? myParent,
     IEnumerable<VertexInformation> myUniques,
     SecurityToken mySecurity,
     TransactionToken myTransaction)
 {
     return StoreVertexType(myStore, myVertex, myType.ToString(), myComment, myCreationDate, myIsAbstract, myIsSealed, myIsUserDefined, myParent, myUniques, mySecurity, myTransaction);
 }
コード例 #37
0
        //generate training set for given viewport (training purposes)
        private ArrayList generateTrainingSet(BaseTypes.viewport vprt, Bitmap bmp)
        {
            int smallShift;
            int largeShift;
            int CoordX,CoordY, Radius = 0,Width,Height;
            Point TL = new Point(0,0);
            double[] temporaryDoubleVector; //training set element
            ByteVector temporaryByteVector; //reqd to obtain double vector
            ArrayList trainingSet=new ArrayList();
            Rectangle crop;

            switch (vprt)
            {
                case BaseTypes.viewport.XY:
                {
                    smallShift=xyRadius+(int)(0.5*xyRadius);
                    largeShift=xyRadius*2;//+(int)(0.5*xyRadius);
                    CoordX=xyCoordX;
                    CoordY=xyCoordY;
                    Radius=xyRadius;

                    break;
                }

                case BaseTypes.viewport.XZ:
                {
                    smallShift=xzRadius+(int)(0.5*xzRadius);
                    largeShift=xzRadius*2;//+(int)(0.5*xzRadius);
                    CoordX=xzCoordX;
                    CoordY=xzCoordZ;
                    Radius=xzRadius;

                    break;
                }

                case BaseTypes.viewport.YZ:
                {
                    smallShift=yzRadius+(int)(0.5*yzRadius);
                    largeShift=yzRadius*2;//+(int)(0.5*yzRadius);
                    CoordX=yzCoordY;
                    CoordY=yzCoordZ;
                    Radius=yzRadius;

                    break;
                }
                default :
                {
                    smallShift=xyRadius+(int)(0.5*xyRadius);
                    largeShift=xyRadius*2;//+(int)(0.5*xyRadius);
                    CoordX=xyCoordX;
                    CoordY=xyCoordY;
                    Radius=xyRadius;
                    break;
                }
            }

            smallShift=Radius;
            largeShift=Radius+(int)(0.5*xyRadius);
            Width=Height=Radius*2;

            //add sixteen wrong answers (image shifted by 50% and 75%)
            for (int x=-1; x<2; x++)
                for (int y=-1; y<2; y++)
                {
                    if (!((x==0) && (y==0))) //To bylaby poprawna dana
                    {
                        int a = (int)x*(int)smallShift;
                        TL.X=(CoordX-Radius)+a;

                        a =(int)y*(int)smallShift;
                        TL.Y=(CoordY-Radius)+a;

                        crop = new Rectangle(TL.X,TL.Y,Width,Height);
                        temporaryByteVector=new ByteVector(BitmapFilters.CropBitmap(bmp, crop));
                        temporaryDoubleVector=temporaryByteVector.GetDoubleVector();
                        trainingSet.Add(temporaryDoubleVector);

                        a = (int)x*(int)largeShift;
                        TL.X=(CoordX-Radius)+a;

                        a =(int)y*(int)largeShift;
                        TL.Y=(CoordY-Radius)+a;

                        crop = new Rectangle(TL.X,TL.Y,Width,Height);
                        temporaryByteVector=new ByteVector(BitmapFilters.CropBitmap(bmp, crop));
                        temporaryDoubleVector=temporaryByteVector.GetDoubleVector();
                        trainingSet.Add(temporaryDoubleVector);
                    }
                }

            //the following code caused not really good results during precise tracking, but still helps
            //add eight correct answers (genuine image shifted by 1)
            for (int x=-1; x<2; x++)
                for (int y=-1; y<2; y++)
                {
                    if (!((x==0) && (y==0))) //To bylaby poprawna dana
                    {
                        int a = (int)x*(int)1;
                        TL.X=(CoordX-Radius)+a;

                        a =(int)y*(int)1;
                        TL.Y=(CoordY-Radius)+a;

                        crop = new Rectangle(TL.X,TL.Y,Width,Height);
                        temporaryByteVector=new ByteVector(BitmapFilters.CropBitmap(bmp, crop));
                        temporaryDoubleVector=temporaryByteVector.GetDoubleVector();
                        trainingSet.Add(temporaryDoubleVector);
                    }
                }

            //add eight answer vectors from genuine image
            for (int x=0; x<8; x++)
            {
                crop = new Rectangle((CoordX-Radius),(CoordY-Radius),Width,Height);
                temporaryByteVector=new ByteVector(BitmapFilters.CropBitmap(bmp, crop));
                temporaryDoubleVector=temporaryByteVector.GetDoubleVector();
                trainingSet.Add(temporaryDoubleVector);
            }

            return trainingSet;
        }
コード例 #38
0
        //train point in certain viewport (generate training set and train neural network)
        private void trainPoint(BaseTypes.viewport vprt,Bitmap bmp, ref NeuralNetwork Ann, int hls, int ovs, int hlc, iActivationFunction af, double tr, int tic, int miw, int maw)
        {
            trainingSet=new ArrayList();

            switch (vprt)
            {

                case BaseTypes.viewport.XY:
                {
                    trainingSet=(ArrayList)(generateTrainingSet(BaseTypes.viewport.XY,bmp).Clone());
                    //create new neural network object
                    Ann =  new NeuralNetwork((int)Math.Pow((xyRadius*2),2),hls, ovs,hlc,af);
                    //initialize weights
                    Ann.DrawWeights(miw, maw);
                    //train network
                    trainNetwork(trainingSet,ref Ann,tr,tic);
                    break;
                }
                case BaseTypes.viewport.XZ:
                {
                    trainingSet=(ArrayList)(generateTrainingSet(BaseTypes.viewport.XZ,bmp).Clone());
                    //create new neural network object
                    Ann =  new NeuralNetwork((int)Math.Pow((xzRadius*2),2),hls, ovs,hlc,af);
                    //initialize weights
                    Ann.DrawWeights(miw, maw);
                    //train network
                    trainNetwork(trainingSet,ref Ann,tr,tic);
                    break;
                }
                case BaseTypes.viewport.YZ:
                {
                    trainingSet=(ArrayList)(generateTrainingSet(BaseTypes.viewport.YZ,bmp).Clone());
                    //create new neural network object
                    Ann =  new NeuralNetwork((int)Math.Pow((yzRadius*2),2),hls, ovs,hlc,af);
                    //initialize weights
                    Ann.DrawWeights(miw, maw);
                    //train network
                    trainNetwork(trainingSet,ref Ann,tr,tic);
                    break;
                }
            }
        }
コード例 #39
0
        //visualization function
        public Bitmap visualizePoint(Bitmap inputPicture, BaseTypes.viewport vprt)
        {
            //bledne paramtery sa--> nie wiadomo dlaczego!!
            int x1, y1, x2, y2;

            switch (vprt)
            {

                case  BaseTypes.viewport.TopLeft:
                {
                    x1 = xyCoordX-xyRadius;
                    y1 = xyCoordY-xyRadius;
                    x2 = xyRadius * 2;
                    y2 = xyRadius * 2;
                    break;
                }

                case  BaseTypes.viewport.TopRight:
                {
                    x1 = xzCoordX-xzRadius;
                    y1 = xzCoordZ-xzRadius;
                    x2 = xzRadius * 2;
                    y2 = xzRadius * 2;
                    break;
                }

                case  BaseTypes.viewport.BottomLeft:
                {
                    x1 = yzCoordY-yzRadius;
                    y1 = yzCoordZ-yzRadius;
                    x2 = yzRadius * 2;
                    y2 = yzRadius * 2;
                    break;
                }
                default :
                {
                    x1 = xyCoordX-xyRadius;
                    y1 = xyCoordY-xyRadius;
                    x2 = xyRadius * 2;
                    y2 = xyRadius * 2;
                    break;
                }
            }

            gr = Graphics.FromImage(inputPicture);
            Pen pen = new System.Drawing.Pen(pColor);

            gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Rectangle tRect = new Rectangle(x1,y1,x2,y2);

            gr.DrawRectangle(pen,tRect);
            gr.FillRectangle(new SolidBrush(Color.FromArgb(30, 255, 255, 255)), tRect);

            gr.DrawLine(pen,x1,y1,x1+x2,y1+y2);
            gr.DrawLine(pen,x1+x2,y1,x1,y1+y2);
            gr.DrawLine(pen,x1+(int)(x2/2),y1+(int)(y2/2),x1+x2+5,y1+(int)(y2/2));

            StringFormat sf=(StringFormat)StringFormat.GenericTypographic.Clone();

            sf.Alignment=StringAlignment.Near;
            sf.LineAlignment=StringAlignment.Near;

            gr.DrawString(pName,new Font("Silkscreen",5,GraphicsUnit.Point),Brushes.Orange,new Rectangle(x1,y1-10,100,y1),sf);
            gr.DrawString("Px#: \n"+Convert.ToString(x2*y2),new Font("Silkscreen",5,GraphicsUnit.Point),Brushes.Orange,new Rectangle(x1,y1+y2,60,y1+y2+10),sf);
            gr.DrawString("x: "+Convert.ToString(x1+(int)(x2/2))+"\n"+"y: "+Convert.ToString(y1+(int)(y2/2)),new Font("Silkscreen",5,GraphicsUnit.Point),Brushes.Orange,new Rectangle(x1+x2+6,y1+(int)(y2/2)-5,60,y1+(int)(y2/2)+5),sf);

            gr.Dispose();

            return inputPicture;
        }
コード例 #40
0
 // The constructor obtains the state information.
 public locatePointThread( BaseTypes.viewport Vprt,Rectangle ScanArea,Bitmap Bmp,int AcceptanceThreshold,int radius, NeuralNetwork aan, locatePointThreadCallback callbackDelegate)
 {
     this.vprt = Vprt;
     this.scanArea = ScanArea;
     this.bmp = Bmp;
     this.acceptanceThreshold = AcceptanceThreshold;
     this.Radius=radius;
     this.Ann=aan;
     callback = callbackDelegate;
 }
コード例 #41
0
 internal CacheEntryMetadataSearcher(BaseTypes.Func<string,string,bool> predicate)
 {
     _predicate = predicate;
 }
コード例 #42
0
ファイル: BaseTypeReference.cs プロジェクト: Xtremrules/dot42
 /// <summary>
 /// Default ctor
 /// </summary>
 private BaseTypeReference(char code, BaseTypes type, Type clrType)
 {
     this.code = code;
     this.type = type;
     this.clrType = clrType;
 }
コード例 #43
0
ファイル: Nodes.cs プロジェクト: inspirer/uml-designer
 internal static BaseType BaseType( BaseTypes typeid, Symbol s )
 {
     BaseType res = new BaseType();
     res.kind = Kind.BaseType;
     res.start = s.pos;
     res.end = s.endpos;
     res.typeid = typeid;
     return res;
 }
コード例 #44
0
ファイル: BaseTypeReference.cs プロジェクト: Xtremrules/dot42
 /// <summary>
 /// Try to lookup a base type reference by it's descriptor code.
 /// </summary>
 internal static bool TryGetByCode(char code, out BaseTypeReference type)
 {
     type = baseTypes.FirstOrDefault(x => x.code == code);
     return (type != null);
 }
コード例 #45
0
ファイル: BaseTypeReference.cs プロジェクト: Xtremrules/dot42
 /// <summary>
 /// Try to lookup a base type reference by it's CLR equivalent.
 /// </summary>
 internal static bool TryGetByClrType(Type clrType, out BaseTypeReference type)
 {
     type = baseTypes.FirstOrDefault(x => x.clrType == clrType);
     return (type != null);
 }
コード例 #46
0
 public KeyValuePair<string,string>[] SearchInMetadata(BaseTypes.Func<string,string,bool> predicate)
 {
     KeyValuePair<string, string>[] ret = null;
     using (var searcher = new CacheEntryMetadataSearcher(predicate))
     {
         _cacheEntryDescriptor.VisitMetaData(searcher);
         ret = searcher.GetResult();
     }
     return ret;
 }
コード例 #47
0
        //callback procedure used to retrieve results from tracking thread
        public void locatePointThreadCallbackResult(int xA, int yA, BaseTypes.viewport vPrt, bool tracked)
        {
            if (!tracked) vprtNotTracked=vPrt;

            switch (vPrt)
            {
                case BaseTypes.viewport.XY:
                {
                    this.xyCoordX=xA;
                    this.xyCoordY=yA;
                    break;
                }
                case BaseTypes.viewport.XZ:
                {
                    this.xzCoordX=xA;
                    this.xzCoordZ=yA;
                    break;
                }
                case BaseTypes.viewport.YZ:
                {
                    this.yzCoordY=xA;
                    this.yzCoordZ=yA;
                    break;
                }

            }
            leftToProcess--;

            if (leftToProcess==0)
            {
                if (vprtNotTracked!=BaseTypes.viewport.None)
                {
                    //locating missing point, using data from other viewports
                    switch (vprtNotTracked)
                    {

                        case BaseTypes.viewport.XY:
                        {
                            this.xyCoordX=
                        (int)((trackingPoint.DistanceQuotientXY*(this.xzCoordX - prevXZCoordX))/trackingPoint.DistanceQuotientXZ);

                            this.xyCoordY=
                        (int)((trackingPoint.DistanceQuotientXY*(this.yzCoordY - prevYZCoordY))/trackingPoint.DistanceQuotientYZ);

                            break;
                        }

                        case BaseTypes.viewport.XZ:
                        {
                            this.xzCoordX=
                        (int)((trackingPoint.DistanceQuotientXZ*(this.xyCoordX - prevXYCoordX))/trackingPoint.DistanceQuotientXY);

                            this.xzCoordZ=
                        (int)((trackingPoint.DistanceQuotientXZ*(this.yzCoordZ - prevYZCoordZ))/trackingPoint.DistanceQuotientYZ);
                            break;
                        }
                        case BaseTypes.viewport.YZ:
                        {
                            this.yzCoordY=
                        (int)((trackingPoint.DistanceQuotientYZ*(this.xyCoordY - prevXYCoordY))/trackingPoint.DistanceQuotientXY);

                            this.yzCoordZ=
                        (int)((trackingPoint.DistanceQuotientYZ*(this.xzCoordZ - prevXZCoordZ))/trackingPoint.DistanceQuotientXZ);
                            break;
                        }

                    }

                }

                OnFrameProcessed();
            }
        }