Exemplo n.º 1
0
        public void TestNamedCollection()
        {
            INamedList <int>       l1  = new NamedList <int>("l1", 11);
            INamedCollection <int> nc1 = new NamedCollection <int>("NamedCollection 1 ", l1);

            nc1.OnNameChanged += Nc1_OnNameChanged;
            l1.OnNameChanged  += Nc1_OnNameChanged;


            Console.WriteLine(nc1);
            Console.WriteLine(l1);

            l1.Name = "Named List #1";

            for (int i = 0; i < 11; i++)
            {
                nc1.Add(i);
            }

            nc1.Name = "NamedCollection 1";
            nc1.Name = "Collection 1, which is named.";

            Console.WriteLine(nc1);
            Console.WriteLine(l1);
        }
Exemplo n.º 2
0
        private DataSet QueryResultsParseDataSet(string fields, NamedList namedList, string highlightFields, out long recordCount)
        {
            ObjectDeserializeTable <T> objectDeserializeTable = new ObjectDeserializeTable <T>(this._TableName, fields);
            ISolrResponseParser <NamedList, QueryResults <DataRow> > solrResponseParser = new BinaryQueryResultsParser <DataRow>(objectDeserializeTable);

            if (!string.IsNullOrWhiteSpace(highlightFields))
            {
                BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
                IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);
                objectDeserializeTable.Highlight = highlight;
            }
            QueryResults <DataRow> queryResults = solrResponseParser.Parse(namedList);

            recordCount = queryResults.NumFound;
            DataSet   dataSet   = new DataSet();
            DataTable dataTable = objectDeserializeTable.CreateDataTable();

            foreach (DataRow current in queryResults)
            {
                dataTable.Rows.Add(current.ItemArray);
            }
            dataSet.Tables.Add(dataTable);
            DataTable dataTable2 = new DataTable();

            dataTable2.TableName = "RecordCount";
            dataTable2.Columns.Add("RecordCount", typeof(long));
            DataRow dataRow = dataTable2.NewRow();

            dataRow["RecordCount"] = recordCount;
            dataTable2.Rows.Add(dataRow);
            dataSet.Tables.Add(dataTable2);
            return(dataSet);
        }
Exemplo n.º 3
0
        public static DataSet ParserResultsDataSet <T>(this NamedList namedList, string fields, out long recordCount, string tableName = "") where T : class, new()
        {
            ObjectDeserializeTable <T> objectDeserializeTable = new ObjectDeserializeTable <T>(tableName, fields);
            ISolrResponseParser <NamedList, QueryResults <DataRow> > solrResponseParser = new BinaryQueryResultsParser <DataRow>(objectDeserializeTable);
            BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
            IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);

            objectDeserializeTable.Highlight = highlight;
            QueryResults <DataRow> queryResults = solrResponseParser.Parse(namedList);

            recordCount = queryResults.NumFound;
            DataSet   dataSet   = new DataSet();
            DataTable dataTable = objectDeserializeTable.CreateDataTable();

            foreach (DataRow current in queryResults)
            {
                dataTable.Rows.Add(current.ItemArray);
            }
            dataSet.Tables.Add(dataTable);
            DataTable dataTable2 = new DataTable();

            dataTable2.TableName = "RecordCount";
            dataTable2.Columns.Add("RecordCount", typeof(long));
            DataRow dataRow = dataTable2.NewRow();

            dataRow["RecordCount"] = recordCount;
            dataTable2.Rows.Add(dataRow);
            dataSet.Tables.Add(dataTable2);
            return(dataSet);
        }
        public IList <FacetField> Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var facetCountsNamedList = (NamedList)result.Get("facet_counts");

            if (facetCountsNamedList == null)
            {
                return(null);
            }

            var facetQueriesNamedList = (NamedList)facetCountsNamedList.Get("facet_queries");

            if (facetQueriesNamedList == null)
            {
                return(null);
            }

            var facetFieldsResult = new List <FacetField>(facetQueriesNamedList.Count);

            for (var i = 0; i < facetQueriesNamedList.Count; i++)
            {
                facetFieldsResult.Add(new FacetField()
                {
                    Name = facetQueriesNamedList.GetName(i), Count = Convert.ToInt32(facetQueriesNamedList.GetVal(i))
                });
            }

            return(facetFieldsResult);
        }
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="result">名称对象集合</param>
        /// <returns>查询结果</returns>
        public QueryResults <T> Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var queryResults     = new QueryResults <T>();
            var solrDocumentList = (SolrDocumentList)result.Get("response");

            if (solrDocumentList == null)
            {
                return(null);
            }

            queryResults.NumFound = solrDocumentList.NumFound;
            queryResults.MaxScore = solrDocumentList.MaxScore;

            var docs = objectDeserialize.Deserialize(solrDocumentList);

            foreach (T doc in docs)
            {
                queryResults.Add(doc);
            }

            return(queryResults);
        }
Exemplo n.º 6
0
        public void UnicleNameTest()
        {
            var t = new NamedList <NamedElement>();

            var el = new NamedElement();

            el.Rename("dsa");

            var el2 = new NamedElement();

            el2.Rename("dsa");

            t.Add(el);

            try
            {
                t.Add(el);
            }
            catch (InvalidOperationException)
            {
                try
                {
                    t[0] = el2;
                }
                catch (InvalidOperationException)
                {
                    return;
                }
            }

            throw new Exception("Exception has not throwed by NamedList");
        }
Exemplo n.º 7
0
        protected virtual ResponseHeader Update(UpdateOptions objUpdateOptions)
        {
            ISolrResponseParser <NamedList, ResponseHeader> solrResponseParser = new BinaryResponseHeaderParser();
            NamedList result = this.GetUpdateOperations().Update("/update", objUpdateOptions);

            return(solrResponseParser.Parse(result));
        }
