Exemple #1
0
		/// <summary>
		/// Determine equality, based only on extent IDs.
		/// </summary>
		/// <param name="other">the other CosmosExtent to compare</param>
		/// <returns>true if other is a CosmosExtent with an equal ExtentId; false otherwise</returns>
		public bool Equals(CosmosExtent other)
		{
			return extentId == other.extentId;
			//	&& length == other.length && sequence == other.sequence;
		}
Exemple #2
0
		/// <summary>
		/// Retrieve the set of extents that make up the given stream, in sorted order.
		/// </summary>
		/// <remarks>
		/// For basic stream usage, the extents do not need to be considered.
		/// This method is intended for advanced manipulation of the underlying
		/// Cosmos data.
		/// </remarks>
		/// <param name="fileName">the name of the stream</param>
		/// <returns>the list of extents, or null if it cannot be retrieved.</returns>
		public static CosmosExtent[] GetExtents(string fileName)
		{
			try
			{
				// extract volume name:
				string volume = fileName;
				int v = volume.IndexOf("//");
				if (v < 0) return null;
				v += 2;
				v = volume.IndexOf('/', v);
				if (v < 0) return null;
				v++;
				v = volume.IndexOf('/', v);
				if (v < 0) return null;
				v++;
				volume = volume.Substring(0, v);

				System.Diagnostics.Process proc = CosmosExec(string.Format(cosmosExtentsCmdArgs, fileName));

				string[] chunks;
				using (StreamReader outReader = proc.StandardOutput)
				{
					chunks = outReader.ReadToEnd().Replace("\r\n", "\n").Replace("\n\n", "\0").Split('\0');
				}
				proc.WaitForExit();
				int exit = proc.ExitCode;
				proc.Close();
				// what are the error conditions? What about an empty stream? ***
				if (exit != 0 || chunks.Length < 2)
				{
					if (exit != 0 || chunks.Length == 0 || chunks[0].ToLower().Trim().StartsWith("command failed"))
					{
						return null;
					}
					return new CosmosExtent[0];
				}

				CosmosExtent[] res = new CosmosExtent[chunks.Length - 1];
				for (int i = 1; i < chunks.Length; i++)
				{
					res[i - 1] = new CosmosExtent(volume, chunks[i]);
				}
				return res;
			}
			catch
			{
				return null;
			}
		}
Exemple #3
0
		/// <summary>
		/// Create a copy of this CosmosExtent.
		/// </summary>
		/// <returns>a copy of this CosmosExtent</returns>
		/// <remarks>
		/// Note that the Nodes array is shared with any new copies.
		/// </remarks>
		public CosmosExtent Clone()
		{
			CosmosExtent res = new CosmosExtent(extentId, length);
			res.sequence = sequence;
			res.volume = volume;
			res.nodes = nodes;
			return res;
		}