Example #1
0
		protected new void AddTermFrequencies(System.IO.TextReader r, System.Collections.IDictionary termFreqMap, System.String fieldName)
		{
			var analyzer = Analyzers[fieldName];
			TokenStream ts = analyzer.TokenStream(fieldName, r);
			TermAttribute termAtt = (TermAttribute)ts.AddAttribute(typeof(TermAttribute));
			int tokenCount = 0;
			while (ts.IncrementToken())
			{
				// for every token
				System.String word = termAtt.Term();
				tokenCount++;
				if (tokenCount > GetMaxNumTokensParsed())
				{
					break;
				}
				if (IsNoiseWord(word))
				{
					continue;
				}

				// increment frequency
				var cnt = (Int)termFreqMap[word];
				if (cnt == null)
				{
					termFreqMap[word] = new Int();
				}
				else
				{
					cnt.x++;
				}
			}
		}
 private void BuildSubTree(Int.AC.ReadModel.Menus.Menu model, int level)
 {
     var tempList = menuList.Where(s => s.ParentId == model.Id).OrderBy(m => m.Sort).ToList();
     level++;
     foreach (var a in tempList)
     {
         a.TreeLevel = level;
         treeList.Add(a);
         BuildSubTree(a, level);
     }
 }
Example #3
0
        private static void ReferenceTypeExample()
        {
            Int i = new Int(100);
            Int j = i; // reference type so reference copied into i
            Console.WriteLine(i); // 100
            Console.WriteLine(j); // 100

            i.SetValue(30);
            Console.WriteLine(i); // 30
            Console.WriteLine(j); // 30 <- the shocking difference
        }
Example #4
0
 // Parses an age from an int and tries to make an age from the given int.
 static Option <Age> ParseAge(string s) =>
 Int.Parse(s).Bind(Age.Of);
Example #5
0
	extern private static Int gnutls_credentials_set
			(IntPtr session, Int type, IntPtr cred);
Example #6
0
File: RdWr.cs Project: pszmyd/SHS
 public static void Write(Int val, Wr wr)
 {
     wr.WriteInt32(val);
 }
Example #7
0
        public DataValue ToDataValue()
        {
            DataValue result = null;

            switch (this._Type)
            {
            case Types.Ind:
                result = new Ind(this._Name, (string)this._InitialValue);
                break;

            case Types.Character:
                result = new Character(this._Name, this._Length, (string)this._InitialValue);
                break;

            case Types.Int8:
            case Types.Int16:
            case Types.Int32:
            case Types.Int64:
                result = new Int(this._Name, this._Type, Convert.ToInt32(this._InitialValue));
                break;

            case Types.Structure:
                result = new Structure(this._Name, this._Qualified);
                break;

            case Types.FixedDecimal:     //Packed / Zoned
                result = new FixedDecimal(this._Name, this._Type, this._Precision, Convert.ToDouble(this._InitialValue));
                break;

            case Types.Float:
            case Types.Double:
                result = new Float(this._Name, this._Type, Convert.ToDouble(this._InitialValue));
                break;

            case Types.Timestamp:
                result = new Timestamp(this._Name, Convert.ToInt32(this._InitialValue));
                break;

            case Types.File:
                if (this._WorkStation)
                {
                    result = new Typing.Files.Display(this._Name, this._File, this._UserOpen);
                }
                else
                {
                    result = new Typing.Files.Table(this._Name, this._File, this._UserOpen);
                }
                break;

            default:
                Error.ThrowRuntimeError("DataSet.ToDataValue", this._Type.ToString() + " is not a ready data type.");
                break;
            }

            if (this._DataArea != null)
            {
                result.SetDataAreaName(this._DataArea);
            }
            if (IsArray())
            {
                result.SetArray(this._Dimentions);
            }
            if (this._Type == Types.Structure && _Subfields != null)
            {
                result.SetSubfields(_Subfields.ToArray()); //Must be run after array size has been set
            }
            return(result);
        }
 private ICell Cell(Int index) => _cellBoard.At(index);
 public int Visit(Int node)
 {
     return(Int32.Parse(node.AnchorToken.Lexeme));
 }
        // Then change the first one of the functions to return an `Either`.

        static Either <string, int> ParseIntVerbose(this string s)
        => Int.Parse(s).ToEither(() => $"'{s}' is not a valid representation of an int");
