Exemplo n.º 1
0
        protected virtual void OnInspecterVertexGUI(VertexProperty vertex)
        {
            EditorGUI.showMixedValue = vertex.position.hasMultipleDifferentValues;
            EditorGUI.BeginChangeCheck();
            var position = EditorGUILayout.Vector2Field("Position", vertex.position.vector2Value);

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                vertex.position.vector2Value = position;
                this.sobj.ApplyModifiedProperties();
                this.sobj.Update();
            }


            EditorGUI.showMixedValue = vertex.color.hasMultipleDifferentValues;
            EditorGUI.BeginChangeCheck();
            var color = EditorGUILayout.ColorField("Color", vertex.color.colorValue);

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                vertex.color.colorValue = color;
                this.sobj.ApplyModifiedProperties();
                this.sobj.Update();
            }
        }
Exemplo n.º 2
0
        public void ShouldReturnCommonStringRepresentationForToString()
        {
            var vertexProperty = new VertexProperty((long)24, "name", "marko", new Vertex(1));

            var stringRepresentation = vertexProperty.ToString();

            Assert.Equal("vp[name->marko]", stringRepresentation);
        }
Exemplo n.º 3
0
        public static Mesh LoadFbx(string filename, VertexProperty properties = VertexProperty.All)
        {
            var mesh = new Mesh(properties);

            mesh.Vertices.AddRange(FileHelper.LoadFbx(filename));

            return(mesh);
        }
Exemplo n.º 4
0
        public void ShouldReturnTrueForEqualsOfTwoEqualVertexProperties()
        {
            var firstVertexProperty  = new VertexProperty((long)24, "name", "marko", new Vertex(1));
            var secondVertexProperty = new VertexProperty((long)24, "name", "marko", new Vertex(1));

            var areEqual = firstVertexProperty.Equals(secondVertexProperty);

            Assert.True(areEqual);
        }
Exemplo n.º 5
0
        internal static string GetTypePropertyString(Vertex v)
        {
            VertexProperty _type = null;

            // Would be great if one could test if this property was there
            try { _type = v.GetVertexProperties("_type").FirstOrDefault(); } catch (Exception) { }
            if (_type == null)
            {
                return(String.Empty);
            }
            return(_type.Value.ToString());
        }
Exemplo n.º 6
0
        public async override Task Execute(SaveVertexCommand cmd)
        {
            var vertexProps = await UnitOfWork.Db.VertexProperties.Where(
                p => p.VertexId == cmd.VertexId && p.Deleted == null).ToListAsync();

            foreach (var propModel in cmd.Props)
            {
                // close old value if present
                var prop = vertexProps.FirstOrDefault(p => p.SchemaUri == propModel.SchemaUri);

                // serialize value to json
                var jsonValue = JsonConvention.SerializeObject(propModel.Value);

                if (prop != null)
                {
                    if (prop.JsonValue == jsonValue)
                    {
                        // nothing to update
                        continue;
                    }
                    else
                    {
                        // different value - close old property and continue
                        prop.Deleted = _clock.TimeStamp;
                    }
                }

                // if value is null do not add anything
                if (propModel.Value == null)
                {
                    continue;
                }

                // create property
                var newProp = new VertexProperty()
                {
                    Id        = Guid.NewGuid(),
                    VertexId  = cmd.VertexId,
                    SchemaUri = propModel.SchemaUri,
                    Created   = _clock.TimeStamp,
                    JsonValue = jsonValue
                };
                UnitOfWork.Db.VertexProperties.Add(newProp);

                // prevent inserting duplicates
                vertexProps.Add(newProp);
            }

            await Events.OnNext(new SaveVertexCompletedEvent()
            {
                Command = cmd
            });
        }
Exemplo n.º 7
0
        public void ShouldSerializeVertexProperty(int version)
        {
            var writer         = CreateGraphSONWriter(version);
            var vertexProperty = new VertexProperty("blah", "keyA", true, new Vertex("stephen"));

            var graphSON = writer.WriteObject(vertexProperty);

            const string expected =
                "{\"@type\":\"g:VertexProperty\",\"@value\":{\"id\":\"blah\",\"label\":\"keyA\",\"value\":true,\"vertex\":\"stephen\"}}";

            Assert.Equal(expected, graphSON);
        }
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            VertexProperty vertexProperty = objectData;
            var            valueDict      = new Dictionary <string, dynamic>
            {
                { "id", writer.ToDict(vertexProperty.Id) },
                { "label", vertexProperty.Label },
                { "value", writer.ToDict(vertexProperty.Value) },
                { "vertex", writer.ToDict(vertexProperty.Vertex.Id) }
            };

            return(GraphSONUtil.ToTypedValue(nameof(VertexProperty), valueDict));
        }
