コード例 #1
0
    public cLineValue(string Key, string sLine)
    {
        sKey      = Key;
        sRawValue = ((sLine.Length > 0) ? sLine : "");

        if (sLine.IndexOf(',') > -1)                                            // Supposing is a MultiVal string
        {
            iType = ( byte )LineValueType.MULTI;
            List <cValue> vValues = Utils.String_RecognizeValues(sLine);
            if (vValues.Count < 1)
            {
                return;
            }
            pMultiValue = new cMultiValue(vValues);
        }
        else             // Single value
        {
            iType = ( byte )LineValueType.SINGLE;
            cValue pValue = Utils.String_RecognizeValue(sLine);
            if (pValue == null)
            {
                Debug.LogError(" cLineValue::Constructor: for key " + Key + " value type is undefined");
                return;
            }
            this.pValue = pValue;
        }

        bIsOK = true;
    }
コード例 #2
0
ファイル: ValueTests.cs プロジェクト: uzbekdev1/MPT.Tools
        public void New_Magnitude_And_Units_with_Only_Magnitude_Creates_Magnitude()
        {
            string expectedValue = "Yielding";
            cValue value1        = new cValue(expectedValue, "");

            Assert.AreEqual(expectedValue, value1.Magnitude);
        }
コード例 #3
0
ファイル: ValueTests.cs プロジェクト: uzbekdev1/MPT.Tools
        public string New_Numerical_Magnitude_And_Units_Creates_Magnitude_And_Unit_Value(
            double unitMagnitude,
            string unitValue)
        {
            cValue value1 = new cValue(unitMagnitude, unitValue);

            return((value1.Magnitude + " " + value1.Units).Trim());
        }
コード例 #4
0
ファイル: ValueTests.cs プロジェクト: uzbekdev1/MPT.Tools
        public string ConvertTo_Converts_Magnitude_and_Unit_Value_to_Current_Unit_with_No_Unit_Value(
            string valueStart,
            string unitConvert)
        {
            cValue value1 = new cValue(valueStart);

            value1.ConvertTo(unitConvert);

            return((value1.Magnitude + " " + value1.Units).Trim());
        }
コード例 #5
0
ファイル: ValueTests.cs プロジェクト: uzbekdev1/MPT.Tools
        [TestCase("1", "kip*ft", "12", "Kip, in", ExpectedResult = "1 (kip*ft)")]   // TODO: normalize kip/Kip, etc.
        public string ConvertFrom_Converts_Magnitude_and_Unit_Value_to_Current_Unit(
            string magnitudeStart,
            string unitStart,
            string magnitudeConvert,
            string unitConvert)
        {
            cValue value1 = new cValue(magnitudeStart, unitStart);

            value1.ConvertFrom(magnitudeConvert, unitConvert);

            return((value1.Magnitude + " " + value1.Units).Trim());
        }
コード例 #6
0
    public void                                    SetValue(string Key, cValue Value)
    {
        cLineValue pLineValue = GetLineValue(Key);

        // if not exists create one
        if (pLineValue == null)
        {
            pLineValue = new cLineValue(Key, ( byte )LineValueType.SINGLE);
        }
        pLineValue.Clear();
        pLineValue.Set(Value);
    }
コード例 #7
0
    public cValue                                  GetMultiValue(string Key, int Index, int Type)
    {
        cLineValue pLineValue = null; cMultiValue pMultiValue = null; cValue pValue = null;

        if ((pLineValue = GetLineValue(Key)) != null)
        {
            if ((pMultiValue = pLineValue.GetMultiValue()) != null)
            {
                if ((pValue = pMultiValue.At(Index - 1)) != null)
                {
                    return(pValue);
                }
            }
        }

        return(null);
    }
コード例 #8
0
    public bool                                    bGetMultiValue(string Key, out cValue Out, int Index, int Type)
    {
        cLineValue pLineValue = null; cMultiValue pMultiValue = null; cValue pValue = null;

        if ((pLineValue = GetLineValue(Key)) != null)
        {
            if ((pMultiValue = pLineValue.GetMultiValue()) != null)
            {
                if ((pValue = pMultiValue.At(Index - 1)) != null)
                {
                    Out = pValue;
                    return(true);
                }
            }
        }

        Out = null;
        return(false);
    }
コード例 #9
0
ファイル: Utils.cs プロジェクト: boris47/Freelance
    // parse a string and return a list of values
    static public List <cValue> String_RecognizeValues(string _Line)
    {
        List <cValue> Values = new List <cValue> ();
        string        Line   = _Line;
        int           Start  = 0;

        for (int i = 0; i < Line.Length; i++)
        {
            if (Line[i] == ',')
            {
                string Result = (Line.Substring(Start, i - Start)).Trim();
                Values.Add(String_RecognizeValue(Result));
                Start = i + 1;
            }
        }
        cValue Value = String_RecognizeValue(Line.Substring(Start));    // last value is not followed by a colon

        Values.Add(Value);                                              // So we save the last part of string entirely
        return(Values);
    }