Exemplo n.º 8
0
        public FacetData(INamedList responseHeader)
        {
            if (responseHeader.IsNullOrEmpty()) return;
            Queries = responseHeader.GetOrDefault<INamedList>("facet_queries");

            var fieldsList = responseHeader.GetOrDefault<INamedList>("facet_fields");
            if (fieldsList != null)
            {
                Fields=new NamedList();
                for (int i = 0; i < fieldsList.Count; i++)
                {
                    var innerList = fieldsList.GetOrDefault<IList>(i);
                    if (innerList == null) continue;
                    var list = new NamedList();
                    for (int j = 0; j < innerList.Count; j = j + 2)
                    {
                        var valKey = innerList[j] as string;
                        if (valKey != null)
                            list.Add(valKey, innerList[j + 1]);
                    }

                    Fields.Add(fieldsList.GetKey(i), list);
                }
            }

            //Fields = responseHeader.GetOrDefault<INamedList>("facet_fields");
            Dates = responseHeader.GetOrDefault<INamedList>("facet_dates");
            Ranges = responseHeader.GetOrDefault<INamedList>("facet_ranges");
        }
Exemplo n.º 9
0
        public int GetCount(string condition)
        {
            NamedList result = this.QueryLimit("*", condition, "", "", 0, 0, "", "");
            ISolrResponseParser <NamedList, QueryResults <NullResult> > solrResponseParser = new BinaryQueryResultsParser <NullResult>(new NullResultObjectDeserialize());
            QueryResults <NullResult> queryResults = solrResponseParser.Parse(result);

            return(Convert.ToInt32(queryResults.NumFound));
        }
Exemplo n.º 10
0
 public Package(Identifier?alias, IReadOnlyList <Unit> units)
 {
     Alias    = alias;
     Units    = units;
     Packages = new List <Package>();
     Members  = new NamedList <INamedMember>();
     Errors   = new Errors();
     Scope    = new PackageScope(this);
 }
Exemplo n.º 11
0
 protected SolrUriBuilder(SolrUriBuilder server, string core, string handler)
 {
     if (server == null) throw new ArgumentNullException("server");
     if (!server.IsBaseUrl) throw new ArgumentException("server");
     ServerAddress = server.ServerAddress;
     Core = core;
     Handler = handler;
     Query = new NamedList<string>();
 }
Exemplo n.º 12
0
        /// <summary>
        /// Configure a named argument with multiple values.
        /// </summary>
        /// <typeparam name="TArg">Argument type.</typeparam>
        /// <param name="getExpr">
        /// Getter expression describing where the values are stored.
        /// </param>
        /// <returns></returns>
        public NamedList <TConf, TArg> HasNamedArgumentList <TArg>(
            Expression <Func <TConf, TArg> > getExpr)
        {
            var named = new NamedList <TConf, TArg>(this,
                                                    GetDefinitionFromExpression(getExpr));

            FluentConfig.Add(named);
            return(named);
        }
Exemplo n.º 13
0
        public IDictionary <string, FacetRange> Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var facetCountsNamedList = (NamedList)result.Get("facet_counts");

            if (facetCountsNamedList == null)
            {
                return(null);
            }

            var facetRangesNamedList = (NamedList)facetCountsNamedList.Get("facet_ranges");

            if (facetRangesNamedList == null)
            {
                return(null);
            }

            var facetRangesResult = new Dictionary <string, FacetRange>(facetRangesNamedList.Count);

            for (var i = 0; i < facetRangesNamedList.Count; i++)
            {
                var fieldName  = facetRangesNamedList.GetName(i);
                var fieldValue = (NamedList)facetRangesNamedList.GetVal(i);

                if (!facetRangesResult.ContainsKey(fieldName))
                {
                    facetRangesResult.Add(fieldName, new FacetRange()
                    {
                        Start = fieldValue.Get("start"), End = fieldValue.Get("end"), Gap = fieldValue.Get("gap")
                    });
                }

                var countsNamedList = (NamedList)fieldValue.Get("counts");

                if (countsNamedList != null)
                {
                    facetRangesResult[fieldName].Counts = new List <FacetField>(countsNamedList.Count);

                    for (var j = 0; j < countsNamedList.Count; j++)
                    {
                        facetRangesResult[fieldName].Counts.Add(new FacetField()
                        {
                            Name = countsNamedList.GetName(j), Count = Convert.ToInt32(countsNamedList.GetVal(j))
                        });
                    }
                }
            }

            return(facetRangesResult);
        }
Exemplo n.º 14
0
 public void WriteNamedList(NamedList nl)
 {
     WriteTag(nl is SimpleOrderedMap ? ORDERED_MAP : NAMED_LST, nl.Count);
     for (int i = 0; i < nl.Count; i++)
     {
         String name = nl.GetName(i);
         WriteExternString(name);
         Object val = nl.GetVal(i);
         WriteVal(val);
     }
 }
 /// <summary>
 /// This should launch an open file dialog instead of the usual thing.
 /// </summary>
 /// <param name="context">ITypeDescriptorContext</param>
 /// <param name="provider">IServiceProvider</param>
 /// <param name="value">The object being displayed</param>
 /// <returns>A new version of the object if the dialog was ok.</returns>
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     _original = value as IPointScheme;
     _editCopy = _original.Copy();
     IWindowsFormsEditorService dialogProvider = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
     NamedList<IPointCategory> cats = new NamedList<IPointCategory>(_editCopy.Categories, "Category");
     CollectionPropertyGrid frm = new CollectionPropertyGrid(cats);
     frm.ChangesApplied += FrmChangesApplied;
     frm.AddItemClicked += FrmAddItemClicked;
     dialogProvider.ShowDialog(frm);
     return _original; // don't bother swapping out the edit copy, just store copies of the categories when changes are applied.
 }
