当前位置: 首页>>代码示例>>C#>>正文


C# File.GetBinary方法代码示例

本文整理汇总了C#中File.GetBinary方法的典型用法代码示例。如果您正苦于以下问题:C# File.GetBinary方法的具体用法?C# File.GetBinary怎么用?C# File.GetBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在File的用法示例。


在下文中一共展示了File.GetBinary方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Storage2_Compatibility_BinaryCrossReference

		public void Storage2_Compatibility_BinaryCrossReference()
		{
			var file1 = new File(TestRoot);
            file1.Name = "Storage2_Compatibility_BinaryCrossReference-1";
			file1.GetBinary("Binary").FileName = "1.txt";
			file1.GetBinary("Binary").SetStream(Tools.GetStreamFromString("1111"));
			file1.Save();
			var file1id = file1.Id;

			var file2 = new File(TestRoot);
            file1.Name = "Storage2_Compatibility_BinaryCrossReference-2";
            file2.GetBinary("Binary").FileName = "2.txt";
			file2.GetBinary("Binary").SetStream(Tools.GetStreamFromString("2222"));
			file2.Save();
			var file2id = file2.Id;

			file1 = Node.Load<File>(file1id);
			file2 = Node.Load<File>(file2id);
			file2.Binary = file1.Binary;
			file2.Save();
			file1.GetBinary("Binary").FileName = "3.txt";
			file1.GetBinary("Binary").SetStream(Tools.GetStreamFromString("3333"));
			file1.Save();

		}
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:25,代码来源:NodeTest.cs

示例2: Storage2_Milestone3_SaveNode

		public void Storage2_Milestone3_SaveNode()
		{
			var fileName = "Storage2_Milestone2_TestFile.txt";
			var filePath = RepositoryPath.Combine(TestRoot.Path, fileName);
			var text = "Lorem ipsum dolor sit amet...";

			if(Node.Exists(filePath))
                Node.ForceDelete(filePath);

			var stream = Tools.GetStreamFromString(text);

			var file = new File(TestRoot);
			file.Name = fileName;
			file.GetBinary("Binary").FileName = fileName;
			file.GetBinary("Binary").SetStream(stream);

			file.Save();
            
			var loaded = Node.Load<File>(filePath);
			var loadedStream = loaded.GetBinary("Binary").GetStream();
			var loadedText = Tools.GetStreamString(loadedStream);

			Assert.IsTrue(loadedText == text);

			loaded.GetBinary("Binary").FileName = "abc.txt";
			loaded.Save();

			Assert.IsTrue(true);
		}
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:29,代码来源:NodeTest.cs

