本文整理汇总了C#中Microsoft.Azure.Documents.Client.DocumentClient.CreateStoredProcedureAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentClient.CreateStoredProcedureAsync方法的具体用法?C# DocumentClient.CreateStoredProcedureAsync怎么用?C# DocumentClient.CreateStoredProcedureAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Documents.Client.DocumentClient
的用法示例。
在下文中一共展示了DocumentClient.CreateStoredProcedureAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
if (args.Count() < 4)
{
Console.WriteLine("You must specify the following parameters: Document DB endpoint URL, secret key, database name, and collection name.");
Console.WriteLine("Program terminated. Press any key to exit");
Console.ReadKey();
return; // exit program
}
// setup DocumentDB client using passed parameters
Uri endpoint = new Uri(args[0]);
string authKey = args[1];
string databaseId = args[2];
string collectionId = args[3];
var connectionPolicy = new ConnectionPolicy()
{
ConnectionProtocol = Protocol.Https,
ConnectionMode = ConnectionMode.Gateway
};
client = new DocumentClient(endpoint, authKey, connectionPolicy);
Database database = client.CreateDatabaseQuery().Where(db => db.Id == databaseId).ToArray().FirstOrDefault();
DocumentCollection collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == collectionId).ToArray().FirstOrDefault();
// get list of SP files
var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory());
foreach (FileInfo tmpFile in currentDir.GetFiles("SP_*.js"))
{
string storedProecureId = tmpFile.Name.Substring(3, (tmpFile.Name.Length - 6));
Console.WriteLine("Found File: " + storedProecureId);
var storedProc = new StoredProcedure()
{
Id = storedProecureId,
Body = File.ReadAllText(tmpFile.FullName)
};
TryDeleteStoredProcedure(collection.SelfLink, storedProc.Id);
client.CreateStoredProcedureAsync(collection.SelfLink, storedProc, null).Wait();
}
Console.WriteLine("Stored Procedure Setup completed. Press any key to continue.");
Console.ReadKey();
}
示例2: CreateSprocIfNotExists
private static async Task CreateSprocIfNotExists(string scriptFileName, string scriptId, string scriptName)
{
var client = new DocumentClient(new Uri(Endpoint), AuthKey);
Uri collectionLink = UriFactory.CreateDocumentCollectionUri(DbName, CollectionName);
var sproc = new StoredProcedure
{
Id = scriptId,
Body = File.ReadAllText(scriptFileName)
};
bool needToCreate = false;
Uri sprocUri = UriFactory.CreateStoredProcedureUri(DbName, CollectionName, scriptName);
try
{
await client.ReadStoredProcedureAsync(sprocUri);
}
catch (DocumentClientException de)
{
if (de.StatusCode != HttpStatusCode.NotFound)
{
throw;
}
else
{
needToCreate = true;
}
}
if (needToCreate)
{
await client.CreateStoredProcedureAsync(collectionLink, sproc);
}
}