Exemplo n.º 16
0
 private bool MaybeAlreadyError <T>(NamedList <T> members, INamed named)
     where T : class, INamedMember
 {
     if (members.ContainsKey(named))
     {
         var already = members[named].Name;
         Errors.AtToken(ErrNo.Syntax001, named.Name, $"``{named.Name}´´ defined here ...");
         Errors.AtToken(ErrNo.Syntax002, already, $"... is already defined here");
         return(true);
     }
     return(false);
 }
Exemplo n.º 17
0
        public NamedList ReadNamedList(FastInputStream dis)
        {
            int       sz = ReadSize(dis);
            NamedList nl = new NamedList();

            for (int i = 0; i < sz; i++)
            {
                String name = (String)ReadVal(dis);
                Object val  = ReadVal(dis);
                nl.Add(name, val);
            }
            return(nl);
        }
Exemplo n.º 18
0
        public SolrDocument ReadSolrDocument(FastInputStream dis)
        {
            NamedList    nl  = (NamedList)ReadVal(dis);
            SolrDocument doc = new SolrDocument();

            for (int i = 0; i < nl.Count; i++)
            {
                String name = nl.GetName(i);
                Object val  = nl.GetVal(i);
                doc.SetField(name, val);
            }
            return(doc);
        }
Exemplo n.º 19
0
        public static IEnumerable <T> ParserResults <T>(this NamedList namedList, string fields, out long recordCount, string tableName = "") where T : class, new()
        {
            ObjectDeserializeT <T> objectDeserializeT = new ObjectDeserializeT <T>(tableName, fields);
            ISolrResponseParser <NamedList, QueryResults <T> > solrResponseParser = new BinaryQueryResultsParser <T>(objectDeserializeT);
            BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
            IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);

            objectDeserializeT.Highlight = highlight;
            QueryResults <T> queryResults = solrResponseParser.Parse(namedList);

            recordCount = queryResults.NumFound;
            return(queryResults);
        }
Exemplo n.º 20
0
        public void _Sequence_ReadWrite()
        {
            var list = new NamedList <object>();

            for (int i = 0; i < Round; i++)
            {
                list.Add(i.ToString(), i);
            }
            for (int i = 0; i < Round; i++)
            {
                Assert.True(i == (int)list[i.ToString()]);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// This should launch an open file dialog instead of the usual thing.
        /// </summary>
        /// <param name="context">ITypeDescriptorContext.</param>
        /// <param name="provider">IServiceProvider.</param>
        /// <param name="value">The object being displayed.</param>
        /// <returns>A new version of the object if the dialog was ok.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            _original = value as IPointScheme;
            _editCopy = _original.Copy();
            IWindowsFormsEditorService dialogProvider = (IWindowsFormsEditorService)provider?.GetService(typeof(IWindowsFormsEditorService));
            NamedList <IPointCategory> cats           = new NamedList <IPointCategory>(_editCopy.Categories, "Category");
            CollectionPropertyGrid     frm            = new CollectionPropertyGrid(cats);

            frm.ChangesApplied += FrmChangesApplied;
            frm.AddItemClicked += FrmAddItemClicked;
            dialogProvider?.ShowDialog(frm);
            return(_original); // don't bother swapping out the edit copy, just store copies of the categories when changes are applied.
        }
Exemplo n.º 22
0
        public Class(TokenSpan span, ClassKind kind, Identifier name, TypeParameterList?typeParameters, IType?provides, String?doc, MemberList items)
        {
            Span           = span;
            Kind           = kind;
            Name           = name;
            TypeParameters = typeParameters;
            Provides       = provides;
            Doc            = doc;
            Items          = items;

            Members = new NamedList <INamedMember>();
            Fields  = new NamedList <Field>();
            Methods = new NamedList <Method>();
        }
Exemplo n.º 23
0
        public virtual void Test()
        {
            NamedList original = new NamedList("foo");

            original.Add("bar");
            A().Provider().StoreNew(original);
            A().Provider().Commit();
            ReplicateAll(A().Provider(), B().Provider());
            NamedList replicated = (NamedList)B().Provider().GetStoredObjects(typeof(NamedList
                                                                                     )).GetEnumerator().Current;

            Assert.AreEqual(original.Name(), replicated.Name());
            CollectionAssert.AreEqual(original, replicated);
        }
Exemplo n.º 24
0
        private IEnumerable <GroupResultInfo <T> > QueryGroupResultsParseT(string fields, NamedList namedList, string highlightFields, out int matchesCount)
        {
            ObjectDeserializeT <T> objectDeserializeT = new ObjectDeserializeT <T>(this._TableName, fields);

            matchesCount = 0;
            ISolrResponseParser <NamedList, IList <GroupQueryResults <T> > > solrResponseParser = new BinaryGroupQueryResultsParser <T>(objectDeserializeT);

            if (!string.IsNullOrWhiteSpace(highlightFields))
            {
                BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
                IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);
                objectDeserializeT.Highlight = highlight;
            }
            List <GroupResultInfo <T> >        list  = new List <GroupResultInfo <T> >();
            IList <GroupQueryResults <T> >     list2 = solrResponseParser.Parse(namedList);
            IEnumerable <GroupResultInfo <T> > result;

            if (list2 == null || list2.Count == 0)
            {
                result = list;
            }
            else
            {
                NamedList namedList2 = (NamedList)namedList.Get("grouped");
                int       num        = 0;
                foreach (GroupQueryResults <T> current in list2)
                {
                    matchesCount = current.Matches;
                    NamedList namedList3 = (NamedList)namedList2.GetVal(num);
                    object    obj        = namedList3.Get("ngroups");
                    if (obj != null)
                    {
                        matchesCount = Convert.ToInt32(obj);
                    }
                    foreach (GroupQueryResult <T> current2 in current.Groups)
                    {
                        list.Add(new GroupResultInfo <T>
                        {
                            Data         = current2.QueryResults,
                            RecordCount  = current2.QueryResults.NumFound,
                            MatchesCount = current.Matches,
                            GroupValue   = current2.GroupValue
                        });
                    }
                    num++;
                }
                result = list;
            }
            return(result);
        }
