/// <summary> /// Save a single segment's info. </summary> public override void Write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) { string fileName = IndexFileNames.SegmentFileName(si.Name, "", Lucene40SegmentInfoFormat.SI_EXTENSION); si.AddFile(fileName); IndexOutput output = dir.CreateOutput(fileName, ioContext); bool success = false; try { CodecUtil.WriteHeader(output, Lucene40SegmentInfoFormat.CODEC_NAME, Lucene40SegmentInfoFormat.VERSION_CURRENT); // Write the Lucene version that created this segment, since 3.1 output.WriteString(si.Version); output.WriteInt(si.DocCount); output.WriteByte((sbyte)(si.UseCompoundFile ? SegmentInfo.YES : SegmentInfo.NO)); output.WriteStringStringMap(si.Diagnostics); output.WriteStringStringMap(CollectionsHelper.EmptyMap<string, string>()); output.WriteStringSet(si.Files); success = true; } finally { if (!success) { IOUtils.CloseWhileHandlingException(output); si.Dir.DeleteFile(fileName); } else { output.Dispose(); } } }
/// <summary> /// Reads the Action parameters payload and returns the WCF DS value representation of each parameter. /// </summary> /// <param name="segmentInfo">Info about the parameters payload to read.</param> /// <returns>The WCF DS representation of the parameters read.</returns> protected override object Read(SegmentInfo segmentInfo) { Debug.Assert(segmentInfo != null, "segmentInfo != null"); Debug.Assert( segmentInfo.TargetSource == RequestTargetSource.ServiceOperation && segmentInfo.Operation != null && segmentInfo.Operation.Kind == OperationKind.Action, "The ParametersDeserializer should only be called for an Action segment."); IEdmOperation operation = this.GetOperation(segmentInfo.Operation); ODataParameterReader reader = this.MessageReader.CreateODataParameterReader(operation); AssertReaderFormatIsExpected(this.MessageReader, ODataFormat.Json); Dictionary<string, object> parameters = new Dictionary<string, object>(EqualityComparer<string>.Default); ResourceType parameterResourceType; object convertedParameterValue; while (reader.Read()) { if (reader.State == ODataParameterReaderState.Completed) { break; } switch (reader.State) { case ODataParameterReaderState.Value: parameterResourceType = segmentInfo.Operation.Parameters.Single(p => p.Name == reader.Name).ParameterType; convertedParameterValue = this.ConvertValue(reader.Value, ref parameterResourceType); break; case ODataParameterReaderState.Collection: ODataCollectionReader collectionReader = reader.CreateCollectionReader(); parameterResourceType = segmentInfo.Operation.Parameters.Single(p => p.Name == reader.Name).ParameterType; Debug.Assert(parameterResourceType.ResourceTypeKind == ResourceTypeKind.Collection, "parameterResourceType.ResourceTypeKind == ResourceTypeKind.Collection"); convertedParameterValue = this.ConvertValue(ParameterDeserializer.ReadCollectionParameterValue(collectionReader), ref parameterResourceType); break; default: Debug.Assert(false, "Unreachable code path in Read()."); throw new InvalidOperationException(Microsoft.OData.Service.Strings.DataServiceException_GeneralError); } parameters.Add(reader.Name, convertedParameterValue); } // ODataLib allows nullable parameters to be missing from the payload. When that happens, we use null for the parameter value. foreach (IEdmOperationParameter parameterMetadata in operation.Parameters.Skip(operation.IsBound ? 1 : 0)) { object value; if (!parameters.TryGetValue(parameterMetadata.Name, out value)) { Debug.Assert(parameterMetadata.Type.IsNullable, "ODataParameterReader should only allows nullable parameters to be missing from the payload."); parameters.Add(parameterMetadata.Name, null); } } return parameters; }
/// <summary> /// Create the object graph from the given payload and return the top level object. /// </summary> /// <param name="segmentInfo">Info about the object being created.</param> /// <returns>Instance of the object created.</returns> protected override object Deserialize(SegmentInfo segmentInfo) { Debug.Assert(segmentInfo != null, "segmentInfo != null"); Debug.Assert( segmentInfo.TargetKind == RequestTargetKind.MediaResource, "The MediaResourceDeserializer only support the MediaResource target kind."); return this.Service.OperationContext.RequestMessage.RequestStream; }
public SepPostingsReader(Directory dir, FieldInfos fieldInfos, SegmentInfo segmentInfo, IOContext context, IntStreamFactory intFactory, string segmentSuffix) { var success = false; try { var docFileName = IndexFileNames.SegmentFileName(segmentInfo.Name, segmentSuffix, SepPostingsWriter.DOC_EXTENSION); _docIn = intFactory.OpenInput(dir, docFileName, context); _skipIn = dir.OpenInput( IndexFileNames.SegmentFileName(segmentInfo.Name, segmentSuffix, SepPostingsWriter.SKIP_EXTENSION), context); if (fieldInfos.HasFreq()) { _freqIn = intFactory.OpenInput(dir, IndexFileNames.SegmentFileName(segmentInfo.Name, segmentSuffix, SepPostingsWriter.FREQ_EXTENSION), context); } else { _freqIn = null; } if (fieldInfos.HasProx()) { _posIn = intFactory.OpenInput(dir, IndexFileNames.SegmentFileName(segmentInfo.Name, segmentSuffix, SepPostingsWriter.POS_EXTENSION), context); _payloadIn = dir.OpenInput( IndexFileNames.SegmentFileName(segmentInfo.Name, segmentSuffix, SepPostingsWriter.PAYLOAD_EXTENSION), context); } else { _posIn = null; _payloadIn = null; } success = true; } finally { if (!success) { Dispose(); } } }
internal static QueryResultInfo GetSingleResultFromRequest(SegmentInfo segmentInfo) { Debug.Assert(segmentInfo != null && segmentInfo.RequestEnumerable != null, "segmentInfo != null && segmentInfo.RequestEnumerable != null"); var queryResults = new QueryResultInfo(segmentInfo.RequestEnumerable); try { WebUtil.CheckResourceExists(queryResults.MoveNext(), segmentInfo.Identifier); WebUtil.CheckNullDirectReference(queryResults.Current, segmentInfo); return queryResults; } catch { // Dispose the Enumerator in case of error WebUtil.Dispose(queryResults); throw; } }
/// <summary> /// Sole constructor. </summary> public Lucene40StoredFieldsReader(Directory d, SegmentInfo si, FieldInfos fn, IOContext context) { string segment = si.Name; bool success = false; FieldInfos = fn; try { FieldsStream = d.OpenInput(IndexFileNames.SegmentFileName(segment, "", Lucene40StoredFieldsWriter.FIELDS_EXTENSION), context); string indexStreamFN = IndexFileNames.SegmentFileName(segment, "", Lucene40StoredFieldsWriter.FIELDS_INDEX_EXTENSION); IndexStream = d.OpenInput(indexStreamFN, context); CodecUtil.CheckHeader(IndexStream, Lucene40StoredFieldsWriter.CODEC_NAME_IDX, Lucene40StoredFieldsWriter.VERSION_START, Lucene40StoredFieldsWriter.VERSION_CURRENT); CodecUtil.CheckHeader(FieldsStream, Lucene40StoredFieldsWriter.CODEC_NAME_DAT, Lucene40StoredFieldsWriter.VERSION_START, Lucene40StoredFieldsWriter.VERSION_CURRENT); Debug.Assert(Lucene40StoredFieldsWriter.HEADER_LENGTH_DAT == FieldsStream.FilePointer); Debug.Assert(Lucene40StoredFieldsWriter.HEADER_LENGTH_IDX == IndexStream.FilePointer); long indexSize = IndexStream.Length() - Lucene40StoredFieldsWriter.HEADER_LENGTH_IDX; this.Size_Renamed = (int)(indexSize >> 3); // Verify two sources of "maxDoc" agree: if (this.Size_Renamed != si.DocCount) { throw new CorruptIndexException("doc counts differ for segment " + segment + ": fieldsReader shows " + this.Size_Renamed + " but segmentInfo shows " + si.DocCount); } NumTotalDocs = (int)(indexSize >> 3); success = true; } finally { // With lock-less commits, it's entirely possible (and // fine) to hit a FileNotFound exception above. In // this case, we want to explicitly close any subset // of things that were opened so that we don't have to // wait for a GC to do so. if (!success) { try { Dispose(); } // ensure we throw our original exception catch (Exception) { } } } }
public IntlSingleFlightSearch(FlightRoute route) { flight.TripType = TripType.OW; flight.PassengerType = PassengerType.ADT; flight.PassengerCount = 1; flight.ClassGrade = SeatGrade.Y; flight.SalesType = SalesType.Online; flight.FareType = FareType.All; flight.ResultMode = ResultMode.LowestPrice; flight.OrderBy = OrderBy.Price; flight.Direction = Direction.Asc; SegmentInfo segmentinfo = new SegmentInfo(); segmentinfo.DCode = route.DepartCity; segmentinfo.ACode = route.ArriveCity; segmentinfo.DDate = (DateTime) route.DepartDate; segmentinfo.TimePeriod = "0000-2400"; flight.SegmentInfos.Add(segmentinfo); }
public override SegmentInfo Read(Directory dir, string segment, IOContext context) { string fileName = IndexFileNames.SegmentFileName(segment, "", Lucene40SegmentInfoFormat.SI_EXTENSION); IndexInput input = dir.OpenInput(fileName, context); bool success = false; try { CodecUtil.CheckHeader(input, Lucene40SegmentInfoFormat.CODEC_NAME, Lucene40SegmentInfoFormat.VERSION_START, Lucene40SegmentInfoFormat.VERSION_CURRENT); string version = input.ReadString(); int docCount = input.ReadInt(); if (docCount < 0) { throw new CorruptIndexException("invalid docCount: " + docCount + " (resource=" + input + ")"); } bool isCompoundFile = input.ReadByte() == SegmentInfo.YES; IDictionary<string, string> diagnostics = input.ReadStringStringMap(); input.ReadStringStringMap(); // read deprecated attributes ISet<string> files = input.ReadStringSet(); CodecUtil.CheckEOF(input); SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics); si.Files = files; success = true; return si; } finally { if (!success) { IOUtils.CloseWhileHandlingException(input); } else { input.Dispose(); } } }
/// <summary> /// Reads the input request payload and returns the WCF DS value representation of it. /// </summary> /// <param name="segmentInfo">Info about the request to read.</param> /// <returns>The WCF DS representation of the value read.</returns> protected override object Read(SegmentInfo segmentInfo) { Debug.Assert(segmentInfo != null, "segmentInfo != null"); Debug.Assert( segmentInfo.TargetKind == RequestTargetKind.PrimitiveValue || segmentInfo.TargetKind == RequestTargetKind.OpenPropertyValue, "The RawValuDeserializer only supports PrimitiveValue and OpenPropertyValue target kinds."); ResourceProperty property = segmentInfo.ProjectedProperty; ResourceType propertyResourceType; IEdmTypeReference propertyTypeReference; if (property == null) { propertyResourceType = null; propertyTypeReference = null; } else { propertyResourceType = property.ResourceType; propertyTypeReference = this.GetTypeReference(propertyResourceType, property.CustomAnnotations.ToList()); } object rawValue = this.MessageReader.ReadValue(propertyTypeReference); Debug.Assert(rawValue != null, "The raw value can never be null."); AssertReaderFormatIsExpected(this.MessageReader, ODataFormat.RawValue); object convertedValue = ODataMessageReaderDeserializer.ConvertPrimitiveValue(rawValue, ref propertyResourceType); if (property == null) { // Set the target resource type for open properties so we can reason over the property type later. // The target resource type of an open property segment is determined when converting the payload value above. Debug.Assert(segmentInfo.TargetResourceType == null, "segmentInfo.TargetResourceType == null"); segmentInfo.TargetResourceType = propertyResourceType; } else { Debug.Assert(segmentInfo.TargetResourceType != null, "segmentInfo.TargetResourceType != null"); } return convertedValue; }
public void AddRoutes(FlightRoute goRoute, DateTime departDate, DateTime backDate) { FlightRoute backRoute = new FlightRoute(); backRoute.ArriveCity = goRoute.DepartCity; backRoute.DepartCity = goRoute.ArriveCity; backRoute.DepartDate = backDate; SegmentInfo goSegmentinfo = new SegmentInfo(); goSegmentinfo.DCode = goRoute.DepartCity; goSegmentinfo.ACode = goRoute.ArriveCity; goSegmentinfo.DDate = departDate; goSegmentinfo.TimePeriod = "0000-2400"; SegmentInfo backSegmentinfo = new SegmentInfo(); backSegmentinfo.ACode = backRoute.ArriveCity; backSegmentinfo.DCode = backRoute.DepartCity; backSegmentinfo.DDate = backDate; backSegmentinfo.TimePeriod = "0000-2400"; flight.SegmentInfos.Add(goSegmentinfo); flight.SegmentInfos.Add(backSegmentinfo); }
// private String segment; /// <summary> /// Sole constructor. </summary> public Lucene40PostingsReader(Directory dir, FieldInfos fieldInfos, SegmentInfo segmentInfo, IOContext ioContext, string segmentSuffix) { bool success = false; IndexInput freqIn = null; IndexInput proxIn = null; try { freqIn = dir.OpenInput(IndexFileNames.SegmentFileName(segmentInfo.Name, segmentSuffix, Lucene40PostingsFormat.FREQ_EXTENSION), ioContext); CodecUtil.CheckHeader(freqIn, FRQ_CODEC, VERSION_START, VERSION_CURRENT); // TODO: hasProx should (somehow!) become codec private, // but it's tricky because 1) FIS.hasProx is global (it // could be all fields that have prox are written by a // different codec), 2) the field may have had prox in // the past but all docs w/ that field were deleted. // Really we'd need to init prxOut lazily on write, and // then somewhere record that we actually wrote it so we // know whether to open on read: if (fieldInfos.HasProx()) { proxIn = dir.OpenInput(IndexFileNames.SegmentFileName(segmentInfo.Name, segmentSuffix, Lucene40PostingsFormat.PROX_EXTENSION), ioContext); CodecUtil.CheckHeader(proxIn, PRX_CODEC, VERSION_START, VERSION_CURRENT); } else { proxIn = null; } this.FreqIn = freqIn; this.ProxIn = proxIn; success = true; } finally { if (!success) { IOUtils.CloseWhileHandlingException(freqIn, proxIn); } } }
/// <summary> /// Reads the input request payload and returns the WCF DS value representation of it. /// </summary> /// <param name="segmentInfo">Info about the request to read. For entity reference requests this is null.</param> /// <returns>The WCF DS representation of the value read. For entity reference link this is the Uri of the link.</returns> protected override object Read(SegmentInfo segmentInfo) { Debug.Assert(segmentInfo == null, "segmentInfo == null"); Debug.Assert(this.RequestDescription.LinkUri, "The EntityReferenceLinkDeserializer only supports $ref payloads."); ODataEntityReferenceLink entityReferenceLink = this.MessageReader.ReadEntityReferenceLink(); Debug.Assert(entityReferenceLink != null, "ReadEntityReferenceLink should never return null."); Uri entityReferenceUri = entityReferenceLink.Url; Debug.Assert(entityReferenceUri != null, "The Url of the entity reference link should never be null."); #pragma warning disable 618 AssertReaderFormatIsExpected(this.MessageReader, ODataFormat.Atom, ODataFormat.Json); #pragma warning restore 618 // We must fail on empty URI string entityReferenceUriAsString = UriUtil.UriToString(entityReferenceUri); if (string.IsNullOrEmpty(entityReferenceUriAsString)) { throw DataServiceException.CreateBadRequestError(Microsoft.OData.Service.Strings.BadRequest_MissingUriForLinkOperation); } // Resolve the URI against the service return RequestUriProcessor.GetAbsoluteUriFromReference(entityReferenceUri, this.Service.OperationContext.AbsoluteServiceUri); }
public SimpleTextTermVectorsReader(Directory directory, SegmentInfo si, IOContext context) { bool success = false; try { _input = directory.OpenInput(IndexFileNames.SegmentFileName(si.Name, "", SimpleTextTermVectorsWriter.VECTORS_EXTENSION), context); success = true; } finally { if (!success) { try { Dispose(); } catch (Exception) { // ensure we throw our original exception } } } ReadIndex(si.DocCount); }
/// <summary> /// Assumes the payload to represent a single object and processes accordingly /// </summary> /// <param name="segmentInfo">info about the object being created</param> /// <returns>the newly formed object that the payload represents</returns> protected override object CreateSingleObject(SegmentInfo segmentInfo) { SyndicationItem item = ReadSyndicationItem(this.factory.CreateSyndicationItemFormatter(), this.xmlReader); return this.CreateObject(segmentInfo, true /*topLevel*/, item); }
public Lucene3xStoredFieldsReader(Directory d, SegmentInfo si, FieldInfos fn, IOContext context) { string segment = Lucene3xSegmentInfoFormat.GetDocStoreSegment(si); int docStoreOffset = Lucene3xSegmentInfoFormat.GetDocStoreOffset(si); int size = si.DocCount; bool success = false; FieldInfos = fn; try { if (docStoreOffset != -1 && Lucene3xSegmentInfoFormat.GetDocStoreIsCompoundFile(si)) { d = StoreCFSReader = new CompoundFileDirectory(si.Dir, IndexFileNames.SegmentFileName(segment, "", Lucene3xCodec.COMPOUND_FILE_STORE_EXTENSION), context, false); } else { StoreCFSReader = null; } FieldsStream = d.OpenInput(IndexFileNames.SegmentFileName(segment, "", FIELDS_EXTENSION), context); string indexStreamFN = IndexFileNames.SegmentFileName(segment, "", FIELDS_INDEX_EXTENSION); IndexStream = d.OpenInput(indexStreamFN, context); Format = IndexStream.ReadInt(); if (Format < FORMAT_MINIMUM) { throw new IndexFormatTooOldException(IndexStream, Format, FORMAT_MINIMUM, FORMAT_CURRENT); } if (Format > FORMAT_CURRENT) { throw new IndexFormatTooNewException(IndexStream, Format, FORMAT_MINIMUM, FORMAT_CURRENT); } long indexSize = IndexStream.Length() - FORMAT_SIZE; if (docStoreOffset != -1) { // We read only a slice out of this shared fields file this.DocStoreOffset = docStoreOffset; this.Size = size; // Verify the file is long enough to hold all of our // docs Debug.Assert(((int)(indexSize / 8)) >= size + this.DocStoreOffset, "indexSize=" + indexSize + " size=" + size + " docStoreOffset=" + docStoreOffset); } else { this.DocStoreOffset = 0; this.Size = (int)(indexSize >> 3); // Verify two sources of "maxDoc" agree: if (this.Size != si.DocCount) { throw new CorruptIndexException("doc counts differ for segment " + segment + ": fieldsReader shows " + this.Size + " but segmentInfo shows " + si.DocCount); } } NumTotalDocs = (int)(indexSize >> 3); success = true; } finally { // With lock-less commits, it's entirely possible (and // fine) to hit a FileNotFound exception above. In // this case, we want to explicitly close any subset // of things that were opened so that we don't have to // wait for a GC to do so. if (!success) { try { Dispose(); } // keep our original exception catch (Exception t) { } } } }
public BlockTermsReader(TermsIndexReaderBase indexReader, Directory dir, FieldInfos fieldInfos, SegmentInfo info, PostingsReaderBase postingsReader, IOContext context, String segmentSuffix) { _postingsReader = postingsReader; _input = dir.OpenInput( IndexFileNames.SegmentFileName(info.Name, segmentSuffix, BlockTermsWriter.TERMS_EXTENSION), context); var success = false; try { _version = ReadHeader(_input); // Have PostingsReader init itself postingsReader.Init(_input); // Read per-field details SeekDir(_input, _dirOffset); int numFields = _input.ReadVInt(); if (numFields < 0) { throw new CorruptIndexException(String.Format("Invalid number of fields: {0}, Resource: {1}", numFields, _input)); } for (var i = 0; i < numFields; i++) { var field = _input.ReadVInt(); var numTerms = _input.ReadVLong(); Debug.Assert(numTerms >= 0); var termsStartPointer = _input.ReadVLong(); var fieldInfo = fieldInfos.FieldInfo(field); var sumTotalTermFreq = fieldInfo.FieldIndexOptions == FieldInfo.IndexOptions.DOCS_ONLY ? -1 : _input.ReadVLong(); var sumDocFreq = _input.ReadVLong(); var docCount = _input.ReadVInt(); var longsSize = _version >= BlockTermsWriter.VERSION_META_ARRAY ? _input.ReadVInt() : 0; if (docCount < 0 || docCount > info.DocCount) { // #docs with field must be <= #docs throw new CorruptIndexException( String.Format("Invalid DocCount: {0}, MaxDoc: {1}, Resource: {2}", docCount, info.DocCount, _input)); } if (sumDocFreq < docCount) { // #postings must be >= #docs with field throw new CorruptIndexException( String.Format("Invalid sumDocFreq: {0}, DocCount: {1}, Resource: {2}", sumDocFreq, docCount, _input)); } if (sumTotalTermFreq != -1 && sumTotalTermFreq < sumDocFreq) { // #positions must be >= #postings throw new CorruptIndexException( String.Format("Invalid sumTotalTermFreq: {0}, sumDocFreq: {1}, Resource: {2}", sumTotalTermFreq, sumDocFreq, _input)); } try { _fields.Add(fieldInfo.Name, new FieldReader(fieldInfo, this, numTerms, termsStartPointer, sumTotalTermFreq, sumDocFreq, docCount, longsSize)); } catch (ArgumentException) { throw new CorruptIndexException(String.Format("Duplicate fields: {0}, Resource: {1}", fieldInfo.Name, _input)); } } success = true; } finally { if (!success) { _input.Dispose(); } } _indexReader = indexReader; }
// note: just like segmentreader in 3.x, we open up all the files here (including separate norms) up front. // but we just don't do any seeks or reading yet. public Lucene3xNormsProducer(Directory dir, SegmentInfo info, FieldInfos fields, IOContext context) { Directory separateNormsDir = info.Dir; // separate norms are never inside CFS Maxdoc = info.DocCount; string segmentName = info.Name; bool success = false; try { long nextNormSeek = NORMS_HEADER.Length; //skip header (header unused for now) foreach (FieldInfo fi in fields) { if (fi.HasNorms()) { string fileName = GetNormFilename(info, fi.Number); Directory d = HasSeparateNorms(info, fi.Number) ? separateNormsDir : dir; // singleNormFile means multiple norms share this file bool singleNormFile = IndexFileNames.MatchesExtension(fileName, NORMS_EXTENSION); IndexInput normInput = null; long normSeek; if (singleNormFile) { normSeek = nextNormSeek; if (SingleNormStream == null) { SingleNormStream = d.OpenInput(fileName, context); OpenFiles.Add(SingleNormStream); } // All norms in the .nrm file can share a single IndexInput since // they are only used in a synchronized context. // If this were to change in the future, a clone could be done here. normInput = SingleNormStream; } else { normInput = d.OpenInput(fileName, context); OpenFiles.Add(normInput); // if the segment was created in 3.2 or after, we wrote the header for sure, // and don't need to do the sketchy file size check. otherwise, we check // if the size is exactly equal to maxDoc to detect a headerless file. // NOTE: remove this check in Lucene 5.0! string version = info.Version; bool isUnversioned = (version == null || StringHelper.VersionComparator.Compare(version, "3.2") < 0) && normInput.Length() == Maxdoc; if (isUnversioned) { normSeek = 0; } else { normSeek = NORMS_HEADER.Length; } } NormsDocValues norm = new NormsDocValues(this, normInput, normSeek); Norms[fi.Name] = norm; nextNormSeek += Maxdoc; // increment also if some norms are separate } } // TODO: change to a real check? see LUCENE-3619 Debug.Assert(SingleNormStream == null || nextNormSeek == SingleNormStream.Length(), SingleNormStream != null ? "len: " + SingleNormStream.Length() + " expected: " + nextNormSeek : "null"); success = true; } finally { if (!success) { IOUtils.CloseWhileHandlingException(OpenFiles); } } ramBytesUsed = new AtomicLong(); }
public override bool WriteData(SegmentInfo segment, int offset, byte[] buffer, int bufferOffset, int length) { return(true); }
public override TermVectorsReader VectorsReader(Directory directory, SegmentInfo segmentInfo, FieldInfos fieldInfos, IOContext context) { return(new Lucene40TermVectorsReader(directory, segmentInfo, fieldInfos, context)); }
public override SegmentInfo Read(Directory directory, string segmentName, IOContext context) { var scratch = new BytesRef(); string segFileName = IndexFileNames.SegmentFileName(segmentName, "", SimpleTextSegmentInfoFormat.SI_EXTENSION); ChecksumIndexInput input = directory.OpenChecksumInput(segFileName, context); bool success = false; try { SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_VERSION)); string version = ReadString(SimpleTextSegmentInfoWriter.SI_VERSION.Length, scratch); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_DOCCOUNT)); int docCount = Convert.ToInt32(ReadString(SimpleTextSegmentInfoWriter.SI_DOCCOUNT.Length, scratch), CultureInfo.InvariantCulture); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_USECOMPOUND)); bool isCompoundFile = Convert.ToBoolean(ReadString(SimpleTextSegmentInfoWriter.SI_USECOMPOUND.Length, scratch), CultureInfo.InvariantCulture); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_NUM_DIAG)); int numDiag = Convert.ToInt32(ReadString(SimpleTextSegmentInfoWriter.SI_NUM_DIAG.Length, scratch), CultureInfo.InvariantCulture); IDictionary<string, string> diagnostics = new Dictionary<string, string>(); for (int i = 0; i < numDiag; i++) { SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_DIAG_KEY)); string key = ReadString(SimpleTextSegmentInfoWriter.SI_DIAG_KEY.Length, scratch); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_DIAG_VALUE)); string value = ReadString(SimpleTextSegmentInfoWriter.SI_DIAG_VALUE.Length, scratch); diagnostics[key] = value; } SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_NUM_FILES)); int numFiles = Convert.ToInt32(ReadString(SimpleTextSegmentInfoWriter.SI_NUM_FILES.Length, scratch), CultureInfo.InvariantCulture); var files = new HashSet<string>(); for (int i = 0; i < numFiles; i++) { SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_FILE)); string fileName = ReadString(SimpleTextSegmentInfoWriter.SI_FILE.Length, scratch); files.Add(fileName); } SimpleTextUtil.CheckFooter(input); var info = new SegmentInfo(directory, version, segmentName, docCount, isCompoundFile, null, diagnostics) {Files = files}; success = true; return info; } finally { if (!success) { IOUtils.CloseWhileHandlingException(input); } else { input.Dispose(); } } }
public override StoredFieldsWriter FieldsWriter(Directory directory, SegmentInfo si, IOContext context) { return(new CompressingStoredFieldsWriter(directory, si, segmentSuffix, context, formatName, compressionMode, chunkSize)); }
public override SegmentInfo Read(Directory directory, string segmentName, IOContext context) { var scratch = new BytesRef(); string segFileName = IndexFileNames.SegmentFileName(segmentName, "", SimpleTextSegmentInfoFormat.SI_EXTENSION); ChecksumIndexInput input = directory.OpenChecksumInput(segFileName, context); bool success = false; try { SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_VERSION)); string version = ReadString(SimpleTextSegmentInfoWriter.SI_VERSION.Length, scratch); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_DOCCOUNT)); int docCount = Convert.ToInt32(ReadString(SimpleTextSegmentInfoWriter.SI_DOCCOUNT.Length, scratch), CultureInfo.InvariantCulture); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_USECOMPOUND)); bool isCompoundFile = Convert.ToBoolean(ReadString(SimpleTextSegmentInfoWriter.SI_USECOMPOUND.Length, scratch), CultureInfo.InvariantCulture); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_NUM_DIAG)); int numDiag = Convert.ToInt32(ReadString(SimpleTextSegmentInfoWriter.SI_NUM_DIAG.Length, scratch), CultureInfo.InvariantCulture); IDictionary <string, string> diagnostics = new Dictionary <string, string>(); for (int i = 0; i < numDiag; i++) { SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_DIAG_KEY)); string key = ReadString(SimpleTextSegmentInfoWriter.SI_DIAG_KEY.Length, scratch); SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_DIAG_VALUE)); string value = ReadString(SimpleTextSegmentInfoWriter.SI_DIAG_VALUE.Length, scratch); diagnostics[key] = value; } SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_NUM_FILES)); int numFiles = Convert.ToInt32(ReadString(SimpleTextSegmentInfoWriter.SI_NUM_FILES.Length, scratch), CultureInfo.InvariantCulture); var files = new HashSet <string>(); for (int i = 0; i < numFiles; i++) { SimpleTextUtil.ReadLine(input, scratch); Debug.Assert(StringHelper.StartsWith(scratch, SimpleTextSegmentInfoWriter.SI_FILE)); string fileName = ReadString(SimpleTextSegmentInfoWriter.SI_FILE.Length, scratch); files.Add(fileName); } SimpleTextUtil.CheckFooter(input); var info = new SegmentInfo(directory, version, segmentName, docCount, isCompoundFile, null, diagnostics) { Files = files }; success = true; return(info); } finally { if (!success) { IOUtils.CloseWhileHandlingException(input); } else { input.Dispose(); } } }
public override StoredFieldsReader FieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) { return(new Lucene40StoredFieldsReader(directory, si, fn, context)); }
public override StoredFieldsWriter FieldsWriter(Directory directory, SegmentInfo si, IOContext context) { return(new AssertingStoredFieldsWriter(@in.FieldsWriter(directory, si, context))); }
public override StoredFieldsReader FieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) { return(new AssertingStoredFieldsReader(@in.FieldsReader(directory, si, fn, context), si.DocCount)); }
/// <summary> /// Write <see cref="SegmentInfo"/> data. </summary> /// <exception cref="IOException"> If an I/O error occurs. </exception> public abstract void Write(Directory dir, SegmentInfo info, FieldInfos fis, IOContext ioContext);
public Lucene3xTermVectorsReaderAnonymousInnerClassHelper(PreFlexRWTermVectorsFormat outerInstance, Directory directory, SegmentInfo segmentInfo, FieldInfos fieldInfos, IOContext context) : base(directory, segmentInfo, fieldInfos, context) { this.OuterInstance = outerInstance; }
public override TermVectorsWriter VectorsWriter(Directory directory, SegmentInfo segmentInfo, IOContext context) { return(new AssertingTermVectorsWriter(@in.VectorsWriter(directory, segmentInfo, context))); }
public override StoredFieldsWriter FieldsWriter(Directory directory, SegmentInfo si, IOContext context) { return(new Lucene40StoredFieldsWriter(directory, si.Name, context)); }
public override StoredFieldsReader FieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) { return(new CompressingStoredFieldsReader(directory, si, segmentSuffix, fn, context, formatName, compressionMode)); }
private void LoadComments() { foreach (KeyValuePair <int, LineInfo> kvp in _lines) { try { LineInfo line = kvp.Value; SpanInfo span = _spans[line.SpanID]; SegmentInfo segment = _segments[span.SegmentID]; if (_files[line.FileID].Data == null) { //File was not found. if (_filesNotFound.Add(_files[line.FileID].Name)) { _errorCount++; } continue; } bool isAsm = Path.GetExtension(_files[line.FileID].Name).StartsWith(".s"); string comment = ""; for (int i = line.LineNumber; i >= 0; i--) { string sourceCodeLine = _files[line.FileID].Data[i]; if (sourceCodeLine.Trim().Length == 0) { //Ignore empty lines continue; } Regex regex; if (i == line.LineNumber) { regex = isAsm ? _asmFirstLineRegex : _cFirstLineRegex; } else { regex = isAsm ? _asmPreviousLinesRegex : _cPreviousLinesRegex; } Match match = regex.Match(sourceCodeLine); if (match.Success) { string matchedComment = match.Groups[1].Value.Replace("\t", " "); if (string.IsNullOrWhiteSpace(comment)) { comment = matchedComment; } else { comment = matchedComment + Environment.NewLine + comment; } } else if (i != line.LineNumber) { break; } } if (comment.Length > 0) { CodeLabel label; if (segment.IsRam) { int address = span.Offset + segment.Start; if (!_ramLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.InternalRam, Label = string.Empty }; _ramLabels[span.Offset] = label; } } else { int address = span.Offset + segment.FileOffset - iNesHeaderSize; if (!_romLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.PrgRom, Label = string.Empty }; _romLabels[span.Offset] = label; } } label.Comment = comment; } } catch { _errorCount++; } } }
/// <summary> /// Sole constructor. </summary> public CompressingStoredFieldsReader(Directory d, SegmentInfo si, string segmentSuffix, FieldInfos fn, IOContext context, string formatName, CompressionMode compressionMode) { this.compressionMode = compressionMode; string segment = si.Name; bool success = false; fieldInfos = fn; numDocs = si.DocCount; ChecksumIndexInput indexStream = null; try { string indexStreamFN = IndexFileNames.SegmentFileName(segment, segmentSuffix, Lucene40StoredFieldsWriter.FIELDS_INDEX_EXTENSION); string fieldsStreamFN = IndexFileNames.SegmentFileName(segment, segmentSuffix, Lucene40StoredFieldsWriter.FIELDS_EXTENSION); // Load the index into memory indexStream = d.OpenChecksumInput(indexStreamFN, context); string codecNameIdx = formatName + CompressingStoredFieldsWriter.CODEC_SFX_IDX; version = CodecUtil.CheckHeader(indexStream, codecNameIdx, CompressingStoredFieldsWriter.VERSION_START, CompressingStoredFieldsWriter.VERSION_CURRENT); if (Debugging.AssertsEnabled) { Debugging.Assert(CodecUtil.HeaderLength(codecNameIdx) == indexStream.GetFilePointer()); } indexReader = new CompressingStoredFieldsIndexReader(indexStream, si); long maxPointer = -1; if (version >= CompressingStoredFieldsWriter.VERSION_CHECKSUM) { maxPointer = indexStream.ReadVInt64(); CodecUtil.CheckFooter(indexStream); } else { #pragma warning disable 612, 618 CodecUtil.CheckEOF(indexStream); #pragma warning restore 612, 618 } indexStream.Dispose(); indexStream = null; // Open the data file and read metadata fieldsStream = d.OpenInput(fieldsStreamFN, context); if (version >= CompressingStoredFieldsWriter.VERSION_CHECKSUM) { if (maxPointer + CodecUtil.FooterLength() != fieldsStream.Length) { throw new CorruptIndexException("Invalid fieldsStream maxPointer (file truncated?): maxPointer=" + maxPointer + ", length=" + fieldsStream.Length); } } else { maxPointer = fieldsStream.Length; } this.maxPointer = maxPointer; string codecNameDat = formatName + CompressingStoredFieldsWriter.CODEC_SFX_DAT; int fieldsVersion = CodecUtil.CheckHeader(fieldsStream, codecNameDat, CompressingStoredFieldsWriter.VERSION_START, CompressingStoredFieldsWriter.VERSION_CURRENT); if (version != fieldsVersion) { throw new CorruptIndexException("Version mismatch between stored fields index and data: " + version + " != " + fieldsVersion); } if (Debugging.AssertsEnabled) { Debugging.Assert(CodecUtil.HeaderLength(codecNameDat) == fieldsStream.GetFilePointer()); } if (version >= CompressingStoredFieldsWriter.VERSION_BIG_CHUNKS) { chunkSize = fieldsStream.ReadVInt32(); } else { chunkSize = -1; } packedIntsVersion = fieldsStream.ReadVInt32(); decompressor = compressionMode.NewDecompressor(); this.bytes = new BytesRef(); success = true; } finally { if (!success) { IOUtils.DisposeWhileHandlingException(this, indexStream); } } }
/// <summary> /// Reads from legacy 3.x segments_N. </summary> private SegmentCommitInfo ReadLegacySegmentInfo(Directory dir, int format, IndexInput input) { // check that it is a format we can understand if (format > Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS) { throw new IndexFormatTooOldException(input, format, Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS, Lucene3xSegmentInfoFormat.FORMAT_3_1); } if (format < Lucene3xSegmentInfoFormat.FORMAT_3_1) { throw new IndexFormatTooNewException(input, format, Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS, Lucene3xSegmentInfoFormat.FORMAT_3_1); } string version; if (format <= Lucene3xSegmentInfoFormat.FORMAT_3_1) { version = input.ReadString(); } else { version = null; } string name = input.ReadString(); int docCount = input.ReadInt32(); long delGen = input.ReadInt64(); int docStoreOffset = input.ReadInt32(); IDictionary <string, string> attributes = new Dictionary <string, string>(); // parse the docstore stuff and shove it into attributes string docStoreSegment; bool docStoreIsCompoundFile; if (docStoreOffset != -1) { docStoreSegment = input.ReadString(); docStoreIsCompoundFile = input.ReadByte() == SegmentInfo.YES; attributes[Lucene3xSegmentInfoFormat.DS_OFFSET_KEY] = Convert.ToString(docStoreOffset, CultureInfo.InvariantCulture); attributes[Lucene3xSegmentInfoFormat.DS_NAME_KEY] = docStoreSegment; attributes[Lucene3xSegmentInfoFormat.DS_COMPOUND_KEY] = Convert.ToString(docStoreIsCompoundFile, CultureInfo.InvariantCulture); } else { docStoreSegment = name; docStoreIsCompoundFile = false; } // pre-4.0 indexes write a byte if there is a single norms file byte b = input.ReadByte(); //System.out.println("version=" + version + " name=" + name + " docCount=" + docCount + " delGen=" + delGen + " dso=" + docStoreOffset + " dss=" + docStoreSegment + " dssCFs=" + docStoreIsCompoundFile + " b=" + b + " format=" + format); Debug.Assert(1 == b, "expected 1 but was: " + b + " format: " + format); int numNormGen = input.ReadInt32(); IDictionary <int, long> normGen; if (numNormGen == SegmentInfo.NO) { normGen = null; } else { normGen = new Dictionary <int, long>(); for (int j = 0; j < numNormGen; j++) { normGen[j] = input.ReadInt64(); } } bool isCompoundFile = input.ReadByte() == SegmentInfo.YES; int delCount = input.ReadInt32(); Debug.Assert(delCount <= docCount); bool hasProx = input.ReadByte() == 1; IDictionary <string, string> diagnostics = input.ReadStringStringMap(); if (format <= Lucene3xSegmentInfoFormat.FORMAT_HAS_VECTORS) { // NOTE: unused int hasVectors = input.ReadByte(); } // Replicate logic from 3.x's SegmentInfo.files(): ISet <string> files = new JCG.HashSet <string>(); if (isCompoundFile) { files.Add(IndexFileNames.SegmentFileName(name, "", IndexFileNames.COMPOUND_FILE_EXTENSION)); } else { AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xFieldInfosReader.FIELD_INFOS_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xPostingsFormat.FREQ_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xPostingsFormat.PROX_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xPostingsFormat.TERMS_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xPostingsFormat.TERMS_INDEX_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xNormsProducer.NORMS_EXTENSION)); } if (docStoreOffset != -1) { if (docStoreIsCompoundFile) { files.Add(IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xCodec.COMPOUND_FILE_STORE_EXTENSION)); } else { files.Add(IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xStoredFieldsReader.FIELDS_INDEX_EXTENSION)); files.Add(IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xStoredFieldsReader.FIELDS_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xTermVectorsReader.VECTORS_INDEX_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xTermVectorsReader.VECTORS_FIELDS_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xTermVectorsReader.VECTORS_DOCUMENTS_EXTENSION)); } } else if (!isCompoundFile) { files.Add(IndexFileNames.SegmentFileName(name, "", Lucene3xStoredFieldsReader.FIELDS_INDEX_EXTENSION)); files.Add(IndexFileNames.SegmentFileName(name, "", Lucene3xStoredFieldsReader.FIELDS_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xTermVectorsReader.VECTORS_INDEX_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xTermVectorsReader.VECTORS_FIELDS_EXTENSION)); AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xTermVectorsReader.VECTORS_DOCUMENTS_EXTENSION)); } // parse the normgen stuff and shove it into attributes if (normGen != null) { attributes[Lucene3xSegmentInfoFormat.NORMGEN_KEY] = Convert.ToString(numNormGen, CultureInfo.InvariantCulture); foreach (KeyValuePair <int, long> ent in normGen) { long gen = ent.Value; if (gen >= SegmentInfo.YES) { // Definitely a separate norm file, with generation: files.Add(IndexFileNames.FileNameFromGeneration(name, "s" + ent.Key, gen)); attributes[Lucene3xSegmentInfoFormat.NORMGEN_PREFIX + ent.Key] = Convert.ToString(gen, CultureInfo.InvariantCulture); } else if (gen == SegmentInfo.NO) { // No separate norm } else { // We should have already hit indexformat too old exception Debug.Assert(false); } } } SegmentInfo info = new SegmentInfo(dir, version, name, docCount, isCompoundFile, null, diagnostics, attributes.AsReadOnly()); info.SetFiles(files); SegmentCommitInfo infoPerCommit = new SegmentCommitInfo(info, delCount, delGen, -1); return(infoPerCommit); }
public void Post([FromBody] SegmentInfo segment) { DB.AddSegment(segment); }
//private Directory cfsReader; // LUCENENET NOTE: cfsReader not used public Lucene3xFields(Directory dir, FieldInfos fieldInfos, SegmentInfo info, IOContext context, int indexDivisor) { si = info; // NOTE: we must always load terms index, even for // "sequential" scan during merging, because what is // sequential to merger may not be to TermInfosReader // since we do the surrogates dance: if (indexDivisor < 0) { indexDivisor = -indexDivisor; } bool success = false; try { var r = new TermInfosReader(dir, info.Name, fieldInfos, context, indexDivisor); if (indexDivisor == -1) { TisNoIndex = r; } else { TisNoIndex = null; Tis = r; } this.context = context; this.fieldInfos = fieldInfos; // make sure that all index files have been read or are kept open // so that if an index update removes them we'll still have them FreqStream = dir.OpenInput(IndexFileNames.SegmentFileName(info.Name, "", Lucene3xPostingsFormat.FREQ_EXTENSION), context); bool anyProx = false; foreach (FieldInfo fi in fieldInfos) { if (fi.IsIndexed) { fields[fi.Name] = fi; preTerms[fi.Name] = new PreTerms(this, fi); if (fi.IndexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) { anyProx = true; } } } if (anyProx) { ProxStream = dir.OpenInput(IndexFileNames.SegmentFileName(info.Name, "", Lucene3xPostingsFormat.PROX_EXTENSION), context); } else { ProxStream = null; } success = true; } finally { // With lock-less commits, it's entirely possible (and // fine) to hit a FileNotFound exception above. In // this case, we want to explicitly close any subset // of things that were opened so that we don't have to // wait for a GC to do so. if (!success) { Dispose(); } } this.dir = dir; }
public void Put(long segmentID, [FromBody] SegmentInfo segment) { DB.UpdateSegment(segment); }
public override TermVectorsWriter VectorsWriter(Directory directory, SegmentInfo segmentInfo, IOContext context) { return(new Lucene40TermVectorsWriter(directory, segmentInfo.Name, context)); }
public Lucene3xTermVectorsReader(Directory d, SegmentInfo si, FieldInfos fieldInfos, IOContext context) { string segment = Lucene3xSegmentInfoFormat.GetDocStoreSegment(si); int docStoreOffset = Lucene3xSegmentInfoFormat.GetDocStoreOffset(si); int size = si.DocCount; bool success = false; try { if (docStoreOffset != -1 && Lucene3xSegmentInfoFormat.GetDocStoreIsCompoundFile(si)) { d = storeCFSReader = new CompoundFileDirectory(si.Dir, IndexFileNames.SegmentFileName(segment, "", Lucene3xCodec.COMPOUND_FILE_STORE_EXTENSION), context, false); } else { storeCFSReader = null; } string idxName = IndexFileNames.SegmentFileName(segment, "", VECTORS_INDEX_EXTENSION); tvx = d.OpenInput(idxName, context); format = CheckValidFormat(tvx); string fn = IndexFileNames.SegmentFileName(segment, "", VECTORS_DOCUMENTS_EXTENSION); tvd = d.OpenInput(fn, context); int tvdFormat = CheckValidFormat(tvd); fn = IndexFileNames.SegmentFileName(segment, "", VECTORS_FIELDS_EXTENSION); tvf = d.OpenInput(fn, context); int tvfFormat = CheckValidFormat(tvf); if (Debugging.AssertsEnabled) { Debugging.Assert(format == tvdFormat); Debugging.Assert(format == tvfFormat); } numTotalDocs = (int)(tvx.Length >> 4); if (-1 == docStoreOffset) { this.docStoreOffset = 0; this.size = numTotalDocs; if (Debugging.AssertsEnabled) { Debugging.Assert(size == 0 || numTotalDocs == size); } } else { this.docStoreOffset = docStoreOffset; this.size = size; // Verify the file is long enough to hold all of our // docs if (Debugging.AssertsEnabled) { Debugging.Assert(numTotalDocs >= size + docStoreOffset, () => "numTotalDocs=" + numTotalDocs + " size=" + size + " docStoreOffset=" + docStoreOffset); } } this.fieldInfos = fieldInfos; success = true; } finally { // With lock-less commits, it's entirely possible (and // fine) to hit a FileNotFound exception above. In // this case, we want to explicitly close any subset // of things that were opened so that we don't have to // wait for a GC to do so. if (!success) { try { Dispose(); } // keep our original exception catch (Exception) { } } } }
public GET(IConnection con, ContentInfo info, SegmentInfo segment) : this(con, info, segment, "file") { }
public Segment(SegmentInfo segmentInfo) { if (segmentInfo == null) throw new ArgumentNullException("segmentInfo"); _segmentInfo = segmentInfo; }
/// <summary>Reads the current object from the <paramref name="item"/>.</summary> /// <param name="segmentInfo">segmentinfo containing information about the current element that is getting processes</param> /// <param name="topLevel">true if the element currently pointed by the xml reader refers to a top level element</param> /// <param name="item">Item to read from.</param> /// <returns>returns the clr object with the data populated</returns> private object CreateObject(SegmentInfo segmentInfo, bool topLevel, SyndicationItem item) { Debug.Assert(item != null, "item != null"); Debug.Assert(topLevel || !this.Update, "deep updates not supported"); this.RecurseEnter(); object result; // update the object count everytime you encounter a new resource this.CheckAndIncrementObjectCount(); // Process the type annotation. ResourceType currentResourceType = this.GetResourceType(item, segmentInfo.TargetResourceType); if (currentResourceType.ResourceTypeKind != ResourceTypeKind.EntityType) { throw DataServiceException.CreateBadRequestError(Strings.BadRequest_OnlyEntityTypesMustBeSpecifiedInEntryElement(currentResourceType.FullName)); } // We have the actual type info from the payload. Update the request/response DSV if any property is FF mapped with KeepInContent=false. this.UpdateAndCheckEpmRequestResponseDSV(currentResourceType, topLevel); // Get a resource cookie from the provider. ResourceSetWrapper container; if (segmentInfo.TargetKind == RequestTargetKind.OpenProperty) { // Open navigation properties are not supported on OpenTypes. throw DataServiceException.CreateBadRequestError(Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(segmentInfo.Identifier)); } else { Debug.Assert(segmentInfo.TargetKind == RequestTargetKind.Resource, "segmentInfo.TargetKind == RequestTargetKind.Resource"); container = segmentInfo.TargetContainer; } DataServiceHostWrapper host = this.Service.OperationContext.Host; if (this.Update) { Debug.Assert(currentResourceType.ResourceTypeKind == ResourceTypeKind.EntityType, "only expecting entity types"); // Only verify ETag if there is going to be some update applied (that's the idea) // In reality: // - for normal entities (V1 compatible) - don't check ETags if there is no content element. (Same as in V1) // - for V2 stuff - check ETags always as we can't tell if there's going to be something modified or not // with EPM properties can be anywhere in the payload and thus even without content there still can be updates // with MLE the properties are not in the content element but in their own element // It's hard to recognize if there's going to be update up front and so this below is an approximation // which seems to be good enough. Note that if we add new ways of handling properties in the content // the condition below might need to change. bool verifyETag = topLevel && (HasContent(item) || currentResourceType.HasEntityPropertyMappings || currentResourceType.IsMediaLinkEntry); bool replaceResource = topLevel && host.AstoriaHttpVerb == AstoriaVerbs.PUT; // if its a top level resource, then it cannot be null result = this.GetObjectFromSegmentInfo(currentResourceType, segmentInfo, verifyETag, topLevel /*checkForNull*/, replaceResource); if (this.Tracker != null) { this.Tracker.TrackAction(result, container, UpdateOperations.Change); } } else { if (segmentInfo.TargetKind == RequestTargetKind.Resource) { DataServiceConfiguration.CheckResourceRights(segmentInfo.TargetContainer, EntitySetRights.WriteAppend); } result = this.Updatable.CreateResource(container.Name, currentResourceType.FullName); if (this.Tracker != null) { this.Tracker.TrackAction(result, container, UpdateOperations.Add); } } // Process the content in the entry. EpmContentDeSerializer.EpmAppliedPropertyInfo propertiesApplied = new EpmContentDeSerializer.EpmAppliedPropertyInfo(); this.ApplyProperties(item, currentResourceType, propertiesApplied, result); // Perform application of epm properties here if (currentResourceType.HasEntityPropertyMappings) { new EpmContentDeSerializer(currentResourceType, result).DeSerialize( item, new EpmContentDeSerializer.EpmContentDeserializerState { IsUpdateOperation = this.Update, Updatable = this.Updatable, Service = this.Service, PropertiesApplied = propertiesApplied }); } // Process the links in the entry. foreach (SyndicationLink link in item.Links) { string navigationPropertyName = UriUtil.GetNameFromAtomLinkRelationAttribute(link.RelationshipType); if (null == navigationPropertyName) { continue; } Deserializer.CheckForBindingInPutOperations(host.AstoriaHttpVerb); Debug.Assert(segmentInfo.TargetContainer != null, "segmentInfo.TargetContainer != null"); this.ApplyLink(link, segmentInfo.TargetContainer, currentResourceType, result, navigationPropertyName); } this.RecurseLeave(); return result; }
/// <summary> /// Returns true if the payload is correct for the top level non-entity target. /// </summary> /// <param name="jsonObject">json object representing the data in the payload.</param> /// <param name="segment">information about the last segment in the request uri.</param> /// <param name="resource">resource object as specified in the payload.</param> /// <returns>returns true if the payload is correct for non-entity resource.</returns> private static bool HandleTopLevelNonEntityProperty(JsonReader.JsonObjectRecords jsonObject, SegmentInfo segment, out object resource) { Debug.Assert(jsonObject != null, "jsonObject != null"); Debug.Assert(segment != null, "segment != null"); resource = null; if (segment.TargetKind == RequestTargetKind.Primitive || segment.TargetKind == RequestTargetKind.OpenProperty || segment.TargetKind == RequestTargetKind.ComplexObject) { if (jsonObject.Count == 1 && jsonObject.Entries.TryGetValue(segment.Identifier, out resource)) { // For open property, assume it to be a primitive or complex payload. // If its targeting an entity, then the type must be specified return true; } else if (segment.TargetKind != RequestTargetKind.OpenProperty) { throw DataServiceException.CreateBadRequestError(Strings.BadRequestStream_InvalidResourceEntity); } } // its an entity resource payload return false; }
internal void SetProperties() { if (_propertiesSet) return; // first make sure your set to your input's properties foreach (InternalRecordSource source in _inputList) { source.SetProperties(); if (_passThruInputSorting) _sorting = source.Sorting; if (_passThruInputBucketting) _bucketting = source.Bucketting; if (_passThruInputSegmenting) _segmenting = source.Segmenting; if (_passThruInputReduced) _isReduced = source.IsReduced; } _propertiesSet = true; }
void OnGUI() { GUI.skin.button.fontStyle = FontStyle.Normal; GUIStyle myButtonStyle = new GUIStyle(GUI.skin.button); myButtonStyle.fontSize = FONTSIZE; GUIStyle myBoxStyle = new GUIStyle(GUI.skin.box); myBoxStyle.fontSize = FONTSIZE; int buttonWidth = 155; int buttonHeight = 25; int buttonWidthHalf = buttonWidth / 2; int buttonHeightTriggerTheme = 25; int intensitySliderOffsetX = 170; int spacingX = 15; int spacingY = 25; int spacingYsmall = 5; int xPos = spacingX; int yPos = 10; int yPosOld; PsaiInfo psaiInfo = PsaiCore.Instance.GetPsaiInfo(); int currentThemeId = PsaiCore.Instance.GetCurrentThemeId(); int currentSegmentId = PsaiCore.Instance.GetCurrentSegmentId(); int upcomingThemeId = psaiInfo.upcomingThemeId; bool currentSegmentChangedInThisFrame = (currentSegmentId != _playingSegmentIdInLastFrame); bool currentThemeChangedInThisFrame = (currentThemeId != _playingThemeIdInLastFrame); bool forceSegmentInfoUpdateInThisFrame = false; SegmentInfo currentSegmentInfo = new SegmentInfo(); timerForceSegmentInfoUpdateCounter += Time.deltaTime; if (timerForceSegmentInfoUpdateCounter > FORCE_SEGMENT_INFO_UPDATE_INTERVAL_IN_SECONDS) { timerForceSegmentInfoUpdateCounter -= FORCE_SEGMENT_INFO_UPDATE_INTERVAL_IN_SECONDS; forceSegmentInfoUpdateInThisFrame = true; } if (_segmentInfos.ContainsKey(currentSegmentId)) { if (currentSegmentChangedInThisFrame || forceSegmentInfoUpdateInThisFrame) { _segmentInfos[currentSegmentId] = PsaiCore.Instance.GetSegmentInfo(currentSegmentId); } currentSegmentInfo = _segmentInfos[currentSegmentId]; } Color oldColor = GUI.backgroundColor; if (psaiInfo.psaiState == PsaiState.notready) { GUI.color = Color.white; GUI.Label(new Rect(xPos, yPos, Screen.width, 200), "NO SOUNDTRACK LOADED\n Troubleshooting:\n1. The folder containing all psai soundtrack data must be located within the 'Resources' folder of your project.\n2. Your Scene must contain the 'Psai.prefab' Game Object with both a PsaiSoundtrackLoader and a PsaiCoreManager-Component.\n3. The PsaiSoundtrackLoader-Component needs to hold the path to the soundtrack file. Drag & Drop that file from your Soundtrack folder in the Project window.", guiStyle); return; } yPos = spacingYsmall; xPos = spacingX; GUI.color = Color.white; int intensitySliderWidth = Screen.width / 5; int intensitySliderHeight = spacingY; xPos = intensitySliderOffsetX; ////////////////////////////////////////////////////////////////////////// // intensity indicator bar ////////////////////////////////////////////////////////////////////////// int intensityIndicatorHeight = (int)(spacingY * 2.0f / 2.5f); if (_showIntensityLevels) { xPos = intensitySliderOffsetX; _textureIntensity.wrapMode = TextureWrapMode.Repeat; _textureWhiteAlpha.wrapMode = TextureWrapMode.Repeat; GUI.Box(new Rect(xPos, yPos, intensitySliderWidth, intensityIndicatorHeight * 2), "", myBoxStyle); if (psaiInfo.psaiState == PsaiState.playing) { float intensityOfCurrentSegment = currentSegmentInfo.intensity; float currentIntensity = PsaiCore.Instance.GetCurrentIntensity(); float upcomingIntensity = psaiInfo.upcomingIntensity; float intensityOfCurrentSegmentIndicatorWidth = intensitySliderWidth * intensityOfCurrentSegment; float dynamicIntensityBarHeight = intensityIndicatorHeight; // *3 / 4; float dynamicIntensityBarOffsetY = intensityIndicatorHeight; // intensitySliderHeight / 8; GUI.color = COLOR_DARKGREEN; GUI.DrawTextureWithTexCoords(new Rect(xPos, yPos, intensityOfCurrentSegmentIndicatorWidth, intensityIndicatorHeight), _textureIntensity, new Rect(0, 0, 1, 1)); // non-interrupting Trigger has been received: show upcoming intensity if (Mathf.Abs(upcomingIntensity - currentIntensity) > 0.01f) { GUI.color = new Color(0.5f + 0.5f * _flashIntensity, 0.5f + 0.5f * _flashIntensity, 0, 0.66f); GUI.DrawTextureWithTexCoords(new Rect(xPos, yPos + dynamicIntensityBarOffsetY, (intensitySliderWidth * upcomingIntensity), dynamicIntensityBarHeight), _textureIntensity, new Rect(0, 0, 1, 1)); } else { GUI.color = COLOR_LIGHTGREEN; GUI.DrawTextureWithTexCoords(new Rect(xPos, yPos + dynamicIntensityBarOffsetY, intensitySliderWidth * currentIntensity, dynamicIntensityBarHeight), _textureIntensity, new Rect(0, 0, 1, 1)); } } xPos = spacingX; GUI.color = COLOR_LIGHTGREY; GUI.Label(new Rect(xPos, yPos - spacingYsmall, 300, spacingY), "Segment Intensity:", guiStyle); GUI.color = COLOR_LIGHTGREY; GUI.Label(new Rect(xPos, yPos - spacingYsmall + intensityIndicatorHeight, 300, spacingY), "Dynamic Intensity:", guiStyle); } ////////////////////////////////////////////////////////////////////////// // Add To Current Intensity Button ////////////////////////////////////////////////////////////////////////// if (_showIntensityControls) { xPos = intensitySliderOffsetX + intensitySliderWidth + spacingX; if (psaiInfo.psaiState == PsaiState.playing) { GUI.color = Color.white; } else { GUI.color = COLOR_LIGHTGREY; } } ////////////////////////////////////////////////////////////////////////// // Hold Intensity Button ////////////////////////////////////////////////////////////////////////// if (_showIntensityControls) { bool holdButtonEnabled = psaiInfo.psaiState == PsaiState.playing && !PsaiCore.Instance.CutSceneIsActive() && !PsaiCore.Instance.MenuModeIsActive(); if (psaiInfo.intensityIsHeld) { GUI.color = COLOR_CURRENT_THEME; GUI.DrawTextureWithTexCoords(new Rect(xPos, yPos, buttonWidthHalf, intensitySliderHeight + intensityIndicatorHeight * 2), _textureWhiteFull, new Rect(0, 0, 1, 1)); } if (holdButtonEnabled) { GUI.color = Color.white; } else { GUI.color = COLOR_DARKGREY; } if (GUI.Button(new Rect(xPos, yPos, buttonWidthHalf, intensitySliderHeight + intensityIndicatorHeight * 2), "Hold\nIntensity", myButtonStyle) && holdButtonEnabled) { PsaiCore.Instance.HoldCurrentIntensity(!psaiInfo.intensityIsHeld); } xPos += buttonWidthHalf + spacingX; ////////////////////////////////////////////////////////////////////////// // Add to Intensity Button ////////////////////////////////////////////////////////////////////////// if (GUI.Button(new Rect(xPos, yPos, buttonWidthHalf, intensitySliderHeight + intensityIndicatorHeight * 2), "add to\nIntensity", myButtonStyle)) { if (_deltaIntensityValue > 1.0f) _deltaIntensityValue = 1.0f; if (_deltaIntensityValue < -1.0f) _deltaIntensityValue = -1.0f; _deltaIntensityString = _deltaIntensityValue.ToString("F2"); PsaiCore.Instance.AddToCurrentIntensity(_deltaIntensityValue); } xPos += buttonWidthHalf + spacingX / 2; GUI.color = COLOR_LIGHTGREY; _deltaIntensityString = GUI.TextField(new Rect(xPos, yPos + intensitySliderHeight, buttonWidth / 4, intensityIndicatorHeight * 2), _deltaIntensityString, 25); if (!float.TryParse(_deltaIntensityString, out _deltaIntensityValue)) { _deltaIntensityString = _deltaIntensityValue.ToString("F2"); } } yPos += intensityIndicatorHeight * 2; yPos += intensitySliderHeight; ////////////////////////////////////////////////////////////////////////// // Volume Slider ////////////////////////////////////////////////////////////////////////// if (_showMainVolumeSlider) { int volumeSliderWidth = spacingX * 2; xPos = Screen.width - volumeSliderWidth; //xPos += buttonWidthHalf + spacingX; int volumeSliderHeight = yPos - spacingYsmall; GUI.color = Color.white; _volume = GUI.VerticalSlider(new Rect(xPos, yPos - volumeSliderHeight, volumeSliderWidth, volumeSliderHeight), PsaiCore.Instance.GetVolume(), 1.0f, 0.0f); { PsaiCore.Instance.SetVolume(_volume); } //xPos += volumeSliderWidth; GUI.Label(new Rect(xPos - volumeSliderWidth * 2, spacingYsmall, 200, spacingY), "volume", guiStyle); GUI.Label(new Rect(xPos - volumeSliderWidth * 2, spacingY, 200, spacingY), _volume.ToString("F3"), guiStyle); } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // Trigger intensity slider ////////////////////////////////////////////////////////////////////////// int themeTriggerSectionTotalHeight = _themeTypesToThemeIds.Keys.Count * (buttonHeightTriggerTheme + spacingYsmall); if (_showThemeTriggerSection) { yPos -= spacingY; xPos = spacingX; GUI.color = Color.white; GUI.Label(new Rect(xPos, yPos, 200, spacingY), "set Start-Intensity: " + _intensity.ToString("f3"), guiStyle); yPos += spacingYsmall * 2; xPos = intensitySliderOffsetX; float intensitySliderValue = GUI.HorizontalSlider(new Rect(xPos, yPos, intensitySliderWidth, intensitySliderHeight), _intensity, 0.0f, 1.0f); { _intensity = intensitySliderValue; } ////////////////////////////////////////////////////////////////////////// yPos += spacingY; yPos += spacingYsmall; ////////////////////////////////////////////////////////////////////////// // Theme Trigger Buttons ////////////////////////////////////////////////////////////////////////// int maxThemeCountPerType = 0; yPosOld = yPos; foreach (ThemeType themeType in _themeTypesToThemeIds.Keys) { xPos = spacingX; if (_showThemeTriggerSection) { GUI.color = COLOR_LIGHTGREY; GUI.Label(new Rect(xPos, yPos, intensitySliderOffsetX, 50), Theme.ThemeTypeToString(themeType) + " :", guiStyle); } List<int> themeIdList = _themeTypesToThemeIds[themeType]; if (maxThemeCountPerType < themeIdList.Count) { maxThemeCountPerType = themeIdList.Count; } yPos += buttonHeight + spacingYsmall; } int themeTriggerButtonSectionWidth = maxThemeCountPerType * (buttonWidth + spacingX); _scrollPositionTriggerSection = GUI.BeginScrollView(new Rect(intensitySliderOffsetX, yPosOld, Screen.width - intensitySliderOffsetX, themeTriggerSectionTotalHeight), _scrollPositionTriggerSection, new Rect(0, 0, themeTriggerButtonSectionWidth, themeTriggerSectionTotalHeight)); yPos = 0; bool triggeringIsPossible = !PsaiCore.Instance.CutSceneIsActive() && !PsaiCore.Instance.MenuModeIsActive(); SetGuiColorForBox(triggeringIsPossible); foreach (ThemeType themeType in _themeTypesToThemeIds.Keys) { xPos = 0; List<int> themeIdList = _themeTypesToThemeIds[themeType]; foreach (int themeId in themeIdList) { ThemeInfo themeInfo = _themeInfos[themeId]; if (themeInfo.type == ThemeType.highlightLayer && currentSegmentId != -1 && PsaiCore.Instance.CheckIfAtLeastOneDirectTransitionOrLayeringIsPossible(currentSegmentId, themeInfo.id) == false) { GUI.enabled = false; } bool drawButtonBackground = false; if (themeId == psaiInfo.lastBasicMoodThemeId) { GUI.color = new Color(0.0f, 1.0f, 0.0f, 0.3f); drawButtonBackground = true; } if (themeId == upcomingThemeId) { Color flashColor = new Color(1.0f, 1.0f, 0.0f, _flashIntensity); GUI.color = flashColor; drawButtonBackground = true; } if (themeId == currentThemeId) { switch (psaiInfo.psaiState) { case PsaiState.playing: GUI.color = new Color(0.1f, 1.0f, 0.1f, 1.0f); break; case PsaiState.rest: GUI.color = new Color(0.0f, 0.5f, 0.0f, _flashIntensity); break; } drawButtonBackground = true; } if (drawButtonBackground) { GUI.DrawTextureWithTexCoords(new Rect(xPos, yPos, buttonWidth, buttonHeightTriggerTheme), _textureWhiteFull, new Rect(0, 0, 1, 1)); GUI.color = Color.white; } GUI.color = Color.white; if (GUI.Button(new Rect(xPos, yPos, buttonWidth, buttonHeightTriggerTheme), themeInfo.name, myButtonStyle)) { PsaiCore.Instance.TriggerMusicTheme(themeInfo.id, intensitySliderValue); if (themeInfo.type == ThemeType.highlightLayer) { _highlightTriggered = true; } } GUI.contentColor = oldColor; GUI.backgroundColor = oldColor; xPos += buttonWidth + spacingX; GUI.enabled = true; } yPos += buttonHeight + spacingYsmall; } GUI.EndScrollView(); yPos = yPosOld; } else { yPos += spacingYsmall * 3; } yPos += themeTriggerSectionTotalHeight; xPos = spacingX; yPos += spacingYsmall; ////////////////////////////////////////////////////////////////////////// // Control Button Boxes ////////////////////////////////////////////////////////////////////////// int boxHeightStandard = (buttonHeight + spacingY) * 2; int boxHeightSettings = boxHeightStandard + spacingYsmall * 2; int boxWidth = buttonWidth + spacingX * 2; int boxSectionWidthTotal = boxWidth * 5 + spacingX * 4; int boxHeightWithScrollbar = boxHeightSettings + spacingYsmall + 5; if (_showControlButtonSection) { _scrollPositionControlBoxes = GUI.BeginScrollView(new Rect(0, yPos, Screen.width, boxHeightWithScrollbar), _scrollPositionControlBoxes, new Rect(0, 0, boxSectionWidthTotal, boxHeightStandard)); xPos = Math.Max(0, (int)(((Screen.width - boxSectionWidthTotal) / 2.0f) - spacingX / 2.0f)); yPosOld = yPos; yPos = 0; GUI.BeginGroup(new Rect(xPos, yPos, boxWidth, boxHeightStandard)); { int x = spacingX; int y = 0; bool boxIsActive = !_paused && (psaiInfo.psaiState == PsaiState.playing || psaiInfo.psaiState == PsaiState.rest) && !PsaiCore.Instance.CutSceneIsActive() && !PsaiCore.Instance.MenuModeIsActive(); SetGuiColorForBox(boxIsActive); GUI.Box(new Rect(0, 0, boxWidth, boxHeightStandard), "Stop Music", myBoxStyle); if (boxIsActive) { y += buttonHeight; if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), "immediately", myButtonStyle)) { PsaiCore.Instance.StopMusic(true); } // you can still stop the music in rest mode, to prevent psai from waking up again. if (psaiInfo.psaiState == PsaiState.playing) { y += buttonHeight + spacingYsmall; if (psaiInfo.upcomingPsaiState == PsaiState.silence) { GUI.color = new Color(0.5f + 0.5f * _flashIntensity, 0.5f + 0.5f * _flashIntensity, 0, 0.66f); GUI.DrawTextureWithTexCoords(new Rect(x, y, buttonWidth, buttonHeight), _textureWhiteFull, new Rect(0, 0, 1, 1)); } GUI.color = Color.white; if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), "via End-Segment", myButtonStyle)) { PsaiCore.Instance.StopMusic(false); } } } } GUI.EndGroup(); xPos += boxWidth + spacingX; GUI.BeginGroup(new Rect(xPos, yPos, boxWidth, boxHeightStandard), guiStyle); { int x = spacingX; int y = 0; bool boxIsActive = !_paused && psaiInfo.psaiState == PsaiState.playing && !PsaiCore.Instance.CutSceneIsActive() && !PsaiCore.Instance.MenuModeIsActive(); SetGuiColorForBox(boxIsActive); GUI.Box(new Rect(0, 0, boxWidth, boxHeightStandard), "Return To Last Basic Mood", myBoxStyle); if (boxIsActive) { y += buttonHeight; if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), "immediately", myButtonStyle)) { PsaiCore.Instance.ReturnToLastBasicMood(true); } y += buttonHeight + spacingYsmall; if (psaiInfo.returningToLastBasicMood) { GUI.color = new Color(0.5f + 0.5f * _flashIntensity, 0.5f + 0.5f * _flashIntensity, 0, 0.66f); GUI.DrawTextureWithTexCoords(new Rect(x, y, buttonWidth, buttonHeight), _textureWhiteFull, new Rect(0, 0, 1, 1)); } GUI.color = Color.white; if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), "via End-Segment", myButtonStyle)) { PsaiCore.Instance.ReturnToLastBasicMood(false); } } } GUI.EndGroup(); xPos += boxWidth + spacingX; GUI.BeginGroup(new Rect(xPos, yPos, boxWidth, boxHeightStandard), guiStyle); { int x = spacingX; int y = buttonHeight; bool boxIsActive = psaiInfo.psaiState == PsaiState.playing; SetGuiColorForBox(boxIsActive); GUI.Box(new Rect(0, 0, boxWidth, boxHeightStandard), "", myBoxStyle); string buttonLabelPause; if (boxIsActive) { if (psaiInfo.paused) { GUI.backgroundColor = Color.white; buttonLabelPause = "Play"; } else { GUI.backgroundColor = COLOR_DARKGREY; buttonLabelPause = "Pause"; } if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight * 2), buttonLabelPause, myButtonStyle)) { _paused = !psaiInfo.paused; PsaiCore.Instance.SetPaused(_paused); } } } GUI.EndGroup(); xPos += boxWidth + spacingX; ////////////////////////////////////////////////////////////////////////// // Menu Mode ////////////////////////////////////////////////////////////////////////// if (_configureMenuMode) { GUI.BeginGroup(new Rect(xPos, yPos, boxWidth, boxHeightSettings), guiStyle); { bool boxIsActive = !_paused; SetGuiColorForBox(boxIsActive); int x = spacingX; int y = 0; y += buttonHeight; GUI.Box(new Rect(0, 0, boxWidth, boxHeightSettings), "Menu Mode Settings", myBoxStyle); if (boxIsActive) { if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), _themeInfos[_menuThemeId].name)) { _menuThemeIndex++; if (_menuThemeIndex == _themeIds.Length) { _menuThemeIndex = 0; } _menuThemeId = _themeIds[_menuThemeIndex]; } y += buttonHeight; GUI.Label(new Rect(x, y, buttonWidthHalf, buttonHeight), "intensity:", guiStyle); GUI.Label(new Rect(x + buttonWidthHalf / 4, y + 15, buttonWidthHalf, buttonHeight), _menuThemeIntensity.ToString("F2"), guiStyle); y += spacingYsmall; float menuIntensitySliderValue = GUI.HorizontalSlider(new Rect(x + buttonWidthHalf, y + spacingYsmall, buttonWidthHalf, buttonHeight), _menuThemeIntensity, 0.0f, 1.0f); { _menuThemeIntensity = menuIntensitySliderValue; } y += buttonHeight; if (GUI.Button(new Rect(x, y, buttonWidthHalf, buttonHeight), "OK", myButtonStyle)) { _configureMenuMode = false; _menuThemeIntensityOld = _menuThemeIntensity; } if (GUI.Button(new Rect(x + buttonWidthHalf, y, buttonWidthHalf, buttonHeight), "Cancel", myButtonStyle)) { _configureMenuMode = false; _menuThemeIntensity = _menuThemeIntensityOld; _menuThemeId = _menuThemeIdOld; } } } GUI.EndGroup(); } else { GUI.BeginGroup(new Rect(xPos, yPos, boxWidth, boxHeightStandard), guiStyle); { bool boxIsActive = !_paused; SetGuiColorForBox(boxIsActive); int x = spacingX; int y = 0; y += buttonHeight; GUI.Box(new Rect(0, 0, boxWidth, boxHeightStandard), "Menu Mode", myBoxStyle); if (boxIsActive) { if (!PsaiCore.Instance.MenuModeIsActive()) { if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), "Enter", myButtonStyle)) { PsaiCore.Instance.MenuModeEnter(_menuThemeId, _menuThemeIntensity); } if (GUI.Button(new Rect(x, y + buttonHeight + spacingYsmall, buttonWidth, buttonHeight), "Configure", myButtonStyle)) { _configureMenuMode = true; _menuThemeIdOld = _menuThemeId; _menuThemeIntensityOld = _menuThemeIntensity; } } else { if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), "Leave", myButtonStyle)) { PsaiCore.Instance.MenuModeLeave(); } } } } GUI.EndGroup(); } xPos += boxWidth + spacingX; if (_configureCutScene) { GUI.BeginGroup(new Rect(xPos, yPos, boxWidth, boxHeightSettings), guiStyle); { int x = spacingX; int y = 0; y += buttonHeight; GUI.Box(new Rect(0, 0, boxWidth, boxHeightSettings), "CutScene Settings", myBoxStyle); if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), _themeInfos[_cutSceneThemeId].name, myButtonStyle)) { _cutSceneThemeIndex++; if (_cutSceneThemeIndex == _themeIds.Length) { _cutSceneThemeIndex = 0; } _cutSceneThemeId = _themeIds[_cutSceneThemeIndex]; } y += buttonHeight; GUI.Label(new Rect(x, y, buttonWidthHalf, buttonHeight), "intensity:", guiStyle); GUI.Label(new Rect(x + buttonWidthHalf / 4, y + 15, buttonWidthHalf, buttonHeight), _cutSceneThemeIntensity.ToString("F2"), guiStyle); y += spacingYsmall; float cutSceneIntensitySliderValue = GUI.HorizontalSlider(new Rect(x + buttonWidthHalf, y + spacingYsmall, buttonWidthHalf, buttonHeight), _cutSceneThemeIntensity, 0.0f, 1.0f); { _cutSceneThemeIntensity = cutSceneIntensitySliderValue; } y += buttonHeight; if (GUI.Button(new Rect(x, y, buttonWidthHalf, buttonHeight), "OK", myButtonStyle)) { _configureCutScene = false; _cutSceneThemeIntensityOld = _cutSceneThemeIntensity; } if (GUI.Button(new Rect(x + buttonWidthHalf, y, buttonWidthHalf, buttonHeight), "Cancel", myButtonStyle)) { _configureCutScene = false; _cutSceneThemeIntensity = _cutSceneThemeIntensityOld; _cutSceneThemeId = _cutSceneThemeIdOld; } } GUI.EndGroup(); } else { GUI.BeginGroup(new Rect(xPos, yPos, boxWidth, boxHeightStandard), guiStyle); { int x = spacingX; int y = 0; y += buttonHeight; bool boxIsActive = !_paused && !PsaiCore.Instance.MenuModeIsActive(); SetGuiColorForBox(boxIsActive); GUI.Box(new Rect(0, 0, boxWidth, boxHeightStandard), "CutScene", myBoxStyle); if (boxIsActive) { if (!PsaiCore.Instance.CutSceneIsActive()) { if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), "Enter", myButtonStyle)) { PsaiCore.Instance.CutSceneEnter(_cutSceneThemeId, _cutSceneThemeIntensity); } if (GUI.Button(new Rect(x, y + buttonHeight + spacingYsmall, buttonWidth, buttonHeight), "Configure", myButtonStyle)) { _configureCutScene = true; _cutSceneThemeIdOld = _cutSceneThemeId; _cutSceneThemeIntensityOld = _cutSceneThemeIntensity; } } else { if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), "Leave immediately", myButtonStyle)) { PsaiCore.Instance.CutSceneLeave(true, false); } y += buttonHeight + spacingYsmall; if (GUI.Button(new Rect(x, y, buttonWidth, buttonHeight), "Leave smoothly", myButtonStyle)) { PsaiCore.Instance.CutSceneLeave(false, false); } } } } GUI.EndGroup(); } GUI.EndScrollView(); yPos = yPosOld; } GUI.color = Color.white; yPos += boxHeightSettings; yPos += spacingYsmall * 2; int playbackStatsGroupOffsetX = spacingX; xPos = playbackStatsGroupOffsetX; int playbackStatsGroupWidth = (int)(Screen.width / 2.0f) - playbackStatsGroupOffsetX - spacingX; int playbackStatsGroupHeight = (int)spacingY * 7; if (currentThemeChangedInThisFrame) { _selectedThemeId = PsaiCore.Instance.GetCurrentThemeId(); } ////////////////////////////////////////////////////////////////////////// // Bottom Section ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // Toggle View Button ////////////////////////////////////////////////////////////////////////// //int playStateInfoBoxHeight = (FONTSIZE + spacingY) * 6; int segmentInfoSectionOffsetX = playbackStatsGroupOffsetX + playbackStatsGroupWidth + spacingX; if (_showListSections) { xPos = spacingX; string buttonLabel = (_showListView == true) ? "Listview" : "Playstate"; if (GUI.Button(new Rect(xPos, yPos, buttonWidthHalf, buttonHeight), buttonLabel, myButtonStyle)) { _showListView = !_showListView; _switchedToListViewInCurrentFrame = _showListView; } yPos += buttonHeight; ////////////////////////////////////////////////////////////////////// /// Theme / Segment Info Scrollview ////////////////////////////////////////////////////////////////////// xPos = playbackStatsGroupOffsetX; if (_showListView) { int themeListViewWidth = playbackStatsGroupWidth; int segmentListViewWidth = Screen.width - segmentInfoSectionOffsetX - spacingX; int listViewHeight = (int)((Screen.height - yPos) * 0.90f); int lineHeight = 22; int themeListContentHeight = Mathf.Max(_themeInfos.Keys.Count * lineHeight, listViewHeight); //yPos = Screen.height - themeListContentHeight; GUI.Label(new Rect(xPos + themeListViewWidth / 2, yPos - lineHeight, themeListViewWidth, lineHeight), "Themes", guiStyle); GUI.Box(new Rect(xPos, yPos, themeListViewWidth, listViewHeight), "", myBoxStyle); // /// Themelist Column Headlines // for (int columnIndex = 0; columnIndex < _columnWidthsRatiosThemeList.Length; columnIndex++) { int columnWidth = themeListViewWidth / _columnWidthsRatiosThemeList[columnIndex]; if (GUI.Button(new Rect(xPos, yPos, columnWidth, buttonHeight), _columnNamesThemeList[columnIndex], "Label")) { switch (columnIndex) { case 0: _themeIdsList.Sort(CompareThemesByName); break; case 1: _themeIdsList.Sort(); break; case 2: _themeIdsList.Sort(CompareThemesByType); break; } _sortThemesAscending = !_sortThemesAscending; if (_sortThemesAscending) { _themeIdsList.Reverse(); } } xPos += columnWidth; } xPos = playbackStatsGroupOffsetX; GUI.BeginGroup(new Rect(xPos, yPos, themeListViewWidth, listViewHeight), guiStyle); { _scrollPositionThemeList = GUI.BeginScrollView(new Rect(0, lineHeight, themeListViewWidth, listViewHeight - lineHeight), _scrollPositionThemeList, new Rect(0, 0, themeListViewWidth - spacingX * 2, themeListContentHeight), false, true); int y = 0; for (int themeIndex = 0; themeIndex < _themeIds.Length; themeIndex++) { ThemeInfo themeInfo = _themeInfos[_themeIdsList[themeIndex]]; if (_selectedThemeId == themeInfo.id) { GUI.color = Color.white; GUI.DrawTextureWithTexCoords(new Rect(0, y, themeListViewWidth, lineHeight), _textureWhiteAlpha, new Rect(0, 0, 1, 1)); } if (themeInfo.id == currentThemeId) { GUI.color = COLOR_CURRENT_THEME; } else if (themeInfo.id == upcomingThemeId) { GUI.color = COLOR_UPCOMING_THEME; } else if (_selectedThemeId == themeInfo.id) { GUI.color = Color.white; } else { GUI.color = COLOR_LIGHTGREY; } int xOffsetColumn = 0; for (int columnIndex = 0; columnIndex < _columnWidthsRatiosThemeList.Length; columnIndex++) { int columnWidth = themeListViewWidth / _columnWidthsRatiosThemeList[columnIndex]; string columnString = ""; switch (columnIndex) { case 0: columnString = themeInfo.name; break; case 1: columnString = themeInfo.id.ToString(); break; case 2: columnString = psai.net.Theme.ThemeTypeToString(themeInfo.type); break; } if (GUI.Button(new Rect(xOffsetColumn, y, themeListViewWidth, lineHeight), columnString, "Label")) { _selectedThemeId = themeInfo.id; } xOffsetColumn += columnWidth; } y += lineHeight; } GUI.EndScrollView(); } GUI.EndGroup(); xPos = segmentInfoSectionOffsetX; ////////////////////////////////////////////////////////////////////////// // SegmentList ////////////////////////////////////////////////////////////////////////// GUI.color = Color.white; GUI.Label(new Rect(xPos + segmentListViewWidth / 2, yPos - lineHeight, segmentListViewWidth, lineHeight), "Segments", guiStyle); GUI.Box(new Rect(xPos, yPos, segmentListViewWidth, listViewHeight), "", myBoxStyle); if (_themeInfos.ContainsKey(_selectedThemeId)) { int[] segmentIds = _themeInfos[_selectedThemeId].segmentIds; bool selectedThemeChangedInThisFrame = (_selectedThemeId != _selectedThemeIdInLastFrame); if (selectedThemeChangedInThisFrame || _switchedToListViewInCurrentFrame || _highlightTriggered) { _segmentIdsListOfSelectedTheme.Clear(); _segmentIdsListOfSelectedTheme.AddRange(segmentIds); RebuildSegmentInfoCache(); _highlightTriggered = false; } int segmentListContentHeight = Mathf.Max(_themeInfos[_selectedThemeId].segmentIds.Length * lineHeight, listViewHeight); // /// Column Headlines // for (int columnIndex = 0; columnIndex < _columnWidthsRatiosSegments.Length; columnIndex++) { int columnWidth = segmentListViewWidth / _columnWidthsRatiosSegments[columnIndex]; if (GUI.Button(new Rect(xPos, yPos, columnWidth, buttonHeight), _columnNamesSegments[columnIndex], "Label")) { switch (columnIndex) { case 0: _segmentIdsListOfSelectedTheme.Sort(CompareSegmentsByName); break; case 1: _segmentIdsListOfSelectedTheme.Sort(CompareSegmentsBySuitablilies); break; case 2: _segmentIdsListOfSelectedTheme.Sort(CompareSegmentsByIntensity); break; case 3: _segmentIdsListOfSelectedTheme.Sort(CompareSegmentsByPlaycount); break; } _sortSegmentsAscending = !_sortSegmentsAscending; if (_sortSegmentsAscending) { _segmentIdsListOfSelectedTheme.Reverse(); } } xPos += columnWidth; } GUI.BeginGroup(new Rect(segmentInfoSectionOffsetX, yPos, segmentListViewWidth, listViewHeight), guiStyle); { _scrollPositionSegmenttList = GUI.BeginScrollView(new Rect(0, lineHeight, segmentListViewWidth, listViewHeight - lineHeight), _scrollPositionSegmenttList, new Rect(0, 0, segmentListViewWidth - spacingX * 2, segmentListContentHeight), false, true); int y = 0; for (int segmentIndex = 0; segmentIndex < _segmentIdsListOfSelectedTheme.Count; segmentIndex++) { int segmentId = _segmentIdsListOfSelectedTheme[segmentIndex]; if (segmentId == currentSegmentId) { GUI.color = COLOR_CURRENT_THEME; // make sure the playing snippet is visible if (currentSegmentChangedInThisFrame && _autoScrollToCurrentSegment) { _scrollPositionSegmenttList.y = segmentIndex * lineHeight; } } else if (segmentId == psaiInfo.targetSegmentId) { GUI.color = COLOR_UPCOMING_THEME; } else { GUI.color = COLOR_LIGHTGREY; } if (_playbackCountdowns.ContainsKey(segmentId) && _playbackCountdowns[segmentId] > 0) { GUI.color = COLOR_CURRENT_THEME; } SegmentInfo segmentInfo = _segmentInfos[segmentId]; int xOffsetColumn = 0; for (int columnIndex = 0; columnIndex < _columnWidthsRatiosSegments.Length; columnIndex++) { string columnString = ""; switch (columnIndex) { case 0: columnString = segmentInfo.name; break; case 1: columnString = Segment.GetStringFromSegmentSuitabilities(segmentInfo.segmentSuitabilitiesBitfield); break; case 2: columnString = segmentInfo.intensity.ToString("F2"); break; case 3: columnString = segmentInfo.playcount.ToString(); break; } int columnNameWidth = segmentListViewWidth / _columnWidthsRatiosSegments[columnIndex]; //GUI.Label(new Rect(xOffsetColumn, y, columnNameWidth, lineHeight), columnString); if (GUI.Button(new Rect(xOffsetColumn, y, columnNameWidth, lineHeight), columnString, "Label")) { PsaiCore.Instance.PlaySegment(segmentId); StorePlaybackCountdownForSnippet(segmentId); } xOffsetColumn += columnNameWidth; } y += lineHeight; } GUI.EndScrollView(); } GUI.EndGroup(); } } else { ////////////////////////////////////////////////////////////////////////// // Theme Info Box ////////////////////////////////////////////////////////////////////////// int middleYpos = yPos; yPos = Mathf.Max(middleYpos, Screen.height - playbackStatsGroupHeight - this._textureNeedMusic.height - buttonHeight- spacingY); if (psaiInfo.psaiState == PsaiState.playing) { GUI.color = Color.white; } else { GUI.color = COLOR_DARKGREY; } GUI.BeginGroup(new Rect(xPos, yPos, playbackStatsGroupWidth, playbackStatsGroupHeight), guiStyle); { int x = spacingX; int y = 0; int middleX = (int)(playbackStatsGroupWidth / 2.0f); GUI.Box(new Rect(0, 0, playbackStatsGroupWidth, playbackStatsGroupHeight), "current Theme playing", myBoxStyle); x += spacingX; y += spacingY; string strThemeName = ""; string strThemeId = ""; string strThemeType = ""; if (currentThemeId > 0) { ThemeInfo themeInfo = _themeInfos[currentThemeId]; strThemeName = themeInfo.name; strThemeId = themeInfo.id.ToString(); strThemeType = psai.net.Theme.ThemeTypeToString(themeInfo.type); } GUI.Label(new Rect(x, y, playbackStatsGroupWidth, spacingY), "Name: ", guiStyle); GUI.Label(new Rect(middleX, y, playbackStatsGroupWidth, spacingY), strThemeName, guiStyle); y += spacingY; GUI.Label(new Rect(x, y, playbackStatsGroupWidth, spacingY), "id: ", guiStyle); GUI.Label(new Rect(middleX, y, playbackStatsGroupWidth, spacingY), strThemeId, guiStyle); y += spacingY; GUI.Label(new Rect(x, y, playbackStatsGroupWidth, spacingY), "ThemeType: ", guiStyle); GUI.Label(new Rect(middleX, y, playbackStatsGroupWidth, spacingY), strThemeType, guiStyle); y += spacingY; y += spacingY; y += spacingY; GUI.Label(new Rect(x, y, playbackStatsGroupWidth, spacingY), "psai state: " + psaiInfo.psaiState.ToString(), guiStyle); if (psaiInfo.remainingMillisecondsInRestMode > 0) { string wakeUpString = "Waking up in: " + psaiInfo.remainingMillisecondsInRestMode.ToString(); GUI.Label(new Rect(middleX, y, playbackStatsGroupWidth, spacingY), wakeUpString, guiStyle); } } GUI.EndGroup(); ////////////////////////////////////////////////////////////////////////// // Segment Info Box ////////////////////////////////////////////////////////////////////////// xPos = segmentInfoSectionOffsetX; int snippetGroupWidth = playbackStatsGroupWidth; int snippetGroupHeight = playbackStatsGroupHeight; GUI.BeginGroup(new Rect(xPos, yPos, snippetGroupWidth, snippetGroupHeight), guiStyle); { int xSegment = spacingX; int ySegment = 0; int middleXsegmentGroup = (int)(snippetGroupWidth / 2); GUI.Box(new Rect(0, 0, snippetGroupWidth, snippetGroupHeight), "current Segment playing", myBoxStyle); xSegment += spacingX; ySegment += spacingY; string strSegmentName = ""; string strSegmentId = ""; string strIntensity = ""; string strSegmentType = ""; string strSegmentPlaycount = ""; if (currentSegmentId > 0) { SegmentInfo segmentInfo = _segmentInfos[currentSegmentId]; strSegmentName = segmentInfo.name; strSegmentId = segmentInfo.id.ToString(); strIntensity = segmentInfo.intensity.ToString("F2"); strSegmentType = Segment.GetStringFromSegmentSuitabilities(segmentInfo.segmentSuitabilitiesBitfield); strSegmentPlaycount = segmentInfo.playcount.ToString(); } GUI.Label(new Rect(xSegment, ySegment, playbackStatsGroupWidth, spacingY), "Name: ", guiStyle); GUI.Label(new Rect(middleXsegmentGroup, ySegment, playbackStatsGroupWidth, spacingY), strSegmentName); ySegment += spacingY; GUI.Label(new Rect(xSegment, ySegment, playbackStatsGroupWidth, spacingY), "id: ", guiStyle); GUI.Label(new Rect(middleXsegmentGroup, ySegment, playbackStatsGroupWidth, spacingY), strSegmentId); ySegment += spacingY; GUI.Label(new Rect(xSegment, ySegment, playbackStatsGroupWidth, spacingY), "Intensity: ", guiStyle); GUI.Label(new Rect(middleXsegmentGroup, ySegment, playbackStatsGroupWidth, spacingY), strIntensity); ySegment += spacingY; GUI.Label(new Rect(xSegment, ySegment, playbackStatsGroupWidth, spacingY), "Suitabilities: ", guiStyle); GUI.Label(new Rect(middleXsegmentGroup, ySegment, playbackStatsGroupWidth, spacingY), strSegmentType); ySegment += spacingY; GUI.Label(new Rect(xSegment, ySegment, playbackStatsGroupWidth, spacingY), "times played: "); GUI.Label(new Rect(middleXsegmentGroup, ySegment, playbackStatsGroupWidth, spacingY), strSegmentPlaycount); ySegment += spacingY; string strRemainingMillisOfCurrentSnippet = PsaiCore.Instance.GetRemainingMillisecondsOfCurrentSegmentPlayback().ToString(); GUI.Label(new Rect(xSegment, ySegment, snippetGroupWidth, spacingY), "remaining ms: ", guiStyle); GUI.Label(new Rect(middleXsegmentGroup, ySegment, snippetGroupWidth, spacingY), strRemainingMillisOfCurrentSnippet, guiStyle); ySegment += spacingY; string strCountdownUntilNextSnippet = PsaiCore.Instance.GetRemainingMillisecondsUntilNextSegmentStart().ToString(); GUI.Label(new Rect(xSegment, ySegment, snippetGroupWidth, spacingY), "ms until next Segment: ", guiStyle); GUI.Label(new Rect(middleXsegmentGroup, ySegment, snippetGroupWidth, spacingY), strCountdownUntilNextSnippet, guiStyle); } GUI.EndGroup(); // Sonic Liberty Logo if (_textureNeedMusic != null) { GUI.color = Color.white; yPos += playbackStatsGroupHeight; yPos += spacingY; //yPos += spacingYsmall; GUI.DrawTextureWithTexCoords(new Rect(Screen.width - _textureNeedMusic.width - 22, yPos, _textureNeedMusic.width, _textureNeedMusic.height), _textureNeedMusic, new Rect(0, 0, 1, 1)); } } xPos = spacingX; yPos = Screen.height - (guiStyle.fontSize + 5); if (_lastErrorString != null && _lastErrorString.Length > 0) { GUI.color = COLOR_LIGHTRED; GUI.Label(new Rect(xPos, yPos, playbackStatsGroupWidth, guiStyle.fontSize), "last error: " + _lastErrorString, guiStyle); } _playingThemeIdInLastFrame = currentThemeId; _playingSegmentIdInLastFrame = currentSegmentId; _selectedThemeIdInLastFrame = _selectedThemeId; _switchedToListViewInCurrentFrame = false; // decrement countdowns if (_playbackCountdowns.Count > 0) { List<int> snippetIdsToRemove = new List<int>(); int[] countdownKeysList = new int[_playbackCountdowns.Count]; _playbackCountdowns.Keys.CopyTo(countdownKeysList, 0); foreach (int snippetId in countdownKeysList) { int countDownMs = _playbackCountdowns[snippetId]; countDownMs -= (int)(Time.deltaTime * 1000.0f); if (countDownMs > 0) _playbackCountdowns[snippetId] = countDownMs; else snippetIdsToRemove.Add(snippetId); } foreach (int snippetId in snippetIdsToRemove) { _playbackCountdowns.Remove(snippetId); } } } }
public RequestDescription(SegmentInfo[] segmentInfos) { this.segmentInfos = segmentInfos; }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public static void CalculateSegments(SliderInfo pInfo, List<SegmentInfo> pSegments) { pSegments.Clear(); int mult = (pInfo.TrackStartPosition < pInfo.TrackEndPosition ? 1 : -1); float half = 0.5f*mult; float handleMinPos = pInfo.TrackStartPosition + pInfo.HandleSize*half; float handleMaxPos = pInfo.TrackEndPosition - pInfo.HandleSize*half; float handlePos = Mathf.Lerp(handleMinPos, handleMaxPos, pInfo.HandleValue); float jumpPos = Mathf.Lerp(handleMinPos, handleMaxPos, pInfo.JumpValue); float zeroPos = Mathf.Lerp(handleMinPos, handleMaxPos, pInfo.ZeroValue); bool hasJump = (pInfo.JumpSize > 0); bool isJumpTooNear = (Mathf.Abs(handlePos-jumpPos) < (pInfo.HandleSize+pInfo.JumpSize)*0.6f); var handleSeg = new SegmentInfo { Type = SegmentType.Handle, StartPositionType = PositionType.HandleStart, EndPositionType = PositionType.HandleEnd, StartPosition = handlePos-pInfo.HandleSize*half, EndPosition = handlePos+pInfo.HandleSize*half }; pSegments.Add(handleSeg); if ( hasJump && !isJumpTooNear && pInfo.JumpValue >= 0 ) { var jumpSeg = new SegmentInfo { Type = SegmentType.Jump, StartPositionType = PositionType.JumpStart, EndPositionType = PositionType.JumpEnd, StartPosition = jumpPos-pInfo.JumpSize*half, EndPosition = jumpPos+pInfo.JumpSize*half }; pSegments.Insert((handlePos*mult < jumpPos*mult ? 1 : 0), jumpSeg); } //// if ( pInfo.FillType == SliderFillType.Zero ) { var zeroSeg = new SegmentInfo { Type = SegmentType.Zero, StartPositionType = PositionType.Zero, EndPositionType = PositionType.Zero, StartPosition = zeroPos, EndPosition = zeroPos }; int zeroI; if ( zeroPos*mult < pSegments[0].StartPosition*mult ) { zeroI = 0; pSegments.Insert(zeroI, zeroSeg); } else if ( pSegments.Count > 1 && zeroPos*mult < pSegments[1].StartPosition*mult ) { zeroI = 1; pSegments.Insert(zeroI, zeroSeg); } else { zeroI = pSegments.Count; pSegments.Add(zeroSeg); } if ( zeroI > 0 ) { SegmentInfo beforeZeroSeg = pSegments[zeroI-1]; if ( zeroSeg.StartPosition*mult < beforeZeroSeg.EndPosition*mult ) { zeroSeg.StartPosition = beforeZeroSeg.EndPosition; zeroSeg.EndPosition = beforeZeroSeg.EndPosition; zeroSeg.StartPositionType = beforeZeroSeg.EndPositionType; zeroSeg.EndPositionType = beforeZeroSeg.EndPositionType; pSegments[zeroI] = zeroSeg; } } } //// var startSeg = new SegmentInfo { Type = SegmentType.Start, StartPositionType = PositionType.TrackStart, EndPositionType = PositionType.TrackStart, StartPosition = pInfo.TrackStartPosition, EndPosition = pInfo.TrackStartPosition }; var endSeg = new SegmentInfo { Type = SegmentType.End, StartPositionType = PositionType.TrackEnd, EndPositionType = PositionType.TrackEnd, StartPosition = pInfo.TrackEndPosition, EndPosition = pInfo.TrackEndPosition }; pSegments.Insert(0, startSeg); pSegments.Add(endSeg); //// bool isFilling = false; SegmentType fillToSegType; switch ( pInfo.FillType ) { case SliderFillType.Zero: fillToSegType = SegmentType.Zero; break; case SliderFillType.MinimumValue: fillToSegType = SegmentType.Start; break; case SliderFillType.MaximumValue: fillToSegType = SegmentType.End; break; default: throw new Exception("Unhandled fill type: "+pInfo.FillType); } //// for ( int i = 1 ; i < pSegments.Count ; i++ ) { SegmentInfo prevSeg = pSegments[i-1]; SegmentInfo nextSeg = pSegments[i]; if ( prevSeg.Type == SegmentType.Handle || prevSeg.Type == fillToSegType ) { isFilling = !isFilling; } var trackSeg = new SegmentInfo { Type = SegmentType.Track, StartPositionType = prevSeg.EndPositionType, EndPositionType = nextSeg.StartPositionType, StartPosition = prevSeg.EndPosition, EndPosition = nextSeg.StartPosition, IsFill = isFilling }; pSegments.Insert(i, trackSeg); i++; } }
protected internal override long Size(SegmentInfo info) { return(SizeDocs(info)); }
/// <summary> /// Invokes the given request expression and return the resulting IEnumerable. /// </summary> /// <param name="segmentInfo">Request segment</param> /// <returns>Result enumeration</returns> internal IEnumerable GetResultEnumerableFromRequest(SegmentInfo segmentInfo) { object result = this.Execute(segmentInfo.RequestExpression); // This is a hook for exposing the query out to debuggers and tests. IQueryable query = result as IQueryable; if (query != null) { this.dataService.InternalOnRequestQueryConstructed(query); } if ((segmentInfo.SingleResult && query == null) || result is IDataServiceInvokable) { // If the result is a single object, we wrap it in an object array. result = new object[] { result }; } return (IEnumerable)result; }
public override TermVectorsReader VectorsReader(Directory directory, SegmentInfo segmentInfo, FieldInfos fieldInfos, IOContext context) { return(new AssertingTermVectorsReader(@in.VectorsReader(directory, segmentInfo, fieldInfos, context))); }
public override void Write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) { var segFileName = IndexFileNames.SegmentFileName(si.Name, "", SimpleTextSegmentInfoFormat.SI_EXTENSION); si.AddFile(segFileName); var success = false; var output = dir.CreateOutput(segFileName, ioContext); try { var scratch = new BytesRef(); SimpleTextUtil.Write(output, SI_VERSION); SimpleTextUtil.Write(output, si.Version, scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, SI_DOCCOUNT); SimpleTextUtil.Write(output, Convert.ToString(si.DocCount, CultureInfo.InvariantCulture), scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, SI_USECOMPOUND); SimpleTextUtil.Write(output, Convert.ToString(si.UseCompoundFile, CultureInfo.InvariantCulture).ToLowerInvariant(), scratch); SimpleTextUtil.WriteNewline(output); IDictionary <string, string> diagnostics = si.Diagnostics; int numDiagnostics = diagnostics == null ? 0 : diagnostics.Count; SimpleTextUtil.Write(output, SI_NUM_DIAG); SimpleTextUtil.Write(output, Convert.ToString(numDiagnostics, CultureInfo.InvariantCulture), scratch); SimpleTextUtil.WriteNewline(output); if (numDiagnostics > 0) { foreach (var diagEntry in diagnostics) { SimpleTextUtil.Write(output, SI_DIAG_KEY); SimpleTextUtil.Write(output, diagEntry.Key, scratch); SimpleTextUtil.WriteNewline(output); SimpleTextUtil.Write(output, SI_DIAG_VALUE); SimpleTextUtil.Write(output, diagEntry.Value, scratch); SimpleTextUtil.WriteNewline(output); } } var files = si.GetFiles(); var numFiles = files == null ? 0 : files.Count; SimpleTextUtil.Write(output, SI_NUM_FILES); SimpleTextUtil.Write(output, Convert.ToString(numFiles, CultureInfo.InvariantCulture), scratch); SimpleTextUtil.WriteNewline(output); if (numFiles > 0) { foreach (var fileName in files) { SimpleTextUtil.Write(output, SI_FILE); SimpleTextUtil.Write(output, fileName, scratch); SimpleTextUtil.WriteNewline(output); } } SimpleTextUtil.WriteChecksum(output, scratch); success = true; } finally { if (!success) { IOUtils.DisposeWhileHandlingException(output); try { dir.DeleteFile(segFileName); } catch (Exception) { //Esnure we throw original exeception } } else { output.Dispose(); } } }
public override StoredFieldsWriter FieldsWriter(Directory directory, SegmentInfo si, IOContext context) { throw UnsupportedOperationException.Create("this codec can only be used for reading"); }
/// <summary> /// Assumes the payload to represent a single object and processes accordingly /// </summary> /// <param name="segmentInfo">info about the object being created</param> /// <returns>the newly formed object that the payload represents</returns> protected override object CreateSingleObject(SegmentInfo segmentInfo) { object jsonObject = this.jsonReader.ReadValue(); bool existingRelationship; return this.CreateObject(jsonObject, segmentInfo, true /*topLevel*/, out existingRelationship); }
// note: just like segmentreader in 3.x, we open up all the files here (including separate norms) up front. // but we just don't do any seeks or reading yet. public Lucene3xNormsProducer(Directory dir, SegmentInfo info, FieldInfos fields, IOContext context) { Directory separateNormsDir = info.Dir; // separate norms are never inside CFS maxdoc = info.DocCount; string segmentName = info.Name; bool success = false; try { long nextNormSeek = NORMS_HEADER.Length; //skip header (header unused for now) foreach (FieldInfo fi in fields) { if (fi.HasNorms) { string fileName = GetNormFilename(info, fi.Number); Directory d = HasSeparateNorms(info, fi.Number) ? separateNormsDir : dir; // singleNormFile means multiple norms share this file bool singleNormFile = IndexFileNames.MatchesExtension(fileName, NORMS_EXTENSION); IndexInput normInput = null; long normSeek; if (singleNormFile) { normSeek = nextNormSeek; if (singleNormStream == null) { singleNormStream = d.OpenInput(fileName, context); openFiles.Add(singleNormStream); } // All norms in the .nrm file can share a single IndexInput since // they are only used in a synchronized context. // If this were to change in the future, a clone could be done here. normInput = singleNormStream; } else { normInput = d.OpenInput(fileName, context); openFiles.Add(normInput); // if the segment was created in 3.2 or after, we wrote the header for sure, // and don't need to do the sketchy file size check. otherwise, we check // if the size is exactly equal to maxDoc to detect a headerless file. // NOTE: remove this check in Lucene 5.0! string version = info.Version; bool isUnversioned = (version == null || StringHelper.VersionComparer.Compare(version, "3.2") < 0) && normInput.Length == maxdoc; if (isUnversioned) { normSeek = 0; } else { normSeek = NORMS_HEADER.Length; } } NormsDocValues norm = new NormsDocValues(this, normInput, normSeek); norms[fi.Name] = norm; nextNormSeek += maxdoc; // increment also if some norms are separate } } // TODO: change to a real check? see LUCENE-3619 Debug.Assert(singleNormStream == null || nextNormSeek == singleNormStream.Length, singleNormStream != null ? "len: " + singleNormStream.Length + " expected: " + nextNormSeek : "null"); success = true; } finally { if (!success) { IOUtils.DisposeWhileHandlingException(openFiles); } } ramBytesUsed = new AtomicInt64(); }
/// <summary> /// Create the object given the list of the properties. One of the properties will be __metadata property /// which will contain type information /// </summary> /// <param name="jsonObject">list of the properties and values specified in the payload</param> /// <param name="segmentInfo">info about the object being created</param> /// <param name="topLevel">true if the current object is a top level one, otherwise false</param> /// <param name="existingRelationship">does this resource already binded to its parent</param> /// <returns>instance of the object created</returns> private object CreateObject(object jsonObject, SegmentInfo segmentInfo, bool topLevel, out bool existingRelationship) { this.RecurseEnter(); existingRelationship = true; bool existingResource = true; object resource = null; ResourceType resourceType; JsonReader.JsonObjectRecords jsonObjectRecord; if (topLevel) { // Every top level json content must be JsonObjectRecords - primitive, complex or entity jsonObjectRecord = jsonObject as JsonReader.JsonObjectRecords; if (jsonObjectRecord == null) { throw DataServiceException.CreateBadRequestError(Strings.BadRequestStream_InvalidResourceEntity); } object nonEntityResource; if (HandleTopLevelNonEntityProperty(jsonObjectRecord, segmentInfo, out nonEntityResource)) { // if the segment refers to primitive type, then return the value if (segmentInfo.TargetKind == RequestTargetKind.Primitive || nonEntityResource == null || (segmentInfo.TargetKind == RequestTargetKind.OpenProperty && WebUtil.IsPrimitiveType(nonEntityResource.GetType()))) { return nonEntityResource; } jsonObject = nonEntityResource; } } else if ( jsonObject == null || (segmentInfo.TargetKind == RequestTargetKind.OpenProperty && WebUtil.IsPrimitiveType(jsonObject.GetType())) || segmentInfo.TargetKind == RequestTargetKind.Primitive) { // For reference properties, we do not know if there was already some relationship setup // By setting it to null, we are unbinding the old relationship and hence existing relationship // is false // For open properties, if its null, there is no way we will be able to deduce the type existingRelationship = false; return jsonObject; } // Otherwise top level json content must be JsonObjectRecords, since we don't allow multiple inserts // at the top level jsonObjectRecord = jsonObject as JsonReader.JsonObjectRecords; if (jsonObjectRecord == null) { throw DataServiceException.CreateBadRequestError(Strings.BadRequestStream_InvalidResourceEntity); } ResourceType targetResourceType = null; if (segmentInfo.TargetKind != RequestTargetKind.OpenProperty) { targetResourceType = segmentInfo.TargetResourceType; Debug.Assert(targetResourceType != null, "Should be able to resolve type for well known segments"); Debug.Assert( targetResourceType.ResourceTypeKind == ResourceTypeKind.ComplexType || targetResourceType.ResourceTypeKind == ResourceTypeKind.EntityType, "targetType must be entity type or complex type"); } // Get the type and uri from the metadata element, if specified string uri; bool metadataElementSpecified; resourceType = this.GetTypeAndUriFromMetadata( jsonObjectRecord.Entries, targetResourceType, topLevel, out uri, out metadataElementSpecified); Debug.Assert((resourceType != null && resourceType.ResourceTypeKind != ResourceTypeKind.Primitive) || uri != null, "Either uri or resource type must be specified"); if ((uri != null || resourceType.ResourceTypeKind == ResourceTypeKind.EntityType) && segmentInfo.TargetKind == RequestTargetKind.OpenProperty) { // Open navigation properties are not supported on OpenTypes. throw DataServiceException.CreateBadRequestError(Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(segmentInfo.Identifier)); } this.CheckAndIncrementObjectCount(); if ((resourceType != null && resourceType.ResourceTypeKind != ResourceTypeKind.ComplexType) || uri != null) { // For inserts/updates, its okay not to specify anything in the payload. // Someone might just want to create a entity with default values or // merge nothing or replace everything with default values. if (this.Update) { if (!topLevel) { if (metadataElementSpecified && jsonObjectRecord.Count > 1 || !metadataElementSpecified) { throw DataServiceException.CreateBadRequestError(Strings.BadRequest_DeepUpdateNotSupported); } else if (uri == null) { throw DataServiceException.CreateBadRequestError(Strings.BadRequest_UriMissingForUpdateForDeepUpdates); } } if (topLevel) { // Checking for merge vs replace semantics // Only checking for top level resource entity // since we don't support update of deep resources resource = GetObjectFromSegmentInfo( resourceType, segmentInfo, true /*checkETag*/, true /*checkForNull*/, this.Service.OperationContext.Host.AstoriaHttpVerb == AstoriaVerbs.PUT /*replaceResource*/); } else { // case of binding at the first level. existingRelationship = false; return this.GetTargetResourceToBind(uri, false /*checkNull*/); } } else { // For insert, its a new resource that is getting created or an existing resource // getting binded. Either case, its a new relationship. existingRelationship = false; // For POST operations, the following rules holds true: // 1> If the uri is specified for navigation properties and no other property is specified, then its a bind operation. // Otherwise, ignore the uri and insert the new resource. if (uri != null) { if (segmentInfo.TargetSource == RequestTargetSource.Property && jsonObjectRecord.Count == 1) { this.RecurseLeave(); return this.GetTargetResourceToBind(uri, false /*checkNull*/); } } } } Debug.Assert(resourceType != null, "resourceType != null"); if (resourceType.ResourceTypeKind == ResourceTypeKind.ComplexType) { Debug.Assert(resource == null, "resource == null"); resource = this.Updatable.CreateResource(null, resourceType.FullName); existingResource = false; } else if (!this.Update) { Debug.Assert(resource == null, "resource == null"); if (segmentInfo.TargetKind == RequestTargetKind.Resource) { // check for append rights whenever we need to create a resource DataServiceConfiguration.CheckResourceRights(segmentInfo.TargetContainer, EntitySetRights.WriteAppend); resource = this.Updatable.CreateResource(segmentInfo.TargetContainer.Name, resourceType.FullName); // If resourceType is FF mapped with KeepInContent=false and the response format is Atom, we need to raise the response DSV version // Note that we only need to do this for POST since PUT responds with 204 and DSV=1.0 // // Errr, mismatching request and response formats don't meet the bar at this point, commenting out the fix... // //// this.UpdateAndCheckEpmRequestResponseDSV(resourceType, topLevel); this.Tracker.TrackAction(resource, segmentInfo.TargetContainer, UpdateOperations.Add); } else { Debug.Assert(segmentInfo.TargetKind == RequestTargetKind.OpenProperty, "segmentInfo.TargetKind == RequestTargetKind.OpenProperty"); // Open navigation properties are not supported on OpenTypes. throw DataServiceException.CreateBadRequestError(Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(segmentInfo.Identifier)); } existingResource = false; } bool changed = this.PopulateProperties(jsonObjectRecord, resource, segmentInfo.TargetContainer, resourceType); // For put operations, you need not specify any property and that means reset all the properties. // hence for put operations, change is always true. changed = changed || this.Service.OperationContext.Host.AstoriaHttpVerb == AstoriaVerbs.PUT; if (changed && existingResource && segmentInfo.TargetContainer != null) { this.Tracker.TrackAction(resource, segmentInfo.TargetContainer, UpdateOperations.Change); } this.RecurseLeave(); return resource; }
public override StoredFieldsWriter FieldsWriter(Directory directory, SegmentInfo si, IOContext context) { throw new NotSupportedException("this codec can only be used for reading"); }
/*--------------------------------------------------------------------------------------------*/ public static void CalculateTicks(SliderInfo pInfo, List<SegmentInfo> pSliderSegments, List<SegmentInfo> pTicks) { pTicks.Clear(); if ( pInfo.TickCount <= 1 ) { return; } //// float handStart = -1; float handEnd = -1; float jumpStart = -1; float jumpEnd = -1; for ( int i = 0 ; i < pSliderSegments.Count ; i++ ) { SegmentInfo seg = pSliderSegments[i]; if ( seg.Type == SegmentType.Handle ) { handStart = seg.StartPosition; handEnd = seg.EndPosition; } if ( seg.Type == SegmentType.Jump ) { jumpStart = seg.StartPosition; jumpEnd = seg.EndPosition; } } //// int mult = (pInfo.TrackStartPosition < pInfo.TrackEndPosition ? 1 : -1); float half = 0.5f*mult; float handleMinPos = pInfo.TrackStartPosition + pInfo.HandleSize*half; float handleMaxPos = pInfo.TrackEndPosition - pInfo.HandleSize*half; for ( int i = 0 ; i < pInfo.TickCount ; i++ ) { float prog = i/(pInfo.TickCount-1f); float tickCenterPos = Mathf.Lerp(handleMinPos, handleMaxPos, prog); var tick = new SegmentInfo { Type = SegmentType.Tick, StartPositionType = PositionType.TickStart, EndPositionType = PositionType.TickEnd, StartPosition = tickCenterPos-pInfo.TickSize*half, EndPosition = tickCenterPos+pInfo.TickSize*half }; float startMult = tick.StartPosition*mult; float endMult = tick.EndPosition*mult; bool startsInHand = (startMult >= handStart*mult && startMult <= handEnd*mult); bool endsInHand = (endMult >= handStart*mult && endMult <= handEnd*mult); bool startsInJump = (startMult >= jumpStart*mult && startMult <= jumpEnd*mult); bool endsInJump = (endMult >= jumpStart*mult && endMult <= jumpEnd*mult); tick.IsHidden = ((startsInHand && endsInHand) || (startsInJump && endsInJump)); if ( startsInHand ) { tick.StartPosition = handEnd; } if ( endsInHand ) { tick.EndPosition = handStart; } if ( startsInJump ) { tick.StartPosition = jumpEnd; } if ( endsInJump ) { tick.EndPosition = jumpStart; } pTicks.Add(tick); } }
public Lucene3xStoredFieldsReader(Directory d, SegmentInfo si, FieldInfos fn, IOContext context) { string segment = Lucene3xSegmentInfoFormat.GetDocStoreSegment(si); int docStoreOffset = Lucene3xSegmentInfoFormat.GetDocStoreOffset(si); int size = si.DocCount; bool success = false; fieldInfos = fn; try { if (docStoreOffset != -1 && Lucene3xSegmentInfoFormat.GetDocStoreIsCompoundFile(si)) { d = storeCFSReader = new CompoundFileDirectory(si.Dir, IndexFileNames.SegmentFileName(segment, "", Lucene3xCodec.COMPOUND_FILE_STORE_EXTENSION), context, false); } else { storeCFSReader = null; } fieldsStream = d.OpenInput(IndexFileNames.SegmentFileName(segment, "", FIELDS_EXTENSION), context); string indexStreamFN = IndexFileNames.SegmentFileName(segment, "", FIELDS_INDEX_EXTENSION); indexStream = d.OpenInput(indexStreamFN, context); format = indexStream.ReadInt32(); if (format < FORMAT_MINIMUM) { throw new IndexFormatTooOldException(indexStream, format, FORMAT_MINIMUM, FORMAT_CURRENT); } if (format > FORMAT_CURRENT) { throw new IndexFormatTooNewException(indexStream, format, FORMAT_MINIMUM, FORMAT_CURRENT); } long indexSize = indexStream.Length - FORMAT_SIZE; if (docStoreOffset != -1) { // We read only a slice out of this shared fields file this.docStoreOffset = docStoreOffset; this.size = size; // Verify the file is long enough to hold all of our // docs Debug.Assert(((int)(indexSize / 8)) >= size + this.docStoreOffset, "indexSize=" + indexSize + " size=" + size + " docStoreOffset=" + docStoreOffset); } else { this.docStoreOffset = 0; this.size = (int)(indexSize >> 3); // Verify two sources of "maxDoc" agree: if (this.size != si.DocCount) { throw new CorruptIndexException("doc counts differ for segment " + segment + ": fieldsReader shows " + this.size + " but segmentInfo shows " + si.DocCount); } } numTotalDocs = (int)(indexSize >> 3); success = true; } finally { // With lock-less commits, it's entirely possible (and // fine) to hit a FileNotFound exception above. In // this case, we want to explicitly close any subset // of things that were opened so that we don't have to // wait for a GC to do so. if (!success) { try { Dispose(); } // keep our original exception #pragma warning disable 168 catch (Exception t) #pragma warning restore 168 { } } } }
/// <summary> /// Sole constructor. </summary> public Lucene40TermVectorsReader(Directory d, SegmentInfo si, FieldInfos fieldInfos, IOContext context) { string segment = si.Name; int size = si.DocCount; bool success = false; try { string idxName = IndexFileNames.SegmentFileName(segment, "", VECTORS_INDEX_EXTENSION); Tvx = d.OpenInput(idxName, context); int tvxVersion = CodecUtil.CheckHeader(Tvx, CODEC_NAME_INDEX, VERSION_START, VERSION_CURRENT); string fn = IndexFileNames.SegmentFileName(segment, "", VECTORS_DOCUMENTS_EXTENSION); Tvd = d.OpenInput(fn, context); int tvdVersion = CodecUtil.CheckHeader(Tvd, CODEC_NAME_DOCS, VERSION_START, VERSION_CURRENT); fn = IndexFileNames.SegmentFileName(segment, "", VECTORS_FIELDS_EXTENSION); Tvf = d.OpenInput(fn, context); int tvfVersion = CodecUtil.CheckHeader(Tvf, CODEC_NAME_FIELDS, VERSION_START, VERSION_CURRENT); Debug.Assert(HEADER_LENGTH_INDEX == Tvx.FilePointer); Debug.Assert(HEADER_LENGTH_DOCS == Tvd.FilePointer); Debug.Assert(HEADER_LENGTH_FIELDS == Tvf.FilePointer); Debug.Assert(tvxVersion == tvdVersion); Debug.Assert(tvxVersion == tvfVersion); NumTotalDocs = (int)(Tvx.Length() - HEADER_LENGTH_INDEX >> 4); this.Size_Renamed = NumTotalDocs; Debug.Assert(size == 0 || NumTotalDocs == size); this.FieldInfos = fieldInfos; success = true; } finally { // With lock-less commits, it's entirely possible (and // fine) to hit a FileNotFound exception above. In // this case, we want to explicitly close any subset // of things that were opened so that we don't have to // wait for a GC to do so. if (!success) { try { Dispose(); } // ensure we throw our original exception catch (Exception t) { } } } }
/// <summary> /// Sole constructor. </summary> public CompressingTermVectorsReader(Directory d, SegmentInfo si, string segmentSuffix, FieldInfos fn, IOContext context, string formatName, CompressionMode compressionMode) { this.compressionMode = compressionMode; string segment = si.Name; bool success = false; fieldInfos = fn; numDocs = si.DocCount; ChecksumIndexInput indexStream = null; try { // Load the index into memory string indexStreamFN = IndexFileNames.SegmentFileName(segment, segmentSuffix, CompressingTermVectorsWriter.VECTORS_INDEX_EXTENSION); indexStream = d.OpenChecksumInput(indexStreamFN, context); string codecNameIdx = formatName + CompressingTermVectorsWriter.CODEC_SFX_IDX; version = CodecUtil.CheckHeader(indexStream, codecNameIdx, CompressingTermVectorsWriter.VERSION_START, CompressingTermVectorsWriter.VERSION_CURRENT); if (Debugging.AssertsEnabled) { Debugging.Assert(CodecUtil.HeaderLength(codecNameIdx) == indexStream.Position); // LUCENENET specific: Renamed from getFilePointer() to match FileStream } indexReader = new CompressingStoredFieldsIndexReader(indexStream, si); if (version >= CompressingTermVectorsWriter.VERSION_CHECKSUM) { indexStream.ReadVInt64(); // the end of the data file CodecUtil.CheckFooter(indexStream); } else { #pragma warning disable 612, 618 CodecUtil.CheckEOF(indexStream); #pragma warning restore 612, 618 } indexStream.Dispose(); indexStream = null; // Open the data file and read metadata string vectorsStreamFN = IndexFileNames.SegmentFileName(segment, segmentSuffix, CompressingTermVectorsWriter.VECTORS_EXTENSION); vectorsStream = d.OpenInput(vectorsStreamFN, context); string codecNameDat = formatName + CompressingTermVectorsWriter.CODEC_SFX_DAT; int version2 = CodecUtil.CheckHeader(vectorsStream, codecNameDat, CompressingTermVectorsWriter.VERSION_START, CompressingTermVectorsWriter.VERSION_CURRENT); if (version != version2) { throw RuntimeException.Create("Version mismatch between stored fields index and data: " + version + " != " + version2); } if (Debugging.AssertsEnabled) { Debugging.Assert(CodecUtil.HeaderLength(codecNameDat) == vectorsStream.Position); // LUCENENET specific: Renamed from getFilePointer() to match FileStream } packedIntsVersion = vectorsStream.ReadVInt32(); chunkSize = vectorsStream.ReadVInt32(); decompressor = compressionMode.NewDecompressor(); this.reader = new BlockPackedReaderIterator(vectorsStream, packedIntsVersion, CompressingTermVectorsWriter.BLOCK_SIZE, 0); success = true; } finally { if (!success) { IOUtils.DisposeWhileHandlingException(this, indexStream); } } }