1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.IO;
|
---|
24 | using System.Runtime.Serialization;
|
---|
25 | using System.Runtime.Serialization.Formatters.Binary;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Hive.Contracts {
|
---|
28 | [DataContract]
|
---|
29 | public class StreamedObject<T> : Stream {
|
---|
30 | private T encapsulatedObject;
|
---|
31 |
|
---|
32 | private Stream stream =
|
---|
33 | new MemoryStream();
|
---|
34 |
|
---|
35 | public StreamedObject(T encapsulatedObject) {
|
---|
36 | this.encapsulatedObject = encapsulatedObject;
|
---|
37 |
|
---|
38 | BinaryFormatter formatter = new BinaryFormatter();
|
---|
39 | formatter.Serialize(this.stream, this.encapsulatedObject);
|
---|
40 |
|
---|
41 | this.stream.Seek(0, SeekOrigin.Begin);
|
---|
42 | }
|
---|
43 |
|
---|
44 | public T EncapsulatedObject {
|
---|
45 | get {
|
---|
46 | return this.encapsulatedObject;
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public override bool CanRead {
|
---|
51 | get { return this.stream.CanRead; }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public override bool CanSeek {
|
---|
55 | get { throw new NotImplementedException(); }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public override bool CanWrite {
|
---|
59 | get { throw new NotImplementedException(); }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public override void Flush() {
|
---|
63 | throw new NotImplementedException();
|
---|
64 | }
|
---|
65 |
|
---|
66 | public override long Length {
|
---|
67 | get { return this.stream.Length; }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public override long Position {
|
---|
71 | get {
|
---|
72 | return this.stream.Position;
|
---|
73 | }
|
---|
74 | set {
|
---|
75 | if(this.stream.Position != value)
|
---|
76 | throw new NotImplementedException();
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | public override int Read(byte[] buffer, int offset, int count) {
|
---|
81 | int read = this.stream.Read(buffer, offset, count);
|
---|
82 |
|
---|
83 | return read;
|
---|
84 | }
|
---|
85 |
|
---|
86 | public override long Seek(long offset, SeekOrigin origin) {
|
---|
87 | throw new NotImplementedException();
|
---|
88 | }
|
---|
89 |
|
---|
90 | public override void SetLength(long value) {
|
---|
91 | throw new NotImplementedException();
|
---|
92 | }
|
---|
93 |
|
---|
94 | public override void Write(byte[] buffer, int offset, int count) {
|
---|
95 | throw new NotImplementedException();
|
---|
96 | }
|
---|
97 |
|
---|
98 | public override void Close() {
|
---|
99 | this.stream.Close();
|
---|
100 | base.Close();
|
---|
101 | }
|
---|
102 | protected override void Dispose(bool disposing) {
|
---|
103 | this.stream.Dispose();
|
---|
104 | base.Dispose(disposing);
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|