Skip to content

Commit 766d25e

Browse files
authored
Merge pull request #105196 from SnehaGunda/breadcrumb
Using environment variables and referencing code blocks
2 parents 1aeac32 + f3899bd commit 766d25e

File tree

2 files changed

+25
-79
lines changed

2 files changed

+25
-79
lines changed

.openpublishing.publish.config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@
419419
"url": "https://github.com/Azure/azure-cosmosdb-java",
420420
"branch": "master"
421421
},
422+
{
423+
"path_to_root": "azure-cosmosdb-graph-dotnet",
424+
"url": "https://github.com/Azure-Samples/azure-cosmos-db-graph-gremlindotnet-getting-started",
425+
"branch": "master"
426+
},
422427
{
423428
"path_to_root": "azure-cosmosdb-java-v4-getting-started",
424429
"url": "https://github.com/Azure-Samples/azure-cosmos-java-getting-started",

articles/cosmos-db/create-graph-dotnet.md

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ms.service: cosmos-db
66
ms.subservice: cosmosdb-graph
77
ms.devlang: dotnet
88
ms.topic: quickstart
9-
ms.date: 05/21/2019
9+
ms.date: 02/21/2020
1010
ms.author: lbosq
1111

1212
---
@@ -78,74 +78,21 @@ This step is optional. If you're interested in learning how the database resourc
7878
7979
The following snippets are all taken from the Program.cs file.
8080
81-
* Set your connection parameters based on the account created above (Line 19):
82-
83-
```csharp
84-
private static string hostname = "your-endpoint.gremlin.cosmosdb.azure.com";
85-
private static int port = 443;
86-
private static string authKey = "your-authentication-key";
87-
private static string database = "your-database";
88-
private static string collection = "your-graph-container";
89-
```
90-
91-
* The Gremlin commands to be executed are listed in a Dictionary (Line 26):
92-
93-
```csharp
94-
private static Dictionary<string, string> gremlinQueries = new Dictionary<string, string>
95-
{
96-
{ "Cleanup", "g.V().drop()" },
97-
{ "AddVertex 1", "g.addV('person').property('id', 'thomas').property('firstName', 'Thomas').property('age', 44).property('pk', 'pk')" },
98-
{ "AddVertex 2", "g.addV('person').property('id', 'mary').property('firstName', 'Mary').property('lastName', 'Andersen').property('age', 39).property('pk', 'pk')" },
99-
{ "AddVertex 3", "g.addV('person').property('id', 'ben').property('firstName', 'Ben').property('lastName', 'Miller').property('pk', 'pk')" },
100-
{ "AddVertex 4", "g.addV('person').property('id', 'robin').property('firstName', 'Robin').property('lastName', 'Wakefield').property('pk', 'pk')" },
101-
{ "AddEdge 1", "g.V('thomas').addE('knows').to(g.V('mary'))" },
102-
{ "AddEdge 2", "g.V('thomas').addE('knows').to(g.V('ben'))" },
103-
{ "AddEdge 3", "g.V('ben').addE('knows').to(g.V('robin'))" },
104-
{ "UpdateVertex", "g.V('thomas').property('age', 44)" },
105-
{ "CountVertices", "g.V().count()" },
106-
{ "Filter Range", "g.V().hasLabel('person').has('age', gt(40))" },
107-
{ "Project", "g.V().hasLabel('person').values('firstName')" },
108-
{ "Sort", "g.V().hasLabel('person').order().by('firstName', decr)" },
109-
{ "Traverse", "g.V('thomas').out('knows').hasLabel('person')" },
110-
{ "Traverse 2x", "g.V('thomas').out('knows').hasLabel('person').out('knows').hasLabel('person')" },
111-
{ "Loop", "g.V('thomas').repeat(out()).until(has('id', 'robin')).path()" },
112-
{ "DropEdge", "g.V('thomas').outE('knows').where(inV().has('id', 'mary')).drop()" },
113-
{ "CountEdges", "g.E().count()" },
114-
{ "DropVertex", "g.V('thomas').drop()" },
115-
};
116-
```
81+
* Set your connection parameters based on the account created above:
11782
83+
:::code language="csharp" source="~/azure-cosmosdb-graph-dotnet/GremlinNetSample/Program.cs" id="configureConnectivity":::
11884
119-
* Create a `GremlinServer` connection object using the parameters provided above (Line 52):
85+
* The Gremlin commands to be executed are listed in a Dictionary:
12086
121-
```csharp
122-
var gremlinServer = new GremlinServer(hostname, port, enableSsl: true,
123-
username: "/dbs/" + database + "/colls/" + collection,
124-
password: authKey);
125-
```
126-
127-
* Create a new `GremlinClient` object (Line 56):
87+
:::code language="csharp" source="~/azure-cosmosdb-graph-dotnet/GremlinNetSample/Program.cs" id="defineQueries":::
12888
129-
```csharp
130-
var gremlinClient = new GremlinClient(gremlinServer, new GraphSON2Reader(), new GraphSON2Writer(), GremlinClient.GraphSON2MimeType);
131-
```
89+
* Create a new `GremlinServer` and `GremlinClient` connection objects using the parameters provided above:
13290
133-
* Execute each Gremlin query using the `GremlinClient` object with an async task (Line 63). This will read the Gremlin queries from the dictionary defined above (Line 26):
91+
:::code language="csharp" source="~/azure-cosmosdb-graph-dotnet/GremlinNetSample/Program.cs" id="defineClientandServerObjects":::
13492
135-
```csharp
136-
var results = await gremlinClient.SubmitAsync<dynamic>(query.Value);
137-
```
93+
* Execute each Gremlin query using the `GremlinClient` object with an async task. You can read the Gremlin queries from the dictionary defined in the previous step and execute them. Later get the result and read the values, which are formatted as a dictionary, using the `JsonSerializer` class from Newtonsoft.Json package:
13894
139-
* Retrieve the result and read the values, which are formatted as a dictionary, using the `JsonSerializer` class from Newtonsoft.Json:
140-
141-
```csharp
142-
foreach (var result in results)
143-
{
144-
// The vertex results are formed as dictionaries with a nested dictionary for their properties
145-
string output = JsonConvert.SerializeObject(result);
146-
Console.WriteLine(String.Format("\tResult:\n\t{0}", output));
147-
}
148-
```
95+
:::code language="csharp" source="~/azure-cosmosdb-graph-dotnet/GremlinNetSample/Program.cs" id="executeQueries":::
14996
15097
## Update your connection string
15198
@@ -159,29 +106,23 @@ Now go back to the Azure portal to get your connection string information and co
159106
160107
![Copy the endpoint](./media/create-graph-dotnet/endpoint.png)
161108
162-
To run this sample, copy the **Gremlin Endpoint** value, delete the port number at the end, that is the URI becomes `https://<your cosmos db account name>.gremlin.cosmosdb.azure.com`
163-
164-
2. In Program.cs paste the value over `your-endpoint` in the `hostname` variable in line 19.
165-
166-
`"private static string hostname = "<your cosmos db account name>.gremlin.cosmosdb.azure.com";`
167-
168-
The endpoint value should now look like this:
169-
170-
`"private static string hostname = "testgraphacct.gremlin.cosmosdb.azure.com";`
171-
172-
3. Next, navigate to the **Keys** tab and copy **PRIMARY KEY** value from the portal, and paste it in the `authkey` variable, replacing the `"your-authentication-key"` placeholder in line 21.
109+
To run this sample, copy the **Gremlin Endpoint** value, delete the port number at the end, that is the URI becomes `https://<your cosmos db account name>.gremlin.cosmosdb.azure.com`. The endpoint value should look like `testgraphacct.gremlin.cosmosdb.azure.com`
173110
174-
`private static string authKey = "your-authentication-key";`
111+
1. Next, navigate to the **Keys** tab and copy the **PRIMARY KEY** value from the Azure portal.
175112
176-
4. Using the information of the database created above, paste the database name inside of the `database` variable in line 22.
113+
1. After you have copied the URI and PRIMARY KEY of your account, save them to a new environment variable on the local machine running the application. To set the environment variable, open a command prompt window, and run the following command. Make sure to replace <Your_Azure_Cosmos_account_URI> and <Your_Azure_Cosmos_account_PRIMARY_KEY> values.
177114
178-
`private static string database = "your-database";`
115+
```console
116+
setx EndpointUrl "https://<your cosmos db account name>.gremlin.cosmosdb.azure.com"
117+
setx PrimaryKey "<Your_Azure_Cosmos_account_PRIMARY_KEY>"
118+
```
179119
180-
5. Similarly, using the information of the container created above, paste the collection (which is also the graph name) inside of the `collection` variable in line 23.
120+
1. Open the *Program.cs* file and update the "database and "container" variables with the database and container (which is also the graph name) names created above.
181121
182-
`private static string collection = "your-collection-or-graph";`
122+
`private static string database = "your-database-name";`
123+
`private static string container = "your-container-or-graph-name";`
183124
184-
6. Save the Program.cs file.
125+
1. Save the Program.cs file.
185126
186127
You've now updated your app with all the info it needs to communicate with Azure Cosmos DB.
187128

0 commit comments

Comments
 (0)