Example #11
0
	extern public static void jpeg_CreateDecompress
			(ref jpeg_decompress_struct cinfo, Int version, size_t structsize);
Example #12
0
	extern private static IntPtr BIO_new_socket(Int sock, Int close_flag);
Example #13
0
	extern private static Int SSL_write(IntPtr ssl, byte[] buf, Int num);
Example #14
0
	extern private static Int SSL_read(IntPtr ssl, byte[] buf, Int num);
Example #15
0
	extern private static Int SSL_CTX_use_RSAPrivateKey_ASN1
			(IntPtr ctx, byte[] d, Int len);
Example #16
0
	extern private static Int SSL_CTX_use_certificate_ASN1
			(IntPtr ctx, byte[] d, Int len);
Example #17
0
	extern private static Int gnutls_certificate_set_x509_key_mem
			(IntPtr cred, ref gnutls_datum cert,
			 ref gnutls_datum key, Int type);
Example #18
0
 public IntInterval LeftCut(Int inclusiveLimit)
 {
     return(new IntInterval(First, inclusiveLimit));
 }
Example #19
0
 public IntInterval(Int first, Int last)
 {
     First = first;
     Last  = last;
 }
Example #20
0
	extern public static void jpeg_set_quality
				(ref jpeg_compress_struct cinfo, Int quality,
				 Int force_baseline);
Example #21
0
 public void Int_InapropriateData_DoesNotDecode(string input)
 {
     Assert.Equal("Expected an integer value", Int.DecodeString(input).Match(x => "", x => x.Errors.First().Message));
 }
Example #22
0
	extern public static void jpeg_set_linear_quality
				(ref jpeg_compress_struct cinfo, Int scale_factor,
				 Int force_baseline);
Example #23
0
        public void DllFind()
        {
            var list = new DlList<Int>();
            list.AddLast(new Int(1));
            list.AddLast(new Int(2));
            list.AddLast(new Int(3));
            list.AddLast(new Int(4));

            var four = new Int(4);
            var five = new Int(5);

            Assert.AreEqual(four.Value, list.Find(four).Data.Value);
            Assert.IsFalse(list.Find(five).Data.Value.Equals(five.Value));
        }
Example #24
0
	extern public static void jpeg_add_quant_table
				(ref jpeg_compress_struct cinfo, Int which_tbl,
				 void *basic_table, Int scale_factor, Int force_baseline);
Example #25
0
 public static Int Read(Int val, Rd rd)
 {
     return(rd.ReadInt32());
 }
Example #26
0
	extern public static Int jpeg_quality_scaling(Int quality);
Example #27
0
	extern private static Int gnutls_record_recv
			(IntPtr session, byte[] data, Int size);
Example #28
0
	extern public static void jpeg_suppress_tables
				(ref jpeg_compress_struct cinfo, Int suppress);
Example #29
0
        /// <summary> Adds term frequencies found by tokenizing text from reader into the Map words</summary>
        /// <param name="r">a source of text to be tokenized
        /// </param>
        /// <param name="termFreqMap">a Map of terms and their frequencies
        /// </param>
        /// <param name="fieldName">Used by analyzer for any special per-field analysis
        /// </param>
        private void  AddTermFrequencies(System.IO.StreamReader r, System.Collections.IDictionary termFreqMap, System.String fieldName)
        {
            TokenStream ts = analyzer.TokenStream(fieldName, r);
            Lucene.Net.Analysis.Token token;
            int tokenCount = 0;
            while ((token = ts.Next()) != null)
            {
                // for every token
                System.String word = token.TermText();
                tokenCount++;
                if (tokenCount > maxNumTokensParsed)
                {
                    break;
                }
                if (IsNoiseWord(word))
                {
                    continue;
                }
				
                // increment frequency
                Int cnt = (Int) termFreqMap[word];
                if (cnt == null)
                {
                    termFreqMap[word] = new Int();
                }
                else
                {
                    cnt.x++;
                }
            }
        }
