public void Load_FrameworkTempletes_en()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("en-US");
            SetUpFixtureForTesting(ProgrammingLanguages.CSharp);

            var          frameworkTemplates = GenContext.ToolBox.Repo.GetFrameworks().ToList();
            MetadataInfo template           = frameworkTemplates != null && frameworkTemplates.Count > 0 ? frameworkTemplates[0] : null;

            Assert.NotNull(template);
            Assert.Equal <string>("Test Framework", template.DisplayName);
            Assert.Equal <string>("Test Framework Summary", template.Summary);
            Assert.Equal <string>("Test Framework Description", template.Description);
        }
        public void Load_ProjectTemplates_unknown()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("xx-XX");
            SetUpFixtureForTesting(ProgrammingLanguages.CSharp);

            var          projectTemplates = GenContext.ToolBox.Repo.GetProjectTypes().ToList();
            MetadataInfo template         = projectTemplates != null && projectTemplates.Count > 0 ? projectTemplates[0] : null;

            Assert.NotNull(template);
            Assert.Equal <string>("Test Project Type Base", template.DisplayName);
            Assert.Equal <string>("Test Project Type Base Summary", template.Summary);
            Assert.Equal <string>("Test Project Type Base Description", template.Description);
        }
Beispiel #3
0
        public MetadataInfoTreeContainer EditInfo(MetadataInfoTreeContainer infoToUpdate, List <MetadataInfoTreeContainer> suppliedInfo)
        {
            var emptyMetadataInfo = MetadataInfo.Create();

            emptyMetadataInfo.AudioMetadata = new AudioStreamMetadata
            {
                SampleRate = SampleRate ?? 44100,
                Duration   = Duration ?? TimeSpan.MaxValue,
                DurationTs = long.MaxValue,
            };

            return(MetadataInfoTreeContainer.Create(AudioStream.Create(emptyMetadataInfo)));
        }
        public void Load_ProjectTemplates_es()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("es-ES");
            SetUpFixtureForTesting(ProgrammingLanguages.CSharp);

            var          projectTemplates = GenContext.ToolBox.Repo.GetProjectTypes().ToList();
            MetadataInfo template         = projectTemplates != null && projectTemplates.Count > 0 ? projectTemplates[0] : null;

            Assert.NotNull(template);
            Assert.Equal <string>("Proyecto de prueba", template.DisplayName);
            Assert.Equal <string>("Resumen del proyecto de prueba", template.Summary);
            Assert.Equal <string>("Descripción del proyecto de prueba", template.Description);
        }
        public void Load_FrontEndFrameworkMetadata_es()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("es-ES");
            SetUpFixtureForTesting(ProgrammingLanguages.CSharp);

            _context.ProjectType = "pt1";
            var          frameworkTemplates = GenContext.ToolBox.Repo.GetFrontEndFrameworks(_context).ToList();
            MetadataInfo template           = frameworkTemplates != null && frameworkTemplates.Count > 0 ? frameworkTemplates[0] : null;

            Assert.NotNull(template);
            Assert.Equal("Framework de prueba", template.DisplayName);
            Assert.Equal("Resumen de Framework de prueba", template.Summary);
            Assert.Equal("Descripción de Framework de prueba", template.Description);
        }
        public void Load_BackEndFrameworkMetadata_unknown()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("xx-XX");
            SetUpFixtureForTesting(ProgrammingLanguages.CSharp);

            _context.ProjectType = "pt3";
            var          frameworkTemplates = GenContext.ToolBox.Repo.GetBackEndFrameworks(_context).ToList();
            MetadataInfo template           = frameworkTemplates != null && frameworkTemplates.Count > 0 ? frameworkTemplates[0] : null;

            Assert.NotNull(template);
            Assert.Equal("Test Backend Framework Base", template.DisplayName);
            Assert.Equal("Test Backend Framework Base Summary", template.Summary);
            Assert.Equal("Test Backend Framework Base Description", template.Description);
        }
        /// <summary>
        /// Always Invoked after all pending updates have been applied.
        /// </summary>
        /// <remarks>It is Safe to Use the Domain Models and Services here as the database will match the current entity model.</remarks>
        private void PostUpdate(bool isNewInstall)
        {
            // Work that should only be peformed for a new install.
            if (isNewInstall)
            {
                // Create the SQL Login for the App Pool.
                // TODO: We may want to do this every time in case the app pool identity changes?
                AppPoolIdentityLogin.Create(Context.TargetDatabaseConnectionString, Context.AppPoolIdentity);

                // Create a new RMS System
                RMSSystemFactory.CreateNewRmsSystem(Context.SystemName, ProductVersion);

                // Enable FileStreaming on the Media Database
                MediaFileStreaming.Enable();

                // Setup Durable Instancing
                MicrosoftDurableInstancing.Setup();
            }

            #region Update System

            // Always Update the Metadata BEFORE templates are Updated
            MetadataInfo.Update(Context.TargetImplementation);

            // Update Classic RMS Codes (NCIC, Violation, UCR, etc)
            ClassicRmsCodes.UpdateFromClassicRms(Context.ClassicDatabaseConnectionString);

            #endregion

            #region Update Agencies

            // Update the System Codes in all Agencies.
            AgencyCodes.UpdateAllAgencies(Context.ClassicDatabaseConnectionString);

            // Update the TriTechDefault Templates in all Agencies.
            TriTechDefaultTemplates.UpdateAllAgencies();

            // Update the Implementation Default Templates in all Agencies.
            ImplementationTemplates.UpdateAllAgencies(Context.TargetImplementation);

            // Update any Agency specific Violation Codes
            AgencyViolationCodes.UpdateAllAgencies(Context.ClassicDatabaseConnectionString);

            #endregion

            // Always Make Sure the AppPool login has access to the databases.
            // TODO: This assumes the Login was already created on Install.
            AppPoolIdentityPermissions.Apply(Context.AppPoolIdentity);
        }
