/// <summary> /// Gets random index of part with specified status /// </summary> /// <param name="status"></param> /// <returns>returns 0-based index of the part, or -1 if no such part exists.</returns> public long GetPartIndex(EPartStatus status) { int count = 0; long i; //first it tries to choose randomly do { ++count; i = LongRandom(NumberOfParts); } while (PartStatus[i] != status && count < 30); if (PartStatus[i] == status) { return(i); } //after 30 tries, it just finds in ordered way. for (i = 0; i < NumberOfParts; ++i) { if (PartStatus[i] == status) { return(i); } } return(-1); }
/// <summary> /// Opens file and initializes separation into parts. /// </summary> /// <param name="filePath"></param> private void OpenFile(string filePath) { stream = File.Open(filePath, FileMode.OpenOrCreate); var split = filePath.Split('\\'); FileName = split[split.Length - 1]; Size = stream.Length; NumberOfParts = (Size - 1) / PartSize + 1; PartStatus = new EPartStatus[NumberOfParts]; //Hash = hashFromStream(stream); Hash = "THISISJUSTLONGENOUGHSTRING0DEPRECATED"; }