Exemplo n.º 9
0
        public void ShouldDeserializeVertexProperty(int version)
        {
            var graphSon =
                "{\"@type\":\"g:VertexProperty\",\"@value\":{\"id\":\"anId\",\"label\":\"aKey\",\"value\":true,\"vertex\":{\"@type\":\"g:Int32\",\"@value\":9}}}";
            var reader = CreateStandardGraphSONReader(version);

            VertexProperty readVertexProperty = reader.ToObject(JObject.Parse(graphSon));

            Assert.Equal("anId", readVertexProperty.Id);
            Assert.Equal("aKey", readVertexProperty.Label);
            Assert.True(readVertexProperty.Value);
            Assert.NotNull(readVertexProperty.Vertex);
        }
Exemplo n.º 10
0
        public void ShouldDeserializeVertexPropertyWithLabel(int version)
        {
            var graphSon =
                "{\"@type\":\"g:VertexProperty\", \"@value\":{\"id\":{\"@type\":\"g:Int32\",\"@value\":1},\"label\":\"name\",\"value\":\"marko\"}}";
            var reader = CreateStandardGraphSONReader(version);

            VertexProperty readVertexProperty = reader.ToObject(JObject.Parse(graphSon));

            Assert.Equal(1, readVertexProperty.Id);
            Assert.Equal("name", readVertexProperty.Label);
            Assert.Equal("marko", readVertexProperty.Value);
            Assert.Null(readVertexProperty.Vertex);
        }
Exemplo n.º 11
0
 public override void Mouse_Down(Point pointNow)
 {
     foreach (var vertex in Globals.VertexData)
     {
         if (vertex.Coordinates.X - (Globals.VertRadius) <= pointNow.X &&
             pointNow.X <= vertex.Coordinates.X + (Globals.VertRadius) &&
             vertex.Coordinates.Y - (Globals.VertRadius) <= pointNow.Y &&
             pointNow.Y <= vertex.Coordinates.Y + (Globals.VertRadius))
         {
             VertexProperty.PropertiesVertexWindow(vertex);
             return;
         }
     }
 }
Exemplo n.º 12
0
        public static Mesh FromRaw(IEnumerable <float> raws, VertexProperty properties = VertexProperty.All)
        {
            Mesh          mesh   = new Mesh(properties);
            Queue <float> queue  = new Queue <float>(raws);
            int           stride = Vertex.Stride(properties);

            while (queue.Count > 0)
            {
                var vert = Vertex.FromRaw(queue.Pop(stride));
                mesh.Vertices.Add(vert);
            }

            return(mesh);
        }
