Example #1
0
        private static void WriteEdgeKeyIndices(BinaryWriter writer, TinkerGrapĥ tinkerGrapĥ)
        {
            Contract.Requires(writer != null);
            Contract.Requires(tinkerGrapĥ != null);

            // Write the number of edge key indices
            writer.Write(tinkerGrapĥ.EdgeKeyIndex.Index.Count);

            foreach (var index in tinkerGrapĥ.EdgeKeyIndex.Index)
            {
                // Write the key index name
                writer.Write(index.Key);

                // Write the number of items associated with this key index name
                writer.Write(index.Value.Count);
                foreach (var item in index.Value)
                {
                    // Write the item key
                    WriteTypedData(writer, item.Key);

                    // Write the number of edges in this item
                    writer.Write(item.Value.Count);
                    foreach (var e in item.Value)
                    {
                        // Write the edge identifier
                        WriteTypedData(writer, e.Value.Id);
                    }
                }
            }
        }
            public override void SaveGraphData(TinkerGrapĥ tinkerGrapĥ, string directory)
            {
                var filePath = string.Concat(directory, GraphFileGraphml);

                DeleteFile(filePath);
                GraphMlWriter.OutputGraph(tinkerGrapĥ, filePath);
            }
            public override void SaveGraphData(TinkerGrapĥ tinkerGrapĥ, string directory)
            {
                var filePath = string.Concat(directory, GraphFileGraphson);

                DeleteFile(filePath);
                GraphSonWriter.OutputGraph(tinkerGrapĥ, filePath, GraphSonMode.EXTENDED);
            }
