コード例 #1
0
 public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer) {
     var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
     
     // Get the value for each member in the dynamic object
     var clay = obj as IClayBehaviorProvider;
     clay.Behavior.GetMembers(() => null, clay, values);
     return values.ToDictionary(kv => kv.Key, kv => (object)((dynamic)kv.Value).Get());
 }
コード例 #2
0
        private IDictionary<string, object> ExecuteInsertCommand(IDbCommand command, Dictionary<string, FbParameter> columnParameters, bool resultRequired)
        {
            command.ExecuteNonQuery();

            if (resultRequired)
            {
                return columnParameters.ToDictionary(p => p.Key, p => p.Value.Value is DBNull ? null : p.Value.Value);
            }

            return null;
        }
コード例 #3
0
ファイル: frmProject.cs プロジェクト: NullSoldier/Launchpad
        public frmProject(SPWrapper sp)
        {
            Check.ArgNull (sp, "sp");
            this.sp = sp;
            InitializeComponent();

            configToFields = new Dictionary<string, Setting> {
                //BOTH
                {"id",					new TextSetting (inID)},
                {"display_name",		new TextSetting (inDisplayName)},
                {"authorization_key",	new TextSetting (inAuthKey)},
                {"version",				new TextSetting (inVersion)},
                {"loading_screen_file", new TextSetting (inLoading)},
                {"url_schemes",			new TextSetting (inURLSchemes)},
                {"orientations",		new ComboSetting<Orientation> (cmbOrientation,
                    OrientationSerialize.fromOrientation,
                    OrientationSerialize.toOrientation)},
                // IOS
                //{"ios_device_families",	new ComboSetting (cmbDeviceFamily)},
                {"ios_resources",		new FileSetting (fileResourcesiOS)},
                {"ios_dev_identity",	new FileSetting (fileIdentity)},
                {"ios_add_icon_gloss",	new BoolSetting (inGlassEffect)},
                {"ios_dev_mobile_provision_file", new FileSetting (fileProvision)},
                {"ios_app_runs_in_background", new BoolSetting  (inBackground)},
                {"ios_device_families", new ComboSetting<DeviceFamily> (cmbFamiliesiOS,
                    FamilySerialize.fromFamily,
                    FamilySerialize.toFamily)},
                // ANDROID
                {"version_code",		new TextSetting (inVersionAndroid)},
                {"keystore_file",		new FileSetting (fileKeystore)},
                {"keystore_password_file",new FileSetting (fileKeystorePassword)},
                {"key_password_file",	new FileSetting (fileKeyPassword)},
                {"android_resources", new FileSetting (fileResourcesAndroid)}
            };
            fieldsToConfig = configToFields.ToDictionary (p => p.Value, p => p.Key);
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: smalinin/netserializer
        public static void Register(Type[] regTypes)
        {
            if (!s_initialized)
                throw new InvalidOperationException("NetSerializer not initialized");

            var ctypes = CollectTypes(regTypes);
            var types = ctypes.Select(v => v).Where(v => !s_typeMap.ContainsKey(v)).ToArray<Type>();

            #if GENERATE_DEBUGGING_ASSEMBLY
            GenerateAssembly(types, s_typeMap);
            #endif
            s_typeMap = GenerateDynamic(types, s_typeMap);
            s_typeID_TypeData = s_typeMap.ToDictionary(kvp => kvp.Value.TypeID, kvp => kvp.Value);
            #if GENERATE_SWITCH
            s_Type_caseIDtypeIDMap = s_typeMap.ToDictionary(kvp => kvp.Key, kvp => (uint)(kvp.Value.TypeID | (kvp.Value.CaseID << 16)));
            s_caseID_typeIDMap = s_typeMap.ToDictionary(kvp => kvp.Value.TypeID, kvp => kvp.Value.CaseID);
            #endif
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: smalinin/netserializer
        public static void Initialize(Type[] rootTypes)
        {
            if (s_initialized)
                throw new InvalidOperationException("NetSerializer already initialized");

            var types = CollectTypes(rootTypes);

            #if GENERATE_DEBUGGING_ASSEMBLY
            GenerateAssembly(types, s_typeMap);
            #endif
            s_typeMap = GenerateDynamic(types, s_typeMap);
            s_typeID_TypeData = s_typeMap.ToDictionary(kvp => kvp.Value.TypeID, kvp => kvp.Value);

            #if GENERATE_SWITCH
            s_Type_caseIDtypeIDMap = s_typeMap.ToDictionary(kvp => kvp.Key, kvp => (uint)(kvp.Value.TypeID | (kvp.Value.CaseID << 16)));
            s_caseID_typeIDMap = s_typeMap.ToDictionary(kvp => kvp.Value.TypeID, kvp => kvp.Value.CaseID);
            #endif
                s_initialized = true;
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: farseev/mobility
        private void ButtonConsolidateOutputFiles_Click(object sender, RoutedEventArgs e)
        {
            var writeEachConceptFeature = CheckBoxExtractTextFeaturesEachTweet.IsChecked.Value;
            var concepteaturesOutputTableName = TextBoxConceptFeatures.Text;
            var conceptFeaturesOutputTable = database.GetCollection<BsonDocument>(concepteaturesOutputTableName);
            var imagesFolder = TextBoxImagesFilesFolder.Text;
            var filesInDir = Directory.GetFiles(imagesFolder, "*.txt");

            var normaliseFeatures = CheckBoxNormaliseFeatures.IsChecked.Value;

            Task.Run(() =>
            {
                var filesProcessed = 0;

                foreach (var file in filesInDir)
                {
                    try
                    {
                        var imageId = Path.GetFileNameWithoutExtension(file);

                        if (imageId == tweetsPathFileName) continue;

                        var userRecordValues = File.ReadAllText(file)
                            .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                        var concepts = userRecordValues.Select(userRecordValue => float.Parse(userRecordValue, CultureInfo.InvariantCulture)).ToList();

                        if (featureSetSize != concepts.Count)
                        {
                            Write("Inconsistent features set size: " + concepts.Count + " " + imageId);
                            continue;
                        }

                        var twitterId = mediaTable.FindOne(Query.EQ("_id", imageId))["twitter_id"].AsString;

                        if (!usersScores.Contains(twitterId))
                        {
                            usersScores.Add(twitterId, new Dictionary<string, List<float>>());
                        }

                        usersScores[twitterId].Add(imageId, concepts);
                    }
                    catch (Exception exc)
                    {
                        Write(exc.ToString());
                    }

                    filesProcessed++;

                    if (filesProcessed % 1000 == 0)
                    {
                        Write("File processed: " + filesProcessed);
                    }
                }

                var min = double.MaxValue;
                var max = double.MinValue;

                foreach (var userScore in usersScores)
                {
                    foreach (var scoreList in userScore.Value)
                    {
                        foreach (var score in scoreList.Value)
                        {
                            if (score < min) min = score;
                            if (score > max) max = score;
                        }
                    }
                }

                double range;
                double topUp;

                if (Math.Sign(max) == Math.Sign(min))
                {
                    range = Math.Abs(max) - Math.Abs(min);
                    topUp = - Math.Abs(min);
                }
                else
                {
                    range = Math.Abs(max) + Math.Abs(min);
                    topUp = Math.Abs(min);
                }

                Write("Max: " + max);
                Write("Min: " + min);
                Write("Range: " + range);
                Write("Topup: " + topUp);

                foreach (var userScore in usersScores)
                {
                    if (writeEachConceptFeature)
                    {
                        foreach (var scoreList in userScore.Value)
                        {
                            var conceptFeaturesDoc = new BsonDocument
                            {
                                {"_id", scoreList.Key},
                                {"concepts", new BsonArray(scoreList.Value)}
                            };

                            conceptFeaturesOutputTable.Insert(conceptFeaturesDoc);
                        }
                    }
                    else
                    {
                        if (conceptFeaturesOutputTable.FindOne(Query.EQ("_id", userScore.Key)) != null) continue;

                        var probabilities = new Dictionary<int, double>();
                        var numberOfPicturesTaken = userScore.Value.Count;

                        var conceptFeaturesDoc = new BsonDocument
                        {
                            {"_id", userScore.Key},
                            {"numberOfImages", numberOfPicturesTaken}
                        };

                        foreach (var scoreList in userScore.Value)
                        {
                            var counter = 0;

                            foreach (var score in scoreList.Value)
                            {
                                counter++;
                                var probability = (score + topUp)/range;

                                if (!probabilities.ContainsKey(counter))
                                {
                                    probabilities.Add(counter, 0);
                                }

                                if (binaryFeatures)
                                {
                                    probabilities[counter] += probability > treshhold ? 1 : 0;
                                }
                                else
                                {
                                    probabilities[counter] += probability;
                                }
                            }
                        }

                        if (!normaliseFeatures)
                        {
                            numberOfPicturesTaken = 1;
                        }

                        var record =
                            probabilities.ToDictionary(probability => probability.Key.ToString(CultureInfo.InvariantCulture),
                                probability => probability.Value/numberOfPicturesTaken);

                        conceptFeaturesDoc.AddRange(record);
                        conceptFeaturesOutputTable.Insert(conceptFeaturesDoc);
                    }
                }
            });
        }
コード例 #7
0
        /// <summary>
        /// Save pre-selection forest.
        /// </summary>
        /// <param name="decisionForest">The forest with each tree corresponding to a unit.</param>
        /// <param name="candidateGroups">The candidate group collection.</param>
        /// <param name="unitCandidateNameIds">Given candidate idx.</param>
        /// <param name="customFeatures">Cusotmized linguistic feature list.</param>
        /// <param name="outputPath">The output path.</param>
        public void Write(DecisionForest decisionForest,
            ICollection<CandidateGroup> candidateGroups, 
            IDictionary<string, int> unitCandidateNameIds,
            HashSet<string> customFeatures,
            string outputPath)
        {
            foreach (Question question in decisionForest.QuestionList)
            {
                question.Language = _phoneSet.Language;
                question.ValueSetToCodeValueSet(_posSet, _phoneSet, customFeatures);
            }

            FileStream file = new FileStream(outputPath, FileMode.Create);
            try
            {
                using (DataWriter writer = new DataWriter(file))
                {
                    file = null;
                    uint position = 0;

                    // Write header section place holder
                    PreselectionFileHeader header = new PreselectionFileHeader();
                    position += (uint)header.Write(writer);

                    HtsFontSerializer serializer = new HtsFontSerializer();

                    // Write feature, question and prepare string pool
                    HtsQuestionSet questionSet = new HtsQuestionSet
                    {
                        Items = decisionForest.QuestionList,
                        Header = new HtsQuestionSetHeader { HasQuestionName = false },
                        CustomFeatures = customFeatures,
                    };

                    using (StringPool stringPool = new StringPool())
                    {
                        Dictionary<string, uint> questionIndexes = new Dictionary<string, uint>();

                        header.QuestionOffset = position;
                        header.QuestionSize = serializer.Write(
                            questionSet, writer, stringPool, questionIndexes, customFeatures);
                        position += header.QuestionSize;

                        // Write leaf referenced data to buffer
                        IEnumerable<INodeData> dataNodes = GetCandidateNodes(candidateGroups);
                        using (MemoryStream candidateSetBuffer = new MemoryStream())
                        {
                            Dictionary<string, int> namedSetOffset = new Dictionary<string, int>();

                            int candidateSetSize = HtsFontSerializer.Write(
                                dataNodes, new DataWriter(candidateSetBuffer), namedSetOffset);

                            // Write decision forest
                            Dictionary<string, uint[]> namedOffsets =
                                namedSetOffset.ToDictionary(p => p.Key, p => new[] { (uint)p.Value });

                            header.DecisionTreeSectionOffset = position;

                            header.DecisionTreeSectionSize = (uint)Write(decisionForest, unitCandidateNameIds,
                                questionIndexes, questionSet, namedOffsets, new DecisionForestSerializer(), writer);
                            position += header.DecisionTreeSectionSize;

                            // Write string pool
                            header.StringPoolOffset = position;
                            header.StringPoolSize = HtsFontSerializer.Write(stringPool, writer);
                            position += header.StringPoolSize;

                            // Write leaf referenced data
                            header.CandidateSetSectionOffset = position;
                            header.CandidateSetSectionSize = writer.Write(candidateSetBuffer.ToArray());
                            position += header.CandidateSetSectionSize;
                        }

                        // Write header section place holder
                        using (PositionRecover recover = new PositionRecover(writer, 0))
                        {
                            header.Write(writer);
                        }
                    }              
                }
            }
            finally
            {
                if (null != file)
                {
                    file.Dispose();
                }
            }
        }
コード例 #8
0
 private ParamPack(string name, Dictionary<string, string> parameters)
 {
     Name = name;
     _parameters = parameters.ToDictionary(kv => kv.Key, kv => kv.Value);
 }
コード例 #9
0
ファイル: MyAssetMesh.cs プロジェクト: 2asoft/SpaceEngineers
        MyRenderMeshInfo LoadMesh(string assetName, out MyLODDescriptor[] LodDescriptors)
        {
            //Debug.Assert(assetName.EndsWith(".mwm"));
            #region Temporary for mwm endings
            if (!assetName.EndsWith(".mwm"))
            {
                assetName += ".mwm";
            }
            #endregion

            var meshVertexInput = MyVertexInputLayout.Empty;
            LodDescriptors = null;
            MyRenderMeshInfo result = new MyRenderMeshInfo();

            var importer = new MyModelImporter();
            var fsPath = Path.IsPathRooted(assetName) ? assetName : Path.Combine(MyFileSystem.ContentPath, assetName);

            if (!MyFileSystem.FileExists(fsPath))
            {
                System.Diagnostics.Debug.Fail("Model " + assetName + " does not exists!");

                return MyAssetsLoader.GetDebugMesh().LODs[0].m_meshInfo;
            }


            string contentPath = null;
            if (Path.IsPathRooted(assetName) && assetName.ToLower().Contains("models"))
                contentPath = assetName.Substring(0, assetName.ToLower().IndexOf("models"));

            try
            {

                importer.ImportData(fsPath, new string[]
                    {
                        MyImporterConstants.TAG_VERTICES,
                        MyImporterConstants.TAG_BLENDINDICES,
                        MyImporterConstants.TAG_BLENDWEIGHTS,
                        MyImporterConstants.TAG_NORMALS,
                        MyImporterConstants.TAG_TEXCOORDS0,
                        MyImporterConstants.TAG_TANGENTS,
                        MyImporterConstants.TAG_BINORMALS,
                        MyImporterConstants.TAG_BONES,
                        MyImporterConstants.TAG_MESH_PARTS,
                        MyImporterConstants.TAG_BOUNDING_BOX,
                        MyImporterConstants.TAG_BOUNDING_SPHERE,
                        MyImporterConstants.TAG_LODS,
                    });
                Dictionary<string, object> tagData = importer.GetTagData();

                // extract data
                var positions = (HalfVector4[])tagData[MyImporterConstants.TAG_VERTICES];
                System.Diagnostics.Debug.Assert(positions.Length > 0);
                var verticesNum = positions.Length;
                var boneIndices = (Vector4I[])tagData[MyImporterConstants.TAG_BLENDINDICES];
                var boneWeights = (Vector4[])tagData[MyImporterConstants.TAG_BLENDWEIGHTS];
                var normals = (Byte4[])tagData[MyImporterConstants.TAG_NORMALS];
                var texcoords = (HalfVector2[])tagData[MyImporterConstants.TAG_TEXCOORDS0];
                var tangents = (Byte4[])tagData[MyImporterConstants.TAG_TANGENTS];
                var bintangents = (Byte4[])tagData[MyImporterConstants.TAG_BINORMALS];
                var tangentBitanSgn = new Byte4[verticesNum];
                for (int i = 0; i < verticesNum; i++)
                {
                    var N = VF_Packer.UnpackNormal(normals[i].PackedValue);
                    var T = VF_Packer.UnpackNormal(tangents[i].PackedValue);
                    var B = VF_Packer.UnpackNormal(bintangents[i].PackedValue);

                    var tanW = new Vector4(T.X, T.Y, T.Z, 0);

                    tanW.W = T.Cross(N).Dot(B) < 0 ? -1 : 1;
                    tangentBitanSgn[i] = VF_Packer.PackTangentSignB4(ref tanW);
                }
                
                bool hasBonesInfo = boneIndices.Length > 0 && boneWeights.Length > 0;
                var bones = (MyModelBone[])tagData[MyImporterConstants.TAG_BONES];

                //
                var vertexBuffers = new List<IVertexBuffer>();
                IIndexBuffer indexBuffer = null;
                var submeshes = new Dictionary<MyMeshDrawTechnique, List<MyDrawSubmesh>>();
                var submeshes2 = new Dictionary<MyMeshDrawTechnique, List<MySubmeshInfo>>();
                var submeshesMeta = new List<MySubmeshInfo>();

                int indicesNum = 0;
                bool missingMaterial = false;
                if (tagData.ContainsKey(MyImporterConstants.TAG_MESH_PARTS))
                {
                    var indices = new List<uint>(positions.Length);
                    uint maxIndex = 0;

                    var meshParts = tagData[MyImporterConstants.TAG_MESH_PARTS] as List<MyMeshPartInfo>;
                    foreach (MyMeshPartInfo meshPart in meshParts)
                    {
                        # region Bones indirection
                        int[] bonesRemapping = null;
                        if (boneIndices.Length > 0 && bones.Length > MyRender11Constants.SHADER_MAX_BONES)
                        {
                            Dictionary<int, int> vertexChanged = new Dictionary<int, int>();

                            Dictionary<int, int> bonesUsed = new Dictionary<int, int>();

                            int trianglesNum = meshPart.m_indices.Count / 3;
                            for (int i = 0; i < trianglesNum; i++)
                            {
                                for (int j = 0; j < 3; j++)
                                {
                                    int index = meshPart.m_indices[i * 3 + j];
                                    if (boneWeights[index].X > 0)
                                        bonesUsed[boneIndices[index].X] = 1;
                                    if (boneWeights[index].Y > 0)
                                        bonesUsed[boneIndices[index].Y] = 1;
                                    if (boneWeights[index].Z > 0)
                                        bonesUsed[boneIndices[index].Z] = 1;
                                    if (boneWeights[index].W > 0)
                                        bonesUsed[boneIndices[index].W] = 1;
                                }
                            }

                            if (bonesUsed.Count > MyRender11Constants.SHADER_MAX_BONES)
                            {
                                Debug.Assert(bonesUsed.Count <= MyRender11Constants.SHADER_MAX_BONES, "Model \"" + assetName + "\"'s part uses more than 60 bones, please split model on more parts");
                            }

                            var partBones = new List<int>(bonesUsed.Keys);
                            partBones.Sort();
                            if (partBones.Count > 0 && partBones[partBones.Count - 1] >= MyRender11Constants.SHADER_MAX_BONES)
                            {
                                for (int i = 0; i < partBones.Count; i++)
                                {
                                    bonesUsed[partBones[i]] = i;
                                }

                                Dictionary<int, int> vertexTouched = new Dictionary<int, int>();

                                for (int i = 0; i < trianglesNum; i++)
                                {
                                    for (int j = 0; j < 3; j++)
                                    {
                                        int index = meshPart.m_indices[i * 3 + j];
                                        if (!vertexTouched.ContainsKey(index))
                                        {
                                            if (boneWeights[index].X > 0)
                                                boneIndices[index].X = bonesUsed[boneIndices[index].X];
                                            if (boneWeights[index].Y > 0)
                                                boneIndices[index].Y = bonesUsed[boneIndices[index].Y];
                                            if (boneWeights[index].Z > 0)
                                                boneIndices[index].Z = bonesUsed[boneIndices[index].Z];
                                            if (boneWeights[index].W > 0)
                                                boneIndices[index].W = bonesUsed[boneIndices[index].W];

                                            vertexTouched[index] = 1;

                                            int changes = 0;
                                            vertexChanged.TryGetValue(index, out changes);
                                            vertexChanged[index] = changes + 1;
                                        }
                                    }
                                }

                                bonesRemapping = partBones.ToArray();
                            }

                            if (vertexChanged.Values.Count > 0)
                                Debug.Assert(vertexChanged.Values.Max() < 2, "Vertex shared between model parts, will likely result in wrong skinning");
                        }

                        #endregion

                        int startIndex = indices.Count;
                        int indexCount = meshPart.m_indices.Count;

                        uint minIndex = (uint)meshPart.m_indices[0];
                        foreach (var i in meshPart.m_indices)
                        {
                            indices.Add((uint)i);
                            minIndex = Math.Min(minIndex, (uint)i);
                        }

                        uint baseVertex = minIndex;

                        for (int i = startIndex; i < startIndex + indexCount; i++)
                        {
                            indices[i] -= minIndex;
                            maxIndex = Math.Max(maxIndex, indices[i]);
                        }

                        #region Material
                        var materialDesc = meshPart.m_MaterialDesc;

                        var matId = MyMeshMaterials1.GetMaterialId(materialDesc, contentPath);
                        var partKey = MyMeshMaterials1.Table[matId.Index].Technique;
                        var materialName = MyMeshMaterials1.Table[matId.Index].Name;

                        var list = submeshes.SetDefault(partKey, new List<MyDrawSubmesh>());
                        list.Add(new MyDrawSubmesh(indexCount, startIndex, (int)baseVertex, MyMeshMaterials1.GetProxyId(matId), bonesRemapping));

                        submeshesMeta.Add(new MySubmeshInfo
                        {
                            IndexCount = indexCount,
                            StartIndex = startIndex,
                            BaseVertex = (int)baseVertex,
                            BonesMapping = bonesRemapping,
                            Material = materialName.ToString(),
                            Technique = partKey
                        });

                        var list2 = submeshes2.SetDefault(partKey, new List<MySubmeshInfo>());
                        list2.Add(submeshesMeta[submeshesMeta.Count - 1]);

                        #endregion

                    }
                    indicesNum = indices.Count;

                    #region Fill gpu buffes
                    unsafe
                    {
                        if (maxIndex <= ushort.MaxValue)
                        {
                            // create 16 bit indices
                            var indices16 = new ushort[indices.Count];
                            for (int i = 0; i < indices.Count; i++)
                            {
                                indices16[i] = (ushort)indices[i];
                            }

                            result.Indices = indices16;

                            fixed (ushort* I = indices16)
                            {
                                indexBuffer = MyManagers.Buffers.CreateIndexBuffer(assetName + " index buffer", indices16.Length, new IntPtr(I), MyIndexBufferFormat.UShort, ResourceUsage.Immutable);
                            }
                        }
                        else
                        {
                            var indicesArray = indices.ToArray();
                            fixed (uint* I = indicesArray)
                            {
                                indexBuffer = MyManagers.Buffers.CreateIndexBuffer(assetName + " index buffer", indices.Count, new IntPtr(I), MyIndexBufferFormat.UInt, ResourceUsage.Immutable);
                            }
                        }
                    }
                    unsafe
                    {
                        if (!hasBonesInfo)
                        {
                            var vertices = new MyVertexFormatPositionH4[verticesNum];

                            for (int i = 0; i < verticesNum; i++)
                            {
                                vertices[i] = new MyVertexFormatPositionH4(positions[i]);
                            }
                            meshVertexInput = meshVertexInput.Append(MyVertexInputComponentType.POSITION_PACKED);

                            result.VertexPositions = vertices;

                            fixed (MyVertexFormatPositionH4* V = vertices)
                            {
                                vertexBuffers.Add(
                                    MyManagers.Buffers.CreateVertexBuffer(
                                        assetName + " vertex buffer " + vertexBuffers.Count, verticesNum,
                                        sizeof(MyVertexFormatPositionH4), new IntPtr(V), ResourceUsage.Immutable));
                            }
                        }
                        else
                        {
                            var vertices = new MyVertexFormatPositionSkinning[verticesNum];
                            for (int i = 0; i < verticesNum; i++)
                            {
                                vertices[i] = new MyVertexFormatPositionSkinning(
                                    positions[i],
                                    new Byte4(boneIndices[i].X, boneIndices[i].Y, boneIndices[i].Z, boneIndices[i].W),
                                    boneWeights[i]);
                            }
                            meshVertexInput = meshVertexInput.Append(MyVertexInputComponentType.POSITION_PACKED)
                                .Append(MyVertexInputComponentType.BLEND_WEIGHTS)
                                .Append(MyVertexInputComponentType.BLEND_INDICES);

                            fixed (MyVertexFormatPositionSkinning* V = vertices)
                            {
                                vertexBuffers.Add(MyManagers.Buffers.CreateVertexBuffer(
                                    assetName + " vertex buffer " + vertexBuffers.Count, verticesNum,
                                    sizeof(MyVertexFormatPositionSkinning), new IntPtr(V), ResourceUsage.Immutable));
                            }
                        }
                        // add second stream
                        {
                            var vertices = new MyVertexFormatTexcoordNormalTangent[verticesNum];
                            for (int i = 0; i < verticesNum; i++)
                            {
                                vertices[i] = new MyVertexFormatTexcoordNormalTangent(texcoords[i], normals[i], tangentBitanSgn[i]);
                            }

                            fixed (MyVertexFormatTexcoordNormalTangent* V = vertices)
                            {
                                vertexBuffers.Add(MyManagers.Buffers.CreateVertexBuffer(
                                    assetName + " vertex buffer " + vertexBuffers.Count, verticesNum,
                                    sizeof(MyVertexFormatTexcoordNormalTangent), new IntPtr(V), ResourceUsage.Immutable));
                            }

                            result.VertexExtendedData = vertices;

                            meshVertexInput = meshVertexInput
                                .Append(MyVertexInputComponentType.NORMAL, 1)
                                .Append(MyVertexInputComponentType.TANGENT_SIGN_OF_BITANGENT, 1)
                                .Append(MyVertexInputComponentType.TEXCOORD0_H, 1);
                        }
                    }
                    #endregion
                }
                #region Extract lods
                if (tagData.ContainsKey(MyImporterConstants.TAG_LODS))
                {
                    var tagLODs = tagData[MyImporterConstants.TAG_LODS];
                    if (((MyLODDescriptor[])tagLODs).Length > 0)
                    {
                    }
                    LodDescriptors = (MyLODDescriptor[])((MyLODDescriptor[])tagLODs).Clone();
                }
                #endregion

                if (missingMaterial)
                {
                    Debug.WriteLine(String.Format("Mesh {0} has missing material", assetName));
                }

                //indexBuffer.SetDebugName(assetName + " index buffer");
                int c = 0;
                //vertexBuffers.ForEach(x => x.SetDebugName(assetName + " vertex buffer " + c++));

                //
                result.BoundingBox = (BoundingBox)tagData[MyImporterConstants.TAG_BOUNDING_BOX];
                result.BoundingSphere = (BoundingSphere)tagData[MyImporterConstants.TAG_BOUNDING_SPHERE];
                result.VerticesNum = verticesNum;
                result.IndicesNum = indicesNum;
                result.VertexLayout = meshVertexInput;
                result.IB = indexBuffer;
                result.VB = vertexBuffers.ToArray();
                result.IsAnimated = hasBonesInfo;
                result.Parts = submeshes.ToDictionary(x => x.Key, x => x.Value.ToArray());
                result.PartsMetadata = submeshes2.ToDictionary(x => x.Key, x => x.Value.ToArray());
                result.m_submeshes = submeshesMeta;

                IsAnimated |= result.IsAnimated;

                importer.Clear();
                return result;
            }
コード例 #10
0
        static HtmlEntity()
        {
            _entityName =
                new Dictionary<int, string>
                    {
                        {160, "nbsp"},
                        {161, "iexcl"},
                        {162, "cent"},
                        {163, "pound"},
                        {164, "curren"},
                        {165, "yen"},
                        {166, "brvbar"},
                        {167, "sect"},
                        {168, "uml"},
                        {169, "copy"},
                        {170, "ordf"},
                        {171, "laquo"},
                        {172, "not"},
                        {173, "shy"},
                        {174, "reg"},
                        {175, "macr"},
                        {176, "deg"},
                        {177, "plusmn"},
                        {178, "sup2"},
                        {179, "sup3"},
                        {180, "acute"},
                        {181, "micro"},
                        {182, "para"},
                        {183, "middot"},
                        {184, "cedil"},
                        {185, "sup1"},
                        {186, "ordm"},
                        {187, "raquo"},
                        {188, "frac14"},
                        {189, "frac12"},
                        {190, "frac34"},
                        {191, "iquest"},
                        {192, "Agrave"},
                        {193, "Aacute"},
                        {194, "Acirc"},
                        {195, "Atilde"},
                        {196, "Auml"},
                        {197, "Aring"},
                        {198, "AElig"},
                        {199, "Ccedil"},
                        {200, "Egrave"},
                        {201, "Eacute"},
                        {202, "Ecirc"},
                        {203, "Euml"},
                        {204, "Igrave"},
                        {205, "Iacute"},
                        {206, "Icirc"},
                        {207, "Iuml"},
                        {208, "ETH"},
                        {209, "Ntilde"},
                        {210, "Ograve"},
                        {211, "Oacute"},
                        {212, "Ocirc"},
                        {213, "Otilde"},
                        {214, "Ouml"},
                        {215, "times"},
                        {216, "Oslash"},
                        {217, "Ugrave"},
                        {218, "Uacute"},
                        {219, "Ucirc"},
                        {220, "Uuml"},
                        {221, "Yacute"},
                        {222, "THORN"},
                        {223, "szlig"},
                        {224, "agrave"},
                        {225, "aacute"},
                        {226, "acirc"},
                        {227, "atilde"},
                        {228, "auml"},
                        {229, "aring"},
                        {230, "aelig"},
                        {231, "ccedil"},
                        {232, "egrave"},
                        {233, "eacute"},
                        {234, "ecirc"},
                        {235, "euml"},
                        {236, "igrave"},
                        {237, "iacute"},
                        {238, "icirc"},
                        {239, "iuml"},
                        {240, "eth"},
                        {241, "ntilde"},
                        {242, "ograve"},
                        {243, "oacute"},
                        {244, "ocirc"},
                        {245, "otilde"},
                        {246, "ouml"},
                        {247, "divide"},
                        {248, "oslash"},
                        {249, "ugrave"},
                        {250, "uacute"},
                        {251, "ucirc"},
                        {252, "uuml"},
                        {253, "yacute"},
                        {254, "thorn"},
                        {255, "yuml"},
                        {402, "fnof"},
                        {913, "Alpha"},
                        {914, "Beta"},
                        {915, "Gamma"},
                        {916, "Delta"},
                        {917, "Epsilon"},
                        {918, "Zeta"},
                        {919, "Eta"},
                        {920, "Theta"},
                        {921, "Iota"},
                        {922, "Kappa"},
                        {923, "Lambda"},
                        {924, "Mu"},
                        {925, "Nu"},
                        {926, "Xi"},
                        {927, "Omicron"},
                        {928, "Pi"},
                        {929, "Rho"},
                        {931, "Sigma"},
                        {932, "Tau"},
                        {933, "Upsilon"},
                        {934, "Phi"},
                        {935, "Chi"},
                        {936, "Psi"},
                        {937, "Omega"},
                        {945, "alpha"},
                        {946, "beta"},
                        {947, "gamma"},
                        {948, "delta"},
                        {949, "epsilon"},
                        {950, "zeta"},
                        {951, "eta"},
                        {952, "theta"},
                        {953, "iota"},
                        {954, "kappa"},
                        {955, "lambda"},
                        {956, "mu"},
                        {957, "nu"},
                        {958, "xi"},
                        {959, "omicron"},
                        {960, "pi"},
                        {961, "rho"},
                        {962, "sigmaf"},
                        {963, "sigma"},
                        {964, "tau"},
                        {965, "upsilon"},
                        {966, "phi"},
                        {967, "chi"},
                        {968, "psi"},
                        {969, "omega"},
                        {977, "thetasym"},
                        {978, "upsih"},
                        {982, "piv"},
                        {8226, "bull"},
                        {8230, "hellip"},
                        {8242, "prime"},
                        {8243, "Prime"},
                        {8254, "oline"},
                        {8260, "frasl"},
                        {8472, "weierp"},
                        {8465, "image"},
                        {8476, "real"},
                        {8482, "trade"},
                        {8501, "alefsym"},
                        {8592, "larr"},
                        {8593, "uarr"},
                        {8594, "rarr"},
                        {8595, "darr"},
                        {8596, "harr"},
                        {8629, "crarr"},
                        {8656, "lArr"},
                        {8657, "uArr"},
                        {8658, "rArr"},
                        {8659, "dArr"},
                        {8660, "hArr"},
                        {8704, "forall"},
                        {8706, "part"},
                        {8707, "exist"},
                        {8709, "empty"},
                        {8711, "nabla"},
                        {8712, "isin"},
                        {8713, "notin"},
                        {8715, "ni"},
                        {8719, "prod"},
                        {8721, "sum"},
                        {8722, "minus"},
                        {8727, "lowast"},
                        {8730, "radic"},
                        {8733, "prop"},
                        {8734, "infin"},
                        {8736, "ang"},
                        {8743, "and"},
                        {8744, "or"},
                        {8745, "cap"},
                        {8746, "cup"},
                        {8747, "int"},
                        {8756, "there4"},
                        {8764, "sim"},
                        {8773, "cong"},
                        {8776, "asymp"},
                        {8800, "ne"},
                        {8801, "equiv"},
                        {8804, "le"},
                        {8805, "ge"},
                        {8834, "sub"},
                        {8835, "sup"},
                        {8836, "nsub"},
                        {8838, "sube"},
                        {8839, "supe"},
                        {8853, "oplus"},
                        {8855, "otimes"},
                        {8869, "perp"},
                        {8901, "sdot"},
                        {8968, "lceil"},
                        {8969, "rceil"},
                        {8970, "lfloor"},
                        {8971, "rfloor"},
                        {9001, "lang"},
                        {9002, "rang"},
                        {9674, "loz"},
                        {9824, "spades"},
                        {9827, "clubs"},
                        {9829, "hearts"},
                        {9830, "diams"},
                        {34, "quot"},
                        {38, "amp"},
                        {60, "lt"},
                        {62, "gt"},
                        {338, "OElig"},
                        {339, "oelig"},
                        {352, "Scaron"},
                        {353, "scaron"},
                        {376, "Yuml"},
                        {710, "circ"},
                        {732, "tilde"},
                        {8194, "ensp"},
                        {8195, "emsp"},
                        {8201, "thinsp"},
                        {8204, "zwnj"},
                        {8205, "zwj"},
                        {8206, "lrm"},
                        {8207, "rlm"},
                        {8211, "ndash"},
                        {8212, "mdash"},
                        {8216, "lsquo"},
                        {8217, "rsquo"},
                        {8218, "sbquo"},
                        {8220, "ldquo"},
                        {8221, "rdquo"},
                        {8222, "bdquo"},
                        {8224, "dagger"},
                        {8225, "Dagger"},
                        {8240, "permil"},
                        {8249, "lsaquo"},
                        {8250, "rsaquo"},
                        {8364, "euro"}
                    };

            _entityValue = _entityName.ToDictionary(x => x.Value, x => x.Key);

            _maxEntitySize = 8 + 1; // we add the # char
        }
コード例 #11
0
 public DatObject(Dictionary<string, string> elements, Pak pak, DatFile file)
 {
     Pak = pak;
     DatFile = file;
     _dictionary = elements.ToDictionary(x => (string)x.Key, x => (string)x.Value);
 }
コード例 #12
0
ファイル: Dynamo.cs プロジェクト: KyleGobel/Chronos
 public DeleteItemResponse DeleteSingle(string tableName, Dictionary<string, object> dictionary)
 {
     var transformDictionary = dictionary.ToDictionary(x => x.Key, x => GetAttributeValueFromObject(x.Value));
     return _client.DeleteItem(tableName, transformDictionary);
 }
コード例 #13
0
ファイル: Dynamo.cs プロジェクト: KyleGobel/Chronos
 public void WriteSingle(string tableName, Dictionary<string,object> dictionary)
 {
     var transformDictionary = dictionary.ToDictionary(x => x.Key, x => GetAttributeValueFromObject(x.Value));
     _client.PutItem(tableName, transformDictionary);
 }
コード例 #14
0
ファイル: TypesUtil.cs プロジェクト: exaphaser/cs2php
 static TypesUtil()
 {
     PRIMITIVE_TYPES = new Dictionary<string, Type>()
     {
         {"void",   typeof(void)},         
         {"bool",    typeof(bool)},       
         {"object",   typeof(object)},       
         {"string",   typeof(string)},         
         {"char",   typeof(char)},         
         {"double",   typeof(double)},         
         {"int",   typeof(int)},         
         {"long",  typeof(long)},
         {"decimal",  typeof(decimal)}
     };
     PRIMITIVE_TYPES_REV = PRIMITIVE_TYPES.ToDictionary(a => a.Value, a => a.Key);
 }
コード例 #15
0
        /// <summary>
        /// Vrátí pozice jednotlivých písmen ve slově
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private Dictionary<char, int[]> GetLettersPositions(string text)
        {
            Dictionary<char, List<int>> positions = new Dictionary<char, List<int>>();

            for (int i = 0; i < text.Length; i++)
            {
                char currLetter = text[i];
                if (positions.ContainsKey(currLetter))
                {
                    positions[currLetter].Add(i);
                }
                else
                {
                    positions[currLetter] = new List<int>() { i };
                }
            }

            return positions.ToDictionary(x => x.Key, x => x.Value.ToArray());
        }
コード例 #16
0
ファイル: Extensions.cs プロジェクト: ritterim/Supurlative
        internal static IDictionary<string, object> TraverseForKeys(
            this object target,
            SupurlativeOptions options,
            string parentKey = null)
        {
            var kvp = new Dictionary<string, object>();

            if (target == null)
                return kvp;

            var valueType = target as Type == null
                ? target.GetType()
                : target as Type;

            var properties = valueType
                .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                .Where(x => x.CanWrite || valueType.CheckIfAnonymousType());

            foreach (var property in properties)
            {
                var fullPropertyName = parentKey == null
                        ? property.Name
                        : string.Format("{0}{1}{2}", parentKey, options.PropertyNameSeperator, property.Name);

                object valueOrPropertyType = property.PropertyType;

                if (target as Type == null)
                {
                    valueOrPropertyType = property.GetValue(target, null)
                        ?? property.PropertyType;
                }

                var formatterAttribute = property.GetCustomAttributes()
                    .Where(x => typeof(BaseFormatterAttribute).IsAssignableFrom(x.GetType()))
                    .Cast<BaseFormatterAttribute>()
                    .FirstOrDefault();

                if (formatterAttribute == null)
                {
                    // find any global formatters
                    formatterAttribute =
                        options
                        .Formatters
                        .Where(x => x.IsMatch(property.PropertyType, options))
                        .FirstOrDefault();
                }

                if (formatterAttribute != null)
                {
                    var targetValue = target == null || target as Type != null
                        ? null
                        : property.GetValue(target, null);

                    try
                    {
                        formatterAttribute.Invoke(
                            fullPropertyName,
                            targetValue,
                            property.PropertyType,
                            kvp,
                            options);
                    }
                    catch (Exception ex)
                    {
                        throw new FormatterException(
                            string.Format("There is a problem invoking the formatter: {0}.", formatterAttribute.GetType().FullName),
                            ex);
                    }
                }
                else
                {
                    var kvpValue = (valueOrPropertyType != null && valueOrPropertyType as Type == null
                            ? valueOrPropertyType.ToString()
                            : null);

                    if (property.PropertyType.IsPrimitive
                        || (!string.IsNullOrEmpty(property.PropertyType.Namespace)
                        && property.PropertyType.Namespace.StartsWith("System")))
                    {
                        kvp.Add(fullPropertyName, kvpValue);
                    }
                    else
                    {
                        var results = TraverseForKeys(valueOrPropertyType, options, fullPropertyName);

                        if (results.Count() == 0)
                        {
                            kvp.Add(fullPropertyName, kvpValue);
                        }
                        else
                        {
                            foreach (var result in results)
                            {
                                kvp.Add(result.Key, result.Value);
                            }
                        }
                    }
                }
            }

            return kvp.ToDictionary(
                x => options.LowercaseKeys ? x.Key.ToLower() : x.Key,
                x => x.Value
            );
        }
コード例 #17
0
ファイル: srng2json.cs プロジェクト: hoehrmann/srng2json
        public void SimulateAll()
        {
            var s2i = new Dictionary<State, int>();
              var names = new Dictionary<string, Dictionary<string, State>>();

              var allNCPatterns = NameTable
            .Values
            .SelectMany(x => x.p1.DescendantNodesAndSelf())
            .ToList();
              var allNamespaces = allNCPatterns
            .Where(x => x.Type == PatternType.NSNAME)
            .Distinct();
              var allLocalNames = allNCPatterns
            .Where(x => x.Type == PatternType.LNNAME)
            .Distinct();

              foreach (var ns in allNamespaces) {
            names.Add(ns.Namespace, new Dictionary<string, State>());

            foreach (var ln in allLocalNames) {

              var all = NameTable
            .Where(x => Deriv(Deriv(x.Value.p1, ns), ln).Nullable)
            .Select(x => Define(x.Key, x.Value.p2))
            .ToList();

              if (all.Count == 0)
            continue;

              var state = Simulate(all.Aggregate(Choice));

              names[ns.Namespace].Add(ln.Name, state);
            }
              }

              var nix = 1;
              var map = Pattern2State.Values.Distinct().ToDictionary(x => x, x => nix++);

              var names2 = names.ToDictionary(x => x.Key,
            x => x.Value.ToDictionary(y => y.Key, y => map[y.Value]));

              var defnull = NameTable.ToDictionary(x => x.Key, x => new HashSet<int>());

              foreach (var entry in Pattern2State.Values.Distinct()) {
            entry.NullableDefines.ToList().ForEach(x => defnull[x].Add(map[entry]));
              }

              Func<Dictionary<string,State>, Dictionary<string,int>> helper =
            delegate(Dictionary<string,State> dict) {
            var nd = new Dictionary<string,int>();
            foreach (var entry in dict) {
              defnull[entry.Key].ToList().ForEach(x => nd.Add(x.ToString(), map[entry.Value]));
            }
            return nd;
              };

              var allstates = Pattern2State.Values
            .Distinct()
            .ToDictionary(x => map[x], x => new {
            Attributes = x.AttrStates.ToDictionary(y => y.Key, y => map[y.Value]),
            IsNullable = x.IsNullable,
            ChildElems = helper(x.ChildStates),
              });

              var states = new object[allstates.Count + 1];
              allstates.ToList().ForEach(x => states[x.Key] = x.Value);

              var serializer = new JavaScriptSerializer();
              var text = serializer.Serialize(new {
            // DefNull = defnull,
            NameMap = names2,
            States = states });
              TextWriter tw = new StreamWriter(Out);
              tw.Write(text);
              tw.Close();
        }
コード例 #18
0
ファイル: Dfs.cs プロジェクト: VsMaX/ITO-P8
        private bool FulFillsPreconditionsCore(Dictionary<int, int> valueMapping, List<Effect> effectList, Stack<Effect> preconditionsStack)
        {
            var preconditionToFulFill = preconditionsStack.Pop();
            if (preconditionToFulFill == null)
                return true;

            var matchingEffects =
                effectList.Where(x => x.EffectType == preconditionToFulFill.EffectType).ToList();

            foreach (var matchingEffect in matchingEffects)
            {
                var valMapping = valueMapping.ToDictionary(x => x.Key, x => x.Value);
                if (!valMapping.ContainsKey(preconditionToFulFill.Parameter1.Value))
                {
                    valMapping.Add(preconditionToFulFill.Parameter1.Value, matchingEffect.Parameter1.Value);
                }
                else if (valMapping[preconditionToFulFill.Parameter1.Value] != matchingEffect.Parameter1.Value)
                {
                    continue;
                }
                if (!valMapping.ContainsKey(preconditionToFulFill.Parameter2.Value))
                {
                    valMapping.Add(preconditionToFulFill.Parameter2.Value, matchingEffect.Parameter2.Value);
                }
                else if (valMapping[preconditionToFulFill.Parameter2.Value] != matchingEffect.Parameter2.Value)
                {
                    continue;
                }
                if (!valueMapping.ContainsKey(preconditionToFulFill.Parameter3.Value))
                {
                    valueMapping.Add(preconditionToFulFill.Parameter3.Value, matchingEffect.Parameter2.Value);
                }
                else if (valMapping[preconditionToFulFill.Parameter3.Value] != matchingEffect.Parameter3.Value)
                {
                    continue;
                }

                if (valueMapping[preconditionToFulFill.Parameter1.Value] == matchingEffect.Parameter1.Value &&
                valueMapping[preconditionToFulFill.Parameter2.Value] == matchingEffect.Parameter2.Value &&
                valueMapping[preconditionToFulFill.Parameter3.Value] == matchingEffect.Parameter3.Value)
                {
                    FulFillsPreconditionsCore(valueMapping, effectList, preconditionsStack);
                }
            }

            return false;
        }
コード例 #19
0
ファイル: PSTData.cs プロジェクト: JohnsonYuan/TTSFramework
        /// <summary>
        /// Write the pst data.
        /// </summary>
        /// <param name="pstFile">The pst file name to be stored.</param>
        /// <param name="data">The pst data to be write.</param>
        /// <param name="ttsPhoneSet">The tts Phone set.</param>
        /// <param name="ttsPosSet">The tts pst set.</param>
        public void WritePSTData(string pstFile, PSTData data, TtsPhoneSet ttsPhoneSet, TtsPosSet ttsPosSet)
        {
            foreach (Question question in data.DecisionForest.QuestionList)
            {
                question.Language = ttsPhoneSet.Language;
                question.ValueSetToCodeValueSet(ttsPosSet, ttsPhoneSet, data.CustomFeatures);
            }

            FileStream file = new FileStream(pstFile, FileMode.Create);
            try
            {
                using (DataWriter writer = new DataWriter(file))
                {
                    file = null;
                    uint position = 0;

                    // Write header section place holder
                    PreselectionFileHeader header = new PreselectionFileHeader();
                    position += (uint)header.Write(writer);

                    HtsFontSerializer serializer = new HtsFontSerializer();

                    using (StringPool stringPool = new StringPool())
                    {
                        Dictionary<string, uint> questionIndexes = new Dictionary<string, uint>();

                        header.QuestionOffset = position;
                        header.QuestionSize = serializer.Write(
                            data.QuestionSet, writer, stringPool, questionIndexes, data.CustomFeatures);
                        position += header.QuestionSize;

                        // Write leaf referenced data to buffer
                        List<CandidateSetData> dataNodes = data.CadidateSets;
                        int val = data.CadidateSets.Sum(c => c.Candidates.Count);
                        using (MemoryStream candidateSetBuffer = new MemoryStream())
                        {
                            Dictionary<string, int> namedSetOffset = new Dictionary<string, int>();

                            int candidateSetSize = HtsFontSerializer.Write(
                                dataNodes, new DataWriter(candidateSetBuffer), namedSetOffset);

                            // Write decision forest
                            Dictionary<string, uint[]> namedOffsets =
                                namedSetOffset.ToDictionary(p => p.Key, p => new[] { (uint)p.Value });

                            header.DecisionTreeSectionOffset = position;

                            header.DecisionTreeSectionSize = (uint)Write(data.DecisionForest, data.TreeIndexes,
                                questionIndexes, data.QuestionSet, namedOffsets, new DecisionForestSerializer(), writer);
                            position += header.DecisionTreeSectionSize;

                            // Write string pool
                            header.StringPoolOffset = position;
                            header.StringPoolSize = HtsFontSerializer.Write(stringPool, writer);
                            position += header.StringPoolSize;

                            // Write leaf referenced data
                            header.CandidateSetSectionOffset = position;
                            header.CandidateSetSectionSize = writer.Write(candidateSetBuffer.ToArray());
                            position += header.CandidateSetSectionSize;
                        }

                        // Write header section place holder
                        using (PositionRecover recover = new PositionRecover(writer, 0))
                        {
                            header.Write(writer);
                        }
                    }
                }
            }
            finally
            {
                if (null != file)
                {
                    file.Dispose();
                }
            }
        }
コード例 #20
0
ファイル: Duplicator.cs プロジェクト: qunyanm/boogie
 public CreateSubstitutionClosure(Dictionary<Variable, Expr> map, bool fallBackOnName = false, Procedure proc = null)
   : base() {
   Contract.Requires(map != null);
   this.map = map;
   this.proc = proc;
   if (fallBackOnName && proc != null)
   {
     this.nameMap = map.ToDictionary(kv => UniqueName(kv.Key, proc), kv => kv.Value);
   }
 }
コード例 #21
0
ファイル: ErrorsSummaryWriter.cs プロジェクト: Ogonik/LWS
 private static Dictionary<ErrorType, ErrorsSummary> _getTotalSummaryForCategory(Dictionary<ErrorType, IEnumerable<KeyValuePair<int, ErrorsSummary>>> summaries)
 {
     return summaries.ToDictionary(pair => pair.Key, pair => _getTotalSummaryForCategory(pair.Value));
 }