/// <summary> /// Gets the cache latency time. /// </summary> /// <param name="dataCache">The data cache.</param> /// <returns></returns> public int?GetCacheLatencyTime(DataCache dataCache) { RequestLatency <DataCache> latency = GetCacheLatency(dataCache); return(latency == null ? (int?)null : latency.Time); }
/// <summary> /// Reads the specified source file path. /// </summary> /// <param name="sourceFilePath">The source file path.</param> public void Read(string sourceFilePath) { string[] lines = File.ReadAllLines(sourceFilePath); int[] descriptions = lines.ToIntArray(0); int videosCount = descriptions[0]; int[] videosSizes = lines.ToIntArray(1); Videos = videosCount.ForEach(v => new Video(v, videosSizes[v])).ToArray(); int cachesCount = descriptions[3]; int cachesSize = descriptions[4]; Caches = cachesCount.ForEach(e => new DataCache(e, cachesSize)).ToArray(); DataCenter = new DataCenter(); int endpointsCount = descriptions[1]; EndPoints = endpointsCount.ForEach(e => new VideoEndpoint(e)).ToArray(); int requestsCount = descriptions[2]; Requests = requestsCount.ForEach(e => new VideoRequest()).ToArray(); string[] linesLeft = lines.Skip(2).ToArray(); int lineIdx = 0; for (int idx = 0; idx < EndPoints.Length; idx++) { VideoEndpoint endpoint = EndPoints[idx]; int[] values = linesLeft.ToIntArray(lineIdx); int dataCenterLatency = values[0]; endpoint.CenterLatency = new RequestLatency <DataCenter>() { Publisher = DataCenter, Time = dataCenterLatency }; int connectionsCount = values[1]; RequestLatency <DataCache>[] latencies = connectionsCount.ForEach(c => new RequestLatency <DataCache>()).ToArray(); lineIdx++; for (int i = 0; i < latencies.Length; i++) { values = linesLeft.ToIntArray(lineIdx); RequestLatency <DataCache> latency = latencies[i]; latency.Publisher = GetCache(values[0]); latency.Time = values[1]; lineIdx++; } endpoint.CacheLatency = latencies; } linesLeft = linesLeft.Skip(lineIdx).ToArray(); Requests = linesLeft.Length.ForEach(e => new VideoRequest()).ToArray(); for (int i = 0; i < linesLeft.Length; i++) { string line = linesLeft[i]; int[] values = line.ToIntArray(); Requests[i].Video = GetVideo(values[0]); Requests[i].Video.Requests = Requests[i].Video.Requests.ConcatElt(Requests[i]).ToArray(); Requests[i].EndPoint = GetEndPoint(values[1]); Requests[i].EndPoint.Requests = Requests[i].EndPoint.Requests.ConcatElt(Requests[i]).ToArray(); Requests[i].RequestCount = values[2]; } DataCenter.Videos.AddRange(Videos); SourceFilePath = sourceFilePath; }
/// <summary> /// Initializes a new instance of the <see cref="VideoEndpoint" /> class. /// </summary> /// <param name="id">The identifier.</param> public VideoEndpoint(int id) { Id = id; Requests = new VideoRequest[0]; CacheLatency = new RequestLatency <DataCache> [0]; }