Exemplo n.º 25
0
 protected SolrUriBuilder(SolrUriBuilder server, string core, string handler)
 {
     if (server == null)
     {
         throw new ArgumentNullException("server");
     }
     if (!server.IsBaseUrl)
     {
         throw new ArgumentException("server");
     }
     ServerAddress = server.ServerAddress;
     Core          = core;
     Handler       = handler;
     Query         = new NamedList <string>();
 }
        public IDictionary <string, IDictionary <string, IList <string> > > Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var highlightingNamedList = (NamedList)result.Get("highlighting");

            if (highlightingNamedList == null)
            {
                return(null);
            }

            var highlightingResult = new Dictionary <string, IDictionary <string, IList <string> > >(highlightingNamedList.Count);

            for (var i = 0; i < highlightingNamedList.Count; i++)
            {
                var itemName      = highlightingNamedList.GetName(i);
                var itemNamedList = (NamedList)highlightingNamedList.GetVal(i);

                if (!highlightingResult.ContainsKey(itemName))
                {
                    highlightingResult[itemName] = new Dictionary <string, IList <string> >(itemNamedList.Count);
                }

                for (var j = 0; j < itemNamedList.Count; j++)
                {
                    var hlItemName      = itemNamedList.GetName(j);
                    var hlItemArrayList = (ArrayList)itemNamedList.GetVal(j);

                    if (!highlightingResult[itemName].ContainsKey(hlItemName))
                    {
                        highlightingResult[itemName][hlItemName] = new List <string>();
                    }

                    if (hlItemArrayList != null)
                    {
                        foreach (object obj in hlItemArrayList)
                        {
                            highlightingResult[itemName][hlItemName].Add(obj.ToString());
                        }
                    }
                }
            }

            return(highlightingResult);
        }
Exemplo n.º 27
0
        public IDictionary <string, IList <FacetField> > Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var facetCountsNamedList = (NamedList)result.Get("facet_counts");

            if (facetCountsNamedList == null)
            {
                return(null);
            }

            var facetFieldsNamedList = (NamedList)facetCountsNamedList.Get("facet_fields");

            if (facetFieldsNamedList == null)
            {
                return(null);
            }

            var facetFieldsResult = new Dictionary <string, IList <FacetField> >(facetFieldsNamedList.Count);

            for (var i = 0; i < facetFieldsNamedList.Count; i++)
            {
                var fieldName = facetFieldsNamedList.GetName(i);

                if (!facetFieldsResult.ContainsKey(fieldName))
                {
                    facetFieldsResult.Add(fieldName, new List <FacetField>());
                }

                var fieldCountNamedList = (NamedList)facetFieldsNamedList.GetVal(i);

                if (fieldCountNamedList != null)
                {
                    for (var j = 0; j < fieldCountNamedList.Count; j++)
                    {
                        facetFieldsResult[fieldName].Add(new FacetField()
                        {
                            Name = fieldCountNamedList.GetName(j), Count = Convert.ToInt32(fieldCountNamedList.GetVal(j))
                        });
                    }
                }
            }

            return(facetFieldsResult);
        }
Exemplo n.º 28
0
        private IEnumerable <T> QueryResultsParseT(string fields, NamedList namedList, string highlightFields, out long recordCount)
        {
            ObjectDeserializeT <T> objectDeserializeT = new ObjectDeserializeT <T>(this._TableName, fields);
            ISolrResponseParser <NamedList, QueryResults <T> > solrResponseParser = new BinaryQueryResultsParser <T>(objectDeserializeT);

            if (!string.IsNullOrWhiteSpace(highlightFields))
            {
                BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
                IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);
                objectDeserializeT.Highlight = highlight;
            }
            QueryResults <T> queryResults = solrResponseParser.Parse(namedList);

            recordCount = queryResults.NumFound;
            return(queryResults);
        }
Exemplo n.º 29
0
        public FacetData(INamedList responseHeader)
        {
            if (responseHeader.IsNullOrEmpty())
            {
                return;
            }
            Queries = responseHeader.GetOrDefault <INamedList>("facet_queries");

            var fieldsList = responseHeader.GetOrDefault <INamedList>("facet_fields");

            if (fieldsList != null)
            {
                Fields = new NamedList();
                for (int i = 0; i < fieldsList.Count; i++)
                {
                    var innerList = fieldsList.GetOrDefault <IList>(i);
                    if (innerList == null)
                    {
                        continue;
                    }
                    var list = new NamedList();
                    for (int j = 0; j < innerList.Count; j = j + 2)
                    {
                        var valKey = innerList[j] as string;
                        if (valKey != null)
                        {
                            list.Add(valKey, innerList[j + 1]);
                        }
                    }

                    Fields.Add(fieldsList.GetKey(i), list);
                }
            }

            //Fields = responseHeader.GetOrDefault<INamedList>("facet_fields");
            Dates  = responseHeader.GetOrDefault <INamedList>("facet_dates");
            Ranges = responseHeader.GetOrDefault <INamedList>("facet_ranges");
        }
Exemplo n.º 30
0
        public void BasicTest()
        {
            var list = new NamedList <NamedElement>();

            var el = new NamedElement();

            list.Add(el);

            var el2 = new NamedElement();

            el2.Rename("asd");
            list.Add(el2);

            //Test

            //Get by indexer
            Assert.AreEqual(el, list[null], $"el:{el}, list[null]:{list[null]}");
            Assert.AreEqual(el2, list["asd"], $"el2:{el2}, list[\"asd\"]:{list["asd"]}");

            //Get by method
            Assert.AreEqual(el, list.GetElementByName(null), $"el:{el}, " +
                            $"list.GetElementByName(null){list.GetElementByName(null)}");

            Assert.AreEqual(el2, list.GetElementByName("asd"), $"el2:{el2}, " +
                            $"list.GetElementByName(\"asd\"){list.GetElementByName("asd")}");

            //Set
            var el3 = new NamedElement();

            el3.Rename("qwe");
            list[null] = el3;

            Assert.IsTrue(!list.Contains(el));
            Assert.AreEqual(el3, list["qwe"], $"el3:{el3}, list[\"qwe\"]:{list["qwe"]}");
            Assert.AreEqual(el2, list["asd"], $"el2:{el2}, list[\"asd\"]:{list["asd"]}");
        }