Example #30
0
	extern public static void jpeg_start_compress
				(ref jpeg_compress_struct cinfo, Int write_all_tables);
Example #31
0
        private void SendPackage(IModbusMaster modbus, Device dv, DataBlock db)
        {
            try
            {
                SendDone.WaitOne(-1);

                switch (db.DataType)
                {
                case "Bit":
                    byte[] bitArys = null;
                    switch (db.TypeOfRead)
                    {
                    case "ReadCoilStatus":
                        bitArys = modbus.ReadCoilStatus((byte)dv.SlaveId, $"{db.StartAddress}",
                                                        db.Length);
                        break;

                    case "ReadInputStatus":
                        bitArys = modbus.ReadInputStatus((byte)dv.SlaveId, $"{db.StartAddress}",
                                                         db.Length);
                        break;

                    default:
                        break;
                    }
                    var BitRs = Bit.ToArray(bitArys);
                    if (bitArys.Length > db.Tags.Count)
                    {
                        return;
                    }
                    for (var j = 0; j < db.Tags.Count; j++)
                    {
                        db.Tags[j].Value        = BitRs[j];
                        db.Tags[j].Checked      = BitRs[j];
                        db.Tags[j].Enabled      = BitRs[j];
                        db.Tags[j].Visible      = BitRs[j];
                        db.Tags[j].ValueSelect1 = BitRs[j];
                        db.Tags[j].ValueSelect2 = BitRs[j];
                        db.Tags[j].Timestamp    = DateTime.Now;
                    }
                    break;

                case "Int":
                    var IntArys = modbus.ReadHoldingRegisters((byte)dv.SlaveId,
                                                              $"{db.StartAddress}", db.Length);
                    var IntRs = Int.ToArray(IntArys);
                    if (IntRs.Length > db.Tags.Count)
                    {
                        return;
                    }
                    for (var j = 0; j < IntRs.Length; j++)
                    {
                        db.Tags[j].Value     = IntRs[j];
                        db.Tags[j].Timestamp = DateTime.Now;
                    }
                    break;

                case "DInt":
                    var DIntArys = modbus.ReadHoldingRegisters((byte)dv.SlaveId,
                                                               $"{db.StartAddress}", db.Length);
                    var DIntRs = Int.ToArray(DIntArys);
                    if (DIntRs.Length > db.Tags.Count)
                    {
                        return;
                    }
                    for (var j = 0; j < DIntRs.Length; j++)
                    {
                        db.Tags[j].Value     = DIntRs[j];
                        db.Tags[j].Timestamp = DateTime.Now;
                    }
                    break;

                case "Word":
                    byte[] wdArys = null;
                    switch (db.TypeOfRead)
                    {
                    case "ReadHoldingRegisters":
                        wdArys = modbus.ReadHoldingRegisters((byte)dv.SlaveId, $"{db.StartAddress}", db.Length);

                        break;

                    case "ReadInputRegisters":
                        wdArys = modbus.ReadInputRegisters((byte)dv.SlaveId, $"{db.StartAddress}", db.Length);

                        break;

                    default:
                        break;
                    }
                    var wdRs = Word.ToArray(wdArys);
                    if (wdRs.Length > db.Tags.Count)
                    {
                        return;
                    }

                    for (var j = 0; j < wdRs.Length; j++)
                    {
                        db.Tags[j].Value     = wdRs[j];
                        db.Tags[j].Timestamp = DateTime.Now;
                    }
                    break;

                case "DWord":
                    var dwArys = modbus.ReadHoldingRegisters((byte)dv.SlaveId,
                                                             $"{db.StartAddress}", db.Length);
                    var dwRs = DWord.ToArray(dwArys);
                    for (var j = 0; j < dwRs.Length; j++)
                    {
                        db.Tags[j].Value     = dwRs[j];
                        db.Tags[j].Timestamp = DateTime.Now;
                    }
                    break;

                case "Real":
                    var rl1Arys = modbus.ReadHoldingRegisters((byte)dv.SlaveId,
                                                              $"{db.StartAddress}", db.Length);
                    var rl1Rs = Real.ToArray(rl1Arys);
                    for (var j = 0; j < rl1Rs.Length; j++)
                    {
                        db.Tags[j].Value     = rl1Rs[j];
                        db.Tags[j].Timestamp = DateTime.Now;
                    }

                    break;
                }
            }
            catch (Exception ex)
            {
                IsConnected = false;
                EventscadaException?.Invoke(this.GetType().Name + "   XModbus.SendPackage", ex.Message);
            }
        }