Exemplo n.º 13
0
        public async Task TestVertexProperty()
        {
            var expected            = new VertexProperty(123, "name", "stephen", null);
            var writer              = CreateGraphBinaryWriter();
            var reader              = CreateGraphBinaryReader();
            var serializationStream = new MemoryStream();

            await writer.WriteAsync(expected, serializationStream);

            serializationStream.Position = 0;
            var actual = await reader.ReadAsync(serializationStream);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 14
0
        public void ShouldDeserializeVertexPropertyWithLabel(int version)
        {
            const string graphSon = "{\"@type\":\"g:VertexProperty\", \"@value\":{\"id\":{\"@type\":\"g:Int32\", " +
                                    "\"@value\":1}, \"label\":\"name\", \"value\":\"marko\"}}";
            var reader = CreateStandardGraphSONReader(version);

            var            jsonElement        = JsonSerializer.Deserialize <JsonElement>(graphSon);
            VertexProperty readVertexProperty = reader.ToObject(jsonElement);

            Assert.Equal(1, readVertexProperty.Id);
            Assert.Equal("name", readVertexProperty.Label);
            Assert.Equal("marko", readVertexProperty.Value);
            Assert.Null(readVertexProperty.Vertex);
        }
Exemplo n.º 15
0
        public void ShouldDeserializeVertexProperty(int version)
        {
            const string graphSon = "{\"@type\":\"g:VertexProperty\", \"@value\":{\"id\":\"anId\", \"label\":\"aKey\", " +
                                    "\"value\":true, \"vertex\":{\"@type\":\"g:Int32\", \"@value\":9}}}";
            var reader = CreateStandardGraphSONReader(version);

            var            jsonElement        = JsonSerializer.Deserialize <JsonElement>(graphSon);
            VertexProperty readVertexProperty = reader.ToObject(jsonElement);

            Assert.Equal("anId", readVertexProperty.Id);
            Assert.Equal("aKey", readVertexProperty.Label);
            Assert.True(readVertexProperty.Value);
            Assert.NotNull(readVertexProperty.Vertex);
        }
Exemplo n.º 16
0
        public void ShouldAssignPropertiesCorrectly()
        {
            const long   id     = 24;
            const string label  = "name";
            const string value  = "marko";
            var          vertex = new Vertex(1);

            var vertexProperty = new VertexProperty(id, label, value, vertex);

            Assert.Equal(label, vertexProperty.Label);
            Assert.Equal(label, vertexProperty.Key);
            Assert.Equal(value, vertexProperty.Value);
            Assert.Equal(id, vertexProperty.Id);
            Assert.Equal(vertex, vertexProperty.Vertex);
        }
Exemplo n.º 17
0
        protected override void OnEnable()
        {
            base.OnEnable();

            this.sobj          = new SerializedObject(this.targets);
            this.fixToAffineUV = this.sobj.FindProperty("fixToAffineUV");
            var quad = this.sobj.FindProperty("quad");

            this.LT              = new VertexProperty(quad.FindPropertyRelative("LT"));
            this.RT              = new VertexProperty(quad.FindPropertyRelative("RT"));
            this.RB              = new VertexProperty(quad.FindPropertyRelative("RB"));
            this.LB              = new VertexProperty(quad.FindPropertyRelative("LB"));
            this.uvOffset        = this.sobj.FindProperty("uvOffset");
            this.uvScale         = this.sobj.FindProperty("uvScale");
            this.editorDrawGizmo = this.sobj.FindProperty("editorDrawGizmo");
        }
Exemplo n.º 18
0
        public async override Task Execute(CreateVertexCommand cmd)
        {
            UnitOfWork.Db.Vertices.Add(new Vertex()
            {
                Id        = cmd.VertexId,
                NetworkId = cmd.NetworkId,
                Created   = _clock.TimeStamp
            });

            if (cmd.Props != null)
            {
                foreach (var propModel in cmd.Props)
                {
                    // serialize value to json
                    var jsonValue = JsonConvention.SerializeObject(propModel.Value);

                    // if value is null do not add anything
                    if (propModel.Value == null)
                    {
                        continue;
                    }

                    // create property
                    var newProp = new VertexProperty()
                    {
                        Id        = Guid.NewGuid(),
                        VertexId  = cmd.VertexId,
                        SchemaUri = propModel.SchemaUri,
                        Created   = _clock.TimeStamp,
                        JsonValue = jsonValue
                    };
                    UnitOfWork.Db.VertexProperties.Add(newProp);
                }
            }

            await Events.OnNext(new SaveVertexCompletedEvent()
            {
                Command = new SaveVertexCommand()
                {
                    VertexId = cmd.VertexId,
                    Props    = cmd.Props
                }
            });
        }
        protected override async Task RunInternalAsync()
        {
            string graphTwinId = MapGraphTwinId(this.hubName, this.twinId);

            Console.WriteLine("Get thermostat vertex ...");
            Vertex vTwin = await this.GetVertexByIdAsync(graphTwinId);

            if (vTwin == null)
            {
                Console.WriteLine("Thermostat does not exist in the graph.");
                return;
            }

            VertexProperty versionProperty = vTwin.GetVertexProperties("version").FirstOrDefault();
            long           currentVersion  = Convert.ToInt64(versionProperty?.Value ?? 0L);
            long           newVersion      = (long)this.jTwin["version"];

            if (currentVersion >= newVersion)
            {
                Console.WriteLine($"Current state has newer version '{currentVersion}' than update version '{newVersion}'. No update required.");
                return;
            }

            Dictionary <string, string> properties = new Dictionary <string, string>
            {
                { "version", newVersion.ToString() }
            };

            string reportedTemperature = this.ParseReportedTemperature(this.jTwin);

            if (!string.IsNullOrWhiteSpace(reportedTemperature))
            {
                properties.Add("temperature", reportedTemperature);
            }
            vTwin = await this.UpdateVertexAsync(graphTwinId, properties);

            Location?location = this.ParseTaggedLocation(this.jTwin);

            if (location != null)
            {
                await this.UpdateLocationAsync(vTwin, location.Value);
            }
        }
Exemplo n.º 20
0
 public static int Stride(VertexProperty p)
 {
     return(((p & VertexProperty.UV) != 0 ? 2 : 0) +
            ((p & VertexProperty.Position) != 0 ? 3 : 0) +
            ((p & VertexProperty.Normal) != 0 ? 3 : 0));
 }
Exemplo n.º 21
0
 set => SetValue(VertexProperty, value);
Exemplo n.º 22
0
 public float[] OnlyRaw(VertexProperty props) => OnlyRaw(Stride(props));
Exemplo n.º 23
0
 public Mesh(VertexProperty properties)
 {
     VertexProperties = properties;
 }
Exemplo n.º 24
0
 public bool HasProperty(VertexProperty property)
 {
     return((VertexProperties & property) == property);
 }
Exemplo n.º 25
0
 public void SetStride(VertexProperty props)
 {
     Stride = Vertex.Stride(props);
 }
Exemplo n.º 26
0
        public (List <Vertex>, List <Edge>) ParserExcel(string path, string scenario)
        {
            var fi = new FileInfo(path);

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            Dictionary <string, Vertex> vRows = new Dictionary <string, Vertex>();
            Dictionary <string, Edge>   eRows = new Dictionary <string, Edge>();

            using (ExcelPackage package = new ExcelPackage(fi))
            {
                //get the first worksheet in the workbook
                ExcelWorksheet worksheet = package.Workbook.Worksheets[0];

                int colCount = worksheet.Dimension.End.Column;  //get Column Count
                int rowCount = worksheet.Dimension.End.Row;     //get row count

                for (int row = 2; row <= rowCount; row++)
                {
                    Vertex aVertex = new Vertex();
                    aVertex.properties = new List <VertexProperty>();
                    aVertex.scenarios  = new List <string>()
                    {
                        scenario
                    };

                    VertexProperty p = null;

                    for (int col = 1; col <= colCount; col++)
                    {
                        string cellStr = worksheet.Cells[row, col].Value?.ToString().Trim();

                        if (!string.IsNullOrWhiteSpace(cellStr))
                        {
                            switch (col)
                            {
                            case 1:

                                aVertex.id = cellStr + "_" + scenario;
                                break;

                            case 2:
                                aVertex.name = cellStr;
                                break;

                            case 3:
                                aVertex.label = cellStr;
                                break;

                            case 4:
                                aVertex.leadSentence = cellStr;
                                break;

                            default:
                                if (col % 2 == 1)
                                {
                                    p      = new VertexProperty();
                                    p.name = cellStr;

                                    col    += 1;
                                    cellStr = worksheet.Cells[row, col].Value?.ToString().Trim();

                                    if (!string.IsNullOrWhiteSpace(cellStr))
                                    {
                                        p.value = cellStr;
                                        aVertex.properties.Add(p);
                                    }
                                }

                                break;
                            }
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(aVertex.id) && !string.IsNullOrWhiteSpace(aVertex.name) && !string.IsNullOrWhiteSpace(aVertex.label))
                    {
                        if (!vRows.ContainsKey(aVertex.id))
                        {
                            vRows.Add(aVertex.id, aVertex);
                        }
                    }
                }

                worksheet = package.Workbook.Worksheets[1];

                colCount = worksheet.Dimension.End.Column;  //get Column Count
                rowCount = worksheet.Dimension.End.Row;     //get row count
                for (int row = 2; row <= rowCount; row++)
                {
                    Edge aEdge = new Edge();
                    aEdge.scenarios = new List <string>()
                    {
                        scenario
                    };

                    for (int col = 1; col <= colCount; col++)
                    {
                        string cellStr = worksheet.Cells[row, col].Value?.ToString().Trim();

                        if (!string.IsNullOrWhiteSpace(cellStr))
                        {
                            switch (col)
                            {
                            case 1:

                                aEdge.relationType = cellStr;
                                break;

                            case 2:
                                aEdge.headVertexId = cellStr + "_" + scenario;
                                break;

                            case 3:
                                aEdge.tailVertexId = cellStr + "_" + scenario;
                                break;
                            }
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(aEdge.relationType) && !string.IsNullOrWhiteSpace(aEdge.headVertexId) && !string.IsNullOrWhiteSpace(aEdge.tailVertexId))
                    {
                        if (vRows.ContainsKey(aEdge.headVertexId) && vRows.ContainsKey(aEdge.tailVertexId))
                        {
                            string key = aEdge.relationType + aEdge.headVertexId + aEdge.tailVertexId;

                            if (!eRows.ContainsKey(key))
                            {
                                eRows.Add(key, aEdge);
                            }
                        }
                    }
                }
            }

            return(vRows.Values.ToList <Vertex>(), eRows.Values.ToList <Edge>());
        }