コード例 #1
0
 private void AddAssemblyReferences(PapyrusAssemblyDefinition papyrusAssembly)
 {
     // Add types
     foreach (var type in papyrusAssembly.Types)
     {
         type.Name.Value = nameConventionResolver.Resolve(type.Name.Value);
         var typeRef = ResolveTypeReference(null, type.Name);
         if (!AddedTypeReferences.Contains(typeRef))
         {
             AddedTypeReferences.Add(typeRef);
         }
         // Add structs
         foreach (var nestedType in type.NestedTypes)
         {
             nestedType.Name.Value = nameConventionResolver.Resolve(nestedType.Name.Value);
             var nestedTypeRef = ResolveTypeReference(null, nestedType.Name);
             if (!AddedTypeReferences.Contains(nestedTypeRef))
             {
                 AddedTypeReferences.Add(nestedTypeRef);
             }
         }
     }
 }
コード例 #2
0
        protected override void OnNextCore(IList <T> values)
        {
            try
            {
                _throwOnMissingConfiguration();

                var elasticClient = _elasticClientFactory();
                Tracer.TraceEvent(TraceEventType.Verbose, 10, "received some buffered items ...");

                var indexName = _indexNameResolver.Resolve <T>();
                var typeName  = _typeNameResolver.Resolve();

                Tracer.TraceEvent(TraceEventType.Verbose, 11, "{0} resolved index name and type name", indexName);
                Tracer.TraceEvent(TraceEventType.Verbose, 12, "{0} checking if index exist...", indexName);

                var indexExist = elasticClient.IndexExists(indexName);

                if (!indexExist.Exists)
                {
                    var createIndexResponse = elasticClient.CreateIndex(
                        new CreateIndexDescriptor(indexName).Mappings(ms =>
                                                                      ms.Map <T>(m => m.AutoMap())));

                    if (!createIndexResponse.IsValid)
                    {
                        Tracer.TraceEvent(TraceEventType.Error, 400, "{0} create index failed. {1}", indexName, createIndexResponse.DebugInformation);
                        return;
                    }
                    Tracer.TraceEvent(TraceEventType.Verbose, 14, "{0} created index", indexName);
                }

                Tracer.TraceEvent(TraceEventType.Information, 15, "{0} going to bulk send...", indexName);

                var bulkResponse = elasticClient.Bulk(br => br.CreateMany(values.Where(i => i != null), (d, v) => d.Document(v).Index(indexName).Type(typeName)));
                if (!bulkResponse.IsValid)
                {
                    Tracer.TraceEvent(TraceEventType.Error, 400, "{0} bulk send failed. {1}", indexName, bulkResponse.DebugInformation);
                    return;
                }

                Tracer.TraceEvent(TraceEventType.Information, 17, "{0} bulk send success.", indexName);
            }
            catch (Exception ex)
            {
                Tracer.TraceEvent(TraceEventType.Error, 178, ex.Message);
                Tracer.TraceEvent(TraceEventType.Error, 179, ex.StackTrace);
            }
        }
コード例 #3
0
        public TypeReference Resolve(ref IList <string> reservedNames, ref IList <TypeReference> referenceList,
                                     ModuleDefinition mainModule, TypeDefinition newType, string fallbackTypeName = null)
        {
            var typeName = !string.IsNullOrEmpty(fallbackTypeName) ? fallbackTypeName : newType.FullName;

            if (typeName.Contains("#"))
            {
                // this is a struct.
                typeName = typeName.Split('#').LastOrDefault();
            }

            var ns = namespaceResolver.Resolve(typeName);
            var tn = typeNameResolver.Resolve(typeName);


            var isArray = tn.Contains("[]");

            if (ns == "System")
            {
                var propies =
                    mainModule.TypeSystem.GetType()
                    .GetProperties()
                    .Where(pr => pr.PropertyType == typeof(TypeReference))
                    .ToList();
                foreach (var propy in propies)
                {
                    var name = propy.Name;
                    if (tn.Replace("[]", "").ToLower() == name.ToLower())
                    {
                        var val = propy.GetValue(mainModule.TypeSystem, null) as TypeReference;
                        return(val != null && isArray && !val.IsArray ? new ArrayType(val) : val);
                    }
                }
                // fallback
                switch (tn.ToLower())
                {
                case "none":
                case "void":
                    return(mainModule.TypeSystem.Void);

                case "byte":
                case "short":
                case "int":
                case "long":
                case "int8":
                case "int16":
                case "int32":
                case "int64":
                    return(isArray ? new ArrayType(mainModule.TypeSystem.Int32) : mainModule.TypeSystem.Int32);

                case "string":
                    return(isArray ? new ArrayType(mainModule.TypeSystem.String) : mainModule.TypeSystem.String);

                case "float":
                case "double":
                    return(isArray ? new ArrayType(mainModule.TypeSystem.Double) : mainModule.TypeSystem.Double);

                case "bool":
                case "boolean":
                    return(isArray ? new ArrayType(mainModule.TypeSystem.Boolean) : mainModule.TypeSystem.Boolean);

                default:
                    return(isArray ? new ArrayType(mainModule.TypeSystem.Object) : mainModule.TypeSystem.Object);
                }
            }
            var tnA      = tn.Replace("[]", "");
            var existing =
                referenceList.FirstOrDefault(ty => ty.FullName.ToLower() == (ns + "." + tnA).ToLower());

            if (existing == null)
            {
                var hasTypeOf = mainModule.Types.FirstOrDefault(t => t.FullName.ToLower() == (ns + "." + tnA).ToLower());
                if (hasTypeOf != null)
                {
                    var typeRef = new TypeReference(hasTypeOf.Namespace, hasTypeOf.Name, mainModule, mainModule)
                    {
                        Scope = mainModule
                    };
                    referenceList.Add(typeRef);
                    return(isArray && !typeRef.IsArray ? new ArrayType(typeRef) : typeRef);
                }
                else
                {
                    if (
                        reservedNames.Any(
                            n => string.Equals(n, tnA, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        tn =
                            reservedNames.FirstOrDefault(
                                j => string.Equals(j, tnA, StringComparison.CurrentCultureIgnoreCase));
                    }

                    var typeRef = new TypeReference(ns, tn, mainModule, mainModule)
                    {
                        Scope = mainModule
                    };


                    referenceList.Add(typeRef);
                    return(isArray && !typeRef.IsArray ? new ArrayType(typeRef) : typeRef);
                }
            }

            return(isArray && !existing.IsArray ? new ArrayType(existing) : existing);
        }