Example #32
0
	extern public static Int jpeg_read_header
				(ref jpeg_decompress_struct cinfo, Int require_image);
Example #33
0
 public bool Contains(Int actual)
 {
     return(actual >= First && actual <= Last);
 }
Example #34
0
	extern public static Int jpeg_resync_to_restart
				(ref jpeg_decompress_struct cinfo, Int desired);
Example #35
0
 public IntInterval RigthCut(Int inclusiveLimit)
 {
     return(new IntInterval(inclusiveLimit, Last));
 }
Example #36
0
 public FizzBuzz(Int current) : this(current, new StrategyResponseAction())
 {
 }
 public override string SocialUPP()
 {
     return(string.Format("{0}{1}{2}", Int.ToString(), Instinct.ToString(), Pack.ToString()));
 }
Example #38
0
 public FizzBuzz(Int current, IResponseAction responseAction)
 {
     _current        = current;
     _responseAction = responseAction;
 }
Example #39
0
 public static Class <MyClass> CreateClassTestFunction(Int n)
 {
     return(new MyClass {
         boxed = n
     });
 }
Example #40
0
 public override string ToString()
 {
     return("[" + Type + "]" + Int.ToString());
 }
Example #41
0
 public void Visit(Int n)
 {
     throw new NotImplementedException();
 }