コード例 #10
0
    public bool                                    bGetVec2(string Key, out Vector2 Out, Vector2 Default)
    {
        cLineValue pLineValue = null; cMultiValue pMultiValue = null;
        cValue     pValue1 = null; cValue pValue2 = null;

        if ((pLineValue = GetLineValue(Key)) != null)
        {
            if ((pMultiValue = pLineValue.GetMultiValue()) != null)
            {
                if (((pValue1 = pMultiValue.At(0)) != null) &&
                    (pValue2 = pMultiValue.At(1)) != null)
                {
                    Out = new Vector2(pValue1.ToFloat(), pValue2.ToFloat());
                    return(true);
                }
            }
        }

        Out = Default;
        return(false);
    }
コード例 #11
0
    // Return the type of a value assigned to a key, or -1
    public int                                             KeyType(string Key)
    {
        if (vSection.Count < 1)
        {
            return(-1);
        }

        cLineValue pLineValue = null; cValue Value = null;

        if ((pLineValue = GetLineValue(Key)) != null)
        {
            int iType = pLineValue.Type();
            switch (iType)
            {
            case ( byte )LineValueType.SINGLE: {
                if ((Value = pLineValue.GetValue()) != null)
                {
                    return(Value.Type());
                }
                Debug.LogError("cSection::KeyType:WARNING! In section " + sName + " a key has no value but designed as SINGLE !!!");
                break;
            }

            case ( byte )LineValueType.MULTI: {
                if ((pLineValue.GetMultiValue() != null))
                {
                    return(iType);
                }
                Debug.LogError("cSection::KeyType:WARNING! In section " + sName + " a key has no value but designed as MULTI !!!");
                break;
            }
            }
        }

        return(-1);
    }
コード例 #12
0
ファイル: ValueTests.cs プロジェクト: uzbekdev1/MPT.Tools
        public string New_Numeric_Value_Creates_Magnitude(double unitMagnitude)
        {
            cValue value1 = new cValue(unitMagnitude);

            return((value1.Magnitude + " " + value1.Units).Trim());
        }
コード例 #13
0
ファイル: ValueTests.cs プロジェクト: uzbekdev1/MPT.Tools
        public string New_Magnitude_Or_Units_Creates_Unit_Value(string magnitudeOrUnit)
        {
            cValue value1 = new cValue(magnitudeOrUnit);

            return(value1.Units);
        }
コード例 #14
0
 public cLineValue Set(cValue _Value)
 {
     pValue = _Value; return(this);
 }
コード例 #15
0
 public void Clear()
 {
     pValue = null; pMultiValue = null;
 }
コード例 #16
0
 public void Destroy()
 {
     pValue = null; pMultiValue = null;
 }
コード例 #17
0
ファイル: MultiValue.cs プロジェクト: boris47/Freelance
 public void             Add(cValue pValue)
 {
     vValues.Add(pValue);
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: guitarxhero/dosdd
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                ShowHelp(true);
                return 0;
            }

            Target = args[args.Length - 1].Trim();
            switch (Target)
            {
                case "localhost":
                case "::1":
                    Target = "127.0.0.1";
                    break;
            }
            int NumberOfThreads = 100;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                    case "/?":
                    case "--help":
                        ShowHelp(false);
                        return 0;

                    case "--version":
                        ShowVersion();
                        return 0;

                    case "-t":
                        if (!int.TryParse(args[i + 1], out NumberOfThreads))
                        {
                            Event.WriteLine("Could not get value for -t");
                            return 0;
                        }

                        if (NumberOfThreads < 1)
                        {
                            Event.WriteLine("Invalid value for -t, must be higher than 0");
                            return 0;
                        }
                        break;
                }
            }

            Event.WriteLine(" -- dosdd started --");

            Event.WriteLine("Pinging for target validation...");
            if (new Ping().Send(Target).Status != IPStatus.Success)
            {
                Event.WriteLine("Validation failed, aborting.");
                return 0;
            }

            Event.WriteLine("Validation succeeded, creating " + NumberOfThreads + " threads...");

            Event.Write("Creating thread: ");
            cValue update = new cValue();
            Thread[] tl = new Thread[NumberOfThreads];

            for (int i = 0; i < NumberOfThreads; i++)
            {
                update.UpdateValue(string.Format("{0}", i + 1));
                Thread t = new Thread(new ThreadStart(PingTarget));
                t.IsBackground = true;
                tl[i] = t;
            }

            update = null;
            Console.WriteLine();
            Event.WriteLine("Cleaning...");
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            Event.WriteLine("Launching all threads!");
            ushort len = (ushort)tl.Length;
            for (int i = 0; i < len; i++)
            {
                tl[i].Start();
            }

            Console.WriteLine("Press Q to Quit.");
            Console.WriteLine("Failure rate:");
            Console.Write("  0% ");
            pb = new ProgressBar();
            pb.MaximumValue = NumberOfThreads;
            pb.Initialize();
            System.Timers.Timer tmr = new System.Timers.Timer(2000);
            tmr.Elapsed += tmr_Elapsed;
            tmr.Start();

            bool exit = false;
            do
            {
                ConsoleKeyInfo cki = Console.ReadKey(true);

                switch (cki.Key)
                {
                    case ConsoleKey.Q:
                        exit = true;
                        break;
                }
            } while (!exit);

            return 0;
        }