示例3: Storage2_Milestone4_UseReferences

		public void Storage2_Milestone4_UseReferences()
		{
			var fileName = "Storage2_Milestone2_TestFile.txt";
			var filePath = RepositoryPath.Combine(TestRoot.Path, fileName);
			var text = "Lorem ipsum dolor sit amet...";

			if(ContentType.GetByName("File2") == null)
				ContentTypeInstaller.InstallContentType(@"<?xml version=""1.0"" encoding=""utf-8""?>
					<ContentType name=""File2"" parentType=""File"" handler=""SenseNet.ContentRepository.File"" xmlns=""http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition"">
						<DisplayName>Folder</DisplayName>
						<Description>Use folders to group information to one place</Description>
						<Icon>Folder</Icon>
						<Fields>
							<Field name=""References"" type=""Reference"" />
						</Fields>
					</ContentType>");

			int rootId = TestRoot.Id;
			int file2ctId = ContentType.GetByName("File2").Id;
			int systemId = Node.LoadNode("/Root/System").Id;

			if (Node.Exists(filePath))
                Node.ForceDelete(filePath);

			//----------------------------- Create

			var file = new File(TestRoot, "File2");
			file.Name = fileName;
			file.GetBinary("Binary").FileName = fileName;
			file.GetBinary("Binary").SetStream(Tools.GetStreamFromString(text));
			file.AddReferences("References", new Node[] { TestRoot, ContentType.GetByName("File2") });

			file.Save();

			//----------------------------- Load

			var loadedNode = Node.Load<File>(filePath);
			var loadedStream = loadedNode.GetBinary("Binary").GetStream();
			var loadedText = Tools.GetStreamString(loadedStream);
			var loadedReferences = loadedNode.GetReferences("References").ToList<Node>();

			Assert.IsTrue(loadedText == text, "#1");
			Assert.IsTrue(loadedReferences.Count == 2, "#2");
			var id0 = loadedReferences[0].Id;
			var id1 = loadedReferences[1].Id;
			Assert.IsTrue(id0 == rootId || id0 == file2ctId, "#3");
			Assert.IsTrue(id1 == rootId || id1 == file2ctId, "#4");

			//----------------------------- Change references

			var refs = ((IEnumerable<Node>)loadedNode["References"]).ToList();
			refs.Remove(TestRoot);

			Assert.IsTrue(refs.Count == 2, "#5");

            loadedNode.RemoveReference("References", TestRoot);
            refs = ((IEnumerable<Node>)loadedNode["References"]).ToList();

			Assert.IsTrue(refs.Count == 1, "#6");
			id0 = refs[0].Id;
			Assert.IsTrue(id0 == file2ctId, "#7");

			refs.Add(Node.LoadNode("/Root/System"));

            loadedNode.SetReferences("References", refs);
            refs = ((IEnumerable<Node>)loadedNode["References"]).ToList();

			Assert.IsTrue(refs.Count == 2, "#8");
			id0 = refs[0].Id;
			id1 = refs[1].Id;
			Assert.IsTrue(id0 == file2ctId, "#9");
			Assert.IsTrue(id1 == systemId, "#10");

			loadedNode.Save();

			//----------------------------- Reload

			var reloadedNode = Node.Load<File>(filePath);
			var reloadedStream = reloadedNode.GetBinary("Binary").GetStream();
			var reloadedText = Tools.GetStreamString(reloadedStream);
			var reloadedReferences = reloadedNode.GetReferences("References").ToList<Node>();

			Assert.IsTrue(reloadedText == text, "#11");
			Assert.IsTrue(reloadedReferences.Count == 2, "#12");
			id0 = reloadedReferences[0].Id;
			id1 = reloadedReferences[1].Id;
            Assert.IsTrue(id0 != id1, "#13");
            Assert.IsTrue(id0 == file2ctId || id0 == systemId, "#14");
            Assert.IsTrue(id1 == file2ctId || id1 == systemId, "#15");

			//----------------------------- Reload

            var identityCheck = reloadedNode.GetReferences("References");
            var countBefore = identityCheck.ToArray().Length;
            reloadedNode.AddReference("References", Repository.Root);
            var countAfter = identityCheck.ToArray().Length;
            Assert.IsTrue(countAfter == countBefore + 1, "#15");
		}
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:98,代码来源:NodeTest.cs

示例4: NodeIsModified_BinaryData

        public void NodeIsModified_BinaryData()
        {
            File file = new File(this.TestRoot);
            file.Binary = new BinaryData();
            file.Binary.SetStream(TestTools.GetTestStream());
            file.Save();
            int id = file.Id;

            file = Node.Load<File>(id);
            var origStream = file.Binary.GetStream();
            var binaryData = file.GetBinary("Binary");
            binaryData.SetStream(null);
            var nullBinary = file.GetBinary("Binary");

            var equals = binaryData == nullBinary;
            var changed = file.IsModified;

            Assert.IsTrue(equals, "#1");
            Assert.IsTrue(changed, "#2");

            file.Binary.SetStream(origStream);
            equals = file.GetBinary("Binary") == nullBinary;
            changed = file.IsModified;

            Assert.IsTrue(equals, "#3");
            Assert.IsFalse(changed, "#4");
        }
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:27,代码来源:NodeTest.cs


注:本文中的File.GetBinary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。