Exemple #1
0
        public static PNumber ToAnotherBase(PNumber number, int toBase)
        {
            double decimalValue   = PNumberToDecimal(number);
            int    destFracDigits = ResultingFracDigits(number.FractionalDigits, number.Base, toBase);

            return(DecimalToPNumber(decimalValue, toBase, destFracDigits));
        }
        public override bool Execute()
        {
            var template  = PDictionary.FromFile(TemplatePath.ItemSpec);
            var resources = template.GetArray("resources");

            foreach (var resource in resources.OfType <PDictionary> ())
            {
                PString url;
                string  name;
                int     slash;

                if (!resource.TryGetValue("URL", out url))
                {
                    continue;
                }

                if ((slash = url.Value.LastIndexOf('/')) == -1)
                {
                    continue;
                }

                name = url.Value.Substring(slash);

                url.Value = OnDemandResourceUrl + name;

                resource["isStreamable"] = new PNumber(IsStreamable ? 1 : 0);
            }

            template.Save(OutputFile.ItemSpec, true, true);

            return(!Log.HasLoggedErrors);
        }
Exemple #3
0
        static void PathTest()
        {
            var t = new PNumber(15);
            var l = new DataTree();

            l.AddElement(new PNumber(4));
            l.AddElement(new PNumber(3));
            l.AddElement(new PNumber(1));
            var t2 = new DataTree();

            t2.AddElement(new PNumber(22));
            var t3 = new DataTree();

            t3.AddElement(new PNumber(14));
            t3.AddElement(t);
            t2.AddElement(t3);
            l.AddElement(t2);
            var d = new DataTree();

            d.AddElement(l.Copy());
            d.AddElement(l);
            d.AddElement(d.Copy());
            Print(d);
            PrintPath(t.Path);
            foreach (var temp in d.GetChildIterator())
            {
                PrintPath(temp.Path);
            }
        }
Exemple #4
0
        bool Clear(ref PObject plist)
        {
            if (Type != null)
            {
                switch (Type.ToLowerInvariant())
                {
                case "string": plist = new PString(string.Empty); break;

                case "array": plist = new PArray(); break;

                case "dict": plist = new PDictionary(); break;

                case "bool": plist = new PBoolean(false); break;

                case "real": plist = new PReal(0); break;

                case "integer": plist = new PNumber(0); break;

                case "date": plist = new PDate(DateTime.Now); break;

                case "data": plist = new PData(new byte[1]); break;

                default:
                    Log.LogError(7045, null, $"Unrecognized Type: {Type}");
                    return(false);
                }
            }
            else
            {
                plist = PObject.Create(plist.Type);
            }

            return(true);
        }
Exemple #5
0
        public override bool Execute()
        {
            Log.LogTaskName ("WriteAssetPackManifest");
            Log.LogTaskProperty ("OutputFile", OutputFile);
            Log.LogTaskProperty ("TemplatePath", TemplatePath);
            Log.LogTaskProperty ("OnDemandResourceUrl", OnDemandResourceUrl);
            Log.LogTaskProperty ("IsStreamable", IsStreamable);

            var template = PDictionary.FromFile (TemplatePath.ItemSpec);
            var resources = template.GetArray ("resources");

            foreach (var resource in resources.OfType<PDictionary> ()) {
                PString url;
                string name;
                int slash;

                if (!resource.TryGetValue ("URL", out url))
                    continue;

                if ((slash = url.Value.LastIndexOf ('/')) == -1)
                    continue;

                name = url.Value.Substring (slash);

                url.Value = OnDemandResourceUrl + name;

                resource["isStreamable"] = new PNumber (IsStreamable ? 1 : 0);
            }

            template.Save (OutputFile.ItemSpec, true, true);

            return !Log.HasLoggedErrors;
        }