Beispiel #8
0
        private void Initialize(object file)
        {
            if ((ViewPageTotalSize / ViewPageCount) % this.BlockSize != 0)
            {
                throw new ArgumentException(string.Format("This '{0}' value of blockSize parameter is invalid.", this.BlockSize));
            }

            //计算缓存区总共有多少个存储块
            _blockCount = (int)(StorageSize / this.BlockSize);

            //计算缓存区的总大(为存储区长度+索引区长度+分配表区长度+文件头长度)
            _capacity = StorageSize + (_blockCount * 4) + (36 * BufferUtility.KB) + MetadataInfo.HeadSize;

            //判断传入参数是否为文件流
            var fileStream = file as FileStream;

            if (fileStream == null)
            {
                var fileInfo = new FileInfo((string)file);

                if (fileInfo.Exists && fileInfo.Length > 0 && fileInfo.Length != _capacity)
                {
                    throw new ArgumentException("file");
                }

                fileStream = new FileStream((string)file, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, this.BlockSize, FileOptions.RandomAccess);

                if (fileStream.Length == 0)
                {
                    fileStream.SetLength(_capacity);
                }
            }
            else
            {
                if (fileStream.Length > 0 && fileStream.Length != _capacity)
                {
                    throw new ArgumentException("file");
                }
            }

            //创建内存映射文件对象
            _memoryMappedFile = MemoryMappedFile.CreateFromFile(fileStream, Path.GetFileName(fileStream.Name), _capacity, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, false);

            //构建默认的元数据描述对象
            _metadata = MetadataInfo.Create(this.BlockSize, _blockCount);

            //创建缓存页面管理器对象
            _pageManager = new MemoryMappedPageManager(this, (uint)_metadata.StorageOffset);
        }
Beispiel #9
0
        public static string CreateMethods(MetadataInfo metadata, System.Data.Linq.DataContext DB)
        {
            var sb = new StringBuilder(4096);

            metadata.dbSets.ForEach((dbSetInfo) =>
            {
                string tableName = GetTableName(DB, dbSetInfo.EntityType);
                if (tableName == string.Empty)
                {
                    return;
                }
                sb.AppendLine(createDbSetMethods(dbSetInfo, tableName));
            });
            return(sb.ToString());
        }
Beispiel #10
0
        public MetadataInfoTreeContainer EditInfo(MetadataInfoTreeContainer infoToUpdate, List <MetadataInfoTreeContainer> suppliedInfo)
        {
            var emptyMetadataInfo = MetadataInfo.Create();

            emptyMetadataInfo.VideoMetadata = new VideoStreamMetadata
            {
                Width            = Size.HasValue ? Size.Value.Width : 320,
                Height           = Size.HasValue ? Size.Value.Height : 240,
                AverageFrameRate = Fraction.Create(FrameRate ?? 25, 1),
                RFrameRate       = Fraction.Create(FrameRate ?? 25, 1),
                Duration         = Duration ?? TimeSpan.MaxValue,
                DurationTs       = long.MaxValue,
            };

            return(MetadataInfoTreeContainer.Create(VideoStream.Create(emptyMetadataInfo)));
        }
Beispiel #11
0
        public void SchemesSingleKeyValue()
        {
            var metadata = new MetadataInfo();

            metadata.Add("Bob", "gary");
            Assert.AreEqual(
                1, metadata.Schemes.Count, "Schemes.Count is unexpected.");
            Assert.AreEqual(
                1,
                metadata.Schemes["Bob"].Count,
                "Schemes[Bob].Count is unexpected.");
            Assert.AreEqual(
                "gary",
                metadata.Schemes["Bob"][0],
                "Schemes[Bob][0] is unexpected.");
        }
Beispiel #12
0
        private byte[] DumpModule(IntPtr moduleHandle, ImageLayout imageLayout, MetadataInfo metadataInfo, string imagePath)
        {
            byte[] peImageData;

            peImageData = PEImageHelper.DirectCopy(_processId, (void *)moduleHandle, imageLayout, !(imagePath is null), imagePath);
            if (imageLayout == ImageLayout.File)
            {
                // 统一为内存格式,方便修复
                FileLayoutToMemoryLayout(ref peImageData, metadataInfo);
            }
            FixDotNetHeaders(peImageData, metadataInfo);
            // 修复.NET头
            peImageData = PEImageHelper.ConvertImageLayout(peImageData, ImageLayout.Memory, ImageLayout.File);
            // 转换回文件格式用于保存
            return(peImageData);
        }