Example #42
0
        /// <summary>
        /// Given a S7 variable type (Bool, Word, DWord, etc.), it converts the bytes in the appropriate C# format.
        /// </summary>
        /// <param name="varType"></param>
        /// <param name="bytes"></param>
        /// <param name="varCount"></param>
        /// <param name="bitAdr"></param>
        /// <returns></returns>
        private object?ParseBytes(VarType varType, byte[] bytes, int varCount, byte bitAdr = 0)
        {
            if (bytes == null || bytes.Length == 0)
            {
                return(null);
            }

            switch (varType)
            {
            case VarType.Byte:
                if (varCount == 1)
                {
                    return(bytes[0]);
                }
                else
                {
                    return(bytes);
                }

            case VarType.Word:
                if (varCount == 1)
                {
                    return(Word.FromByteArray(bytes));
                }
                else
                {
                    return(Word.ToArray(bytes));
                }

            case VarType.Int:
                if (varCount == 1)
                {
                    return(Int.FromByteArray(bytes));
                }
                else
                {
                    return(Int.ToArray(bytes));
                }

            case VarType.DWord:
                if (varCount == 1)
                {
                    return(DWord.FromByteArray(bytes));
                }
                else
                {
                    return(DWord.ToArray(bytes));
                }

            case VarType.DInt:
                if (varCount == 1)
                {
                    return(DInt.FromByteArray(bytes));
                }
                else
                {
                    return(DInt.ToArray(bytes));
                }

            case VarType.Real:
                if (varCount == 1)
                {
                    return(Real.FromByteArray(bytes));
                }
                else
                {
                    return(Real.ToArray(bytes));
                }

            case VarType.LReal:
                if (varCount == 1)
                {
                    return(LReal.FromByteArray(bytes));
                }
                else
                {
                    return(LReal.ToArray(bytes));
                }

            case VarType.String:
                return(String.FromByteArray(bytes));

            case VarType.S7String:
                return(S7String.FromByteArray(bytes));

            case VarType.Timer:
                if (varCount == 1)
                {
                    return(Timer.FromByteArray(bytes));
                }
                else
                {
                    return(Timer.ToArray(bytes));
                }

            case VarType.Counter:
                if (varCount == 1)
                {
                    return(Counter.FromByteArray(bytes));
                }
                else
                {
                    return(Counter.ToArray(bytes));
                }

            case VarType.Bit:
                if (varCount == 1)
                {
                    if (bitAdr > 7)
                    {
                        return(null);
                    }
                    else
                    {
                        return(Bit.FromByte(bytes[0], bitAdr));
                    }
                }
                else
                {
                    return(Bit.ToBitArray(bytes, varCount));
                }

            case VarType.DateTime:
                if (varCount == 1)
                {
                    return(DateTime.FromByteArray(bytes));
                }
                else
                {
                    return(DateTime.ToArray(bytes));
                }

            case VarType.DateTimeLong:
                if (varCount == 1)
                {
                    return(DateTimeLong.FromByteArray(bytes));
                }
                else
                {
                    return(DateTimeLong.ToArray(bytes));
                }

            default:
                return(null);
            }
        }
 public String Visit(Int node)
 {
     return(node.AnchorToken.Lexeme);
 }
Example #44
0
 private void button1_Click(object sender, EventArgs e)
 {
     frm.SetIndex(Int.Parse(textBox1.Text));
 }
Example #45
0
 private void Update(EvaluationContext context)
 {
     Result.Value = Int.GetValue(context);
 }
Example #46
0
 public RemainderInt(Int dividend, Int divisor)
 {
     _dividend = dividend;
     _divisor  = divisor;
 }
 private string CellLine(Int leftCell, Int centerCell, Int rightCell) =>
 $" {Cell(leftCell).Value()}{VertDivider}" +
 $"{Cell(centerCell).Value()}{VertDivider}" +
 $"{Cell(rightCell).Value()}{Environment.NewLine}";
Example #48
0
 public static void Main(string[] args)
 {
     Int i = new Int();
     Console.WriteLine("Asked for version, got [" + i.GetExt() + "]");
 }
Example #49
0
 public static void Write(Int val, Wr wr)
 {
     wr.WriteInt32(val);
 }
Example #50
0
		public void PrintReceivedBackward(Int incomingBackward)
		{
			System.Console.WriteLine("Received Backward Int: " + incomingBackward.Value);
		}
Example #51
0
 public Dummy(Int someId)
 {
     id = someId;
 }
Example #52
0
	extern private static Int gnutls_bye(IntPtr session, Int how);
 /// <summary>
 /// 创建树第一级节点
 /// </summary>
 private void CreateXElement(XElement root, Int.AC.ReadModel.Menus.Menu model)
 {
     var tempList = authorityList.Where(m => m.ParentId == model.Id).ToList();
     foreach (var temp in tempList)
     {
         XElement xe = new XElement("TreeNode", new object[]
         {
             new XAttribute("Text", temp.Text),
             new XAttribute("NodeID",temp.Id),
         });
         root.Add(xe);
         CreateXElement(xe, temp);
     }
 }
