public static IEnumerable <TSource> Take <TSource>(this IEnumerable <TSource> source, int count) { if (source == null) { throw Error.ArgumentNull(nameof(source)); } if (count <= 0) { return(EmptyPartition <TSource> .Instance); } IPartition <TSource> partition = source as IPartition <TSource>; if (partition != null) { return(partition.Take(count)); } IList <TSource> sourceList = source as IList <TSource>; if (sourceList != null) { return(new ListPartition <TSource>(sourceList, 0, count - 1)); } return(TakeIterator(source, count)); }
/// <summary> /// Initializes a new instance of the <see cref="PartitionFactory"/> class. /// </summary> /// <param name="info"> /// The partition info. /// </param> public PartitionFactory(PartitionInfo info) { if (info.Letter == '?') { _partition = new Fat16Partition(info); } else { switch (info.FileSystem) { case FileSystemType.Fat16: _partition = new Fat16Partition(info); break; case FileSystemType.Fat32: _partition = new Fat32Partition(info); break; case FileSystemType.Ntfs: _partition = new NtfsPartition(info); break; case FileSystemType.Unknown: _partition = new Fat16Partition(info); break; default: _partition = new Fat16Partition(info); break; } } }
public Task CaptureImage(IPartition windowsVolume, string destination, IOperationProgress progressObserver = null, CancellationToken cancellationToken = default(CancellationToken)) { Log.Verbose("Capturing image"); return(Task.CompletedTask); }
internal List <PartitioningNode> ComputeDValues(IPartition p1, IPartition p2) { List <PartitioningNode> nodes = new List <PartitioningNode>(); // nodes in foreach (var node in p1.Nodes) { nodes.Add(new PartitioningNode { Node = node, Partition = p1, D = ComputeExternalCost(node, p2) - ComputeInternalCost(node, p1), }); } foreach (var node in p2.Nodes) { nodes.Add(new PartitioningNode { Node = node, Partition = p2, D = ComputeExternalCost(node, p1) - ComputeInternalCost(node, p2), }); } return(nodes); }
/// <summary> /// Advances the enumerator to the next element of the <see cref="IPartition{T}"/>. If there are no more elements, does nothing. /// </summary> /// <param name="partition">The <see cref="IPartition{T}"/> object over which this enumerator is iterating.</param> public void MoveNext(IPartition <T> partition) { if (partition == null || Enumerator == null) { return; } if (SegmentCount > 0) { SegmentCount--; bool Moved = Enumerator.MoveNext(); Debug.Assert(Moved); return; } SegmentIndex = partition.NextSegmentIndex(SegmentIndex); if (SegmentIndex < 0) { Enumerator = null; return; } Enumerator = partition.GetSegmentEnumerator(SegmentIndex, 0, out SegmentCount); Enumerator.MoveNext(); Debug.Assert(SegmentCount > 0); SegmentCount--; }
/// <summary> /// Initializes a new instance of the <see cref="PartitionViewModel"/> class. /// </summary> /// <param name="sessionViewModel">The view model of the session to which this partition belongs.</param> /// <param name="partition">The partition for which to create the view model.</param> public PartitionViewModel(SessionViewModel sessionViewModel, IPartition partition) { this.partition = partition; this.sessionViewModel = sessionViewModel; this.sessionViewModel.DatasetViewModel.PropertyChanged += this.OnDatasetViewModelPropertyChanged; this.streamsById = new Dictionary <int, StreamTreeNode>(); this.StreamTreeRoot = new StreamContainerTreeNode(this, null, null); foreach (var stream in this.partition.AvailableStreams) { this.streamsById[stream.Id] = this.StreamTreeRoot.AddStreamTreeNode(stream); this.streamsById[stream.Id].IsTreeNodeExpanded = true; } // Check if this is a live partition (i.e. it still has a writer attached) this.UpdateLiveStatus(); if (this.IsLivePartition) { this.liveMessageCallback = new LiveMessageReceivedDelegate(this.OnMessageWritten); this.newMetadataCallback = new UpdateStreamMetadataDelegate(this.UpdateStreamMetadata); this.MonitorLivePartition(); } this.IsTreeNodeExpanded = true; // If there's no store backing the partition, alert the user. if (!this.partition.IsStoreValid) { string errorMessage = $"An error occurred while attempting to load the partition {this.partition.Name} from the store at {this.StorePath}."; Application.Current.Dispatcher.BeginInvoke((Action)(() => new MessageBoxWindow(Application.Current.MainWindow, "Error Loading Store", errorMessage, "Close", null).ShowDialog())); } }
private void WriteCrossingEdges(IPartition partition, XmlWriter writer) { writer.WriteStartElement(PartitionSerializerTags.CrossingEdgesTag); IPartitionEdge edge; foreach (var item in partition.GetExternalEdges()) { writer.WriteStartElement(PartitionSerializerTags.CrossingEdgeTag); edge = (IPartitionEdge)item; // edge id writer.WriteStartElement(PartitionSerializerTags.IdTag); edge.Id.Serialize(writer); writer.WriteEndElement(); // id of the 'remote' partition writer.WriteStartElement(PartitionSerializerTags.PartitionIdTag); edge.GetOtherPartition(partition).Id.Serialize(writer); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); }
public static async Task <IPartition> GetPartitionFromDescriptor(this IFileSystem fileSystem, string descriptor) { var mini = Parser.Parse(descriptor); var diskNumber = (int)mini["Disk"]; var label = (string)mini["Label"]; var name = (string)mini["Name"]; var number = (int?)mini["Number"]; var disk = await fileSystem.GetDisk(diskNumber); IPartition part = null; if (part is null && number.HasValue) { part = await disk.GetPartitionByNumber(number.Value); } if (part is null && !(label is null)) { part = await disk.GetPartitionByVolumeLabel(label); } if (part is null && name != null) { part = await disk.GetPartitionByName(name); } if (part == null) { throw new FileSystemException($"Cannot find partition from descriptor {descriptor}"); } return(part); }
public IEnumerable <IEdge> GetEdgesBetween(IPartition other) { if (other == null) { throw new ArgumentNullException("other"); } // shortcut for empty partitions and the same partition checking if (this.Equals(other) || this.IsEmpty || other.IsEmpty) { return(new IEdge[0]); } List <IEdge> edges = new List <IEdge>(); foreach (IEdge edge in this.GetExternalEdges()) { if (other.HasNode(edge.EndB)) { edges.Add(edge); } } return(edges); }
public override object GetMetaData(IPartition part) { if (part.Parent is IDevice device) { return(device.GetStartLBA(part)); } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="PartitionEnumerator{T}"/> class. /// Creates an instance that enumerates objects starting at the specified position in <see cref="IPartition{T}"/>. /// </summary> /// <param name="partition">The enumerated partition.</param> /// <param name="segmentIndex">The segment index of the position of the first element to enumerate.</param> /// <param name="elementIndex">The element index of the position of the first element to enumerate.</param> public PartitionEnumerator(IPartition <T> partition, int segmentIndex, int elementIndex) { Debug.Assert(partition.IsValidPosition(segmentIndex, elementIndex, false)); Partition = partition; SegmentIndex = segmentIndex; Enumerator = partition.GetSegmentEnumerator(segmentIndex, elementIndex, out SegmentCount); }
private void UpdateOriginatingTimeInterval(IPartition partition) { // compute the new originating time interval var oldOriginatingTimeInterval = this.OriginatingTimeInterval; this.OriginatingTimeInterval = this.Partitions.Count() == 0 ? partition.OriginatingTimeInterval : TimeInterval.Coverage(new TimeInterval[] { this.OriginatingTimeInterval, partition.OriginatingTimeInterval }); }
/// <summary> /// Initializes a new instance of the <see cref="PartitionViewModel"/> class. /// </summary> /// <param name="sessionViewModel">The view model of the session to which this partition belongs.</param> /// <param name="partition">The partition for which to create the view model.</param> public PartitionViewModel(SessionViewModel sessionViewModel, IPartition partition) { this.partition = partition; this.sessionViewModel = sessionViewModel; this.StreamTreeRoot = new StreamTreeNode(this); foreach (var stream in this.partition.AvailableStreams) { this.StreamTreeRoot.AddPath(stream); } }
public void PrintPartition(IPartition partition) { if (partition.Position.X >= 0 && partition.Position.X < WindowWidth && partition.Position.Y >= 0 && partition.Position.Y < WindowHeight) { Console.ForegroundColor = partition.Color; Console.SetCursorPosition(partition.Position.X, partition.Position.Y); Console.Write(Partition.Symbol); } }
/// <summary> /// I(a) in KL /// </summary> /// <param name="node"></param> /// <param name="otherPartition"></param> /// <returns></returns> internal int ComputeInternalCost(INode node, IPartition partition) { // node is not in the partiton -> no internal cost if (!partition.HasNode(node)) { logger.Error("A node must be part of the partition to calculate internal cost."); throw new ArgumentException(); } return(ComputeCost(node, partition)); }
/// <summary> /// E(a) in KL /// </summary> /// <param name="node"></param> /// <param name="otherPartition"></param> /// <returns></returns> internal int ComputeExternalCost(INode node, IPartition otherPartition) { // node is in the same otherPartition, then there is no e cost for that otherPartition if (otherPartition.HasNode(node)) { logger.Error("A node mustn't be a part of the partition for computing external costs."); throw new ArgumentException(); } return(ComputeCost(node, otherPartition)); }
protected override void WithContext() { mockPartition1 = MockRepository.GenerateStub<IPartition>(); mockPartition2 = MockRepository.GenerateStub<IPartition>(); mockBackingStore1 = MockRepository.GenerateMock<IBackingStore>(); mockBackingStore2 = MockRepository.GenerateMock<IBackingStore>(); mockQuery = MockRepository.GenerateStub<IPartitionedQuery>(); backingStores = new Dictionary<IPartition, IBackingStore> { {mockPartition1, mockBackingStore1}, {mockPartition2, mockBackingStore2} }; sut = new PartitioningBackingStore(backingStores); }
/// <summary> /// Конструктор класса. Объект создается со ссылкой на реальный объект. /// </summary> /// <param name="computer">Какой-то компьютер.</param> /// <param name="device">Родительский объект класса-заместителя.</param> /// <param name="partition">Реальный удаленный объект.</param> public PartitionProxy(IComputer computer, DeviceProxy device, IPartition partition) : base() { if (computer == null) throw new ArgumentNullException("computer"); if (device == null) throw new ArgumentNullException("device"); _computer = computer; _device = device; _computer.ConnectionChanged += new EventHandler(_computer_ConnectionChanged); Bind(partition); }
/// <summary> /// Конструктор класса. /// </summary> /// <param name="diagram">Родительская диаграмма разделов.</param> /// <param name="partition">Модель раздела.</param> public PartitionControl(DeviceDiagram diagram, IPartition partition, string hostName) { if (diagram == null) throw new ArgumentNullException("diagram"); if (partition == null) throw new ArgumentNullException("partition"); _owner = diagram; _partition = partition; _hostName = hostName; _note = new PartitionNoteControl(this, _hostName); _partition.PropertyChanged += new EventHandler<PartitionEventArgs>(_partition_PropertyChanged); Invalidate(); }
/// <summary> /// Присоединяет прокси к реальному /// удаленному объекту. /// </summary> /// <param name="partition">Удаленный раздел жесткого диска.</param> public void Bind(IPartition partition) { lock (this) { lock (_partitionSync) { _partition = partition; } } // Обновляем кеш. UpdateData(); }
private string GetPartitionSharePath(IPartition partition, string hostName) { string partitionPath = null; string[] mountPoints = partition.GetMountPoints(); foreach (string mountPoint in mountPoints) { if (mountPoint.Length <= 3) { partitionPath = mountPoint; break; } } if (partitionPath == null && mountPoints.Length > 0) partitionPath = mountPoints[0]; if (partitionPath == null) return null; partitionPath = partitionPath.Replace(':', '$'); return Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString() + hostName + Path.DirectorySeparatorChar.ToString() + partitionPath; }
private void Dispose(bool disposing) { if (disposing) { lock (this) { _partition.PropertyChanged -= _partition_PropertyChanged; _partition = null; _owner = null; _note = null; } } }
public DeviceEventArgs(IPartition partition) { _partition = partition; }
public DeviceEventArgs() { _partition = null; }
/// <summary> /// Возвращает массив разделов на удаленном диске. Разделы оборачиваются /// в класс PartitionProxy. /// </summary> /// <returns>Массив объектов класса PartitionProxy.</returns> public IPartition[] GetPartitions() { lock (this) { IPartition[] arr = new IPartition[_partProxies.Count]; for (int i = 0; i < _partProxies.Count; ++i) arr[i] = _partProxies[i]; return arr; } }
public IQuery GetQueryForPartition(IPartition partition) { return GetPartitionedQuery(PartitionedQueryFactories[partition]); }
internal IPartition[] GetPartitionsInternal() { UpdateData(); lock (_syncObject) { IPartition[] nparts = new IPartition[_parts.Count]; int i; for (i = 0; i < _parts.Count; ++i) nparts[i] = _parts[i]; return nparts; } }