Beispiel #13
0
        public void Decompile(byte[] data)
        {
            AbcStream stream = data;

            MinorVersion = stream.ReadShort();
            MajorVersion = stream.ReadShort();
            ConstantPool = stream.ReadConstantPoolInfo();

            MethodArray = new MethodInfo[stream.ReadU30()];
            for (uint i = 0; i < MethodArray.Length; i++)
            {
                MethodArray[i] = stream.ReadMethodInfo(ConstantPool, i);
            }

            MetadataArray = new MetadataInfo[stream.ReadU30()];
            for (int i = 0; i < MetadataArray.Length; i++)
            {
                MetadataArray[i] = stream.ReadMetadataInfo(ConstantPool);
            }

            AbcClassArray = new AbcClass[stream.ReadU30()];

            for (uint i = 0; i < AbcClassArray.Length; i++)
            {
                AbcClassArray[i] = new AbcClass(this, i);
                AbcClassArray[i].InstanceInfo = stream.ReadInstanceInfo(this, i);
            }
            for (uint i = 0; i < AbcClassArray.Length; i++)
            {
                AbcClassArray[i].ClassInfo = stream.ReadClassInfo(this, i);
            }

            ScriptArray = new ScriptInfo[stream.ReadU30()];
            for (uint i = 0; i < ScriptArray.Length; i++)
            {
                ScriptArray[i] = stream.ReadScriptInfo(this, i);
            }

            MethodBodyArray = new MethodBodyInfo[stream.ReadU30()];
            for (uint i = 0; i < MethodBodyArray.Length; i++)
            {
                MethodBodyArray[i] = stream.ReadMethodBodyInfo(this, i);
                MethodArray[MethodBodyArray[i].Method.Index].MethodBody = MethodBodyArray[i];
            }
        }
Beispiel #14
0
        public void CopryightSingleYear()
        {
            var metadata = new MetadataInfo();

            metadata.Add("Copyright", "2014, Dylan Moonfire");
            Assert.AreEqual(
                1,
                metadata.CopyrightYears.Count,
                "CopyrightYears.Count is unexpected.");
            Assert.AreEqual(
                2014,
                metadata.CopyrightYears[0],
                "CopyrightYears[0] is unexpected.");
            Assert.AreEqual(
                "Dylan Moonfire",
                metadata.CopyrightHolder,
                "CopyrightHolder is unexpected.");
        }
Beispiel #15
0
        public void SchemesCommaSeparated()
        {
            var metadata = new MetadataInfo();

            metadata.Add("Bob", "gary, steve");
            Assert.AreEqual(
                1, metadata.Schemes.Count, "Schemes.Count is unexpected.");
            Assert.AreEqual(
                2,
                metadata.Schemes["Bob"].Count,
                "Schemes[Bob].Count is unexpected.");
            Assert.AreEqual(
                "gary",
                metadata.Schemes["Bob"][0],
                "Schemes[Bob][0] is unexpected.");
            Assert.AreEqual(
                "steve",
                metadata.Schemes["Bob"][1],
                "Schemes[Bob][1] is unexpected.");
        }
Beispiel #16
0
        public static void Test()
        {
            var metadataInfo = MetadataInfo.GetMetadataInfo(typeof(MetadataInfo).Module);
            var dotNetPEInfo = metadataInfo.PEInfo;

            PrintStreamInfo("#~ or #-", metadataInfo.TableStream);
            PrintStreamInfo("#Strings", metadataInfo.StringHeap);
            PrintStreamInfo("#US", metadataInfo.UserStringHeap);
            PrintStreamInfo("#GUID", metadataInfo.GuidHeap);
            PrintStreamInfo("#Blob", metadataInfo.BlobHeap);
            Console.WriteLine($"DotNetPEInfo.IsValid: {dotNetPEInfo.IsValid}");
            if (dotNetPEInfo.IsValid)
            {
                Console.WriteLine($"DotNetPEInfo.ImageLayout: {dotNetPEInfo.ImageLayout}");
                Console.WriteLine($"DotNetPEInfo.Cor20HeaderAddress: {((IntPtr)dotNetPEInfo.Cor20HeaderAddress).ToHexString()}");
                Console.WriteLine($"DotNetPEInfo.MetadataAddress: {((IntPtr)dotNetPEInfo.MetadataAddress).ToHexString()}");
                Console.WriteLine($"DotNetPEInfo.MetadataSize: {dotNetPEInfo.MetadataSize}");
            }
            Console.ReadKey(true);
        }
Beispiel #17
0
        private static IContainer LoadMetadataFromFFprobe(this IContainer resource)
        {
            var mediaLoader = new Metadata.FFprobe.MediaLoader(resource);

            if (mediaLoader.HasAudio)
            {
                var audioStreamMetadata = MetadataInfo.Create(mediaLoader.AudioStream);

                resource.Streams.Add(AudioStream.Create(audioStreamMetadata));
            }

            if (mediaLoader.HasVideo)
            {
                var videoStreamMetadata = MetadataInfo.Create(mediaLoader.VideoStream);

                resource.Streams.Add(VideoStream.Create(videoStreamMetadata));
            }

            return(resource);
        }