Example #54
0
            public override void AddGumpLayout()
            {
                AddPage(0);
                AddBackground(0, 0, Width, Height, 9200);

                AddImageTiled(10, 10, 480, 25, 2624);
                AddAlphaRegion(10, 10, 480, 25);

                AddImageTiled(10, 45, 480, 425, 2624);
                AddAlphaRegion(10, 45, 480, 425);

                AddImageTiled(10, 480, 480, 22, 2624);
                AddAlphaRegion(10, 480, 480, 22);

                AddHtmlLocalized(0, 12, Width, 20, 1152352, White, false, false);                              // <center>Mythic Character Skill Selection</center>

                AddHtmlLocalized(0, 45, Width / 3, 20, 1152354, Yellow, false, false);                         // <CENTER>Set Attributes</CENTER>
                AddHtmlLocalized(0, 65, Width / 3, 20, 1152355, User.StatCap.ToString(), Beige, false, false); // <CENTER>Total Must Equal ~1_VAL~

                AddBackground(11, 85, 80, 20, 3000);
                AddBackground(11, 106, 80, 20, 3000);
                AddBackground(11, 127, 80, 20, 3000);

                AddTextEntry(13, 85, 75, 20, 0, 1, Str > 0 ? Str.ToString() : "");
                AddTextEntry(13, 106, 75, 20, 0, 2, Dex > 0 ? Dex.ToString() : "");
                AddTextEntry(13, 127, 75, 20, 0, 3, Int > 0 ? Int.ToString() : "");

                AddHtmlLocalized(98, 85, 100, 20, 3000111, White, false, false);        // Strength
                AddHtmlLocalized(98, 106, 100, 20, 3000113, White, false, false);       // Dexterity
                AddHtmlLocalized(98, 127, 100, 20, 3000112, White, false, false);       // Intelligence

                AddHtmlLocalized(0, 170, Width / 3, 20, 1152356, Yellow, false, false); // <CENTER>Selected Skills</CENTER>

                AddButton(10, Height - 30, 4017, 4018, 0, GumpButtonType.Reply, 0);
                AddHtmlLocalized(42, Height - 30, 100, 20, 1153439, White, false, false); // CANCEL

                for (int i = 0; i < Selected.Length; i++)
                {
                    Skill sk = Selected[i];

                    if (sk == null)
                    {
                        continue;
                    }

                    AddButton(12, 190 + (i * 20), 4017, 4018, 5000 + i, GumpButtonType.Reply, 0);
                    AddHtmlLocalized(45, 190 + (i * 20), 150, 20, sk.Info.Localization, Green, false, false);
                }

                if (HasAllFive)
                {
                    AddHtmlLocalized(Width / 3, 65, ((Width / 3) * 2) - 15, Height - 100, 1152358, LightGreen, false, false);

                    /*Please confirm that you wish to set your attributes as indicated in the upper left area of this window.
                     * If you wish to change these values, edit them and click the EDIT button below.<br><br>Please confirm that
                     * you wish to set the five skills selected on the left to 90.0 skill. If you wish to make changes, click the
                     * [X] button next to a skill name to remove it from the list.<br><br>If are sure you wish to apply the selected
                     * skills and attributes, click the CONTINUE button below.<br><br>If you wish to abort the application of the
                     * Mythic Character Token, click the CANCEL button below.*/

                    AddButton(Width / 3, Height - 100, 4005, 4007, 2500, GumpButtonType.Reply, 0);
                    AddHtmlLocalized((Width / 3) + 32, Height - 100, 100, 20, 1150647, White, false, false); // EDIT

                    AddButton(Width / 3, Height - 120, 4005, 4007, 2501, GumpButtonType.Reply, 0);
                    AddHtmlLocalized((Width / 3) + 32, Height - 120, 100, 20, 1011011, White, false, false); // CONTINUE
                }
                else
                {
                    AddHtmlLocalized(Width / 3, 45, (Width / 3) * 2, 20, 1152357, White, false, false); // <CENTER>Select Five Skills to Advance</CENTER>

                    AddPage(1);

                    BuildSkillCategory(BaseSpecialScrollBook.GetCategoryLocalization(SkillCat.Magic), Width / 3, 65, SkillCat.Magic, ScrollOfAlacrityBook._SkillInfo[SkillCat.Magic]);
                    BuildSkillCategory(BaseSpecialScrollBook.GetCategoryLocalization(SkillCat.Bard), Width / 3, 345, SkillCat.Bard, ScrollOfAlacrityBook._SkillInfo[SkillCat.Bard]);
                    BuildSkillCategory(BaseSpecialScrollBook.GetCategoryLocalization(SkillCat.Combat), (Width / 3) * 2, 65, SkillCat.Combat, ScrollOfAlacrityBook._SkillInfo[SkillCat.Combat]);
                    BuildSkillCategory(BaseSpecialScrollBook.GetCategoryLocalization(SkillCat.Wilderness), (Width / 3) * 2, 305, SkillCat.Wilderness, ScrollOfAlacrityBook._SkillInfo[SkillCat.Wilderness]);

                    AddButton(Width - 120, Height - 30, 4005, 4007, 0, GumpButtonType.Page, 2);
                    AddHtmlLocalized(Width - 85, Height - 30, 75, 20, 3005109, White, false, false); // Next
                    AddPage(2);
                    AddButton(Width - 160, Height - 30, 4014, 4015, 0, GumpButtonType.Page, 1);
                    AddHtmlLocalized(Width - 128, Height - 30, 75, 20, 3010002, White, false, false); // Back

                    BuildSkillCategory(BaseSpecialScrollBook.GetCategoryLocalization(SkillCat.TradeSkills), Width / 3, 65, SkillCat.TradeSkills, ScrollOfAlacrityBook._SkillInfo[SkillCat.TradeSkills]);
                    BuildSkillCategory(BaseSpecialScrollBook.GetCategoryLocalization(SkillCat.Miscellaneous), Width / 3, 285, SkillCat.Miscellaneous, ScrollOfAlacrityBook._SkillInfo[SkillCat.Miscellaneous]);
                    BuildSkillCategory(BaseSpecialScrollBook.GetCategoryLocalization(SkillCat.Thievery), (Width / 3) * 2, 150, SkillCat.Thievery, ScrollOfAlacrityBook._SkillInfo[SkillCat.Thievery]);
                }
            }
