public DocumentsWriterPerThread(string segmentName, Directory directory, LiveIndexWriterConfig indexWriterConfig, InfoStream infoStream, DocumentsWriterDeleteQueue deleteQueue, FieldInfos.Builder fieldInfos)
        {
            this.directoryOrig       = directory;
            this.directory           = new TrackingDirectoryWrapper(directory);
            this.fieldInfos          = fieldInfos;
            this.indexWriterConfig   = indexWriterConfig;
            this.infoStream          = infoStream;
            this.codec               = indexWriterConfig.Codec;
            this.docState            = new DocState(this, infoStream);
            this.docState.similarity = indexWriterConfig.Similarity;
            bytesUsed          = Counter.NewCounter();
            byteBlockAllocator = new DirectTrackingAllocator(bytesUsed);
            pendingUpdates     = new BufferedUpdates();
            intBlockAllocator  = new Int32BlockAllocator(bytesUsed);
            this.deleteQueue   = deleteQueue;
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(numDocsInRAM == 0, "num docs {0}", numDocsInRAM);
            }
            pendingUpdates.Clear();
            deleteSlice = deleteQueue.NewSlice();

            segmentInfo = new SegmentInfo(directoryOrig, Constants.LUCENE_MAIN_VERSION, segmentName, -1, false, codec, null);
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(numDocsInRAM == 0);
            }
            if (INFO_VERBOSE && infoStream.IsEnabled("DWPT"))
            {
                infoStream.Message("DWPT", Thread.CurrentThread.Name + " init seg=" + segmentName + " delQueue=" + deleteQueue);
            }
            // this should be the last call in the ctor
            // it really sucks that we need to pull this within the ctor and pass this ref to the chain!
            consumer = indexWriterConfig.IndexingChain.GetChain(this);
        }
Exemple #2
0
        public void FilterCollectionTest()
        {
            var docEdit = new DocState();
            var props   = docEdit.ToCollection();

            Assert.IsTrue(props != null);
        }
Exemple #3
0
        /// <summary>
        /// Note: Document instance is re-used per-thread </summary>
        public virtual Document NextDoc()
        {
            string line;

            UninterruptableMonitor.Enter(syncLock);
            try
            {
                line = reader.ReadLine();
                if (line == null)
                {
                    // Always rewind at end:
                    if (LuceneTestCase.Verbose)
                    {
                        Console.WriteLine("TEST: LineFileDocs: now rewind file...");
                    }
                    Close();
                    Open(null);
                    line = reader.ReadLine();
                }
            }
            finally
            {
                UninterruptableMonitor.Exit(syncLock);
            }

            DocState docState = threadDocs.Value;

            if (docState == null)
            {
                docState         = new DocState(useDocValues);
                threadDocs.Value = docState;
            }

            int spot = line.IndexOf(SEP);

            if (spot == -1)
            {
                throw RuntimeException.Create("line: [" + line + "] is in an invalid format !");
            }
            int spot2 = line.IndexOf(SEP, 1 + spot);

            if (spot2 == -1)
            {
                throw RuntimeException.Create("line: [" + line + "] is in an invalid format !");
            }

            docState.Body.SetStringValue(line.Substring(1 + spot2, line.Length - (1 + spot2)));
            string title = line.Substring(0, spot);

            docState.Title.SetStringValue(title);
            if (docState.TitleDV != null)
            {
                docState.TitleDV.SetBytesValue(new BytesRef(title));
            }
            docState.TitleTokenized.SetStringValue(title);
            docState.Date.SetStringValue(line.Substring(1 + spot, spot2 - (1 + spot)));
            docState.Id.SetStringValue(Convert.ToString(id.GetAndIncrement(), CultureInfo.InvariantCulture));
            return(docState.Doc);
        }