Beispiel #18
0
        private MetadataInfo GetMetaDataFromOutput(string output, string audioData)
        {
            var data      = SplitDataIntoArray(output);
            var dimension = $"{data[1]}x{data[2]}";
            var duration  = ConvertToTimeSpan(data[4]);
            var bitrate   = Convert.ToUInt32(data[5]);
            var framerate = ConvertToDouble(data[3]);

            var metaData = new MetadataInfo
            {
                AudioCodec = audioData,
                Dimension  = dimension,
                Duration   = duration,
                VideoCodec = data[0],
                Bitrate    = bitrate,
                Framerate  = framerate
            };

            return(metaData);
        }
Beispiel #19
0
        public void SchemesSemicolonWithCommas()
        {
            var metadata = new MetadataInfo();

            metadata.Add("Bob", "gary; steve, larry");
            Assert.AreEqual(
                1, metadata.Schemes.Count, "Schemes.Count is unexpected.");
            Assert.AreEqual(
                2,
                metadata.Schemes["Bob"].Count,
                "Schemes[Bob].Count is unexpected.");
            Assert.AreEqual(
                "gary",
                metadata.Schemes["Bob"][0],
                "Schemes[Bob][0] is unexpected.");
            Assert.AreEqual(
                "steve, larry",
                metadata.Schemes["Bob"][1],
                "Schemes[Bob][1] is unexpected.");
        }
Beispiel #20
0
    public bool Execute(ISerializable parameters_, [NotNullWhen(true)] out ISerializable?result_)
    {
        result_ = null;
        if (parameters_ is not ModuleInfo parameters)
        {
            return(false);
        }

        var module = FindModule(parameters);

        if (module is null)
        {
            return(false);
        }

        var metadataProvider = MetadataLocator.MetadataInfo.Create(module);
        var metadata         = new MetadataInfo(metadataProvider);

        result_ = metadata;
        return(true);
    }