Exemplo n.º 31
0
        public static FacetResult <T> ParserFacetResults <T>(this NamedList namedList, string fields, out long recordCount, string tableName = "") where T : class, new()
        {
            ObjectDeserializeT <T> objectDeserializeT = new ObjectDeserializeT <T>(tableName, fields);
            ISolrResponseParser <NamedList, QueryResults <T> > solrResponseParser = new BinaryQueryResultsParser <T>(objectDeserializeT);
            BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
            IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);

            objectDeserializeT.Highlight = highlight;
            QueryResults <T>        queryResults                      = solrResponseParser.Parse(namedList);
            BinaryFacetFieldsParser binaryFacetFieldsParser           = new BinaryFacetFieldsParser();
            IDictionary <string, IList <FacetField> >     dictionary  = binaryFacetFieldsParser.Parse(namedList);
            IDictionary <string, IList <FacetFieldInfo> > dictionary2 = new Dictionary <string, IList <FacetFieldInfo> >();

            if (dictionary != null && dictionary.Count > 0)
            {
                foreach (KeyValuePair <string, IList <FacetField> > current in dictionary)
                {
                    List <FacetFieldInfo> list = new List <FacetFieldInfo>();
                    foreach (FacetField current2 in current.Value)
                    {
                        list.Add(new FacetFieldInfo
                        {
                            Name  = current2.Name,
                            Count = current2.Count
                        });
                    }
                    dictionary2.Add(current.Key, list);
                }
            }
            FacetResult <T> facetResult = new FacetResult <T>();

            facetResult.Data  = queryResults;
            facetResult.Facet = dictionary2;
            recordCount       = queryResults.NumFound;
            return(facetResult);
        }
Exemplo n.º 32
0
 public void RemoveScript(string script)
 {
     if (_scripts == null) _scripts = FindNamedList("scripts");
     if (_scripts != null) _scripts.RemoveStringsListItem(script);
 }
Exemplo n.º 33
0
 public SqlReaderAdapter()
 {
     _workSheetsOnExam  = new NamedList <IScanNode>();
     _fetalBPSInfoNodes = new NamedList <int, IFetalBPSInfoNode>();
 }
Exemplo n.º 34
0
        protected INamedList ReadNamedList(JsonReader reader)
        {
            if (reader.TokenType != JsonToken.StartObject)
                throw new ArgumentException("requires StartObject token", "reader");
            var list = new NamedList();
            string propertyName = null;
            while (reader.Read())
            {
                switch (reader.TokenType)
                {
                    case JsonToken.Date:
                        if (propertyName == null)
                            throw new InvalidOperationException("propertyName is null...");
                        list.Add(propertyName, ((DateTime)reader.Value).ToLocalTime());
                        propertyName = null;
                        break;

                    case JsonToken.Null:
                    case JsonToken.Boolean:
                    case JsonToken.Bytes:
                    case JsonToken.Float:
                    case JsonToken.Integer:
                    case JsonToken.String:
                        if (propertyName == null)
                            throw new InvalidOperationException("propertyName is null...");

                        list.Add(propertyName, reader.Value);
                        propertyName = null;
                        break;

                    case JsonToken.PropertyName:
                        if (propertyName != null)
                            throw new InvalidOperationException("this shouldn't happen ^^");
                        propertyName = reader.Value as string;
                        break;

                    case JsonToken.StartArray:
                        if (propertyName == null)
                            throw new InvalidOperationException("propertyName is null...");
                        list.Add(propertyName, ReadArray(reader));
                        propertyName = null;
                        break;

                    case JsonToken.StartObject:
                        if (propertyName == null)
                            throw new InvalidOperationException("propertyName is null...");
                        object value;
                        //Workaround because JSON doesn't know the exact type, so it would treat everything as NamedList, which differs from other formats
                        switch (propertyName)
                        {
                            //used for GET Requests
                            case "doc":
                                value = new SolrDocument(ReadNamedList(reader));
                                break;
                            //used for Logging Requests
                            case "history":
                            //used for Select Requests
                            case "response":
                                value = ReadSolrDocumentList(reader);
                                break;
                            default:
                                value = ReadNamedList(reader);
                                break;
                        }
                        list.Add(propertyName,value);
                        propertyName = null;
                        break;

                    case JsonToken.EndArray:
                    case JsonToken.EndObject:
                        if (propertyName != null)
                            throw new InvalidOperationException("this shouldn't happen ^^, again...");
                        return list;

                    case JsonToken.None:
                    case JsonToken.Comment:
                    case JsonToken.Raw:
                    case JsonToken.Undefined:
                        continue;
                    case JsonToken.StartConstructor:
                    case JsonToken.EndConstructor:
                    default:
                        throw new NotSupportedException("Json Constructor not supported!");
                }
            }
            throw new InvalidOperationException("Some shit hit the fan! - eh i mean, this won't happen, i hope :P");
        }
Exemplo n.º 35
0
 public void AddScanPath(string path)
 {
     if (_scanpaths == null) _scanpaths = FindNamedList("scan_paths");
     if (_scanpaths == null)
     {
         _scanpaths = new NamedList("scan_paths", new ListToken());
         Document.Tokens.Add(new WhitespaceToken("\n\n"));
         Document.Tokens.Add(new AddedComment());
         Document.Tokens.Add(_scanpaths);
         Document.Tokens.Add(new TermEndToken());
     }
     _scanpaths.AddStringsListItem(path);
 }
