internal static EventHubListResult DeserializeEventHubListResult(JsonElement element) { Optional <IReadOnlyList <EventHubData> > value = default; Optional <string> nextLink = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("value")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <EventHubData> array = new List <EventHubData>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(EventHubData.DeserializeEventHubData(item)); } value = array; continue; } if (property.NameEquals("nextLink")) { nextLink = property.Value.GetString(); continue; } } return(new EventHubListResult(Optional.ToList(value), nextLink.Value)); }
/// <summary> /// Global event processor for processing output html /// </summary> /// <param name="ehd">EventHubData for output html</param> /// <returns>Event data output, the HtmlDocument after processing</returns> public object ProcessDocument(EventHubData ehd) { var doc = (HtmlDocument)ehd.Data; DateTime st = DateTime.Now; if (Csses != null) { UpdateIncludes(doc, "link", "href", Csses, new Dictionary <string, string> { { "rel", "stylesheet" }, { "type", "text/css" } }); } if (Scripts != null) { UpdateIncludes(doc, "script", "src", Scripts, new Dictionary <string, string> { { "type", "text/javascript" } }); } if (Htmls != null) { InsertHtmls(doc, Htmls); } if (Styles != null) { InsertStyles(doc, Styles); } return(doc); }
private static async Task <EventHubData> CreateEventDataAsync(string offset, long seqNo) { var ed = new EventData { Subject = "Unit.Test", Action = "Verify", }; var e = await new MicrosoftEventHubsEventConverter().ConvertToAsync(ed); var type = typeof(AzureEventHubs.EventData); var pi = type.GetProperty("SystemProperties"); pi.SetValue(e, Activator.CreateInstance(pi.PropertyType, true)); var dict = (Dictionary <string, object>)e.SystemProperties; dict.Add("x-opt-enqueued-time", DateTime.UtcNow); dict.Add("x-opt-offset", offset); dict.Add("x-opt-sequence-number", seqNo); dict.Add("x-opt-partition-key", "0"); var ehd = new EventHubData("testhub", "$Default", "0", e); ((IEventSubscriberData)ehd).SetMetadata(ed); return(ehd); }
public async Task CreateEventhubWithParameter() { //prepare a storage account string accountName = Recording.GenerateAssetName("storage"); Storage.Models.Sku sku = new Storage.Models.Sku("Standard_LRS"); var storageAccountCreateParameters = new StorageAccountCreateParameters(sku, Kind.StorageV2, "eastus2") { AccessTier = AccessTier.Hot }; StorageAccount account = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(true, accountName, storageAccountCreateParameters)).Value; if (Mode != RecordedTestMode.Playback) { await Task.Delay(5000); } //create eventhub string eventHubName = Recording.GenerateAssetName("eventhub"); EventHubData parameter = new EventHubData() { MessageRetentionInDays = 4, PartitionCount = 4, Status = EntityStatus.Active, CaptureDescription = new CaptureDescription() { Enabled = true, Encoding = EncodingCaptureDescription.Avro, IntervalInSeconds = 120, SizeLimitInBytes = 10485763, Destination = new EventHubDestination() { Name = "EventHubArchive.AzureBlockBlob", BlobContainer = "container", ArchiveNameFormat = "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}", StorageAccountResourceId = account.Id.ToString() } } }; EventHub eventHub = (await _eventHubCollection.CreateOrUpdateAsync(true, eventHubName, parameter)).Value; //validate Assert.NotNull(eventHub); Assert.AreEqual(eventHub.Id.Name, eventHubName); Assert.AreEqual(eventHub.Data.Status, parameter.Status); Assert.AreEqual(eventHub.Data.MessageRetentionInDays, parameter.MessageRetentionInDays); Assert.AreEqual(eventHub.Data.PartitionCount, parameter.PartitionCount); Assert.AreEqual(eventHub.Data.CaptureDescription.IntervalInSeconds, parameter.CaptureDescription.IntervalInSeconds); Assert.AreEqual(eventHub.Data.CaptureDescription.SizeLimitInBytes, parameter.CaptureDescription.SizeLimitInBytes); Assert.AreEqual(eventHub.Data.CaptureDescription.Destination.Name, parameter.CaptureDescription.Destination.Name); Assert.AreEqual(eventHub.Data.CaptureDescription.Destination.BlobContainer, parameter.CaptureDescription.Destination.BlobContainer); Assert.AreEqual(eventHub.Data.CaptureDescription.Destination.StorageAccountResourceId, parameter.CaptureDescription.Destination.StorageAccountResourceId); Assert.AreEqual(eventHub.Data.CaptureDescription.Destination.ArchiveNameFormat, parameter.CaptureDescription.Destination.ArchiveNameFormat); await account.DeleteAsync(true); }
private static object ProcessIntercept(EventHubData ehd) { var ed = (DataRouteInterceptEventData)ehd.Data; if (ed.WasHandled) return ed; var route = (Route)ehd.Sender; if (ed.QueryStringParams.ContainsKey("$urlget")) { if (ed.Data == null) return ed; else { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "Index"); ed.RouteData.DataTokens.Add("$urlget", route.GetUrlPattern(ed.RouteData)); ed.WasHandled = true; } } else if (ed.QueryStringParams.ContainsKey("$urlset")) { if (ed.Data != null) { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "AlreadyExists"); } else { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "MoveUrl"); ed.RouteData.DataTokens.Add("$urlset", ed.QueryStringParams["$urlset"]); ed.RouteData.Values.Add("Type", ed.ContentType); } ed.WasHandled = true; } else if (ed.QueryStringParams.ContainsKey("$urldelete")) { if (ed.Data == null) return ed; else { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "Delete"); ed.RouteData.Values.Add("data", ed.Data); ed.WasHandled = true; } } else if (ed.QueryStringParams.ContainsKey("$urlverify")) { if (ed.Data == null) return ed; else { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "VerifyExists"); ed.WasHandled = true; } } return ed; }
public async Task ChangelogSample() { #region Snippet:ChangeLog_Sample string namespaceName = "myNamespace"; string eventhubName = "myEventhub"; string resourceGroupName = "myResourceGroup"; ArmClient client = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync(); ResourceGroupResource resourceGroup = subscription.GetResourceGroups().Get(resourceGroupName); //create namespace EventHubNamespaceData parameters = new EventHubNamespaceData(AzureLocation.WestUS) { Sku = new EventHubsSku(EventHubsSkuName.Standard) { Tier = EventHubsSkuTier.Standard, } }; parameters.Tags.Add("tag1", "value1"); parameters.Tags.Add("tag2", "value2"); EventHubNamespaceCollection eHNamespaceCollection = resourceGroup.GetEventHubNamespaces(); EventHubNamespaceResource eventHubNamespace = eHNamespaceCollection.CreateOrUpdate(WaitUntil.Completed, namespaceName, parameters).Value; //create eventhub EventHubCollection eventHubCollection = eventHubNamespace.GetEventHubs(); EventHubData eventHubData = new EventHubData() { MessageRetentionInDays = 4, PartitionCount = 4, Status = EntityStatus.Active, CaptureDescription = new CaptureDescription() { Enabled = true, Encoding = EncodingCaptureDescription.Avro, IntervalInSeconds = 120, SizeLimitInBytes = 10485763, Destination = new EventHubDestination() { Name = "EventHubArchive.AzureBlockBlob", BlobContainer = "Container", ArchiveNameFormat = "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}", StorageAccountResourceId = subscription.Id.ToString() + "/resourcegroups/v-ajnavtest/providers/Microsoft.Storage/storageAccounts/testingsdkeventhubnew" }, SkipEmptyArchives = true } }; EventHubResource eventHub = eventHubCollection.CreateOrUpdate(WaitUntil.Completed, eventhubName, eventHubData).Value; #endregion }
/// <summary> /// sign in silently first. If that fails, then bring up gui /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void On_Loaded(object sender, RoutedEventArgs e) { List <string> partitionIds = new List <string>(); partitionIds.Add("0"); partitionIds.Add("1"); string entity = "..."; //should start with "iothub-ehub-<hub name>-<random numbers>" string port = "sb://.../"; //should start with "sb://" and end with "sevicebus.windows.net/" string name = "..."; //iothub name string deviceName = "..."; //name of iot device you want to listen to string primaryKey = "..."; EventHubData eventhub = new EventHubData(partitionIds, entity, port, name); IoTAccountData a = new IoTAccountData(null, null, null, null, null, deviceName, "iothubowner", primaryKey, eventhub); //NavigateToMap(a); }
private static async Task <EventHubData> CreateEventDataAsync(long offset, long seqNo) { var ed = new EventData { Subject = "Unit.Test", Action = "Verify", }; var e = await new EventHubsEventConverter().ConvertToAsync(ed); var raw = e.GetRawAmqpMessage(); raw.MessageAnnotations["x-opt-enqueued-time"] = DateTimeOffset.UtcNow; raw.MessageAnnotations["x-opt-offset"] = offset; raw.MessageAnnotations["x-opt-sequence-number"] = seqNo; raw.MessageAnnotations["x-opt-partition-key"] = "0"; var ehd = new EventHubData("testhub", "$Default", "0", e); ((IEventSubscriberData)ehd).SetMetadata(ed); return(ehd); }
public async System.Threading.Tasks.Task <JsonResult> SendMovement(int movement) { try { //Put all of the data into a single class EventHubData ehd = new EventHubData() { Movement = movement, EntryTime = DateTime.UtcNow }; //serialize it var serializedString = JsonConvert.SerializeObject(ehd); ////Create the Event Data object so the data and partition are known EventData data = new EventData(Encoding.UTF8.GetBytes(serializedString)) { PartitionKey = "0" }; ////Get a reference to the event hub EventHubClient client = EventHubClient.CreateFromConnectionString(ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"], "legodemoeventhub"); ////Send the data await client.SendAsync(data); //Return to the client return(Json("", JsonRequestBehavior.AllowGet)); } catch (Exception) { throw; } }
/// <summary> /// Called by infrastructure to automatically build filters from attributes on content types /// </summary> /// <param name="ehd">Event data when called via an event being raised after the repository is built</param> /// <returns>Returns null (needed to have signature of an event processor)</returns> public object BuildFilters(EventHubData ehd) { // Get filters on summary types foreach (Type t in ContentTypeHierarchy.SummaryBaseTypes.Keys.Concat(typeof(Summary))) { foreach (PropertyInfo pi in t.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)) // just the properties declared in this class, not any base class { var lfa = pi.GetCustomAttribute<FieldFilterAttribute>(); if (lfa != null) { Filters.Add(FieldFilter.Create(lfa, pi)); } } } // Get filters on container types foreach (Type t in ContentTypeHierarchy.AllContentTypes.Select(ct => Collator.Instance.ContainerType(ct)).Distinct()) { foreach (PropertyInfo pi in t.GetProperties()) { var lfa = pi.GetCustomAttribute<FieldFilterAttribute>(); if (lfa != null) { Filters.Add(FieldFilter.Create(lfa, pi)); } } } // Get filters on container extension types foreach (Type extT in CompositeTypeManager.Instance.ExtensionTypes) { Type baseT = extT.BaseType; foreach (PropertyInfo pi in extT.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)) { var lfa = pi.GetCustomAttribute<FieldFilterAttribute>(); if (lfa != null) { PropertyInfo mappedPi = CompositeTypeManager.Instance.ExtendedTypes[baseT] .GetProperty(pi.Name); Filters.Add(FieldFilter.Create(lfa, mappedPi)); } } } return null; }
private static object ProcessIntercept(EventHubData ehd) { var ed = (DataRouteInterceptEventData)ehd.Data; if (ed.WasHandled) { return(ed); } var route = (Route)ehd.Sender; if (ed.QueryStringParams.ContainsKey("$urlget")) { if (ed.Data == null) { return(ed); } else { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "Index"); ed.RouteData.DataTokens.Add("$urlget", route.GetUrlPattern(ed.RouteData)); ed.WasHandled = true; } } else if (ed.QueryStringParams.ContainsKey("$urlset")) { if (ed.Data != null) { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "AlreadyExists"); } else { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "MoveUrl"); ed.RouteData.DataTokens.Add("$urlset", ed.QueryStringParams["$urlset"]); ed.RouteData.Values.Add("Type", ed.ContentType); } ed.WasHandled = true; } else if (ed.QueryStringParams.ContainsKey("$urldelete")) { if (ed.Data == null) { return(ed); } else { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "Delete"); ed.RouteData.Values.Add("data", ed.Data); ed.WasHandled = true; } } else if (ed.QueryStringParams.ContainsKey("$urlverify")) { if (ed.Data == null) { return(ed); } else { ed.RouteData.RedirectAction("Lynicon", "UrlManager", "VerifyExists"); ed.WasHandled = true; } } return(ed); }
/// <summary> /// Global event processor for processing output html /// </summary> /// <param name="ehd">EventHubData for output html</param> /// <returns>Event data output, the HtmlDocument after processing</returns> public object ProcessDocument(EventHubData ehd) { var doc = (HtmlDocument)ehd.Data; DateTime st = DateTime.Now; if (Csses != null) UpdateIncludes(doc, "link", "href", Csses, new Dictionary<string, string> { { "rel", "stylesheet" }, { "type", "text/css" } }); if (Scripts != null) UpdateIncludes(doc, "script", "src", Scripts, new Dictionary<string, string> { { "type", "text/javascript" } }); if (Htmls != null) InsertHtmls(doc, Htmls); if (Styles != null) InsertStyles(doc, Styles); return doc; }