Beispiel #21
0
                static async Task UpdateReferenceAsync(
                    ConcurrentDictionary <MetadataId, MetadataInfo> metadataIdToInfo,
                    Project project,
                    PortableExecutableReference reference,
                    CancellationToken cancellationToken)
                {
                    var metadataId = SymbolTreeInfo.GetMetadataIdNoThrow(reference);

                    if (metadataId == null)
                    {
                        return;
                    }

                    // 🐉 PERF: GetMetadataChecksum indirectly uses a ConditionalWeakTable. This call is intentionally
                    // placed before the first 'await' of this asynchronous method to ensure it executes in the
                    // synchronous portion of the caller. https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1270250
                    var checksum = SymbolTreeInfo.GetMetadataChecksum(project.Solution, reference, cancellationToken);

                    if (!metadataIdToInfo.TryGetValue(metadataId, out var metadataInfo) ||
                        metadataInfo.SymbolTreeInfo.Checksum != checksum)
                    {
                        var info = await SymbolTreeInfo.GetInfoForMetadataReferenceAsync(
                            project.Solution, reference, checksum, loadOnly : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                        Contract.ThrowIfNull(info);
                        Contract.ThrowIfTrue(info.Checksum != checksum, "If we computed a SymbolTreeInfo, then its checksum much match our checksum.");

                        // Note, getting the info may fail (for example, bogus metadata).  That's ok.
                        // We still want to cache that result so that don't try to continuously produce
                        // this info over and over again.
                        metadataInfo = new MetadataInfo(info, metadataInfo.ReferencingProjects ?? new HashSet <ProjectId>());
                        metadataIdToInfo[metadataId] = metadataInfo;
                    }

                    // Keep track that this dll is referenced by this project.
                    lock (metadataInfo.ReferencingProjects)
                    {
                        metadataInfo.ReferencingProjects.Add(project.Id);
                    }
                }
Beispiel #22
0
        private void BindGrid()
        {
            // Get the brand for which metadata is being edited
            int   brandId = (BrandSelector.Visible) ? BrandDropDownList1.SelectedId : CurrentUser.PrimaryBrandId;
            Brand brand   = BrandCache.Instance.GetById(brandId);

            // Initialize list to store our metadata
            List <MetadataInfo> metadataList = new List <MetadataInfo>();

            var settings = BrandMetadataSettingManager.GetCustomMetadataSettings(brandId);

            foreach (var setting in settings.Where(s => s.UiControlType == (int)BrandMetadataUiControlType.Select))
            {
                // Only add it to the list if this metadata field is available for cataloguing
                // Otherwise, we'll just skip it as it's of no use to us.
                if (setting.OnAssetForm)
                {
                    MetadataInfo info = new MetadataInfo {
                        BrandId = brand.BrandId.GetValueOrDefault(), GroupNumber = setting.GroupNumber, Name = setting.FieldName
                    };
                    metadataList.Add(info);
                }
            }

            // Toggle control visibility based on results
            NoMetadataPanel.Visible        = (metadataList.Count == 0);
            MetadataGroupsRepeater.Visible = (!NoMetadataPanel.Visible);

            // Only bind the grid if we have metadata to display
            if (MetadataGroupsRepeater.Visible)
            {
                // Sort the list by name
                metadataList.Sort((a, b) => a.Name.CompareTo(b.Name));

                // Bind the list to the repeater
                MetadataGroupsRepeater.DataSource = metadataList;
                MetadataGroupsRepeater.DataBind();
            }
        }
Beispiel #23
0
            public static MetadataInfo Load(Stream stream)
            {
                if (stream == null)
                {
                    throw new ArgumentNullException("stream");
                }

                //重置流指针位置
                stream.Position = 0;

                //定义缓存文件的头部
                byte[] head = new byte[MetadataInfo.HeadSize];

                //读取缓存文件的头部内容
                if (stream.Read(head, 0, head.Length) != head.Length)
                {
                    throw new InvalidOperationException();
                }

                var symbol     = BitConverter.ToInt64(head, 0);
                var version    = BitConverter.ToInt32(head, 8);
                var blockSize  = BitConverter.ToInt32(head, 12);
                var blockCount = BitConverter.ToInt32(head, 16);

                //创建元数据信息对象
                var metadata = new MetadataInfo(symbol, version, blockSize, blockCount);

                //读取索引区数据
                stream.Read(metadata.IndexerBuffer, 0, metadata.IndexerBuffer.Length);
                //读取直接分配表记录数据
                stream.Read(metadata.AllocationTableBuffer, 0, metadata.AllocationTableBuffer.Length);
                //读取间接分配表地址数据
                stream.Read(metadata.AllocationTableAddressBuffer, 0, metadata.AllocationTableAddressBuffer.Length);

                //返回构建成功的元数据对象
                return(metadata);
            }
        public static MetadataHelper Create(TargetMemoryAccess memory, MonoDebuggerInfo info)
        {
            MetadataInfo metadata = new MetadataInfo(memory, info.MonoMetadataInfo);

            return(new MetadataHelper(info, metadata));
        }
Beispiel #25
0
 public QueryProvider(MetadataInfo data)
 {
     _data = data;
 }
		public void Dispose()
		{
			_capacity = 0;
			_metadata = null;
			_memoryMappedFile.Dispose();
		}
Beispiel #27
0
 public static AudioStream Create(MetadataInfo info)
 {
     return new AudioStream(info);
 }
Beispiel #28
0
 public static DataStream Create(MetadataInfo info)
 {
     return new DataStream(info);
 }
Beispiel #29
0
 public DataStream(MetadataInfo info)
     : this()
 {
     Info = info;
 }
        /// <summary>
        /// Updates metadata object using latest category table and old categories collection
        /// </summary>
        /// <param name="metadataObject"></param>
        /// <param name="oldCategories">oldCategories collection (key = nid and value = name)</param>        
        /// <param name="categoryTable">latest category table</param>
        /// <returns></returns>
        private MetadataInfo UpdateCategryInMetadataInfo(MetadataInfo metadataObject, Dictionary<int, string> oldCategories, DataTable categoryTable)
        {
            MetadataInfo RetVal = new MetadataInfo();
            CategoryInfo CategoryObject;

            foreach (DataRow categoryRow in categoryTable.Rows)
            {

                // create new category object for each category
                CategoryObject = new CategoryInfo();
                CategoryObject.CategoryName = Convert.ToString(categoryRow[Metadata_Category.CategoryName]);
                CategoryObject.CategoryNId = Convert.ToInt32(categoryRow[Metadata_Category.CategoryNId]);
                CategoryObject.MetadataText = string.Empty;

                // check for key existance
                if (oldCategories.ContainsKey(CategoryObject.CategoryNId))
                {
                    // check old category name exists in metadata object as metadata object (or metadata text) build on Old categories name
                    if (metadataObject.Categories.ContainsKey(oldCategories[CategoryObject.CategoryNId]))
                    {
                        //-- if category exists in metadata text then update metadata text into category object
                        CategoryObject.MetadataText = metadataObject.Categories[oldCategories[CategoryObject.CategoryNId]].MetadataText;
                    }
                }

                //-- add category into Metadata info object
                if (!RetVal.Categories.ContainsKey(CategoryObject.CategoryName))
                {
                    RetVal.Categories.Add(CategoryObject.CategoryName, CategoryObject);
                }

            }
            return RetVal;
        }
			public static MetadataInfo Load(Stream stream)
			{
				if(stream == null)
					throw new ArgumentNullException("stream");

				//重置流指针位置
				stream.Position = 0;

				//定义缓存文件的头部
				byte[] head = new byte[MetadataInfo.HeadSize];

				//读取缓存文件的头部内容
				if(stream.Read(head, 0, head.Length) != head.Length)
					throw new InvalidOperationException();

				var symbol = BitConverter.ToInt64(head, 0);
				var version = BitConverter.ToInt32(head, 8);
				var blockSize = BitConverter.ToInt32(head, 12);
				var blockCount = BitConverter.ToInt32(head, 16);

				//创建元数据信息对象
				var metadata = new MetadataInfo(symbol, version, blockSize, blockCount);

				//读取索引区数据
				stream.Read(metadata.IndexerBuffer, 0, metadata.IndexerBuffer.Length);
				//读取直接分配表记录数据
				stream.Read(metadata.AllocationTableBuffer, 0, metadata.AllocationTableBuffer.Length);
				//读取间接分配表地址数据
				stream.Read(metadata.AllocationTableAddressBuffer, 0, metadata.AllocationTableAddressBuffer.Length);

				//返回构建成功的元数据对象
				return metadata;
			}
Beispiel #32
0
        public void MetadataSupportInDataViewConstruction()
        {
            var data = ReadBreastCancerExamples();
            var autoSchema = SchemaDefinition.Create(typeof(BreastCancerExample));

            var mlContext = new MLContext(0);

            // Create Metadata.
            var kindFloat = "Testing float as metadata.";
            var valueFloat = 10;
            var coltypeFloat = NumberType.Float;
            var kindString = "Testing string as metadata.";
            var valueString = "Strings have value.";
            var kindStringArray = "Testing string array as metadata.";
            var valueStringArray = "I really have no idea what these features entail.".Split(' ');
            var kindFloatArray = "Testing float array as metadata.";
            var valueFloatArray = new float[] { 1, 17, 7, 19, 25, 0 };
            var kindVBuffer = "Testing VBuffer as metadata.";
            var valueVBuffer = new VBuffer<float>(4, new float[] { 4, 6, 89, 5 });

            var metaFloat = new MetadataInfo<float>(kindFloat, valueFloat, coltypeFloat);
            var metaString = new MetadataInfo<string>(kindString, valueString);

            // Add Metadata.
            var labelColumn = autoSchema[0];
            var labelColumnWithMetadata = new SchemaDefinition.Column(mlContext, labelColumn.MemberName, labelColumn.ColumnType,
                metadataInfos: new MetadataInfo[] { metaFloat, metaString });

            var featureColumnWithMetadata = autoSchema[1];
            featureColumnWithMetadata.AddMetadata(kindStringArray, valueStringArray);
            featureColumnWithMetadata.AddMetadata(kindFloatArray, valueFloatArray);
            featureColumnWithMetadata.AddMetadata(kindVBuffer, valueVBuffer);

            var mySchema = new SchemaDefinition { labelColumnWithMetadata, featureColumnWithMetadata };
            var idv = mlContext.CreateDataView(data, mySchema);

            Assert.True(idv.Schema[0].Metadata.Schema.Count == 2);
            Assert.True(idv.Schema[0].Metadata.Schema[0].Name == kindFloat);
            Assert.True(idv.Schema[0].Metadata.Schema[0].Type == coltypeFloat);
            Assert.True(idv.Schema[0].Metadata.Schema[1].Name == kindString);
            Assert.True(idv.Schema[0].Metadata.Schema[1].Type == TextType.Instance);

            Assert.True(idv.Schema[1].Metadata.Schema.Count == 3);
            Assert.True(idv.Schema[1].Metadata.Schema[0].Name == kindStringArray);
            Assert.True(idv.Schema[1].Metadata.Schema[0].Type is VectorType vectorType && vectorType.ItemType is TextType);
            Assert.Throws<ArgumentOutOfRangeException>(() => idv.Schema[1].Metadata.Schema[kindFloat]);

            float retrievedFloat = 0;
            idv.Schema[0].Metadata.GetValue(kindFloat, ref retrievedFloat);
            Assert.True(Math.Abs(retrievedFloat - valueFloat) < .000001);

            ReadOnlyMemory<char> retrievedReadOnlyMemory = new ReadOnlyMemory<char>();
            idv.Schema[0].Metadata.GetValue(kindString, ref retrievedReadOnlyMemory);
            Assert.True(retrievedReadOnlyMemory.Span.SequenceEqual(valueString.AsMemory().Span));

            VBuffer<ReadOnlyMemory<char>> retrievedReadOnlyMemoryVBuffer = new VBuffer<ReadOnlyMemory<char>>();
            idv.Schema[1].Metadata.GetValue(kindStringArray, ref retrievedReadOnlyMemoryVBuffer);
            Assert.True(retrievedReadOnlyMemoryVBuffer.DenseValues().Select((s, i) => s.ToString() == valueStringArray[i]).All(b => b));

            VBuffer<float> retrievedFloatVBuffer = new VBuffer<float>(1, new float[] { 2 });
            idv.Schema[1].Metadata.GetValue(kindFloatArray, ref retrievedFloatVBuffer);
            VBuffer<float> valueFloatVBuffer = new VBuffer<float>(valueFloatArray.Length, valueFloatArray);
            Assert.True(retrievedFloatVBuffer.Items().SequenceEqual(valueFloatVBuffer.Items()));

            VBuffer<float> retrievedVBuffer = new VBuffer<float>();
            idv.Schema[1].Metadata.GetValue(kindVBuffer, ref retrievedVBuffer);
            Assert.True(retrievedVBuffer.Items().SequenceEqual(valueVBuffer.Items()));

            var ex = Assert.Throws<InvalidOperationException>(() => idv.Schema[1].Metadata.GetValue(kindFloat, ref retrievedReadOnlyMemoryVBuffer));
            Assert.True(ex.IsMarked());
        }
Beispiel #33
0
 public DataReader(BinaryReader reader, MetadataInfo metadataInfo)
 {
     _reader       = reader;
     _metadataInfo = metadataInfo;
     _streamLength = _reader.BaseStream.Length;
 }
Beispiel #34
0
 public AudioStream(MetadataInfo info)
     : this()
 {
     Info = info;
 }
		private void Initialize(object file)
		{
			if((ViewPageTotalSize / ViewPageCount) % this.BlockSize != 0)
				throw new ArgumentException(string.Format("This '{0}' value of blockSize parameter is invalid.", this.BlockSize));

			//计算缓存区总共有多少个存储块
			_blockCount = (int)(StorageSize / this.BlockSize);

			//计算缓存区的总大(为存储区长度+索引区长度+分配表区长度+文件头长度)
			_capacity = StorageSize + (_blockCount * 4) + (36 * BufferUtility.KB) + MetadataInfo.HeadSize;

			//判断传入参数是否为文件流
			var fileStream = file as FileStream;

			if(fileStream == null)
			{
				var fileInfo = new FileInfo((string)file);

				if(fileInfo.Exists && fileInfo.Length > 0 && fileInfo.Length != _capacity)
					throw new ArgumentException("file");

				fileStream = new FileStream((string)file,
											FileMode.OpenOrCreate,
											FileAccess.ReadWrite,
											FileShare.ReadWrite,
											this.BlockSize,
											FileOptions.RandomAccess);

				if(fileStream.Length == 0)
					fileStream.SetLength(_capacity);
			}
			else
			{
				if(fileStream.Length > 0 && fileStream.Length != _capacity)
					throw new ArgumentException("file");
			}

			//创建内存映射文件对象
			_memoryMappedFile = MemoryMappedFile.CreateFromFile(fileStream,
																Path.GetFileName(fileStream.Name),
																_capacity,
																MemoryMappedFileAccess.ReadWrite,
																null,
																HandleInheritability.Inheritable,
																false);

			//构建默认的元数据描述对象
			_metadata = MetadataInfo.Create(this.BlockSize, _blockCount);

			//创建缓存页面管理器对象
			_pageManager = new MemoryMappedPageManager(this, (uint)_metadata.StorageOffset);
		}
            private async Task UpdateReferenceAsync(
                Project project, Compilation compilation, PortableExecutableReference reference, CancellationToken cancellationToken)
            {
                var key = GetReferenceKey(reference);
                if (key == null)
                {
                    return;
                }

                if (!TryGetLastWriteTime(key, out var lastWriteTime))
                {
                    // Couldn't get the write time.  Just ignore this reference.
                    return;
                }

                if (!_metadataPathToInfo.TryGetValue(key, out var metadataInfo) || metadataInfo.TimeStamp == lastWriteTime)
                {
                    var info = await SymbolTreeInfo.TryGetInfoForMetadataReferenceAsync(
                        project.Solution, reference, loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false);

                    // Note, getting the info may fail (for example, bogus metadata).  That's ok.  
                    // We still want to cache that result so that don't try to continuously produce
                    // this info over and over again.
                    metadataInfo = new MetadataInfo(lastWriteTime, info, metadataInfo.ReferencingProjects ?? new HashSet<ProjectId>());
                    _metadataPathToInfo.AddOrUpdate(key, metadataInfo, (_1, _2) => metadataInfo);
                }

                // Keep track that this dll is referenced by this project.
                metadataInfo.ReferencingProjects.Add(project.Id);
            }
Beispiel #37
0
        public override void OnEntering(IScreen last)
        {
            base.OnEntering(last);

            MetadataInfo.FinishTransforms(true);
        }
Beispiel #38
0
 public static MetadataHelper Create(TargetMemoryAccess memory, MonoDebuggerInfo info)
 {
     MetadataInfo metadata = new MetadataInfo (memory, info.MonoMetadataInfo);
     return new MetadataHelper (info, metadata);
 }
Beispiel #39
0
 public MetadataProvider(MetadataInfo data)
 {
     _data = data;
 }
        /// <summary>
        /// Returns MetadaataInfo object from the given metadata text
        /// </summary>
        /// <param name="mdElementType"></param>
        /// <returns></returns>
        private MetadataInfo GetMetadataInfoFrmMetadataText(string metadataText, MetadataElementType mdElementType)
        {
            MetadataInfo RetVal = new MetadataInfo();
            CategoryInfo Category;
            XmlDocument XmlDoc;

            //string ConcatinatedParaNodeText = string.Empty;
            //XmlElement CategoryNode = default(XmlElement);
            //XmlNode CategoryXmlNode = null;
            //DataTable CategoryTable;
            //XmlElement RootNode = default(XmlElement);

            //XmlDocument XmldocumentNew = new XmlDocument();
            //XmlDeclaration xmlDeclaration = default(XmlDeclaration);
            //string XmlString = string.Empty;
            //String ConcatenatedParaNodeText = string.Empty;
            //string CategoryParaXml;

            try
            {
                //xmlDeclaration = XmldocumentNew.CreateXmlDeclaration("1.0", "utf-8", null);
                //RootNode = XmldocumentNew.CreateElement(MetadataManagerConstants.Metadata);
                //XmldocumentNew.InsertBefore(xmlDeclaration, XmldocumentNew.DocumentElement);
                //XmldocumentNew.AppendChild(RootNode);

                //--Load xml from database.
                XmlDoc = new XmlDocument();
                XmlDoc.LoadXml(metadataText);

                //--get categories
                foreach (XmlNode Node in XmlDoc.SelectNodes("metadata/Category"))
                {

                    Category = new CategoryInfo();
                    Category.CategoryName = Convert.ToString(Node.Attributes["name"].Value);
                    Category.CategoryType = DIQueries.MetadataElementTypeText[mdElementType];

                    // get metadata text from xml's Para node
                    if (Node.ChildNodes.Count > 0)
                    {
                        Category.MetadataText = Convert.ToString(Node.ChildNodes[0].InnerXml);
                    }

                    // add category into metadataInfo object
                    if (!RetVal.Categories.ContainsKey(Category.CategoryName))
                    {
                        RetVal.Categories.Add(Category.CategoryName, Category);
                    }
                }

                //foreach (DataRow CategoryNameRow in CategoryTable.Rows)
                //{
                //    Category = new CategoryInfo();
                //    Category.CategoryName = Convert.ToString(CategoryNameRow[DIColumns.Metadata_Category.CategoryName]);
                //    Category.CategoryType = metadataType.ToString();

                //    //--Create new xmlelement as Category
                //    CategoryNode = XmldocumentNew.CreateElement(MetadataManagerConstants.Category);

                //    //--Set attribute values of category element.
                //    CategoryNode.SetAttribute(MetadataManagerConstants.NameAttribute, Category.CategoryName);

                //    //--Select Category node with appropriate attribute name(category name)
                //    CategoryXmlNode = XmlDoc.SelectSingleNode(MetadataManagerConstants.CategoryName + Category.CategoryName + MetadataManagerConstants.ClosingSymbol);

                //    //--Add in category collection
                //    if (CategoryXmlNode != null)
                //    {
                //        CategoryParaXml = CategoryXmlNode.InnerXml;
                //        Category.MetadataText = CategoryXmlNode.InnerXml;

                //        //--check for category in collection
                //        if (!RetVal.Categories.ContainsKey(Category.CategoryName))
                //        {
                //            RetVal.Categories.Add(Category.CategoryName, Category);
                //        }
                //    }
                //}
                //return RetVal;
            }
            catch
            {
                RetVal = null;
            }

            return RetVal;
        }
Beispiel #41
0
 public UpdateProvider(MetadataInfo data, MetadataProvider metadata, QueryProvider query)
 {
     _data     = data;
     _metadata = metadata;
     _query    = query;
 }
        /// <summary>
        /// Returns newmetadata string from collection
        /// </summary>
        /// <param name="metadataObject"></param>
        /// <returns></returns>
        private string GetNewMetadataText(MetadataInfo metadataObject)
        {
            //--Retreive from collection
            string RetVal = String.Empty;
            XmlDeclaration xmlDeclaration = default(XmlDeclaration);
            XmlElement RootNode = default(XmlElement);

            //--Construct xml.
            XmlDocument xmldocNew = new XmlDocument();
            XmlElement CategoryNode = default(XmlElement);
            XmlElement ParaNode = default(XmlElement);

            xmlDeclaration = xmldocNew.CreateXmlDeclaration("1.0", "utf-8", null);
            RootNode = xmldocNew.CreateElement(MetadataManagerConstants.Metadata);
            xmldocNew.InsertBefore(xmlDeclaration, xmldocNew.DocumentElement);
            xmldocNew.AppendChild(RootNode);

            try
            {
                //--construct xml tree
                foreach (CategoryInfo Category in metadataObject.Categories.Values)
                {

                    //--Create new xmlelement as Category
                    CategoryNode = xmldocNew.CreateElement(MetadataManagerConstants.Category);

                    //--Set attribute values of category element.
                    CategoryNode.SetAttribute(MetadataManagerConstants.NameAttribute, Category.CategoryName);

                    // Create para node
                    ParaNode = xmldocNew.CreateElement(MetadataManagerConstants.Para);
                    ParaNode.InnerXml = Category.MetadataText;

                    // append it into Category node
                    CategoryNode.AppendChild(ParaNode);

                    // --Append it into metadata node
                    xmldocNew.DocumentElement.AppendChild(CategoryNode);
                }

                //--return xml string.
                RetVal = xmldocNew.InnerXml;
            }
            catch
            {
                RetVal = String.Empty;
            }

            return RetVal;
        }
            private async Task UpdateReferenceAsync(
                Project project, Compilation compilation, PortableExecutableReference reference, CancellationToken cancellationToken)
            {
                var key = GetReferenceKey(reference);
                if (key == null)
                {
                    return;
                }

                DateTime lastWriteTime;
                if (!TryGetLastWriteTime(key, out lastWriteTime))
                {
                    // Couldn't get the write time.  Just ignore this reference.
                    return;
                }

                MetadataInfo metadataInfo;
                if (!_metadataPathToInfo.TryGetValue(key, out metadataInfo) || metadataInfo.TimeStamp == lastWriteTime)
                {
                    var info = await SymbolTreeInfo.GetInfoForMetadataReferenceAsync(
                        project.Solution, reference, loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false);

                    metadataInfo = new MetadataInfo(lastWriteTime, info, metadataInfo.ReferencingProjects ?? new HashSet<ProjectId>());
                    _metadataPathToInfo.AddOrUpdate(key, metadataInfo, (_1, _2) => metadataInfo);
                }

                // Keep track that this dll is referenced by this project.
                metadataInfo.ReferencingProjects.Add(project.Id);
            }
Beispiel #44
0
 protected MetadataHelper(MonoDebuggerInfo info, MetadataInfo metadata)
 {
     this.MonoDebuggerInfo = info;
     this.MonoMetadataInfo = metadata;
 }