public void AddsMetadataDependencyTelemetry() { UnitTestOutput unitTestOutput = null; DateTimeOffset now = DateTimeOffset.Now; using (var pipeline = DiagnosticPipelineFactory.CreatePipeline(diagnosticPipelineConfiguration_.Value)) { unitTestOutput = pipeline.Sinks.First().Output as UnitTestOutput; TelemetryConfiguration telemetryConfiguration = GetAppInsightsTestTelemetryConfiguration(); EventFlowTelemetryProcessor efTelemetryProcessor = telemetryConfiguration.DefaultTelemetrySink.TelemetryProcessors.OfType <EventFlowTelemetryProcessor>().First(); efTelemetryProcessor.Pipeline = pipeline; TelemetryClient client = new TelemetryClient(telemetryConfiguration); client.TrackDependency("FlawlessDependency", "https://flawless.microsoft.com", "dpName", "payload", now, TimeSpan.FromMilliseconds(178), "201 Created", success: true); } Assert.Equal(1, unitTestOutput.EventCount); Assert.True(unitTestOutput.CapturedEvents.TryDequeue(out EventData eventData)); Assert.Equal(now, eventData.Timestamp); Assert.True(eventData.TryGetMetadata(DependencyData.DependencyMetadataKind, out IReadOnlyCollection <EventMetadata> eventMetadata)); Assert.Equal(1, eventMetadata.Count); EventMetadata dependencyMetadata = eventMetadata.ElementAt(0); Assert.Equal(DataRetrievalResult.Success, DependencyData.TryGetData(eventData, dependencyMetadata, out DependencyData dependencyData)); Assert.True(dependencyData.IsSuccess); Assert.Equal(TimeSpan.FromMilliseconds(178), dependencyData.Duration); Assert.Equal("201 Created", dependencyData.ResponseCode); Assert.Equal("https://flawless.microsoft.com", dependencyData.Target); Assert.Equal("FlawlessDependency", dependencyData.DependencyType); }
private EventDataParsed ParseDependencyEvent(EventData eventData, EventMetadata dependencyMetadata) { var result = DependencyData.TryGetData(eventData, dependencyMetadata, out DependencyData dependencyData); if (result.Status != DataRetrievalStatus.Success) { _healthReporter.ReportProblem($"{nameof(SqlTableOutput)}: {result.Message}", EventFlowContextIdentifiers.Output); return(null); } var dependencyEventData = eventData.DeepClone(); if (dependencyData.Duration != null) { dependencyEventData.Payload[nameof(DependencyData.Duration)] = dependencyData.Duration; } if (dependencyData.IsSuccess != null) { dependencyEventData.Payload[nameof(DependencyData.IsSuccess)] = dependencyData.IsSuccess; } if (dependencyData.ResponseCode != null) { dependencyEventData.Payload[nameof(DependencyData.ResponseCode)] = dependencyData.ResponseCode; } if (dependencyData.Target != null) { dependencyEventData.Payload[nameof(DependencyData.Target)] = dependencyData.Target; } if (dependencyData.DependencyType != null) { dependencyEventData.Payload[nameof(DependencyData.DependencyType)] = dependencyData.DependencyType; } return(new DependencyDataParsed(dependencyEventData, ParseEventCustomProperties(eventData))); }
private IDependentBundleConstraint BuildDependencyConstraintMetadata(DependencyData requireBundleData, IBundleMetadata bundleMetadata) => new DependentBundleConstraint { BundleSymbolicName = requireBundleData.BundleSymbolicName, BundleVersion = requireBundleData.BundleVersion, Owner = bundleMetadata };
public void DependencyDataReadSuccessfully() { // The handling of isSuccess, duration and response code is tested fairly thoroughly by Request tests, // so here wie will just focus on Dependency-specific properties: target and dependency type. EventData eventData = new EventData(); eventData.Payload.Add("isSuccess", true); eventData.Payload.Add("responseCode", "200 OK"); eventData.Payload.Add("duration", 212); eventData.Payload.Add("targetServiceUrl", "http://customerdata"); EventMetadata dependencyMetadata = new EventMetadata("dependency"); dependencyMetadata.Properties.Add("isSuccessProperty", "isSuccess"); dependencyMetadata.Properties.Add("responseCodeProperty", "responseCode"); dependencyMetadata.Properties.Add("durationProperty", "duration"); dependencyMetadata.Properties.Add("targetProperty", "targetServiceUrl"); dependencyMetadata.Properties.Add("dependencyType", "CustomerDataService"); var result = DependencyData.TryGetData(eventData, dependencyMetadata, out DependencyData dd); Assert.Equal(DataRetrievalStatus.Success, result.Status); Assert.True(dd.IsSuccess); Assert.Equal("200 OK", dd.ResponseCode); Assert.Equal(212, dd.Duration.Value.TotalMilliseconds, DoublePrecisionTolerance); Assert.Equal("http://customerdata", dd.Target); Assert.Equal("CustomerDataService", dd.DependencyType); }
public static T Get <T>(DependencyFetchTarget fetchTarget = DependencyFetchTarget.GlobalInstance) where T : class { Initialize(); Type targetType = typeof(T); if (!DependencyImplementations.ContainsKey(targetType)) { Type implementor = FindImplementor(targetType); DependencyImplementations[targetType] = implementor != null ? new DependencyData { ImplementorType = implementor } : null; } DependencyData dependencyImplementation = DependencyImplementations[targetType]; if (dependencyImplementation == null) { return(null); } if (fetchTarget == DependencyFetchTarget.GlobalInstance) { if (dependencyImplementation.GlobalInstance == null) { dependencyImplementation.GlobalInstance = Activator.CreateInstance(dependencyImplementation.ImplementorType); } return((T)dependencyImplementation.GlobalInstance); } return((T)Activator.CreateInstance(dependencyImplementation.ImplementorType)); }
void FindAssetDependencies() { m_DependencyData.Clear(); foreach (var selected in Selection.objects) { if (!AssetDatabase.IsMainAsset(selected)) { continue; } var path = AssetDatabase.GetAssetPath(selected); var dependencies = new List <string>(AssetDatabase.GetDependencies(path)); dependencies.Remove(path); // GetDependencies return asset itself var data = new DependencyData() { AssetPath = path, Dependencies = dependencies, }; m_DependencyData.Add(data); } // Sort dependency lists foreach (var data in m_DependencyData) { data.Dependencies.Sort(); } }
public static void Register<T, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TImpl>() where T : class where TImpl : class, T { Type targetType = typeof(T); Type implementorType = typeof(TImpl); if (!DependencyTypes.Contains(targetType)) DependencyTypes.Add(targetType); lock (s_dependencyLock) DependencyImplementations[targetType] = new DependencyData { ImplementorType = implementorType }; }
public static void RegisterSingleton<T>(T instance) where T : class { Type targetType = typeof(T); Type implementorType = typeof(T); if (!DependencyTypes.Contains(targetType)) DependencyTypes.Add(targetType); lock (s_dependencyLock) DependencyImplementations[targetType] = new DependencyData { ImplementorType = implementorType, GlobalInstance = instance }; }
public ActionResult Index() { var model = new DependencyData { Edges = "A:C, C:B, C:D" }; ViewBag.Message = "Welcome to ASP.NET MVC!"; return(View(model)); }
/// <summary> /// Get Dependency For RuntimeData /// </summary> /// <returns></returns> private static void GetDependencyForRuntimeData(RuntimeData runtimeData, AddinMetadata metadata) { if (null != metadata.Runtime.Items1 && metadata.Runtime.Items1.Length > 0) { foreach (Dependency de in metadata.Runtime.Items1) { DependencyData dd = new DependencyData(); dd.AssemblyName = de.AssemblyName; dd.BundleSymbolicName = de.BundleSymbolicName; runtimeData.AddDependency(dd); } } }
public static void Register <T, TImpl>() where T : class where TImpl : class, T { Type targetType = typeof(T); Type implementorType = typeof(TImpl); if (!DependencyTypes.Contains(targetType)) { DependencyTypes.Add(targetType); } DependencyImplementations[targetType] = new DependencyData { ImplementorType = implementorType }; }
/// <include file="../../docs/Microsoft.Maui.Controls/DependencyService.xml" path="//Member[@MemberName='RegisterSingleton']/Docs" /> public static void RegisterSingleton <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T>(T instance) where T : class { Type targetType = typeof(T); Type implementorType = typeof(T); if (!DependencyTypes.Contains(targetType)) { DependencyTypes.Add(targetType); } lock (s_dependencyLock) DependencyImplementations[targetType] = new DependencyData { ImplementorType = implementorType, GlobalInstance = instance }; }
/// <summary> /// Pulls out the name and location information from a DependencyData class instance and /// concatenates the data together to form a fully qualified path for accessing the file /// with XML routines or any other file access routine the tester needs to use. /// </summary> /// <param name="m_dependency">The DependencyData class instance containing the information of interest.</param> /// <returns>A string representing the fully qualified path and filename of the dependency.</returns> /// <remarks> /// Author(s): teejay /// Revision: 1.0 /// Modified: 6/04/2003 /// </remarks> public string getFullPathFromDependency(DependencyData m_dependency, bool relative) { if (m_dependency == null) { throw new DependencyInvalidData( ); } if (!relative) { return(m_dependency.location + "\\" + m_dependency.name); } else { return(m_dependencyLocation + "\\" + m_dependency.location + "\\" + m_dependency.name); } }
private BulkIndexOperation <EventData> CreateDependencyOperation( EventData eventData, EventMetadata dependencyMetadata, string currentIndexName, string documentTypeName) { var result = DependencyData.TryGetData(eventData, dependencyMetadata, out DependencyData dependencyData); if (result.Status != DataRetrievalStatus.Success) { this.healthReporter.ReportProblem("ElasticSearchOutput: " + result.Message, EventFlowContextIdentifiers.Output); return(null); } var dependencyEventData = eventData.DeepClone(); if (dependencyData.Duration != null) { dependencyEventData.Payload[nameof(DependencyData.Duration)] = dependencyData.Duration; } if (dependencyData.IsSuccess != null) { dependencyEventData.Payload[nameof(DependencyData.IsSuccess)] = dependencyData.IsSuccess; } if (dependencyData.ResponseCode != null) { dependencyEventData.Payload[nameof(DependencyData.ResponseCode)] = dependencyData.ResponseCode; } if (dependencyData.Target != null) { dependencyEventData.Payload[nameof(DependencyData.Target)] = dependencyData.Target; } if (dependencyData.DependencyType != null) { dependencyEventData.Payload[nameof(DependencyData.DependencyType)] = dependencyData.DependencyType; } var operation = CreateOperation(dependencyEventData, currentIndexName, documentTypeName); return(operation); }
public void DependencyDataExpectedReadFailure() { // The handling of isSuccess, duration and response code is tested fairly thoroughly by Request tests, // so here wie will just focus on Dependency-specific properties: target and dependency type. // Target property points to non-existent property EventData eventData = new EventData(); EventMetadata dependencyMetadata = new EventMetadata("dependency"); dependencyMetadata.Properties.Add("targetProperty", "targetServiceUrl"); var result = DependencyData.TryGetData(eventData, dependencyMetadata, out DependencyData dd); Assert.Equal(DataRetrievalStatus.DataMissingOrInvalid, result.Status); Assert.Contains("The expected event property 'targetServiceUrl'", result.Message); // Just make sure that after addressing all the issues you can read all the data successfully eventData.Payload.Add("targetServiceUrl", "http://customerdata"); result = DependencyData.TryGetData(eventData, dependencyMetadata, out dd); Assert.Equal(DataRetrievalStatus.Success, result.Status); }
private bool TrackDependency(EventData e, IReadOnlyCollection<EventMetadata> metadata) { Debug.Assert(metadata != null); bool tracked = false; foreach (EventMetadata dependencyMetadata in metadata) { var result = DependencyData.TryGetData(e, dependencyMetadata, out DependencyData dependencyData); if (result.Status != DataRetrievalStatus.Success) { this.healthReporter.ReportWarning("ApplicationInsightsOutput: " + result.Message, EventFlowContextIdentifiers.Output); continue; } var dt = new DependencyTelemetry(); if (dependencyData.Duration != null) { dt.Duration = dependencyData.Duration.Value; // TODO: add an option to extract request start time from event data DateTimeOffset startTime = e.Timestamp.Subtract(dependencyData.Duration.Value); dt.Timestamp = startTime.ToUniversalTime(); } dt.Success = dependencyData.IsSuccess; dt.ResultCode = dependencyData.ResponseCode; dt.Target = dependencyData.Target; dt.Type = dependencyData.DependencyType; AddProperties(dt, e, setTimestampFromEventData: false); telemetryClient.TrackDependency(dt); tracked = true; } return tracked; }
/// <summary> /// Start Dependencie Bundles(note:Recursive) /// </summary> /// <param name="depenData">DependencyData</param> private void StartBundleByDependencie(DependencyData depenData) { IBundle[] bundles = this.Framework.Bundles.GetBundles(depenData.BundleSymbolicName); if (null != bundles && bundles.Length > 0) { for (int i = 0; i < bundles.Length; i++) { if (!(bundles[i].State == BundleState.Starting || bundles[i].State == BundleState.Active)) { if (null != bundles[i].DataInfo.Runtime.Dependencies && bundles[i].DataInfo.Runtime.Dependencies.Count > 0) { for (int index = 0; index < bundles[i].DataInfo.Runtime.Dependencies.Count; index++) { StartBundleByDependencie(bundles[i].DataInfo.Runtime.Dependencies[index]); } } else { StartBundle(bundles[i]); } } } } }
/// <summary> /// By default we will use relative paths. /// </summary> /// <param name="m_dependency"></param> /// <param name="relative"></param> /// <returns></returns> public string getFullPathFromDependency(DependencyData m_dependency) { return(getFullPathFromDependency(m_dependency, true)); }
/// <summary> /// Adds dependencies to the dependency array list. This function handles the starting /// node in the XML document tree with XML_DEPENDENCY_TAG. Each dependency is parsed /// for id, name, location, and version. /// </summary> /// <param name="m_xmlReader">An XmlTextReader instance starting at the XML_DEPENDENCY_TAG node of the XML document.</param> /// <remarks> /// Author(s): teejay /// Revision: 1.0 /// Modified: 6/04/2003 /// </remarks> private void AddDependency( XmlTextReader m_xmlReader ) { // instantaite a new struct to store the data... DependencyData m_dependencyData = new DependencyData( ); string m_elementName; string m_elementValue; try { while ( m_xmlReader.Read( ) ) { switch ( m_xmlReader.NodeType ) { case XmlNodeType.EndElement: if ( m_xmlReader.Name == XML_DEPENDENCY_TAG ) goto finished; break; case XmlNodeType.Element: // get the name of the element... m_elementName = m_xmlReader.Name; // attempt to read the actual value of the element... m_xmlReader.Read( ); if ( m_xmlReader.NodeType == XmlNodeType.EndElement ) { // no value exists for this element... m_elementValue = ""; } else m_elementValue = m_xmlReader.Value; if ( m_elementName == XML_DEPENDENCY_ID_TAG ) m_dependencyData.id = m_elementValue; if ( m_elementName == XML_DEPENDENCY_NAME_TAG ) m_dependencyData.name = m_elementValue; if ( m_elementName == XML_DEPENDENCY_VERSION_TAG ) m_dependencyData.version = m_elementValue; if ( m_elementName == XML_DEPENDENCY_LOCATION_TAG ) if ( Directory.Exists( m_elementValue ) ) m_dependencyData.location = m_elementValue; else m_dependencyData.location = System.IO.Path.GetFullPath( System.IO.Path.GetFullPath( m_dependencyLocation ) + "\\" + m_elementValue ); break; } } finished: m_dependencyArray.Add( (object) m_dependencyData ); } catch ( XmlException e ) { throw new DependencyErrorParsingXMLException( "[LINE: " + e.LineNumber + " POS: " + e.LinePosition + " MESSAGE: " + e.Message + "] " ); } }
/// <summary> /// Pulls out the name and location information from a DependencyData class instance and /// concatenates the data together to form a fully qualified path for accessing the file /// with XML routines or any other file access routine the tester needs to use. /// </summary> /// <param name="m_dependency">The DependencyData class instance containing the information of interest.</param> /// <returns>A string representing the fully qualified path and filename of the dependency.</returns> /// <remarks> /// Author(s): teejay /// Revision: 1.0 /// Modified: 6/04/2003 /// </remarks> public string getFullPathFromDependency( DependencyData m_dependency, bool relative ) { if ( m_dependency == null ) throw new DependencyInvalidData( ); if ( !relative ) return ( m_dependency.location + "\\" + m_dependency.name ); else return ( m_dependencyLocation + "\\" + m_dependency.location + "\\" + m_dependency.name ); }
/// <summary> /// By default we will use relative paths. /// </summary> /// <param name="m_dependency"></param> /// <param name="relative"></param> /// <returns></returns> public string getFullPathFromDependency( DependencyData m_dependency ) { return getFullPathFromDependency( m_dependency, true ); }
void FindAssetThatDependsOn() { // Build dependency list m_DependencyData.Clear(); var selectedPaths = new List <string>(); foreach (var selected in Selection.objects) { if (!AssetDatabase.IsMainAsset(selected)) { continue; } var path = AssetDatabase.GetAssetPath(selected); if (AssetDatabase.IsValidFolder(path)) { continue; } var data = new DependencyData() { AssetPath = path, }; m_DependencyData.Add(data); selectedPaths.Add(path); } // Iterate all assets var guids = AssetDatabase.FindAssets("t:Object"); for (int i = 0; i < guids.Length; i++) { var guid = guids[i]; var path = AssetDatabase.GUIDToAssetPath(guid); EditorUtility.DisplayProgressBar("Searching", "Asset:" + path + " " + i + "/" + guids.Length, (float)i / (float)guids.Length); if (selectedPaths.Contains(path)) { continue; } var dependencies = AssetDatabase.GetDependencies(path); foreach (var dependency in dependencies) { if (dependency.Equals(path)) { continue; } var index = selectedPaths.IndexOf(dependency); if (index != -1) { m_DependencyData[index].Dependencies.Add(path); } } } // Sort dependency lists foreach (var data in m_DependencyData) { data.Dependencies.Sort(); } EditorUtility.ClearProgressBar(); }
/// <summary> /// Adds dependencies to the dependency array list. This function handles the starting /// node in the XML document tree with XML_DEPENDENCY_TAG. Each dependency is parsed /// for id, name, location, and version. /// </summary> /// <param name="m_xmlReader">An XmlTextReader instance starting at the XML_DEPENDENCY_TAG node of the XML document.</param> /// <remarks> /// Author(s): teejay /// Revision: 1.0 /// Modified: 6/04/2003 /// </remarks> private void AddDependency(XmlTextReader m_xmlReader) { // instantaite a new struct to store the data... DependencyData m_dependencyData = new DependencyData( ); string m_elementName; string m_elementValue; try { while (m_xmlReader.Read( )) { switch (m_xmlReader.NodeType) { case XmlNodeType.EndElement: if (m_xmlReader.Name == XML_DEPENDENCY_TAG) { goto finished; } break; case XmlNodeType.Element: // get the name of the element... m_elementName = m_xmlReader.Name; // attempt to read the actual value of the element... m_xmlReader.Read( ); if (m_xmlReader.NodeType == XmlNodeType.EndElement) { // no value exists for this element... m_elementValue = ""; } else { m_elementValue = m_xmlReader.Value; } if (m_elementName == XML_DEPENDENCY_ID_TAG) { m_dependencyData.id = m_elementValue; } if (m_elementName == XML_DEPENDENCY_NAME_TAG) { m_dependencyData.name = m_elementValue; } if (m_elementName == XML_DEPENDENCY_VERSION_TAG) { m_dependencyData.version = m_elementValue; } if (m_elementName == XML_DEPENDENCY_LOCATION_TAG) { if (Directory.Exists(m_elementValue)) { m_dependencyData.location = m_elementValue; } else { m_dependencyData.location = System.IO.Path.GetFullPath(System.IO.Path.GetFullPath(m_dependencyLocation) + "\\" + m_elementValue); } } break; } } finished: m_dependencyArray.Add((object)m_dependencyData); } catch (XmlException e) { throw new DependencyErrorParsingXMLException("[LINE: " + e.LineNumber + " POS: " + e.LinePosition + " MESSAGE: " + e.Message + "] "); } }