/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetResourcesResponse response = new GetResourcesResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("PaginationToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.PaginationToken = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ResourceTagMappingList", targetDepth)) { var unmarshaller = new ListUnmarshaller <ResourceTagMapping, ResourceTagMappingUnmarshaller>(ResourceTagMappingUnmarshaller.Instance); response.ResourceTagMappingList = unmarshaller.Unmarshall(context); continue; } } return(response); }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonResourceGroupsTaggingAPIConfig config = new AmazonResourceGroupsTaggingAPIConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonResourceGroupsTaggingAPIClient client = new AmazonResourceGroupsTaggingAPIClient(creds, config); GetResourcesResponse resp = new GetResourcesResponse(); do { GetResourcesRequest req = new GetResourcesRequest { PaginationToken = resp.PaginationToken , ResourcesPerPage = maxItems }; resp = client.GetResources(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.ResourceTagMappingList) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.PaginationToken)); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetResourcesResponse response = new GetResourcesResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("Documents", targetDepth)) { var unmarshaller = new ListUnmarshaller <DocumentMetadata, DocumentMetadataUnmarshaller>(DocumentMetadataUnmarshaller.Instance); response.Documents = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Folders", targetDepth)) { var unmarshaller = new ListUnmarshaller <FolderMetadata, FolderMetadataUnmarshaller>(FolderMetadataUnmarshaller.Instance); response.Folders = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Marker", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Marker = unmarshaller.Unmarshall(context); continue; } } return(response); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetResourcesResponse response = new GetResourcesResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("item", targetDepth)) { var unmarshaller = new ListUnmarshaller <Resource, ResourceUnmarshaller>(ResourceUnmarshaller.Instance); response.Items = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("position", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Position = unmarshaller.Unmarshall(context); continue; } } return(response); }
public override void on_GetResourcesResponse(GetResourcesResponse msg, long correlationId) { ResourceVector resources = msg.resources; Console.WriteLine(resources.Count + " resources received."); foreach (Resource resource in msg.resources) { Console.WriteLine("*************************************************"); Console.WriteLine("uri : " + resource.uri); Console.WriteLine("data type : " + resource.dataObjectType); Console.WriteLine("name : " + resource.name); Console.WriteLine("*************************************************"); } Console.WriteLine("Asking to get the first dataobject"); GetDataObjects gdo = new GetDataObjects(); MapStringString uriMap = new MapStringString(); uriMap.Add("0", resources[0].uri); gdo.uris = uriMap; getSession().send(gdo, 0, 0x02); }
static void Main(string[] args) { // Get the user's home path and password persistor from the environment. String homePath = Environment.GetEnvironmentVariable("USERPROFILE"); String persistorPassword = Environment.GetEnvironmentVariable("IONIC_PERSISTOR_PASSWORD"); if (persistorPassword == null || persistorPassword.Length == 0) { Console.WriteLine("Please provide the persistor password as env variable: IONIC_PERSISTOR_PASSWORD"); WaitForInput(); Environment.Exit(1); } // Create an agent object to talk to Ionic. Agent agent = new Agent(); // Create a password persistor for agent initialization. try { DeviceProfilePersistorPassword persistor = new DeviceProfilePersistorPassword(); persistor.FilePath = homePath + "\\.ionicsecurity\\profiles.pw"; persistor.Password = persistorPassword; agent.SetMetadata(Agent.MetaApplicationName, "GetResource Sample"); agent.Initialize(persistor); } catch (SdkException sdkExp) { Console.WriteLine("Agent initialization error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Create a resource request for "classification" marking values // configured in the dashboard. GetResourcesRequest.Resource resourceRequest = new GetResourcesRequest.Resource(); resourceRequest.ResourceId = "marking-values"; resourceRequest.Args = "classification"; GetResourcesResponse resourcesResponse = null; // Fetch the resource "classification" marking values. try { resourcesResponse = agent.GetResource(resourceRequest); } catch (SdkException sdkExp) { Console.WriteLine("Error requesting resource: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Extract the resources from the get resources response. List <GetResourcesResponse.Resource> resources = resourcesResponse.Resources; if (resources.Count == 0) { Console.WriteLine("There are no resources available."); WaitForInput(); Environment.Exit(1); } // Display resources. Console.WriteLine("Classification values:"); foreach (GetResourcesResponse.Resource resource in resources) { Console.WriteLine("Data : " + resource.Data); } WaitForInput(); }
private string ToString(GetResourcesResponse r) { string message = $"Record name {r.Resource.Name}, uri {r.Resource.Uri}"; return(message); }
protected void Decode(byte[] data) { var receivedTime = DateTime.UtcNow; using (var inputStream = new MemoryStream(data)) { // create avro binary decoder to read from memory stream var decoder = new BinaryDecoder(inputStream); var record = Activator.CreateInstance <MessageHeader>(); var reader = new SpecificReader <MessageHeader>(new EtpSpecificReader(record.Schema, record.Schema)); MessageHeader header = reader.Read(record, decoder); // string message = Encoding.UTF8.GetString(inputStream.ToArray()); if (header.Protocol == 0 && header.MessageType == 2) { lock (m_ConnectionLock) { m_HasConnected = true; } var recordSession = Activator.CreateInstance <OpenSession>(); var readerSession = new SpecificReader <OpenSession>(new EtpSpecificReader(recordSession.Schema, recordSession.Schema)); readerSession.Read(recordSession, decoder); string message = ToString(recordSession); var timediff = receivedTime - m_Time; Message?.Invoke(message, timediff.TotalMilliseconds, TraceLevel.Info); } else if (header.Protocol == 3 && header.MessageType == 2) { var responce = Activator.CreateInstance <GetResourcesResponse>(); var bodyreader = new SpecificReader <GetResourcesResponse>(new EtpSpecificReader(responce.Schema, responce.Schema)); GetResourcesResponse bodyheader = bodyreader.Read(responce, decoder); RequestInformation parent; lock (m_RequestInformation) { parent = m_RequestInformation[header.CorrelationId]; } var timediff = receivedTime - parent.RequestTime; string message = ToString(responce); Message?.Invoke(message, timediff.TotalMilliseconds, TraceLevel.Info); if (parent.ChannelItem == null) { ChannelItem channelItem = new ChannelItem() { Name = responce.Resource.Name, Uid = responce.Resource.Uuid, Eml = responce.Resource.Uri, Level = 0, ChildrensCount = responce.Resource.HasChildren }; ChannelItemsReceived?.Invoke(channelItem); } else { ChannelItem channelItem = new ChannelItem() { Name = responce.Resource.Name, Uid = responce.Resource.Uuid, Eml = responce.Resource.Uri, Level = parent.ChannelItem.Level + 1, ChildrensCount = responce.Resource.HasChildren }; ChannelChildrensReceived?.Invoke(channelItem, parent.ChannelItem); } } else if (header.Protocol == 1 && header.MessageType == 2) { var timediff = receivedTime - m_Time; string message = "Channels received: ["; var recordMetadata = Activator.CreateInstance <ChannelMetadata>(); var readerMetadata = new SpecificReader <ChannelMetadata>(new EtpSpecificReader(recordMetadata.Schema, recordMetadata.Schema)); readerMetadata.Read(recordMetadata, decoder); ChannelMetadata metadata = new ChannelMetadata(); metadata.Channels = new List <ChannelMetadataRecord>(); lock (m_ChannelStreamingInfo) { foreach (var channel in recordMetadata.Channels) { if (m_LogCurveEml.Contains(channel.ChannelUri, StringComparer.InvariantCultureIgnoreCase)) { metadata.Channels.Add(channel); ChannelStreamingInfo channelStreamingInfo = new ChannelStreamingInfo() { ChannelId = channel.ChannelId, StartIndex = new StreamingStartIndex() { Item = null }, ReceiveChangeNotification = true }; m_ChannelStreamingInfo.Add(channelStreamingInfo); message = message + $"\n{channel.ChannelId} {channel.ChannelName}"; ChannelMetaDataVM channelMetaData_VM = ETPMapper.Instance().Map <ChannelMetaDataVM>(channel); string json = JsonConvert.SerializeObject(channelMetaData_VM, Formatting.Indented); Message?.Invoke(json, timediff.TotalMilliseconds, TraceLevel.Info); } } ChannelInfoReceived?.Invoke(metadata); } message = message + "\n]"; Message?.Invoke(message, timediff.TotalMilliseconds, TraceLevel.Info); HasDescribing = false; } else if (header.Protocol == 1 && header.MessageType == 3) { var recordData = Activator.CreateInstance <ChannelData>(); var readerdata = new SpecificReader <ChannelData>(new EtpSpecificReader(recordData.Schema, recordData.Schema)); readerdata.Read(recordData, decoder); ChannelDataReceived?.Invoke(recordData.Data); } else if (header.MessageType == 1000) { var timediff = receivedTime - m_Time; var bodyrecord = Activator.CreateInstance <ProtocolException>(); var bodyreader = new SpecificReader <ProtocolException>(new EtpSpecificReader(bodyrecord.Schema, bodyrecord.Schema)); ProtocolException bodyheader = bodyreader.Read(bodyrecord, decoder); string message = $"Error Received ({bodyrecord.ErrorCode}): {bodyrecord.ErrorMessage}"; Message?.Invoke(message, timediff.TotalMilliseconds, TraceLevel.Error); HasDescribing = false; } else { HasDescribing = false; } } }