public void InsertSection(FileSection fileSection) { if (fileSection == null) { return; } if (FileSections[fileSection.SectionNumber] == null) { FileSections[fileSection.SectionNumber] = fileSection; } if (fileSection.SectionNumber == LowestSectionNotReceived) { LowestSectionNotReceived++; while (LowestSectionNotReceived < FileSections.Length ? FileSections[LowestSectionNotReceived] != null : false) { LowestSectionNotReceived++; } } if (LowestSectionNotReceived == FileSections.Length) { Completed = true; } }
public File(int numberOfSections) { NumberOfSections = numberOfSections; FileSections = new FileSection[NumberOfSections]; LowestSectionNotReceived = 0; Completed = false; }
public void ReceivePush(FileSection fileSection) { if (_largestPushReceived == null) { _largestPushReceived = fileSection; } else if (fileSection.SectionNumber > _largestPushReceived.SectionNumber) { _largestPushReceived = fileSection; } if (!File.Completed) { _sectionsToInsert.Add(fileSection); } }
public void Pull() { if (File.Completed) { return; } //User user = RandomContact(); foreach (User contact in ContactList) { if (Functions.Random.Next(2) == 1) { FileSection fileSection = contact.ReceivePull(File.LowestSectionNotReceived); if (fileSection != null) { _sectionsToInsert.Add(fileSection); } } } }
public bool HasSection(FileSection fileSection) { return(FileSections[fileSection.SectionNumber] != null); }