Exemple #4
0
        /// <summary>
        /// Note: Document instance is re-used per-thread </summary>
        public virtual Document NextDoc()
        {
            string line;

            lock (this)
            {
                line = Reader.ReadLine();
                if (line == null)
                {
                    // Always rewind at end:
                    if (LuceneTestCase.VERBOSE)
                    {
                        Console.WriteLine("TEST: LineFileDocs: now rewind file...");
                    }
                    Dispose();
                    Open(null);
                    line = Reader.ReadLine();
                }
            }

            DocState docState = ThreadDocs.Value;

            if (docState == null)
            {
                docState         = new DocState(UseDocValues);
                ThreadDocs.Value = docState;
            }

            int spot = line.IndexOf(SEP);

            if (spot == -1)
            {
                throw new Exception("line: [" + line + "] is in an invalid format !");
            }
            int spot2 = line.IndexOf(SEP, 1 + spot);

            if (spot2 == -1)
            {
                throw new Exception("line: [" + line + "] is in an invalid format !");
            }

            docState.Body.StringValue = line.Substring(1 + spot2, line.Length - (1 + spot2));
            string title = line.Substring(0, spot);

            docState.Title.StringValue = title;
            if (docState.TitleDV != null)
            {
                docState.TitleDV.BytesValue = new BytesRef(title);
            }
            docState.TitleTokenized.StringValue = title;
            docState.Date.StringValue           = line.Substring(1 + spot, spot2 - (1 + spot));
            docState.Id.StringValue             = Convert.ToString(Id.IncrementAndGet());
            return(docState.Doc);
        }
Exemple #5
0
        protected virtual DocState GetDocState()
        {
            DocState ds = docState.Value;

            if (ds == null)
            {
                ds             = new DocState(m_reuseFields, m_valType, m_bodyValType);
                docState.Value = ds;
            }
            return(ds);
        }
Exemple #6
0
        public void ToCollectionTest()
        {
            var docEdit = new DocState();
            var props   = docEdit.ToCollection();

            Assert.IsTrue(props.Any() == false);

            docEdit.Revision.Value = "2";
            props = docEdit.ToCollection();
            Assert.IsTrue(props.Count == 1);

            docEdit.EffectiveDate.Value = "2020-03-12";
            props = docEdit.ToCollection();
            Assert.IsTrue(props.Count == 2);

            docEdit.EffectiveDate.Value = null;
            props = docEdit.ToCollection();
            Assert.IsTrue(props.Count == 1);
        }
        private string GetDocIconByState(DocState state)
        {
            switch (state)
            {
            case DocState.Good:
                return(DocIconGood);

            case DocState.New:
                return(DocIconNew);

            case DocState.Bad:
                return(DocIconBad);

            case DocState.Attention:
                return(DocIconAttention);

            default:
                return("");
            }
        }
Exemple #8
0
        // LUCENENET specific: de-nested IShapeConverter

        public override Document MakeDocument()
        {
            DocState docState = GetDocState();

            Document doc = base.MakeDocument();

            // Set SPATIAL_FIELD from body
            DocData docData = docState.docData;
            //   makeDocument() resets docState.getBody() so we can't look there; look in Document
            string shapeStr = doc.GetField(DocMaker.BODY_FIELD).GetStringValue();
            IShape shape    = MakeShapeFromString(strategy, docData.Name, shapeStr);

            if (shape != null)
            {
                shape = shapeConverter.Convert(shape);
                //index
                foreach (Field f in strategy.CreateIndexableFields(shape))
                {
                    doc.Add(f);
                }
            }

            return(doc);
        }
