Beispiel #1
0
        public void ValuesAreRight()
        {
            Assert.AreEqual(
                true,
                GraphValue.BuildBoolValue(true).BoolValue);

            Assert.AreEqual(
                new byte[] { 0x20, 0x20, 0x20 },
                GraphValue.BuildBytesValue(new byte[] { 0x20, 0x20, 0x20 }).Bytesvalue);

            var now = DateTime.Now;

            Assert.AreEqual(
                Encoding.UTF8.GetBytes(
                    now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo)),
                GraphValue.BuildDateValue(
                    Encoding.UTF8.GetBytes(
                        now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo))).DateValue);

            var valNow = GraphValue.BuildDateValue(now);

            Assert.AreEqual(
                now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo),
                Encoding.UTF8.GetString(valNow.DateValue, 0, valNow.DateValue.Length));

            Assert.AreEqual(
                "blaa",
                GraphValue.BuildDefaultValue("blaa").DefaultValue);

            Assert.AreEqual(
                123,
                GraphValue.BuildDoubleValue(123).DoubleValue);

            Assert.AreEqual(
                Encoding.UTF8.GetBytes("{'type':'Point','coordinates':[-122.4220186,37.772318]}"),
                GraphValue.BuildGeoValue(
                    Encoding.UTF8.GetBytes("{'type':'Point','coordinates':[-122.4220186,37.772318]}")).GeoValue);

            var geojson    = "{'type':'Point','coordinates':[-122.4220186,37.772318]}";
            var geojsonVal = GraphValue.BuildGeoValue(geojson);

            Assert.AreEqual(
                geojson,
                Encoding.UTF8.GetString(geojsonVal.GeoValue, 0, geojsonVal.GeoValue.Length));

            Assert.AreEqual(
                123,
                GraphValue.BuildIntValue(123).IntValue);

            Assert.AreEqual(
                "secret",
                GraphValue.BuildPasswordValue("secret").PasswordValue);

            Assert.AreEqual(
                "something",
                GraphValue.BuildStringValue("something").StringValue);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            using (IDgraphMutationsClient client = DgraphDotNet.Clients.NewDgraphMutationsClient("127.0.0.1:5080")) {
                client.Connect("127.0.0.1:9080");

                client.AlterSchema(
                    "Username: string @index(hash) .\n"
                    + "Password: password .");

                while (true)
                {
                    Console.WriteLine("Hi, please enter your new username");
                    var username = Console.ReadLine();

                    // use Upsert to test for a node and value, and create if
                    // not already in the graph as an atomic operation.
                    var result = client.Upsert("Username", GraphValue.BuildStringValue(username));

                    if (result.IsFailed)
                    {
                        Console.WriteLine("Something went wrong : " + result);
                        continue;
                    }

                    var(node, existed) = result.Value;

                    if (existed)
                    {
                        Console.WriteLine("This user already existed.  Try another username.");
                        continue;
                    }

                    Console.WriteLine("Hi, please enter a password for the new user");
                    var password = Console.ReadLine();

                    using (var txn = client.NewTransactionWithMutations()) {
                        var mutation = txn.NewMutation();
                        var property = Clients.BuildProperty(node, "Password", GraphValue.BuildPasswordValue(password));
                        if (property.IsFailed)
                        {
                            // ... something went wrong
                        }
                        else
                        {
                            mutation.AddProperty(property.Value);
                            var err = mutation.Submit();
                            if (err.IsFailed)
                            {
                                // ... something went wrong
                            }
                        }
                        txn.Commit();
                    }
                }
            }
        }
Beispiel #3
0
 public void ValuesAreRightType()
 {
     Assert.IsTrue(GraphValue.BuildBoolValue(true).IsBoolValue);
     Assert.IsTrue(GraphValue.BuildBytesValue(new byte[] { 0x20, 0x20, 0x20 }).IsBytesValue);
     Assert.IsTrue(GraphValue.BuildDateValue(
                       Encoding.UTF8.GetBytes(
                           DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo)))
                   .IsDateValue);
     Assert.IsTrue(GraphValue.BuildDateValue(DateTime.Now).IsDateValue);
     Assert.IsTrue(GraphValue.BuildDefaultValue("blaa").IsDefaultValue);
     Assert.IsTrue(GraphValue.BuildDoubleValue(123).IsDoubleValue);
     Assert.IsTrue(GraphValue.BuildGeoValue(
                       Encoding.UTF8.GetBytes("{'type':'Point','coordinates':[-122.4220186,37.772318]}"))
                   .IsGeoValue);
     Assert.IsTrue(GraphValue.BuildGeoValue("{'type':'Point','coordinates':[-122.4220186,37.772318]}").IsGeoValue);
     Assert.IsTrue(GraphValue.BuildIntValue(123).IsIntValue);
     Assert.IsTrue(GraphValue.BuildPasswordValue("secret").IsPasswordValue);
     Assert.IsTrue(GraphValue.BuildStringValue("something").IsStringValue);
 }
        static async Task Main(string[] args)
        {
            using (IDgraphMutationsClient client = DgraphDotNet.Clients.NewDgraphMutationsClient("127.0.0.1:5080")) {
                client.Connect("127.0.0.1:9080");

                await client.AlterSchema(
                    "Username: string @index(hash) .\n"
                    + "Password: password .");

                var schemaResult = await client.SchemaQuery();

                if (schemaResult.IsFailed)
                {
                    Console.WriteLine($"Something went wrong getting schema.");
                    return;
                }

                Console.WriteLine("Queried schema and got :");
                foreach (var predicate in schemaResult.Value.Schema)
                {
                    Console.WriteLine(predicate.ToString());
                }

                while (true)
                {
                    Console.WriteLine("Hi, please enter your new username");
                    var username = Console.ReadLine();

                    // use Upsert to test for a node and value, and create if
                    // not already in the graph as an atomic operation.
                    var result = await client.Upsert(
                        "Username",
                        GraphValue.BuildStringValue(username),
                        $"{{\"uid\": \"_:myBlank\", \"Username\": \"{username}\"}}",
                        "myBlank");

                    if (result.IsFailed)
                    {
                        Console.WriteLine("Something went wrong : " + result);
                        continue;
                    }

                    var(node, existed) = result.Value;

                    if (existed)
                    {
                        Console.WriteLine("This user already existed.  Try another username.");
                        continue;
                    }

                    Console.WriteLine("Hi, please enter a password for the new user");
                    var password = Console.ReadLine();

                    using (var txn = client.NewTransactionWithMutations()) {
                        var mutation = txn.NewMutation();
                        var property = Clients.BuildProperty(node, "Password", GraphValue.BuildPasswordValue(password));
                        if (property.IsFailed)
                        {
                            // ... something went wrong
                        }
                        else
                        {
                            mutation.AddProperty(property.Value);
                            var err = await mutation.Submit();

                            if (err.IsFailed)
                            {
                                // ... something went wrong
                            }
                        }
                        await txn.Commit();
                    }
                }
            }
        }