Exemple #6
0
        private void cbActions_SelectedIndexChanged(object sender, EventArgs e)
        {
            PNumber firstNumber  = new PNumber(number1.Text, udBase_value.Value.ToString(), udAccuracy.Value.ToString());
            PNumber secondNumber = new PNumber(number2.Text, udBase_value.Value.ToString(), udAccuracy.Value.ToString());

            try
            {
                switch (cbActions.SelectedItem)
                {
                case "+":
                    tbResultNumber.Text = (firstNumber + secondNumber).getValueString;
                    break;

                case "-":
                    tbResultNumber.Text = (firstNumber - secondNumber).getValueString;
                    break;

                case "*":
                    tbResultNumber.Text = (firstNumber * secondNumber).getValueString;
                    break;

                case "/":
                    tbResultNumber.Text = (firstNumber / secondNumber).getValueString;
                    break;

                default:
                    break;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void AvailableValues_Number_InDictionary()
        {
            var scheme = Load(@"
<PListScheme>
	<Key name = ""keyname"" type = ""Dictionary"">
		<Value name = ""num"" type = ""Number"" required = ""True"">
			<Value name = ""1"" />
			<Value name = ""2"" />
			<Value name = ""3"" />
		</Value>
	</Key>
</PListScheme>");

            var value = new PDictionary();
            var num   = new PNumber(1);

            var root = new PDictionary();

            root.Add("keyname", value);
            value.Add("num", num);

            var available = PListScheme.AvailableValues(num, PListScheme.Match(root, scheme));

            Assert.AreEqual(3, available.Count, "#1");
        }
Exemple #8
0
        public void TestAddProducesCorrectResult()
        {
            var a = new PNumber(10, 10, 5);
            var b = new PNumber(20, 10, 5);
            var r = new PNumber(30, 10, 5);

            DoBinOpTest(r, BinaryOperation.Add, a, b);
        }
Exemple #9
0
        protected JsonParsers()
        {
            Whitespace = Rep(Char(' ').OR(Char('\t').OR(Char('\n')).OR(Char('\r'))));
            Id         = from w in Whitespace
                         from c in Char(char.IsLetter)
                         from cs in Rep(Char(char.IsLetter))
                         select cs.Aggregate(c.ToString(), (acc, ch) => acc + ch);

            WsChr   = chr => Whitespace.AND(Char(chr));
            PString = from begin in WsChr('"')
                      from cs in Rep(EscapedChar())
                      from end in Char('"').REQUIRED("Expected end of string '\"', found end of file")
                      select(Object)(cs.Aggregate(string.Empty, (acc, ch) => acc + ch));

            PNumber = from whitespace in Whitespace
                      from n in Char(char.IsDigit)
                      from ns in Rep(Char(char.IsDigit))
                      select(Object) double.Parse(ns.Aggregate(n.ToString(), (acc, ch) => acc + ch));

            PArray = from begin in WsChr('[')
                     from values in
                     Rep(from value in Value
                         from comma in Rep(Char(','))
                         select value)
                     from end in WsChr(']').REQUIRED("Expected end of array ']', found end of file")
                     select(Object) new ArrayValue(values);

            PObject = from begin in WsChr('{')
                      from props in
                      Rep(from prop in Prop
                          from comma in Rep(Char(','))
                          select prop)
                      from end in WsChr('}').REQUIRED("Expected end of object '}', found end of file")
                      select(Object) new ObjectValue(props.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));

            Prop = from identifier in PString
                   from colon in WsChr(':')
                   from value in Value
                   from comma in Rep(Char(','))
                   select new KeyValuePair <string, Object>((string)identifier, value);

            PBool = from id in Id
                    where (id == "true" || id == "false")
                    select(Object) bool.Parse(id);
            PNull = from id in Id
                    where (id == "null")
                    select(Object) null;
            Value = PNumber
                    .OR(PArray)
                    .OR(PString)
                    .OR(PObject)
                    .OR(PBool)
                    .OR(PNull);
//            .REQUIRED("Input was not a valid JSON value");
            All = Value;
        }
Exemple #10
0
        public void TestClearMethodSetsNumberToDefaultAndStateToOff()
        {
            var m = new Memory.Memory <PNumber>();
            var p = new PNumber(5, 9, 4);

            m.Number = p;
            m.Clear();
            Assert.AreEqual(new PNumber(), m.Number);
            Assert.AreEqual(MemoryState.Off, m.State);
        }
Exemple #11
0
        public void ChangeEvent_PDictionary()
        {
            Func <PDictionary, PDictionary> addKey = d => { d.Add("key", new PNumber(1)); return(d); };

            AssertChangeEmitted(new PDictionary(), d => addKey(d), "#1");
            AssertChangeEmitted(addKey(new PDictionary()), d => d.InsertAfter("key", "key2", new PNumber(1)), "#2");
            AssertChangeEmitted(addKey(new PDictionary()), d => d.Remove("key"), "#3");
            AssertChangeEmitted(addKey(new PDictionary()), d => d ["key"].Replace(new PNumber(77)), "#4");
            AssertChangeEmitted(addKey(new PDictionary()), d => d ["key"] = new PNumber(77), "#6");
        }
Exemple #12
0
        static void TestimNumriElementeve()
        {
            var t = new DataTree();

            t.AddElement(new PNumber(1));

            t.AddElement(new PNumber(2));

            t.AddElement(new PNumber(3));

            Console.WriteLine(t.DataDescription);

            var t2 = new DataTree();

            t2.AddElement(new PNumber(4));
            var temp = new DataTree();

            temp.AddElement(new PNumber(15));
            temp.AddElement(new PNumber(72));
            var temp2 = new PNumber(85);

            temp.AddElement(temp2);
            t2.AddElement(temp);

            t2.AddElement(new PNumber(5));
            t2.AddElement(new PNumber(6));
            t2.AddElement(new PNumber(7));
            t2.AddElement(new PNumber(8));
            t2.AddElement(new PNumber(9));
            Console.WriteLine(t2.DataDescription);
            Console.WriteLine("AfTER CONFORMING  \r\n");
            DataTree.ConformTrees(t, t2, NH_VI.GraphLogic.Operators.DataGroupingModes.CrossReference, out DataTree f1, out DataTree f2);

            Console.WriteLine(f1.DataDescription);
            Console.WriteLine(f2.DataDescription);
            Console.WriteLine("");
            Console.WriteLine("Nr: " + f2.NumberChildEndings());

            var a = f2.GetEmptyTree();

            Console.WriteLine(a.DataDescription);
        }
Exemple #13
0
        static AppleDeviceFamily ParseDeviceFamilyFromNumber(PNumber number)
        {
            switch (number.Value)
            {
            case 1:
                return(AppleDeviceFamily.IPhone);

            case 2:
                return(AppleDeviceFamily.IPad);

            case 3:
                return(AppleDeviceFamily.TV);

            case 4:
                return(AppleDeviceFamily.Watch);

            default:
                throw new ArgumentOutOfRangeException(string.Format("Unknown device family: {0}", number.Value));
            }
        }
Exemple #14
0
        bool CreateValue(string type, string text, out PObject value)
        {
            DateTime date    = DateTime.Now;
            bool     boolean = false;
            double   real    = 0;
            int      integer = 0;

            value = null;

            switch (type.ToLowerInvariant())
            {
            case "string":
                value = new PString(text);
                return(true);

            case "array":
                value = new PArray();
                return(true);

            case "dict":
                value = new PDictionary();
                return(true);

            case "bool":
                if (text == null || !bool.TryParse(text, out boolean))
                {
                    boolean = false;
                }

                value = new PBoolean(boolean);
                return(true);

            case "real":
                if (text != null && !double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out real))
                {
                    Log.LogError(7045, null, "Unrecognized Real Format");
                    return(false);
                }

                value = new PReal(real);
                return(true);

            case "integer":
                if (text != null && !int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out integer))
                {
                    Log.LogError(7045, null, "Unrecognized Integer Format");
                    return(false);
                }

                value = new PNumber(integer);
                return(true);

            case "date":
                if (text != null && !DateTime.TryParse(text, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
                {
                    Log.LogError(7045, null, "Unrecognized Date Format");
                    return(false);
                }

                value = new PDate(date);
                return(true);

            case "data":
                if (text != null)
                {
                    value = new PData(Encoding.UTF8.GetBytes(Value));
                }
                else
                {
                    value = new PData(new byte[0]);
                }
                return(true);

            default:
                Log.LogError(7045, null, $"Unrecognized Type: {type}");
                value = null;
                return(false);
            }
        }
Exemple #15
0
 public HistoryRecord(PNumber input, PNumber output)
 {
     Input  = input;
     Output = output;
 }
Exemple #16
0
        public Environment()
        {
            Output    = new Output();
            EmptyArgs = new SArgs(this);
            True      = new LBoolean(this, true);
            False     = new LBoolean(this, false);
            Undefined = new LUndefined(this);
            Null      = new LNull(this);

            GlobalObject              = new BGlobal(this);
            GlobalEnvironment         = new SLexicalEnvironment(this, new SObjectEnvironmentRecord(this, GlobalObject, false), null);
            MathObject                = new BMath(this);
            JsonObject                = new BJson(this);
            ObjectConstructor         = new CObject(this);
            FunctionConstructor       = new CFunction(this);
            ArrayConstructor          = new CArray(this);
            StringConstructor         = new CString(this);
            BooleanConstructor        = new CBoolean(this);
            NumberConstructor         = new CNumber(this);
            DateConstructor           = new CDate(this);
            RegExpConstructor         = new CRegExp(this);
            ErrorConstructor          = new CError(this);
            EvalErrorConstructor      = new CEvalError(this);
            RangeErrorConstructor     = new CRangeError(this);
            ReferenceErrorConstructor = new CReferenceError(this);
            SyntaxErrorConstructor    = new CSyntaxError(this);
            TypeErrorConstructor      = new CTypeError(this);
            UriErrorConstructor       = new CUriError(this);
            ObjectPrototype           = new PObject(this);
            FunctionPrototype         = new PFunction(this);
            ArrayPrototype            = new PArray(this);
            StringPrototype           = new PString(this);
            BooleanPrototype          = new PBoolean(this);
            NumberPrototype           = new PNumber(this);
            DatePrototype             = new PDate(this);
            RegExpPrototype           = new PRegExp(this);
            ErrorPrototype            = new PError(this);
            EvalErrorPrototype        = new PEvalError(this);
            RangeErrorPrototype       = new PRangeError(this);
            ReferenceErrorPrototype   = new PReferenceError(this);
            SyntaxErrorPrototype      = new PSyntaxError(this);
            TypeErrorPrototype        = new PTypeError(this);
            UriErrorPrototype         = new PUriError(this);

            GlobalObject.Initialize();
            MathObject.Initialize();
            JsonObject.Initialize();
            ObjectConstructor.Initialize();
            FunctionConstructor.Initialize();
            ArrayConstructor.Initialize();
            StringConstructor.Initialize();
            BooleanConstructor.Initialize();
            NumberConstructor.Initialize();
            DateConstructor.Initialize();
            RegExpConstructor.Initialize();
            ErrorConstructor.Initialize();
            EvalErrorConstructor.Initialize();
            RangeErrorConstructor.Initialize();
            ReferenceErrorConstructor.Initialize();
            SyntaxErrorConstructor.Initialize();
            TypeErrorConstructor.Initialize();
            UriErrorConstructor.Initialize();
            ObjectPrototype.Initialize();
            FunctionPrototype.Initialize();
            ArrayPrototype.Initialize();
            StringPrototype.Initialize();
            BooleanPrototype.Initialize();
            NumberPrototype.Initialize();
            DatePrototype.Initialize();
            RegExpPrototype.Initialize();
            ErrorPrototype.Initialize();
            EvalErrorPrototype.Initialize();
            RangeErrorPrototype.Initialize();
            ReferenceErrorPrototype.Initialize();
            SyntaxErrorPrototype.Initialize();
            TypeErrorPrototype.Initialize();
            UriErrorPrototype.Initialize();
        }
Exemple #17
0
 private static double PNumberToDecimal(PNumber number)
 => number.Number;
        static PDictionary OpenIndex()
        {
            PDictionary plist;

            try {
                plist = PDictionary.FromFile(IndexFileName);

                if (Directory.Exists(MobileProvision.ProfileDirectory))
                {
                    var mtime = Directory.GetLastWriteTimeUtc(MobileProvision.ProfileDirectory);

                    if (VersionChanged(plist, IndexVersion))
                    {
                        plist = CreateIndex();
                    }
                    else if (LastModifiedChanged(plist, mtime))
                    {
                        var    table = new Dictionary <string, PDictionary> ();
                        PArray profiles;

                        if (plist.TryGetValue("ProvisioningProfiles", out profiles))
                        {
                            foreach (var profile in profiles.OfType <PDictionary> ())
                            {
                                PString fileName;

                                if (!profile.TryGetValue("FileName", out fileName))
                                {
                                    continue;
                                }

                                table[fileName.Value] = profile;
                            }
                        }
                        else
                        {
                            plist.Add("ProvisioningProfiles", profiles = new PArray());
                        }

                        foreach (var fileName in Directory.EnumerateFiles(MobileProvision.ProfileDirectory))
                        {
                            if (!fileName.EndsWith(".mobileprovision", StringComparison.Ordinal) && !fileName.EndsWith(".provisionprofile", StringComparison.Ordinal))
                            {
                                continue;
                            }

                            bool        unknown = false;
                            PDictionary profile;

                            if (table.TryGetValue(Path.GetFileName(fileName), out profile))
                            {
                                // remove from our lookup table (any leftover key/valie pairs will be used to determine deleted files)
                                table.Remove(Path.GetFileName(fileName));

                                // check if the file has changed since our last resync
                                mtime = File.GetLastWriteTimeUtc(fileName);

                                if (LastModifiedChanged(profile, mtime))
                                {
                                    // remove the old record
                                    profile.Remove();

                                    // treat this provisioning profile as if it is unknown
                                    unknown = true;
                                }
                            }
                            else
                            {
                                unknown = true;
                            }

                            if (unknown)
                            {
                                // unknown provisioning profile; add it to our ProvisioningProfiles array
                                try {
                                    profile = CreateIndexRecord(fileName);
                                    profiles.Add(profile);
                                } catch (Exception ex) {
                                    LoggingService.LogWarning("Error reading provisioning profile '{0}': {1}", fileName, ex);
                                }
                            }
                        }

                        // remove provisioning profiles which have been deleted from the file system
                        foreach (var record in table)
                        {
                            record.Value.Remove();
                        }

                        plist["LastModified"] = new PDate(Directory.GetLastWriteTimeUtc(MobileProvision.ProfileDirectory));
                        plist["Version"]      = new PNumber(IndexVersion);

                        profiles.Sort(CreationDateComparer);

                        Save(plist);
                    }
                }
                else
                {
                    try {
                        File.Delete(IndexFileName);
                    } catch (Exception ex) {
                        LoggingService.LogWarning("Failed to delete stale index '{0}': {1}", IndexFileName, ex);
                    }

                    plist.Clear();
                }
            } catch {
                plist = CreateIndex();
            }

            return(plist);
        }