Example #55
0
File: RdWr.cs Project: pszmyd/SHS
 public static Int Read(Int val, Rd rd)
 {
     return rd.ReadInt32();
 }
Example #56
0
        public static object ToValue(this GraphQLValue source)
        {
            if (source == null)
            {
                return(null);
            }

            switch (source.Kind)
            {
            case ASTNodeKind.NullValue:
            {
                return(null);
            }

            case ASTNodeKind.StringValue:
            {
                var str = source as GraphQLScalarValue;
                Debug.Assert(str != null, nameof(str) + " != null");
                return((string)str.Value);
            }

            case ASTNodeKind.IntValue:
            {
                var str = source as GraphQLScalarValue;

                Debug.Assert(str != null, nameof(str) + " != null");
                if (Int.TryParse(str.Value, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out int intResult))
                {
                    return(intResult);
                }

                // If the value doesn't fit in an integer, revert to using long...
                if (Long.TryParse(str.Value, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out long longResult))
                {
                    return(longResult);
                }

                // If the value doesn't fit in an long, revert to using decimal...
                if (Decimal.TryParse(str.Value, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out decimal decimalResult))
                {
                    return(decimalResult);
                }

                // If the value doesn't fit in an decimal, revert to using BigInteger...
                if (BigInt.TryParse(str.Value, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var bigIntegerResult))
                {
                    return(bigIntegerResult);
                }

                throw new InvalidOperationException($"Invalid number {str.Value}");
            }

            case ASTNodeKind.FloatValue:
            {
                var str = source as GraphQLScalarValue;
                Debug.Assert(str != null, nameof(str) + " != null");

                // the idea is to see if there is a loss of accuracy of value
                // for example, 12.1 or 12.11 is double but 12.10 is decimal
                if (Double.TryParse(
                        str.Value,
                        NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent,
                        CultureInfo.InvariantCulture,
                        out double dbl) == false)
                {
                    dbl = str.Value.Span[0] == '-' ? double.NegativeInfinity : double.PositiveInfinity;
                }

                //it is possible for a FloatValue to overflow a decimal; however, with a double, it just returns Infinity or -Infinity
                if (Decimal.TryParse(
                        str.Value,
                        NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent,
                        CultureInfo.InvariantCulture,
                        out decimal dec))
                {
                    // Cast the decimal to our struct to avoid the decimal.GetBits allocations.
                    var     decBits      = System.Runtime.CompilerServices.Unsafe.As <decimal, DecimalData>(ref dec);
                    decimal temp         = new decimal(dbl);
                    var     dblAsDecBits = System.Runtime.CompilerServices.Unsafe.As <decimal, DecimalData>(ref temp);
                    if (!decBits.Equals(dblAsDecBits))
                    {
                        return(dec);
                    }
                }

                return(dbl);
            }

            case ASTNodeKind.BooleanValue:
            {
                var str = source as GraphQLScalarValue;
                Debug.Assert(str != null, nameof(str) + " != null");
                return((str.Value.Length == 4).Boxed());    /*true.Length=4*/
            }

            case ASTNodeKind.EnumValue:
            {
                var str = source as GraphQLScalarValue;
                Debug.Assert(str != null, nameof(str) + " != null");
                return((string)str.Value);
            }

            case ASTNodeKind.ObjectValue:
            {
                var obj    = source as GraphQLObjectValue;
                var values = new Dictionary <string, object>();

                Debug.Assert(obj != null, nameof(obj) + " != null");
                if (obj.Fields != null)
                {
                    foreach (var f in obj.Fields)
                    {
                        values[(string)f.Name.Value] = ToValue(f.Value);
                    }
                }

                return(values);
            }

            case ASTNodeKind.ListValue:
            {
                var list = source as GraphQLListValue;
                Debug.Assert(list != null, nameof(list) + " != null");

                if (list.Values == null)
                {
                    return(Array.Empty <object>());
                }

                object[] values = list.Values.Select(ToValue).ToArray();
                return(values);
            }

            default:
                throw new InvalidOperationException($"Unsupported value type {source.Kind}");
            }
        }
