public async Task <HttpResponseMessage> Post(HttpRequestMessage request, GraphQLQuery query) { var result = new ExecutionResult(); if (WebServer.isBusy) { result.Errors.Add(new ExecutionError("Service is busy...")); } else { WebServer.isBusy = true; ResolverEntry aEntry = new ResolverEntry(WebServer.Doc, WebServer.aRevitTask); result = await aEntry.GetResultAsync(query); WebServer.isBusy = false; } var httpResult = result.Errors?.Count > 0 ? HttpStatusCode.BadRequest : HttpStatusCode.OK; var json = await _writer.WriteToStringAsync(result); var response = request.CreateResponse(httpResult); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); return(response); }
public MetaDataTypeDefinition ResolveName(String refName) { if (fDebug) { Console.Out.WriteLine("Attempting to resolve in " + this.GetHashCode() + ": " + refName); } EntryPair pair = (EntryPair)mapTable[refName]; if (pair == null) { if (fDebug) { Console.Out.WriteLine("...failed"); } return(null); } else { MetaDataTypeDefinition result = pair.Definition; if (fDebug) { ResolverEntry entry = pair.Entry; Console.Out.WriteLine("...found " + result + " in " + entry); } return(result); } }
private async Task ProcessMessagesAsync(Message message, CancellationToken token) { // Process the message Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}"); if (message.Label == "Request") { // Complete the message so that it is not received again. // This can be done only if the queueClient is created in ReceiveMode.PeekLock mode (which is default). await queueClient.CompleteAsync(message.SystemProperties.LockToken); object result = null; if (_marconiIsBusy) { } else { _marconiIsBusy = true; try { var start = DateTime.UtcNow; string query = Encoding.UTF8.GetString(message.Body); ResolverEntry aEntry = new ResolverEntry(_doc, aRevitTask); result = await aEntry.GetResultAsync(JObject.Parse(query)); } catch (Exception e) { } _marconiIsBusy = false; } var responseMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(result))) { ContentType = "application/json", Label = "Response", CorrelationId = message.MessageId, MessageId = Guid.NewGuid().ToString(), TimeToLive = TimeSpan.FromMinutes(5) }; // Send the message to the queue IQueueClient queueResponseClient = new QueueClient(ServiceBusConnectionStringBuilder); await queueClient.SendAsync(responseMessage); } else { await queueClient.AbandonAsync(message.SystemProperties.LockToken); } // Note: Use the cancellationToken passed as necessary to determine if the queueClient has already been closed. // If queueClient has already been Closed, you may chose to not call CompleteAsync() or AbandonAsync() etc. calls // to avoid unnecessary exceptions. }
public void ResolveMyCustomAttributes(MetaDataResolver[] resolvers) { for (int i = this.entryList.Count - 1; i >= 0; i--) { ResolverEntry entry = (ResolverEntry)this.entryList[i]; MetaData metaData = entry.MetaData; foreach (MetaDataCustomAttribute ca in metaData.CustomAttributes) { // Console.WriteLine(ca.ToString()); ca.resolveReferences(this, resolvers); // Console.WriteLine(ca.ToStringLong()); } } }
private void BuildMap() { // walk entryList in reverse, adding exports to mapTable mapTable = new Hashtable(); for (int i = entryList.Count - 1; i >= 0; i--) { ResolverEntry entry = (ResolverEntry)entryList[i]; MetaData metaData = entry.MetaData; // export public typedefs if (fDebug) { Console.Out.WriteLine("Registering " + metaData.TypeDefs.Length + " public TypeDefs from '" + entry.Filename + "' in " + this.GetHashCode()); } foreach (MetaDataTypeDefinition def in metaData.TypeDefs) { TypeAttributes visibility = def.Flags & TypeAttributes.VisibilityMask; String fullName = def.FullName; if ((visibility == TypeAttributes.Public) || (visibility == TypeAttributes.NestedPublic) || ((visibility == TypeAttributes.NotPublic) && (fullName.StartsWith("System.Runtime.Compiler") || fullName.StartsWith("Microsoft.Win32.Win32Native")))) { if (fDebug) { Console.Out.WriteLine("Registering " + fullName); } mapTable[fullName] = new EntryPair(def, entry); } } // export ExportedTypes if (fDebug) { Console.Out.WriteLine("Registering " + metaData.ExportedTypes.Length + " public ExportTypes from '" + entry.Filename + "'"); } foreach (MetaDataExportedType exportType in metaData.ExportedTypes) { String fullName = (exportType.Namespace.Length > 0) ? exportType.Namespace + "." + exportType.Name : exportType.Name; if (mapTable[fullName] == null) { Console.Out.WriteLine("MetaDataResolver doesn't know how to handle " + fullName + "--" + exportType.ToStringLong()); throw new Exception(); } Console.Out.WriteLine("WARNING: assuming that ExportedType " + exportType.ToStringLong() + " matches " + mapTable[fullName]); } } }
static async Task Main(string[] args) { PISystems piSystems = new PISystems(); var aPiSystem = piSystems.DefaultPISystem; ResolverEntry aEntry = new ResolverEntry(aPiSystem); //string graphQlQueryJsonString = @"{""query"": ""{\n hello \n}\n""}"; string query = @" { piSystem { name afDbs { name afElements { name afAttributes { name value tsPlotValues(startDateTime: "" - 20m"", endDateTime: ""*"") { timeStamp value } } } } } } "; string query2 = @" { afElementTemplates(aAfDatabasePath:""\\\\DESKTOP-GV\\GV_001""){ name } } "; string graphQlQueryJsonString = $@"{{""query"": {JsonConvert.SerializeObject(query2)}}}"; GraphQLQuery graphQLQuery = JsonConvert.DeserializeObject <GraphQLQuery>(graphQlQueryJsonString); var result = await aEntry.GetResultAsync(graphQLQuery); var resultString = await new DocumentWriter().WriteToStringAsync(result); Console.WriteLine(resultString); Console.WriteLine("Done."); Console.ReadLine(); }
public async Task <IHttpActionResult> Post([FromBody] GraphQLQuery query) { if (WebServer.isBusy) { var result = new GraphQLExecutionResult(); result.errors.Add(new ExecutionError("Service is busy...")); return(Ok(result)); } else { WebServer.isBusy = true; ResolverEntry aEntry = new ResolverEntry(WebServer.Doc, WebServer.aRevitTask); GraphQLExecutionResult result = await aEntry.GetResultAsync(query); WebServer.isBusy = false; return(Ok(result)); } }
public EntryPair(MetaDataTypeDefinition definition, ResolverEntry entry) { this.Definition = definition; this.Entry = entry; }
private void LoadMetaData(ArrayList loadedStreams, bool fLoadCode, bool fLoadSectionsFromExecutable, bool fLoadDebugInfo) { // try to load the metadata for all streams in loadedStreams. this.entryList = new ArrayList(); this.metaDataList = new ArrayList(); foreach (LoadedStream stream in loadedStreams) { PELoader loader = null; try { if (fDebug) { Console.Out.WriteLine("loading " + stream.Name + "'"); } loader = new PELoader(stream.Content, stream.Name); } catch (FileNotFoundException) { // failed on raw filename; try prefixing with libDirNames elts if (fDebug) { Console.Out.WriteLine("...failed"); } } StringBuilder sb = new StringBuilder(); if (loader == null) { sb.Append("Unable to load '"); sb.Append(stream.Name); sb.Append("'"); Console.Out.WriteLine(sb.ToString()); Console.Out.WriteLine("Aborting!"); String stackTrace = System.Environment.StackTrace; Console.Out.WriteLine(stackTrace); throw new Exception(sb.ToString()); } TimeSpan diffSpan = System.DateTime.Now.Subtract(startTime); int diffMsec = (int)diffSpan.TotalMilliseconds; String secString = (diffMsec / 1000).ToString(); sb.Append(" ", 0, (8 - secString.Length)); sb.Append(secString); sb.Append('.'); sb.Append((diffMsec % 1000).ToString("000")); sb.Append(": "); sb.Append("Loading metadata "); if (fLoadCode) { sb.Append("with code "); } sb.Append("from '"); sb.Append(stream.Name); sb.Append("'"); Console.Out.WriteLine(sb.ToString()); MetaData metaData = MetaData.loadMetaData(stream.Path, loader, fLoadCode, fLoadDebugInfo); metaDataList.Add(metaData); ResolverEntry entry = new ResolverEntry(metaData, stream.Name); entryList.Add(entry); // if (fLoadSectionsFromExecutable && loader.IsExecutableImage()) { // Console.Out.WriteLine("loading all sections from " + fileName); // loader.loadSections(); // } loader.getStream().Close(); } }