Exemplo n.º 36
0
 public void Initialize()
 {
     _hiddenPatterns = _manager.Content.Load<NamedList<TileMatchPattern>>("Content/Data/hiddenmatchpatterns");
     _hiddenMatcher = new TileMatchPatternMatcher(_hiddenPatterns);
 }
Exemplo n.º 37
0
 public NamedList ReadNamedList(FastInputStream dis)
 {
     int sz = ReadSize(dis);
     NamedList nl = new NamedList();
     for (int i = 0; i < sz; i++)
     {
         String name = (String)ReadVal(dis);
         Object val = ReadVal(dis);
         nl.Add(name, val);
     }
     return nl;
 }
Exemplo n.º 38
0
 public SimpleQueryBuilder(string query)
 {
     QueryParameters = new NamedList<string>();
     QueryParameters.Add("q",query);
 }
 public TileMatchPatternMatcher(NamedList<TileMatchPattern> pattern)
 {
     _pattern = pattern;
 }
Exemplo n.º 40
0
 public List<string> ListModulesBlacklist()
 {
     List<string> result = null;
     if (_blacklist == null) _blacklist = FindNamedList("modules_blacklist");
     if (_blacklist != null) result = _blacklist.GetStringsList();
     return result;
 }
Exemplo n.º 41
0
 public List<string> ListScanPaths()
 {
     List<string> result = null;
     if (_scanpaths == null) _scanpaths = FindNamedList("scan_paths");
     if (_scanpaths != null) result = _scanpaths.GetStringsList();
     if (result == null) result = new List<string>();
     return result;
 }
Exemplo n.º 42
0
 public List<string> ListScripts()
 {
     List<string> result = null;
     if (_scripts == null) _scripts = FindNamedList("scripts");
     if (_scripts != null) result = _scripts.GetStringsList();
     return result;
 }
Exemplo n.º 43
0
 public void RemoveScanPath(string path)
 {
     if (_scanpaths == null) _scanpaths = FindNamedList("scan_paths");
     if (_scanpaths != null) _scanpaths.RemoveStringsListItem(path);
 }