Example #57
0
        /// <summary> Adds terms and frequencies found in vector into the Map termFreqMap</summary>
        /// <param name="termFreqMap">a Map of terms and their frequencies
        /// </param>
        /// <param name="vector">List of terms and their frequencies for a doc/field
        /// </param>
        private void  AddTermFrequencies(System.Collections.IDictionary termFreqMap, TermFreqVector vector)
        {
            System.String[] terms = vector.GetTerms();
            int[] freqs = vector.GetTermFrequencies();
            for (int j = 0; j < terms.Length; j++)
            {
                System.String term = terms[j];
				
                if (IsNoiseWord(term))
                {
                    continue;
                }
                // increment frequency
                Int cnt = (Int) termFreqMap[term];
                if (cnt == null)
                {
                    cnt = new Int();
                    termFreqMap[term] = cnt;
                    cnt.x = freqs[j];
                }
                else
                {
                    cnt.x += freqs[j];
                }
            }
        }
 public static Option <int> DoubleOf(string s)
 => from i in Int.Parse(s)
 select i * 2;
 public B4()
 {
     m_fld1 = new Int();
     m_fld1.fld1 = 12.444M;
     fld2 = new Int() { fld1 = 1111 };
     fld3.fld1 = 444;
 }
Example #60
0
 public Increment(Int origin) => _origin = origin + 1;