Example #4
0
        private static void WriteIndices(BinaryWriter writer, TinkerGrapĥ tinkerGrapĥ)
        {
            Contract.Requires(writer != null);
            Contract.Requires(tinkerGrapĥ != null);

            // Write the number of indices
            writer.Write(tinkerGrapĥ.Indices.Count);

            foreach (var index in tinkerGrapĥ.Indices)
            {
                // Write the index name
                writer.Write(index.Key);

                var tinkerIndex = index.Value;
                var indexClass  = tinkerIndex.Type;

                // Write the index type
                writer.Write((byte)(indexClass == typeof(IVertex) ? 1 : 2));

                // Write the number of items associated with this index name
                writer.Write(tinkerIndex.Index.Count);
                foreach (var tinkerIndexItem in tinkerIndex.Index)
                {
                    // Write the item key
                    writer.Write(tinkerIndexItem.Key);

                    var tinkerIndexItemSet = tinkerIndexItem.Value;

                    // Write the number of sub-items associated with this item
                    writer.Write(tinkerIndexItemSet.Count);
                    foreach (var items in tinkerIndexItemSet)
                    {
                        if (indexClass == typeof(IVertex))
                        {
                            var vertices = items.Value;

                            // Write the number of vertices in this sub-item
                            writer.Write(vertices.Count);
                            foreach (var v in vertices)
                            {
                                // Write the vertex identifier
                                WriteTypedData(writer, v.Value.Id);
                            }
                        }
                        else if (indexClass == typeof(IEdge))
                        {
                            var edges = items.Value;

                            // Write the number of edges in this sub-item
                            writer.Write(edges.Count);
                            foreach (var e in edges)
                            {
                                // Write the edge identifier
                                WriteTypedData(writer, e.Value.Id);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
 protected TinkerElement(string id, TinkerGrapĥ tinkerGrapĥ) : base(tinkerGrapĥ)
 {
     Contract.Requires(id != null);
     Contract.Requires(tinkerGrapĥ != null);
     TinkerGrapĥ = tinkerGrapĥ;
     RawId       = id;
 }
Example #6
0
        /// <summary>
        ///     Write TinkerGrapĥ metadata to a file.
        /// </summary>
        /// <param name="tinkerGrapĥ">the TinkerGrapĥ to pull the data from</param>
        /// <param name="filename">the name of the file to write the TinkerGrapĥ metadata to</param>
        public static void Save(TinkerGrapĥ tinkerGrapĥ, string filename)
        {
            Contract.Requires(tinkerGrapĥ != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(filename));

            var writer = new TinkerMetadataWriter(tinkerGrapĥ);

            writer.Save(filename);
        }
Example #7
0
        /// <summary>
        ///     Read TinkerGrapĥ metadata from a Stream.
        /// </summary>
        /// <param name="tinkerGrapĥ">the IGraph to push the metadata to</param>
        /// <param name="inputStream">the Stream to read the TinkerGrapĥ metadata from</param>
        public static void Load(TinkerGrapĥ tinkerGrapĥ, Stream inputStream)
        {
            Contract.Requires(tinkerGrapĥ != null);
            Contract.Requires(inputStream != null);

            var reader = new TinkerMetadataReader(tinkerGrapĥ);

            reader.Load(inputStream);
        }
Example #8
0
        /// <summary>
        ///     Read TinkerGrapĥ metadata from a file.
        /// </summary>
        /// <param name="tinkerGrapĥ">the TinkerGrapĥ to push the data to</param>
        /// <param name="filename">the name of the file to read the TinkerGrapĥ metadata from</param>
        public static void Load(TinkerGrapĥ tinkerGrapĥ, string filename)
        {
            Contract.Requires(tinkerGrapĥ != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(filename));

            var reader = new TinkerMetadataReader(tinkerGrapĥ);

            reader.Load(filename);
        }
Example #9
0
        /// <summary>
        ///     Write TinkerGrapĥ metadata to an OutputStream.
        /// </summary>
        /// <param name="tinkerGrapĥ">the TinkerGrapĥ to pull the metadata from</param>
        /// <param name="outputStream">the OutputStream to write the TinkerGrapĥ metadata to</param>
        public static void Save(TinkerGrapĥ tinkerGrapĥ, Stream outputStream)
        {
            Contract.Requires(tinkerGrapĥ != null);
            Contract.Requires(outputStream != null);

            var writer = new TinkerMetadataWriter(tinkerGrapĥ);

            writer.Save(outputStream);
        }
Example #10
0
        public static TinkerGrapĥ CreateTinkerGraph()
        {
            Contract.Ensures(Contract.Result <TinkerGrapĥ>() != null);

            var graph = new TinkerGrapĥ();

            CreateTinkerGraph(graph);
            return(graph);
        }
            public override void Save(TinkerGrapĥ tinkerGrapĥ, string directory)
            {
                var filePath = string.Concat(directory, GraphFileDotNet);

                DeleteFile(filePath);
                using (var stream = File.Create(string.Concat(directory, GraphFileDotNet)))
                {
                    var formatter = new BinaryFormatter();
                    formatter.Serialize(stream, tinkerGrapĥ);
                }
            }
            public override void Save(TinkerGrapĥ tinkerGrapĥ, string directory)
            {
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                SaveGraphData(tinkerGrapĥ, directory);
                var filePath = string.Concat(directory, GraphFileMetadata);

                DeleteFile(filePath);
                TinkerMetadataWriter.Save(tinkerGrapĥ, filePath);
            }
Example #13
0
            public TinkerKeyIndex(Type indexClass, TinkerGrapĥ tinkerGrapĥ)
                : base(null, indexClass)
            {
                if (indexClass == null)
                {
                    throw new ArgumentNullException(nameof(indexClass));
                }
                if (tinkerGrapĥ == null)
                {
                    throw new ArgumentNullException(nameof(tinkerGrapĥ));
                }

                _tinkerGrapĥ = tinkerGrapĥ;
            }
Example #14
0
        private static void ReadEdgeKeyIndices(BinaryReader reader, TinkerGrapĥ tinkerGrapĥ)
        {
            Contract.Requires(reader != null);
            Contract.Requires(tinkerGrapĥ != null);

            // Read the number of edge key indices
            var indexCount = reader.ReadInt32();

            for (var i = 0; i < indexCount; i++)
            {
                // Read the key index name
                var indexName = reader.ReadString();

                tinkerGrapĥ.EdgeKeyIndex.CreateKeyIndex(indexName);

                var items = new ConcurrentDictionary <object, ConcurrentDictionary <string, IElement> >();

                // Read the number of items associated with this key index name
                var itemCount = reader.ReadInt32();
                for (var j = 0; j < itemCount; j++)
                {
                    // Read the item key
                    var key = ReadTypedData(reader);

                    var edges = new ConcurrentDictionary <string, IElement>();

                    // Read the number of edges in this item
                    var edgeCount = reader.ReadInt32();
                    for (var k = 0; k < edgeCount; k++)
                    {
                        // Read the edge identifier
                        var e = tinkerGrapĥ.GetEdge(ReadTypedData(reader));
                        if (e != null)
                        {
                            edges.TryAdd(e.Id.ToString(), e);
                        }
                    }

                    items.Put(key, edges);
                }

                tinkerGrapĥ.EdgeKeyIndex.Index.Put(indexName, items);
            }
        }
            public override TinkerGrapĥ Load(string directory)
            {
                if (!Directory.Exists(directory))
                {
                    throw new Exception(string.Concat("Directory ", directory, " does not exist"));
                }

                var graph = new TinkerGrapĥ();

                LoadGraphData(graph, directory);

                var filePath = string.Concat(directory, GraphFileMetadata);

                if (File.Exists(filePath))
                {
                    TinkerMetadataReader.Load(graph, filePath);
                }

                return(graph);
            }
Example #16
0
        public TinkerEdge(string id, IVertex outVertex, IVertex inVertex, string label, TinkerGrapĥ tinkerGrapĥ)
            : base(id, tinkerGrapĥ)
        {
            Contract.Requires(id != null);
            Contract.Requires(outVertex != null);
            Contract.Requires(inVertex != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(label));
            Contract.Requires(tinkerGrapĥ != null);

            Label      = label;
            _outVertex = outVertex;
            _inVertex  = inVertex;
            tinkerGrapĥ.EdgeKeyIndex.AutoUpdate(StringFactory.Label, Label, null, this);
        }
Example #17
0
        private static void ReadIndices(BinaryReader reader, TinkerGrapĥ tinkerGrapĥ)
        {
            Contract.Requires(reader != null);
            Contract.Requires(tinkerGrapĥ != null);

            // Read the number of indices
            var indexCount = reader.ReadInt32();

            for (var i = 0; i < indexCount; i++)
            {
                // Read the index name
                var indexName = reader.ReadString();

                // Read the index type
                var indexType = reader.ReadByte();

                if (indexType != 1 && indexType != 2)
                {
                    throw new InvalidDataException("Unknown index class type");
                }

                var tinkerIndex = new TinkerIndex(indexName, indexType == 1 ? typeof(IVertex) : typeof(IEdge));

                // Read the number of items associated with this index name
                var indexItemCount = reader.ReadInt32();
                for (var j = 0; j < indexItemCount; j++)
                {
                    // Read the item key
                    var indexItemKey = reader.ReadString();

                    // Read the number of sub-items associated with this item
                    var indexValueItemSetCount = reader.ReadInt32();
                    for (var k = 0; k < indexValueItemSetCount; k++)
                    {
                        // Read the number of vertices or edges in this sub-item
                        var setCount = reader.ReadInt32();
                        for (var l = 0; l < setCount; l++)
                        {
                            // Read the vertex or edge identifier
                            if (indexType == 1)
                            {
                                var v = tinkerGrapĥ.GetVertex(ReadTypedData(reader));
                                if (v != null)
                                {
                                    tinkerIndex.Put(indexItemKey, v.GetProperty(indexItemKey), v);
                                }
                            }
                            else if (indexType == 2)
                            {
                                var e = tinkerGrapĥ.GetEdge(ReadTypedData(reader));
                                if (e != null)
                                {
                                    tinkerIndex.Put(indexItemKey, e.GetProperty(indexItemKey), e);
                                }
                            }
                        }
                    }
                }

                tinkerGrapĥ.Indices.Put(indexName, tinkerIndex);
            }
        }
Example #18
0
 public TinkerVertex(string id, TinkerGrapĥ tinkerGrapĥ)
     : base(id, tinkerGrapĥ)
 {
     Contract.Requires(id != null);
     Contract.Requires(tinkerGrapĥ != null);
 }
 public abstract void Save(TinkerGrapĥ tinkerGrapĥ, string directory);
 public override void LoadGraphData(TinkerGrapĥ tinkerGrapĥ, string directory)
 {
     GraphSonReader.InputGraph(tinkerGrapĥ, string.Concat(directory, GraphFileGraphson));
 }
 public void Save(TinkerGrapĥ tinkerGrapĥ, string directory)
 {
     Contract.Requires(tinkerGrapĥ != null);
     Contract.Requires(!string.IsNullOrWhiteSpace(directory));
 }
Example #22
0
        public TinkerMetadataReader(TinkerGrapĥ tinkerGrapĥ)
        {
            Contract.Requires(tinkerGrapĥ != null);

            _tinkerGrapĥ = tinkerGrapĥ;
        }
 public override void LoadGraphData(TinkerGrapĥ tinkerGrapĥ, string directory)
 {
     Contract.Requires(tinkerGrapĥ != null);
     Contract.Requires(!string.IsNullOrWhiteSpace(directory));
 }
 /// <summary>
 ///     Load the data from the TinkerGrapĥ with the specific file format of the implementation.
 /// </summary>
 public abstract void LoadGraphData(TinkerGrapĥ tinkerGrapĥ, string directory);