/// <summary> /// Initializes a new instance of the <see cref="MediaInfo"/> class. /// </summary> /// <param name="container">The input container context.</param> internal unsafe MediaInfo(AVFormatContext *container) { FilePath = new IntPtr(container->url).Utf8ToString(); ContainerFormat = new IntPtr(container->iformat->name).Utf8ToString(); Metadata = new ContainerMetadata(container->metadata); Bitrate = container->bit_rate > 0 ? container->bit_rate : 0; var timeBase = new AVRational { num = 1, den = ffmpeg.AV_TIME_BASE }; Duration = container->duration != ffmpeg.AV_NOPTS_VALUE ? container->duration.ToTimeSpan(timeBase) : TimeSpan.Zero; StartTime = container->start_time != ffmpeg.AV_NOPTS_VALUE ? container->start_time.ToTimeSpan(timeBase) : TimeSpan.Zero; Chapters = new ReadOnlyCollection <MediaChapter>(ParseChapters(container)); fileInfo = new Lazy <FileInfo>(() => { try { var info = new FileInfo(FilePath); return(info); } catch (Exception) { return(null); } }); }
/// <summary> /// Applies a set of metadata fields to the output file. /// </summary> /// <param name="metadata">The metadata object to set.</param> public void SetMetadata(ContainerMetadata metadata) { foreach (var item in metadata.Metadata) { ffmpeg.av_dict_set(&Pointer->metadata, item.Key, item.Value, 0); } }
public Api(Uri baseEndpoint, IApiRequestFactory apiRequestFactory, IDogStatsd statsd) { Log.Debug("Creating new Api"); _tracesEndpoint = new Uri(baseEndpoint, TracesPath); _statsd = statsd; _containerId = ContainerMetadata.GetContainerId(); _apiRequestFactory = apiRequestFactory ?? CreateRequestFactory(); }
public void Parse_ContainerId_From_Cgroup_File(string file, string expected) { // arrange var lines = SplitLines(file); // act string actual = ContainerMetadata.ParseCgroupLines(lines); // assert Assert.Equal(expected, actual); }
private async Task <EnumerationResult> KvpbaseEnumerate(string prefix, string continuationToken) { int startIndex = 0; int count = 1000; if (!String.IsNullOrEmpty(continuationToken)) { if (!KvpbaseParseContinuationToken(continuationToken, out startIndex, out count)) { throw new ArgumentException("Unable to parse continuation token."); } } ContainerMetadata cmd = null; EnumerationResult ret = new EnumerationResult(); try { if (String.IsNullOrEmpty(prefix)) { cmd = await _Kvpbase.EnumerateContainer(_KvpbaseSettings.Container, startIndex, count); } else { EnumerationFilter filter = new EnumerationFilter(); filter.Prefix = prefix; cmd = await _Kvpbase.EnumerateContainer(filter, _KvpbaseSettings.Container, startIndex, count); } } catch (Exception) { throw new IOException("Unable to enumerate objects."); } ret.NextContinuationToken = KvpbaseBuildContinuationToken(startIndex + count, count); if (cmd.Objects != null && cmd.Objects.Count > 0) { foreach (ObjectMetadata curr in cmd.Objects) { BlobMetadata md = new BlobMetadata(); md.Key = curr.ObjectKey; md.ETag = curr.Md5; md.ContentLength = Convert.ToInt64(curr.ContentLength); md.ContentType = curr.ContentType; md.Created = curr.CreatedUtc.Value; ret.Blobs.Add(md); } } return(ret); }
/// <summary> /// Returns the entity specified by <paramref name="link"/>. This can be an entity from /// any entityset in the <see cref="Db"/>. /// </summary> /// <param name="link"></param> /// <returns></returns> protected virtual object GetEntityForLink(Uri link) { // Parse the link to fetch the linkedObject IEdmEntitySet edmEntitySet; object key; if (!this.ParseSingleEntityLink(link, out edmEntitySet, out key)) { return(null); } Type entitySetType = ContainerMetadata.GetEntitySet(edmEntitySet.Name).ElementTypeMetadata.ClrType; return(Db.Set(entitySetType).Find(key)); }
public CIEventMessagePackFormatter(TracerSettings tracerSettings) { var containerId = ContainerMetadata.GetContainerId(); if (containerId is not null) { _containerIdValueBytes = StringEncoding.UTF8.GetBytes(containerId); } else { _containerIdValueBytes = null; } var environment = tracerSettings.Environment; if (environment is not null) { _environmentValueBytes = StringEncoding.UTF8.GetBytes(environment); } else { _environmentValueBytes = null; } var service = tracerSettings.ServiceName; if (service is not null) { _serviceValueBytes = StringEncoding.UTF8.GetBytes(service); } else { _serviceValueBytes = null; } var serviceVersion = tracerSettings.ServiceVersion; if (serviceVersion is not null) { _appVersionValueBytes = StringEncoding.UTF8.GetBytes(serviceVersion); } else { _appVersionValueBytes = null; } _envelopBytes = GetEnvelopeArraySegment(); }
public Api( IApiRequestFactory apiRequestFactory, IDogStatsd statsd, Action <Dictionary <string, float> > updateSampleRates, bool isPartialFlushEnabled, IDatadogLogger log = null) { // optionally injecting a log instance in here for testing purposes _log = log ?? StaticLog; _log.Debug("Creating new Api"); _updateSampleRates = updateSampleRates; _statsd = statsd; _containerId = ContainerMetadata.GetContainerId(); _apiRequestFactory = apiRequestFactory; _isPartialFlushEnabled = isPartialFlushEnabled; _tracesEndpoint = _apiRequestFactory.GetEndpoint(TracesPath); _log.Debug("Using traces endpoint {TracesEndpoint}", _tracesEndpoint.ToString()); }
public void RecordTracerSettings( ImmutableTracerSettings tracerSettings, string defaultServiceName, AzureAppServices appServicesMetadata) { // Increment number of times this has been called var reconfigureCount = Interlocked.Increment(ref _tracerInstanceCount); var appData = new ApplicationTelemetryData( serviceName: defaultServiceName, env: tracerSettings.Environment, tracerVersion: TracerConstants.AssemblyVersion, languageName: "dotnet", languageVersion: FrameworkDescription.Instance.ProductVersion) { ServiceVersion = tracerSettings.ServiceVersion, RuntimeName = FrameworkDescription.Instance.Name, }; _settings = new CurrentSettings(tracerSettings, appData); // The remaining properties can't change, so only need to set them the first time if (reconfigureCount != 1) { SetHasChanges(); return; } _azureApServicesMetadata = appServicesMetadata; var host = HostMetadata.Instance; _hostData = new HostTelemetryData { ContainerId = ContainerMetadata.GetContainerId(), Os = FrameworkDescription.Instance.OSPlatform, OsVersion = Environment.OSVersion.ToString(), Hostname = host.Hostname, KernelName = host.KernelName, KernelRelease = host.KernelRelease, KernelVersion = host.KernelVersion, }; _isTracerInitialized = true; SetHasChanges(); }
public Api(Uri baseEndpoint, DelegatingHandler delegatingHandler, IStatsd statsd) { Log.Debug("Creating new Api"); _tracesEndpoint = new Uri(baseEndpoint, TracesPath); _statsd = statsd; _client = delegatingHandler == null ? new HttpClient() : new HttpClient(delegatingHandler); _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.Language, ".NET"); // report runtime details try { var frameworkDescription = FrameworkDescription.Create(); if (frameworkDescription != null) { _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.LanguageInterpreter, frameworkDescription.Name); _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.LanguageVersion, frameworkDescription.ProductVersion); } } catch (Exception e) { Log.Error(e, "Error getting framework description"); } // report Tracer version _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.TracerVersion, TracerConstants.AssemblyVersion); // report container id (only Linux containers supported for now) var containerId = ContainerMetadata.GetContainerId(); if (containerId != null) { _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.ContainerId, containerId); } // don't add automatic instrumentation to requests from this HttpClient _client.DefaultRequestHeaders.Add(HttpHeaderNames.TracingEnabled, "false"); }
public async Task Http_Headers_Contain_ContainerId() { string expectedContainedId = ContainerMetadata.GetContainerId(); string actualContainerId = null; var agentPort = TcpPortProvider.GetOpenPort(); using (var agent = new MockTracerAgent(agentPort)) { agent.RequestReceived += (sender, args) => { actualContainerId = args.Value.Request.Headers[AgentHttpHeaderNames.ContainerId]; }; var settings = new TracerSettings { Exporter = new ExporterSettings() { AgentUri = new Uri($"http://localhost:{agent.Port}"), } }; var tracer = new Tracer(settings, agentWriter: null, sampler: null, scopeManager: null, statsd: null); using (var scope = tracer.StartActive("operationName")) { scope.Span.ResourceName = "resourceName"; } await tracer.FlushAsync(); var spans = agent.WaitForSpans(1); Assert.Equal(1, spans.Count); Assert.Equal(expectedContainedId, actualContainerId); if (EnvironmentTools.IsWindows()) { // we don't extract the containerId on Windows (yet?) Assert.Null(actualContainerId); } } }
public override void DeleteLink([FromODataUri] TKey key, string relatedKey, string navigationProperty) { IEdmNavigationProperty edmNavigationProperty = GenericNavigationPropertyRoutingConvention.GetNavigationProperty(Request.ODataProperties().Path); Contract.Assert(navigationProperty == edmNavigationProperty.Name); // Get the DbSet containing the linked object IEdmSchemaType schemaType = ((Microsoft.Data.Edm.Library.EdmNavigationProperty)edmNavigationProperty.Partner).DeclaringEntityType; Type relatedType = ContainerMetadata.GetEntitySetFor(schemaType).ElementTypeMetadata.ClrType; object linkKey = ODataUriUtils.ConvertFromUriLiteral(relatedKey, ODataVersion.V3, Request.ODataProperties().Model, Request.ODataProperties().Path.EntitySet.GetSingleKeyType()); object linkedObject = Db.Set(relatedType).Find(linkKey); if (linkedObject == null) { throw new ArgumentException(string.Format("Link: {0}.{1} could not be resolved to an entity", navigationProperty, relatedKey), "link"); } DeleteLink(key, navigationProperty, linkedObject); }
public Api(Uri baseEndpoint, IApiRequestFactory apiRequestFactory, IStatsd statsd) { Log.Debug("Creating new Api"); _tracesEndpoint = new Uri(baseEndpoint, TracesPath); _statsd = statsd; _containerId = ContainerMetadata.GetContainerId(); _apiRequestFactory = apiRequestFactory ?? new ApiWebRequestFactory(); // report runtime details try { _frameworkDescription = FrameworkDescription.Create(); if (_frameworkDescription != null) { Log.Information(_frameworkDescription.ToString()); } } catch (Exception e) { Log.SafeLogError(e, "Error getting framework description"); } }
internal static async Task HttpPutContainer(RequestMetadata md) { string header = _Header + md.Http.Request.SourceIp + ":" + md.Http.Request.SourcePort + " "; if (md.User == null) { _Logging.Warn(header + "HttpPutContainer no authentication material"); md.Http.Response.StatusCode = 401; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(3, 401, null, null), true)); return; } if (md.Http.Request.RawUrlEntries.Count != 2) { _Logging.Warn(header + "HttpPutContainer request URL does not have two entries"); md.Http.Response.StatusCode = 400; md.Http.Response.ContentType = "application.json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(2, 400, "URL path must be of the form /[user]/[container]/[key].", null), true)); return; } if (!md.Params.UserGuid.ToLower().Equals(md.User.GUID.ToLower())) { _Logging.Warn(header + "HttpPutContainer user " + md.User.GUID + " attempting to PUT container in user " + md.Params.UserGuid); md.Http.Response.StatusCode = 401; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(3, 401, null, null), true)); return; } ContainerClient client = null; if (!_ContainerMgr.GetContainerClient(md.Params.UserGuid, md.Params.ContainerName, out client)) { _Logging.Warn(header + "HttpPutContainer unable to find container " + md.Params.UserGuid + "/" + md.Params.ContainerName); md.Http.Response.StatusCode = 404; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(5, 404, null, null), true)); return; } if (md.Params.AuditLog) { #region Audit-Log int count = 100; int index = 0; if (md.Params.Count != null) { count = Convert.ToInt32(md.Params.Count); } if (md.Params.Index != null) { index = Convert.ToInt32(md.Params.Index); } List <AuditLogEntry> entries = client.GetAuditLogEntries( md.Params.AuditKey, md.Params.Action, count, index, md.Params.CreatedBefore, md.Params.CreatedAfter); md.Http.Response.StatusCode = 200; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(entries, true)); return; #endregion } else if (md.Params.Keys) { #region Update-Keys Dictionary <string, string> keys = null; if (md.Http.Request.Data != null && md.Http.Request.ContentLength > 0) { byte[] reqData = Common.StreamToBytes(md.Http.Request.Data); try { keys = Common.DeserializeJson <Dictionary <string, string> >(reqData); } catch (Exception) { _Logging.Warn(header + "HttpPutContainer unable to deserialize request body"); md.Http.Response.StatusCode = 400; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(9, 400, null, null), true)); return; } } client.WriteContainerKeyValuePairs(keys); md.Http.Response.StatusCode = 201; await md.Http.Response.Send(); return; #endregion } else if (md.Params.Search) { #region Search #region Deserialize-Request-Body EnumerationFilter filter = null; if (md.Http.Request.Data != null && md.Http.Request.ContentLength > 0) { byte[] reqData = Common.StreamToBytes(md.Http.Request.Data); try { filter = Common.DeserializeJson <EnumerationFilter>(reqData); } catch (Exception) { _Logging.Warn(header + "HttpPutContainer unable to deserialize request body"); md.Http.Response.StatusCode = 400; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(9, 400, null, null), true)); return; } } #endregion #region Enumerate-and-Return int?index = null; if (md.Params.Index != null) { index = Convert.ToInt32(md.Params.Index); } int?count = null; if (md.Params.Count != null) { count = Convert.ToInt32(md.Params.Count); } ContainerMetadata meta = client.Enumerate( (int?)md.Params.Index, (int?)md.Params.Count, filter, md.Params.OrderBy); if (md.Params.Html) { md.Http.Response.StatusCode = 200; md.Http.Response.ContentType = "text/html"; await md.Http.Response.Send(DirectoryListingPage(meta)); return; } else { md.Http.Response.StatusCode = 200; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(meta, true)); return; } #endregion #endregion } else { #region Update #region Deserialize-Request-Body Container container = null; if (md.Http.Request.Data != null && md.Http.Request.ContentLength > 0) { byte[] reqData = Common.StreamToBytes(md.Http.Request.Data); try { container = Common.DeserializeJson <Container>(reqData); } catch (Exception) { _Logging.Warn(header + "HttpPutContainer unable to deserialize request body"); md.Http.Response.StatusCode = 400; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(9, 400, null, null), true)); return; } } if (container == null) { _Logging.Warn(header + "HttpPutContainer no request body"); md.Http.Response.StatusCode = 400; md.Http.Response.ContentType = "application.json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(2, 400, "No container settings found in request body.", null), true)); return; } #endregion #region Update _DatabaseMgr.Update <Container>(container); _ContainerMgr.Delete(container.UserGUID, container.Name, false); _ContainerMgr.Add(container); md.Http.Response.StatusCode = 200; await md.Http.Response.Send(); return; #endregion #endregion } }
public static async Task HttpGetContainer(RequestMetadata md) { string header = md.Http.Request.SourceIp + ":" + md.Http.Request.SourcePort + " "; #region Retrieve-Container ContainerClient client = null; if (!_ContainerMgr.GetContainerClient(md.Params.UserGuid, md.Params.ContainerName, out client)) { _Logging.Warn(header + "HttpGetContainer unable to find container " + md.Params.UserGuid + "/" + md.Params.ContainerName); md.Http.Response.StatusCode = 404; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(5, 404, null, null), true)); return; } #endregion #region Authenticate-and-Authorize if (!client.Container.IsPublicRead) { if (md.User == null || !(md.User.GUID.ToLower().Equals(md.Params.UserGuid.ToLower()))) { _Logging.Warn(header + "HttpGetContainer unauthorized unauthenticated access attempt to container " + md.Params.UserGuid + "/" + md.Params.ContainerName); md.Http.Response.StatusCode = 401; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(3, 401, null, null), true)); return; } } if (md.Perm != null) { if (!md.Perm.ReadContainer) { _Logging.Warn(header + "HttpGetContainer unauthorized access attempt to container " + md.Params.UserGuid + "/" + md.Params.ContainerName); md.Http.Response.StatusCode = 401; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(new ErrorResponse(3, 401, null, null), true)); return; } } #endregion #region Process if (md.Params.Config) { md.Http.Response.StatusCode = 200; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(client.Container, true)); return; } EnumerationFilter filter = EnumerationFilter.FromRequestMetadata(md); ContainerMetadata meta = client.Enumerate( (int?)md.Params.Index, (int?)md.Params.Count, filter, md.Params.OrderBy); if (md.Params.Keys) { Dictionary <string, string> vals = new Dictionary <string, string>(); client.ReadContainerKeyValues(out vals); md.Http.Response.StatusCode = 200; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(vals, true)); return; } else if (md.Params.Html) { md.Http.Response.StatusCode = 200; md.Http.Response.ContentType = "text/html"; await md.Http.Response.Send(DirectoryListingPage(meta)); return; } else { md.Http.Response.StatusCode = 200; md.Http.Response.ContentType = "application/json"; await md.Http.Response.Send(Common.SerializeJson(meta, true)); return; } #endregion }
public static string DirectoryListingPage(ContainerMetadata meta) { string ret = "<html>" + " <head>" + " <title>Kvpbase :: Directory of /" + meta.UserGuid + "/" + meta.ContainerName + "</title>" + " <style>" + " body {" + " font-family: arial;" + " }" + " pre {" + " background-color: #e5e7ea;" + " color: #333333; " + " }" + " h3 {" + " color: #333333; " + " padding: 4px;" + " border: 4px;" + " }" + " p {" + " color: #333333; " + " padding: 4px;" + " border: 4px;" + " }" + " a {" + " color: #333333;" + " padding: 4px;" + " border: 4px;" + " text-decoration: none; " + " }" + " li {" + " padding: 6px;" + " border: 6px;" + " }" + " td {" + " padding: 4px;" + " text-align: left;" + " }" + " tr {" + " background-color: #ffffff;" + " padding: 4px;" + " text-align: left;" + " }" + " th {" + " background-color: #444444;" + " color: #ffffff;" + " padding: 4px;" + " text-align: left;" + " }" + " </style>" + " </head>" + " <body>" + " <pre>" + WebUtility.HtmlEncode(Logo()) + " </pre>" + " <p>Directory of: /" + meta.UserGuid + "/" + meta.ContainerName + "</p>" + " <p>" + " <table>" + " <tr>" + " <th>Object Key</th>" + " <th>Content Type</th>" + " <th>Size</th>" + " <th>Created (UTC)</th>" + " </tr>"; if (meta.Objects != null && meta.Objects.Count > 0) { foreach (ObjectMetadata obj in meta.Objects) { // <a href='/foo/bar' target='_blank'>foo.bar</a> ret += " <tr>" + " <td><a href='/" + meta.UserGuid + "/" + meta.ContainerName + "/" + obj.ObjectKey + "' target='_blank'>" + obj.ObjectKey + "</a></td>" + " <td>" + obj.ContentType + "</td>" + " <td>" + obj.ContentLength + "</td>" + " <td>" + Convert.ToDateTime(obj.CreatedUtc).ToString(_TimestampFormat) + "</td>" + " </tr>"; } } ret += " </table>" + " </p>" + " </body>" + "</html>"; return(ret); }
/// <summary> /// Applies a set of metadata fields to the output file. /// </summary> /// <param name="metadata">The metadata object to set.</param> /// <returns>The <see cref="MediaBuilder"/> instance.</returns> public MediaBuilder UseMetadata(ContainerMetadata metadata) { container.SetMetadata(metadata); return(this); }