Exemple #9
0
        // create a doc
        // use only part of the body, modify it to keep the rest (or use all if size==0).
        // reset the docdata properties so they are not added more than once.
        private Document CreateDocument(DocData docData, int size, int cnt)
        {
            DocState ds  = GetDocState();
            Document doc = m_reuseFields ? ds.doc : new Document();

            doc.Fields.Clear();

            // Set ID_FIELD
            FieldType ft = new FieldType(m_valType);

            ft.IsIndexed = true;

            Field idField = ds.GetField(ID_FIELD, ft);
            int   id;

            if (r != null)
            {
                id = r.Next(updateDocIDLimit);
            }
            else
            {
                id = docData.ID;
                if (id == -1)
                {
                    id = numDocsCreated.GetAndIncrement();
                }
            }
            idField.SetStringValue(Convert.ToString(id, CultureInfo.InvariantCulture));
            doc.Add(idField);

            // Set NAME_FIELD
            string name = docData.Name;

            if (name == null)
            {
                name = "";
            }
            name = cnt < 0 ? name : name + "_" + cnt;
            Field nameField = ds.GetField(NAME_FIELD, m_valType);

            nameField.SetStringValue(name);
            doc.Add(nameField);

            // Set DATE_FIELD
            DateTime?date       = null;
            string   dateString = docData.Date;

            if (dateString != null)
            {
                // LUCENENET: TryParseExact needs a non-nullable DateTime to work.
                DateTime temp;
                if (DateTime.TryParseExact(dateString, new string[] {
                    // Original format from Java
                    "dd-MMM-yyyy HH:mm:ss",
                    // Actual format from the test files...
                    "yyyyMMddHHmmss"
                }, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    date = temp;
                }
                // LUCENENET: Hail Mary in case the formats above are not adequate
                else if (DateTime.TryParse(dateString, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    date = temp;
                }
            }
            else
            {
                dateString = "";
            }
            Field dateStringField = ds.GetField(DATE_FIELD, m_valType);

            dateStringField.SetStringValue(dateString);
            doc.Add(dateStringField);

            if (date == null)
            {
                // just set to right now
                date = DateTime.Now;
            }

            Field dateField = ds.GetNumericField(DATE_MSEC_FIELD, NumericType.INT64);

            dateField.SetInt64Value(date.Value.Ticks);
            doc.Add(dateField);

            //util.cal.setTime(date);
            //int sec = util.cal.get(Calendar.HOUR_OF_DAY) * 3600 + util.cal.get(Calendar.MINUTE) * 60 + util.cal.get(Calendar.SECOND);
            int sec = Convert.ToInt32(date.Value.ToUniversalTime().TimeOfDay.TotalSeconds);

            Field timeSecField = ds.GetNumericField(TIME_SEC_FIELD, NumericType.INT32);

            timeSecField.SetInt32Value(sec);
            doc.Add(timeSecField);

            // Set TITLE_FIELD
            string title      = docData.Title;
            Field  titleField = ds.GetField(TITLE_FIELD, m_valType);

            titleField.SetStringValue(title == null ? "" : title);
            doc.Add(titleField);

            string body = docData.Body;

            if (body != null && body.Length > 0)
            {
                string bdy;
                if (size <= 0 || size >= body.Length)
                {
                    bdy          = body; // use all
                    docData.Body = "";   // nothing left
                }
                else
                {
                    // attempt not to break words - if whitespace found within next 20 chars...
                    for (int n = size - 1; n < size + 20 && n < body.Length; n++)
                    {
                        if (char.IsWhiteSpace(body[n]))
                        {
                            size = n;
                            break;
                        }
                    }
                    bdy          = body.Substring(0, size - 0); // use part
                    docData.Body = body.Substring(size);        // some left
                }
                Field bodyField = ds.GetField(BODY_FIELD, m_bodyValType);
                bodyField.SetStringValue(bdy);
                doc.Add(bodyField);

                if (storeBytes)
                {
                    Field bytesField = ds.GetField(BYTES_FIELD, StringField.TYPE_STORED);
                    bytesField.SetBytesValue(Encoding.UTF8.GetBytes(bdy));
                    doc.Add(bytesField);
                }
            }

            if (m_indexProperties)
            {
                var props = docData.Props;
                if (props != null)
                {
                    foreach (var entry in props)
                    {
                        Field f = ds.GetField((string)entry.Key, m_valType);
                        f.SetStringValue((string)entry.Value);
                        doc.Add(f);
                    }
                    docData.Props = null;
                }
            }

            //System.out.println("============== Created doc "+numDocsCreated+" :\n"+doc+"\n==========");
            return(doc);
        }
        private DocBase CreateModel()
        {
            // Find assembly
            var a = Assembly.GetExecutingAssembly().GetReferencedAssemblies().FirstOrDefault(a => a.Name == _options.Value.PluginName);

            if (a == null)
            {
                throw new FileNotFoundException("Unable to load assembly for reflection.");
            }

            var model = new DocBase {
                Title    = "MSFS 2020 TouchPortal Plugin",
                Overview = "This plugin will provide a two way interface between Touch Portal and Microsoft Flight Simulator 2020 through SimConnect."
            };

            var assembly     = Assembly.Load(a);
            var assemblyList = assembly.GetTypes().ToList();

            // Get all classes with the TouchPortalCategory
            var classList = assemblyList.Where(t => t.CustomAttributes.Any(att => att.AttributeType == typeof(TouchPortalCategoryAttribute))).OrderBy(o => o.Name).ToList();

            // Loop through categories
            classList.ForEach(cat => {
                var catAttr = (TouchPortalCategoryAttribute)Attribute.GetCustomAttribute(cat, typeof(TouchPortalCategoryAttribute));
                var newCat  = new DocCategory {
                    Name = catAttr.Name
                };

                // Loop through Actions
                var actions = cat.GetMembers().Where(t => t.CustomAttributes.Any(att => att.AttributeType == typeof(TouchPortalActionAttribute))).ToList();
                actions.ForEach(act => {
                    var actionAttribute = (TouchPortalActionAttribute)Attribute.GetCustomAttribute(act, typeof(TouchPortalActionAttribute));
                    var newAct          = new DocAction {
                        Name        = actionAttribute.Name,
                        Description = actionAttribute.Description,
                        Type        = actionAttribute.Type,
                        Format      = actionAttribute.Format
                    };

                    // Loop through Action Data
                    var choiceAttributes = act.GetCustomAttributes <TouchPortalActionChoiceAttribute>()?.ToList();

                    if (choiceAttributes?.Count > 0)
                    {
                        for (int i = 0; i < choiceAttributes.Count; i++)
                        {
                            var data = new DocActionData {
                                Type         = "choice",
                                DefaultValue = choiceAttributes[i].DefaultValue,
                                Values       = string.Join(",", choiceAttributes[i].ChoiceValues)
                            };
                            newAct.Data.Add(data);
                        }
                    }

                    newCat.Actions.Add(newAct);
                });

                newCat.Actions = newCat.Actions.OrderBy(c => c.Name).ToList();

                // Loop through States
                var states = cat.GetFields().Where(m => m.CustomAttributes.Any(att => att.AttributeType == typeof(TouchPortalState))).ToList();
                states.ForEach(state => {
                    var stateAttribute = state.GetCustomAttribute <TouchPortalStateAttribute>();

                    if (stateAttribute != null)
                    {
                        var newState = new DocState {
                            Id           = $"{_options.Value.PluginName}.{catAttr.Id}.State.{stateAttribute.Id}",
                            Type         = stateAttribute.Type,
                            Description  = stateAttribute.Description,
                            DefaultValue = stateAttribute.Default
                        };

                        newCat.States.Add(newState);
                    }
                });

                newCat.States = newCat.States.OrderBy(c => c.Description).ToList();

                // Loop through Events

                model.Categories.Add(newCat);
            });

            model.Categories = model.Categories.OrderBy(c => c.Name).ToList();

            return(model);
        }
Exemple #11
0
        /// <summary>
        /// Note: Document instance is re-used per-thread </summary>
        public virtual Document NextDoc()
        {
            string line;
            lock (this)
            {
                line = Reader.ReadLine();
                if (line == null)
                {
                    // Always rewind at end:
                    if (LuceneTestCase.VERBOSE)
                    {
                        Console.WriteLine("TEST: LineFileDocs: now rewind file...");
                    }
                    Dispose();
                    Open(null);
                    line = Reader.ReadLine();
                }
            }

            DocState docState = ThreadDocs.Value;
            if (docState == null)
            {
                docState = new DocState(UseDocValues);
                ThreadDocs.Value = docState;
            }

            int spot = line.IndexOf(SEP);
            if (spot == -1)
            {
                throw new Exception("line: [" + line + "] is in an invalid format !");
            }
            int spot2 = line.IndexOf(SEP, 1 + spot);
            if (spot2 == -1)
            {
                throw new Exception("line: [" + line + "] is in an invalid format !");
            }

            docState.Body.StringValue = line.Substring(1 + spot2, line.Length - (1 + spot2));
            string title = line.Substring(0, spot);
            docState.Title.StringValue = title;
            if (docState.TitleDV != null)
            {
                docState.TitleDV.BytesValue = new BytesRef(title);
            }
            docState.TitleTokenized.StringValue = title;
            docState.Date.StringValue = line.Substring(1 + spot, spot2 - (1 + spot));
            docState.Id.StringValue = Convert.ToString(Id.IncrementAndGet());
            return docState.Doc;
        }
        public DocumentsWriterPerThread(string segmentName, Directory directory, LiveIndexWriterConfig indexWriterConfig, InfoStream infoStream, DocumentsWriterDeleteQueue deleteQueue, FieldInfos.Builder fieldInfos)
        {
            this.DirectoryOrig = directory;
            this.Directory = new TrackingDirectoryWrapper(directory);
            this.FieldInfos = fieldInfos;
            this.IndexWriterConfig = indexWriterConfig;
            this.InfoStream = infoStream;
            this.Codec = indexWriterConfig.Codec;
            this.docState = new DocState(this, infoStream);
            this.docState.Similarity = indexWriterConfig.Similarity;
            bytesUsed = Counter.NewCounter();
            ByteBlockAllocator = new DirectTrackingAllocator(bytesUsed);
            PendingUpdates = new BufferedUpdates();
            intBlockAllocator = new IntBlockAllocator(bytesUsed);
            this.DeleteQueue = deleteQueue;
            Debug.Assert(numDocsInRAM == 0, "num docs " + numDocsInRAM);
            PendingUpdates.Clear();
            DeleteSlice = deleteQueue.NewSlice();

            SegmentInfo_Renamed = new SegmentInfo(DirectoryOrig, Constants.LUCENE_MAIN_VERSION, segmentName, -1, false, Codec, null);
            Debug.Assert(numDocsInRAM == 0);
            if (INFO_VERBOSE && infoStream.IsEnabled("DWPT"))
            {
                infoStream.Message("DWPT", Thread.CurrentThread.Name + " init seg=" + segmentName + " delQueue=" + deleteQueue);
            }
            // this should be the last call in the ctor
            // it really sucks that we need to pull this within the ctor and pass this ref to the chain!
            Consumer = indexWriterConfig.IndexingChain.GetChain(this);
        }
Exemple #13
0
 private string GetDocIconByState(DocState state)
 {
     switch (state) {
     case DocState.Good:
         return DocIconGood;
     case DocState.New:
         return DocIconNew;
     case DocState.Bad:
         return DocIconBad;
     case DocState.Attention:
         return DocIconAttention;
     default:
         return "";
     }
 }
        private void OpenDoc(uint docCookie)
        {
            uint flags, rLocks, wLocks, id;
            string doc;
            IntPtr data;
            IVsHierarchy hierarchy;
            dt.GetDocumentInfo(docCookie, out flags, out rLocks, out wLocks, out doc, out hierarchy, out id, out data);

            docInfoMap[docCookie] = new DocState
            {
                flags = flags,
                rLocks = rLocks,
                wLocks = wLocks,
                doc = doc,
                hierarchy = hierarchy,
                id = id,
                data = data
            };
        }