Beispiel #1
0
        public void DefaultStreamQuery()
        {
            INode        node = GetRootNode().CreateChild("CreateChildTest5", typeof(string), 0);
            ITypedStream s    = node.OpenDefaultStream(OpenMode.ReadWrite);

            Assert.IsNotNull(s);
        }
Beispiel #2
0
        public void MTAccess()
        {
            INode node = GetRootNode().CreateChild("CreateChildTest16", typeof(string), 0);

            // We access from two threads.
            bool caught = false;

            ParameterizedThreadStart ts = new ParameterizedThreadStart(delegate(object obj) {
                try
                {
                    ITypedStream stream = node.OpenDefaultStream(OpenMode.Write);
                    Thread.Sleep(1000);
                    stream.Dispose();
                }
                catch (MultiWriteAccessException)
                {
                    // Must happen.
                    caught = true;
                }
            });

            Thread t1 = new Thread(ts), t2 = new Thread(ts);

            t1.Start(node);
            t2.Start(node);
            t1.Join();
            t2.Join();

            Assert.IsTrue(caught);
        }
        public void CopyTo([NotNull] ITypedStream s)
        {
            AssertNotDisposed();
            ManagedTypedStream stream = s as ManagedTypedStream;

            lock (Inner)
            {
                stream.AssertNotDisposed();
                lock (stream.Inner)
                {
                    // Implementation notes: should be journalled in future.
                    uint[] locations = Inner.ObjectLocations;
                    for (int i = 0; i < locations.Length; i++)
                    {
                        string type = Inner.GetObjectType(locations[i]);

                        if (usesRaw)
                        {
                            byte[] data = Inner.Read(locations[i]) as byte[];
                            stream.Inner.Write(locations[i], type, data);
                        }
                        else
                        {
                            object data = Inner.Read(locations[i]);
                            stream.Inner.Write(locations[i], type, data);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public void AllocsDeallocs()
        {
            INode n = GetRootNode();

            n = n.CreateChild("CreateChildTest_20", typeof(string), StreamOptions.None);

            // Create big data.
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < 10000; i++)
            {
                builder.Append("Some data.\n");// 24 kBytes
            }

            // Write 2, delete 2 and write two.
            ITypedStream stream = n.OpenDefaultStream(OpenMode.ReadWrite);

            stream.Write(0, builder.ToString());
            stream.Write(1, builder.ToString());
            Assert.IsNotNull(stream.Read(0));
            Assert.IsNotNull(stream.Read(1));
            stream.Erase(1, 1, true);
            stream.Write(2, builder.ToString());
            Assert.IsNotNull(stream.Read(2));
        }
Beispiel #5
0
        public void ReadWriteN()
        {
            ITypedStream stream = CreateStream(typeof(string), 0);

            string[] list = new string[] { "x", "y", "z", "f" };
            stream.WriteObjects(0, list);
            Assert.AreEqual(stream.Read(0, 4).Length, 4);
        }
Beispiel #6
0
        public void InsertBefore()
        {
            ITypedStream stream = CreateStream(typeof(string), 0);
            string       s1 = "my monkey", s2 = "my monkey2";

            stream.Write(0, s1);
            stream.InsertBefore(0, s2);
            Assert.AreEqual((string)stream.Read(0), s2);
        }
Beispiel #7
0
        public void ObjectType()
        {
            ITypedStream stream = CreateStream(typeof(string), StreamOptions.AllowDerivedTypes);
            string       s1 = "my monkey", s2 = "my monkey2";

            stream.Write(0, s1);
            stream.Write(1, s2);
            Assert.AreEqual(stream.GetObjectType(0), typeof(string));
        }
Beispiel #8
0
        public void ReadWrite()
        {
            ITypedStream stream = CreateStream(typeof(string), 0);
            string       s1     = "my monkey";

            stream.Write(0, s1);
            Assert.IsFalse(Object.ReferenceEquals(stream.Read(0), s1));
            Assert.AreEqual(s1, (string)stream.Read(0));
        }
Beispiel #9
0
        /// <summary>
        /// Opens a specific typed stream as generic.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public TypedStream <object> Open(Type type, OpenMode mode)
        {
            ITypedStream s = underNode.GetTypedStream(mode, type);

            if (s == null)
            {
                return(null);
            }
            return(new TypedStream <object>(s));
        }
Beispiel #10
0
        /// <summary>
        /// Opens a specific typed stream in this node
        /// </summary>
        /// <typeparam name="TSomething">The type of the stream to open</typeparam>
        /// <param name="mode">Opening mode to use</param>
        /// <returns>The opened typed stream</returns>
        public TypedStream <TSomething> Open <TSomething>(OpenMode mode)
        {
            ITypedStream s = underNode.GetTypedStream(mode, typeof(TSomething));

            if (s == null)
            {
                return(null);
            }
            return(new TypedStream <TSomething>(s));
        }
Beispiel #11
0
        public void Erase()
        {
            ITypedStream stream = CreateStream(typeof(string), StreamOptions.AllowDerivedTypes);
            string       s1 = "my monkey", s2 = "my monkey2";

            stream.Write(0, s1);
            stream.Write(1, s2);
            stream.Erase(0, 2, true);
            Assert.IsNull(stream.Read(0));
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TypedStream&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="typedStream">The typed stream.</param>
 internal TypedStream(ITypedStream typedStream)
 {
     if (typedStream == null)
     {
         throw new ArgumentNullException("Typed stream must be non-null.");
     }
     if (!Common.IsTypeSameOrDerived(typeof(T), typedStream.StreamType))
     {
         throw new InvalidCastException("Invalid cast on typed stream.");
     }
     internalTS = typedStream;
 }
Beispiel #13
0
            /// <summary>
            /// 一致列の列挙子を提供するインスタンスを作成します。
            /// </summary>
            /// <returns>一致列の列挙子を提供するインスタンスを返します。</returns>
            public Gen::IEnumerable <T> EnumerateElements()
            {
                ITypedStream <T> str = data.target.Clone();

                str.Index = this.Start;
                int iM = this.End;

                do
                {
                    yield return(str.Current);
                }while(str.MoveNext() < iM);
            }
Beispiel #14
0
            public MatchData(Evaluator eval)
            {
                Status s = eval.Status;

                this.root = eval.Node;
#if USE_ARRAY_FOR_CAPTURES
                this.captures = new ICaptureRange[s.Captures.Count + 1];
                s.Captures.CopyTo(this.captures, 0);
                this.captures[s.Captures.Count] = CaptureRangeBase.CreateInstanceForRootNode(eval);
#else
                this.captures = new Gen::List <ICaptureRange>(s.Captures);
                this.captures.Add(CaptureRangeBase.CreateInstanceForRootNode(eval));
#endif
                this.target = s.Target;
            }
Beispiel #15
0
        public void BaseNode()
        {
            INode node1 = GetRootNode().CreateChild("CreateChildTest17_1", typeof(string), StreamOptions.None);
            INode node2 = GetRootNode().CreateChild("CreateChildTest18_2", typeof(object), StreamOptions.AllowDerivedTypes);

            node2.Base = node1;
            using (ITypedStream s2 = node1.OpenDefaultStream(OpenMode.Write))
            {
                s2.Write(0, "myname");
            }

            // We can access it through node 2.
            using (ITypedStream s = node2.GetTypedStream(OpenMode.Read, typeof(string)))
            {
                Assert.AreEqual((string)s.Read(0), "myname");
            }
        }
Beispiel #16
0
        public void Move()
        {
            INode root = GetRootNode().CreateChild("CopyTest", typeof(object), StreamOptions.None);

            INode child = root.CreateChild("Child1", typeof(string), StreamOptions.SingleObject);

            using (ITypedStream ts = child.OpenDefaultStream(OpenMode.Write))
            {
                ts.Write(0, "my data");
            }

            root  = GetRootNode().CreateChild("CopyTest_2", typeof(object), StreamOptions.None);
            child = child.MoveTo(root);

            Assert.AreEqual(typeof(string), child.DefaultType);
            using (ITypedStream ts = child.OpenDefaultStream(OpenMode.Read))
            {
                Assert.AreEqual("my data", ts.Read(0) as string);
            }
        }
Beispiel #17
0
 /// <summary>
 /// 読み取りの対象を指定して Status のインスタンスを初期化します。
 /// </summary>
 /// <param name="target">読み取りの対象を格納しているオブジェクトを指定します。</param>
 public Status(ITypedStream <T> target)
 {
     this.target  = target;
     this.success = default(bool);
 }
 public Response(ITypedStream responseStream, HttpStatusCode statusCode = HttpStatusCode.OK)
 {
     ResponseStream = responseStream;
     StatusCode     = statusCode;
 }
 public Response(ITypedStream responseStream, HttpStatusCode statusCode = HttpStatusCode.OK)
 {
     ResponseStream = responseStream;
     StatusCode = statusCode;
 }
Beispiel #20
0
        public void GetFlags()
        {
            ITypedStream stream = CreateStream(typeof(string), StreamOptions.Compressed);

            Assert.AreEqual(stream.Flags, StreamOptions.Compressed);
        }
 public void CopyTo(ITypedStream stream)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Beispiel #22
0
        public INode CopyTo([NotNull] INode n)
        {
            lock (SyncRoot)
            {
                AssertNotDisposed();

                // Must ensure from the same db and other checks.
                ManagedNode dest = n as ManagedNode;


                // We check if we are not moving to child of our node.
                string pathTo   = dest.Path;
                string pathFrom = Path;

                if (pathTo.Length > pathFrom.Length && pathTo.Substring(0, pathFrom.Length) == pathFrom)
                {
                    throw new InvalidOperationException(string.Format("Moving from path {0} to " +
                                                                      "path {1} which is a child of path {0}", pathFrom, pathTo));
                }

                // We create it with default type.
                INode myCopy;
                using (ITypedStream defaultTS = OpenDefaultStream(OpenMode.Read))
                {
                    myCopy = dest.CreateChild(Name, defaultTS.StreamType, defaultTS.Flags);

                    // Copy data.
                    using (ITypedStream defaultCopyTS = myCopy.OpenDefaultStream(OpenMode.Write))
                    {
                        defaultTS.CopyTo(defaultCopyTS);
                    }
                }

                // All typed streams.
                foreach (Type t in TypedStreams)
                {
                    // Default type already handled.
                    if (t == DefaultType)
                    {
                        continue;
                    }

                    using (ITypedStream ts = GetTypedStream(OpenMode.Read, t))
                    {
                        // Copy data.
                        myCopy.AddTypedStream(ts.StreamType, ts.Flags);

                        using (ITypedStream tsCopy = myCopy.GetTypedStream(OpenMode.Write, ts.StreamType))
                        {
                            ts.CopyTo(tsCopy);
                        }
                    }
                }


                // And all children at last.
                foreach (string s in Children)
                {
                    INode child = this.Find(s);
                    child.CopyTo(myCopy);
                }

                return(myCopy);
            }
        }