Exemplo n.º 44
0
        static void Main(string[] args)
        {
            LongOpt[] opts = new[] {
                new LongOpt("help", Argument.No, null, 'h'),
                new LongOpt("padding", Argument.Required, null, 'p'),
                new LongOpt("startpal", Argument.Required, null, 's'),
                new LongOpt("nullfirst", Argument.No, null, 'n'),
                new LongOpt("twoplayer", Argument.No, null, '2'),
                new LongOpt("format", Argument.Required, null, 'f'),
                new LongOpt("game", Argument.Required, null, 'g'),
                new LongOpt("artcmp", Argument.Required, null, 'c'),
                new LongOpt("lowplane", Argument.Required, null, 0),
                new LongOpt("highplane", Argument.Required, null, 0),
                new LongOpt("palette", Argument.Required, null, 0),
                new LongOpt("center", Argument.Required, null, 0),
                new LongOpt("artfile", Argument.Required, null, 0),
                new LongOpt("mapfile", Argument.Required, null, 0),
                new LongOpt("dplcfile", Argument.Required, null, 0),
                new LongOpt("palfile", Argument.Required, null, 0)
            };
            if (args.Length == 0)
            {
                args = new string[] { "-h" }
            }
            ;
            Getopt          getopt        = new Getopt("SpritePlotter.NET", args, Getopt.digest(opts), opts);
            int             padding       = 2;
            byte            startpal      = 0;
            bool            nullfirst     = false;
            bool            twoplayer     = false;
            MappingsFormat  mapfmt        = MappingsFormat.Binary;
            EngineVersion   mapgame       = EngineVersion.Invalid;
            bool            s3kp          = false;
            CompressionType artcmp        = CompressionType.Uncompressed;
            Bitmap          lowplanefile  = null;
            Bitmap          highplanefile = null;

            Color[] palette    = null;
            Bitmap  centerfile = null;
            string  artfile    = null;
            string  mapfile    = null;
            string  dplcfile   = null;
            string  palfile    = null;
            int     opt        = getopt.getopt();

            while (opt != -1)
            {
                switch (opt)
                {
                case 'h':
                    Console.Write(Properties.Resources.HelpText);
                    return;

                case 'p':
                    padding = int.Parse(getopt.Optarg);
                    break;

                case 's':
                    startpal = byte.Parse(getopt.Optarg);
                    break;

                case 'n':
                    nullfirst = true;
                    break;

                case '2':
                    twoplayer = true;
                    break;

                case 'f':
                    mapfmt = (MappingsFormat)Enum.Parse(typeof(MappingsFormat), getopt.Optarg, true);
                    break;

                case 'g':
                    if (getopt.Optarg.Equals("s3kp", StringComparison.OrdinalIgnoreCase))
                    {
                        mapgame = EngineVersion.S3K;
                        s3kp    = true;
                    }
                    else
                    {
                        mapgame = (EngineVersion)Enum.Parse(typeof(EngineVersion), getopt.Optarg, true);
                    }
                    break;

                case 'c':
                    artcmp = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 0:
                    switch (opts[getopt.Longind].Name)
                    {
                    case "lowplane":
                        lowplanefile = new Bitmap(getopt.Optarg);
                        if (palette == null && (lowplanefile.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
                        {
                            palette = lowplanefile.Palette.Entries;
                        }
                        break;

                    case "highplane":
                        highplanefile = new Bitmap(getopt.Optarg);
                        if (palette == null && (highplanefile.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
                        {
                            palette = highplanefile.Palette.Entries;
                        }
                        break;

                    case "palette":
                        switch (System.IO.Path.GetExtension(getopt.Optarg))
                        {
                        case ".bin":
                            palette = SonLVLColor.Load(getopt.Optarg, EngineVersion.S2).Select(a => a.RGBColor).ToArray();
                            break;

                        case ".bmp":
                        case ".png":
                        case ".jpg":
                        case ".gif":
                            using (Bitmap bmp = new Bitmap(getopt.Optarg))
                            {
                                if ((bmp.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
                                {
                                    palette = bmp.Palette.Entries;
                                }
                                else
                                {
                                    List <Color> pal = new List <Color>();
                                    for (int y = 0; y < bmp.Height; y += 8)
                                    {
                                        for (int x = 0; x < bmp.Width; x += 8)
                                        {
                                            pal.Add(bmp.GetPixel(x, y));
                                        }
                                    }
                                    palette = pal.ToArray();
                                }
                            }
                            break;
                        }
                        break;

                    case "center":
                        centerfile = new Bitmap(getopt.Optarg);
                        break;

                    case "artfile":
                        artfile = getopt.Optarg;
                        break;

                    case "mapfile":
                        mapfile = getopt.Optarg;
                        break;

                    case "dplcfile":
                        dplcfile = getopt.Optarg;
                        break;

                    case "palfile":
                        palfile = getopt.Optarg;
                        break;
                    }
                    break;
                }
                opt = getopt.getopt();
            }
            if (mapgame == EngineVersion.Invalid)
            {
                Console.Error.WriteLine("No game specified.");
                return;
            }
            if (lowplanefile == null && highplanefile == null)
            {
                Console.Error.WriteLine("No image file specified.");
                return;
            }
            if (palette == null)
            {
                Console.Error.WriteLine("No palette specified, and image(s) did not contain palette.");
                return;
            }
            if (artfile == null)
            {
                Console.Error.WriteLine("No output art file specified.");
                return;
            }
            if (mapfile == null)
            {
                Console.Error.WriteLine("No output mappings file specified.");
                return;
            }
            if (palette.Length > 64)
            {
                palette = palette.Take(64).ToArray();                 // lazy
            }
            BitmapBits lowplane = null, highplane = null, combinedplanes = null;

            if (lowplanefile != null)
            {
                if ((lowplanefile.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
                {
                    lowplane = new BitmapBits(lowplanefile);
                }
                else
                {
                    using (Bitmap bmp = lowplanefile.To32bpp())
                        lowplane = LoadBitmap32BppArgb(bmp, palette);
                }
                lowplanefile.Dispose();
                if (highplanefile == null)
                {
                    combinedplanes = lowplane;
                }
            }
            if (highplanefile != null)
            {
                if ((highplanefile.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
                {
                    highplane = new BitmapBits(highplanefile);
                }
                else
                {
                    using (Bitmap bmp = highplanefile.To32bpp())
                        highplane = LoadBitmap32BppArgb(bmp, palette);
                }
                highplanefile.Dispose();
                if (lowplanefile == null)
                {
                    combinedplanes = highplane;
                }
            }
            if (combinedplanes == null)
            {
                combinedplanes = new BitmapBits(Math.Max(lowplane.Width, highplane.Width), Math.Max(lowplane.Height, highplane.Height));
                combinedplanes.DrawBitmap(lowplane, 0, 0);
                combinedplanes.DrawBitmapComposited(highplane, 0, 0);
            }
            List <Point> centers = null;

            if (centerfile != null)
            {
                centers = new List <Point>();
                BitmapBits cntr;
                if ((centerfile.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
                {
                    cntr = new BitmapBits(centerfile);
                }
                else
                {
                    using (Bitmap bmp = centerfile.To32bpp())
                        cntr = LoadBitmap32BppArgb(bmp, Color.Black, Color.White);
                }
                centerfile.Dispose();
                for (int y = 0; y < cntr.Height; y++)
                {
                    for (int x = 0; x < cntr.Width; x++)
                    {
                        if (cntr[x, y] != 0)
                        {
                            centers.Add(new Point(x, y));
                        }
                    }
                }
            }
            List <Rectangle> sprites = new List <Rectangle>();

            for (int y = 0; y < combinedplanes.Height; y++)
            {
                for (int x = 0; x < combinedplanes.Width; x++)
                {
                    if (combinedplanes[x, y] % 16 != 0)
                    {
                        Rectangle newrect = new Rectangle(x - padding, y - padding, (padding * 2) + 1, (padding * 2) + 1);
                        for (int i = 0; i < sprites.Count; i++)
                        {
                            if (newrect.IntersectsWith(sprites[i]))
                            {
                                newrect = Rectangle.Union(newrect, sprites[i]);
                                sprites.RemoveAt(i);
                                i = -1;
                            }
                        }
                        sprites.Add(newrect);
                    }
                }
            }
            List <Rectangle> rows = new List <Rectangle>();

            for (int i = 0; i < sprites.Count; i++)
            {
                Rectangle rect = sprites[i];
                rect.Inflate(-padding, -padding);
                sprites[i] = rect;
                if (rows.Count > 0 && sprites[i].IntersectsWith(rows[rows.Count - 1]))
                {
                    rows[rows.Count - 1] = Rectangle.Union(sprites[i], rows[rows.Count - 1]);
                }
                else
                {
                    rows.Add(new Rectangle(0, sprites[i].Y, combinedplanes.Width, sprites[i].Height));
                }
            }
            List <Rectangle> newsprites = new List <Rectangle>(sprites.Count);

            foreach (Rectangle rect in rows)
            {
                newsprites.AddRange(sprites.Where(a => a.IntersectsWith(rect)).OrderBy(a => a.X));
            }
            sprites = newsprites;
            List <byte[]>             tiles = new List <byte[]>();
            NamedList <MappingsFrame> map   = new NamedList <MappingsFrame>("Map_" + Path.GetFileNameWithoutExtension(mapfile), sprites.Count);
            NamedList <DPLCFrame>     dplc  = null;

            if (dplcfile != null)
            {
                dplc = new NamedList <DPLCFrame>("DPLC_" + Path.GetFileNameWithoutExtension(dplcfile), sprites.Count);
            }
            if (nullfirst)
            {
                map.Add(new MappingsFrame(map.Name + "_Null"));
                if (dplc != null)
                {
                    dplc.Add(new DPLCFrame(dplc.Name + "_Null"));
                }
            }
            for (int i = 0; i < sprites.Count; i++)
            {
                Point center = new Point(sprites[i].Width / 2, sprites[i].Height / 2);
                if (centers != null)
                {
                    foreach (Point item in centers)
                    {
                        if (sprites[i].Contains(item))
                        {
                            center = new Point(item.X - sprites[i].Left, item.Y - sprites[i].Top);
                            break;
                        }
                    }
                }
                MappingsFrame mapframe = new MappingsFrame(map.Name + "_" + i);
                map.Add(mapframe);
                DPLCFrame dplcframe = null;
                if (dplc != null)
                {
                    dplcframe = new DPLCFrame(dplc.Name + "_" + i);
                    dplc.Add(dplcframe);
                }
                if (lowplane != null)
                {
                    SpriteToMap(sprites[i], center, lowplane, tiles, mapframe, dplcframe, startpal, false, twoplayer);
                }
                if (highplane != null)
                {
                    SpriteToMap(sprites[i], center, highplane, tiles, mapframe, dplcframe, startpal, true, twoplayer);
                }
            }
            using (MemoryStream ms = new MemoryStream(tiles.Count * 32))
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                    foreach (byte[] b in tiles)
                    {
                        bw.Write(b);
                    }
                Compression.Compress(ms.ToArray(), artfile, artcmp);
            }
            if (mapfmt == MappingsFormat.Binary)
            {
                File.WriteAllBytes(mapfile, MappingsFrame.GetBytes(map, mapgame));
                if (dplc != null)
                {
                    File.WriteAllBytes(dplcfile, DPLCFrame.GetBytes(dplc, s3kp ? EngineVersion.S2 : mapgame));
                }
            }
            else
            {
                MappingsFrame.ToASM(mapfile, map, mapgame, mapfmt == MappingsFormat.Macro);
                if (dplc != null)
                {
                    DPLCFrame.ToASM(dplcfile, dplc, mapgame, mapfmt == MappingsFormat.Macro, s3kp);
                }
            }
            if (palfile != null)
            {
                using (FileStream fs = File.Create(palfile))
                    using (BinaryWriter bw = new BinaryWriter(fs))
                        foreach (Color c in palette)
                        {
                            bw.Write(ByteConverter.GetBytes(new SonLVLColor(c).MDColor));
                        }
            }
        }
Exemplo n.º 45
0
 public void UnblockModule(string module)
 {
     if (_blacklist == null) _blacklist = FindNamedList("modules_blacklist");
     if (_blacklist != null) _blacklist.RemoveStringsListItem(module);
 }
Exemplo n.º 46
0
 public void AddScript(string script)
 {
     if (_scripts == null) _scripts = FindNamedList("scripts");
     if (_scripts == null)
     {
         _scripts = new NamedList("scripts", new ListToken());
         Document.Tokens.Add(new WhitespaceToken("\n\n"));
         Document.Tokens.Add(new AddedComment());
         Document.Tokens.Add(_scripts);
         Document.Tokens.Add(new TermEndToken());
     }
     _scripts.AddStringsListItem(script);
 }
Exemplo n.º 47
0
        NamedList CreateWebConfigItem()
        {
            /*
            {web,[
                {port, 60210},
                {max, 100},
                {ip, "0.0.0.0"},
                {docroot, "priv/www"}
            ]}.
            */

            Document.Tokens.Add(new WhitespaceToken("\n\n"));
            Document.Tokens.Add(new AddedComment());
            ListToken list = new ListToken();

            // Port
            list.Tokens.Add(new WhitespaceToken("\n    "));
            list.Tokens.Add(new NamedInteger("port", 60210));
            list.Tokens.Add(new CommaToken());

            // Max
            list.Tokens.Add(new WhitespaceToken("\n    "));
            list.Tokens.Add(new NamedInteger("max", 100));
            list.Tokens.Add(new CommaToken());

            // IP
            list.Tokens.Add(new WhitespaceToken("\n    "));
            list.Tokens.Add(new NamedString("ip", "0.0.0.0"));
            list.Tokens.Add(new CommaToken());

            // DocRoot
            list.Tokens.Add(new WhitespaceToken("\n    "));
            list.Tokens.Add(new NamedString("docroot", "priv/www"));
            list.Tokens.Add(new WhitespaceToken("\n"));

            NamedList result = new NamedList("web", list);
            Document.Tokens.Add(result);
            Document.Tokens.Add(new TermEndToken());
            return result;
        }
Exemplo n.º 48
0
 public void WriteNamedList(NamedList nl)
 {
     WriteTag(nl is SimpleOrderedMap ? ORDERED_MAP : NAMED_LST, nl.Count);
     for (int i = 0; i < nl.Count; i++)
     {
         String name = nl.GetName(i);
         WriteExternString(name);
         Object val = nl.GetVal(i);
         WriteVal(val);
     }
 }
Exemplo n.º 49
0
 public void BlockModule(string module)
 {
     if (_blacklist == null) _blacklist = FindNamedList("modules_blacklist");
     if (_blacklist == null)
     {
         _blacklist = new NamedList("modules_blacklist", new ListToken());
         Document.Tokens.Add(new WhitespaceToken("\n\n"));
         Document.Tokens.Add(new AddedComment());
         Document.Tokens.Add(_blacklist);
         Document.Tokens.Add(new TermEndToken());
     }
     _blacklist.AddStringsListItem(module);
 }