Ejemplo n.º 1
0
            }                                            //8
                                                         //-------------
                                                         // around at least 144 bytes in native CLR
            public override string ToString()
            {
                if (BinData == null || BinData.Length < 50)
                {
                    return(JSONWriter.Write(this, JSONWritingOptions.PrettyPrintRowsAsMap));
                }

                return("ID = {0} FirstName={1} LastName={2} BinData[{3}]....".Args(ID, FirstName, LastName, BinData.Length));
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Writes an object as JSON. Does nothing if object is null
 /// </summary>
 public void WriteJSON(object data, JSONWritingOptions options = null)
 {
     if (data == null)
     {
         return;
     }
     setWasWrittenTo();
     m_NetResponse.ContentType = NFX.Web.ContentType.JSON;
     JSONWriter.Write(data, new NonClosingStreamWrap(getStream()), options, Encoding);
 }
Ejemplo n.º 3
0
        private void writeWeb(KeyValuePair <string, List <Row> > table)
        {
            var packager  = new WebViewer.DefaultWebPackager(this, null);
            var targetDir = packager.Build(m_RunSessionPath);

            using (var fs = new FileStream(Path.Combine(targetDir, "scripts", "data-{0}.js".Args(table.Key)), FileMode.Create, FileAccess.Write, FileShare.None, 256 * 1024))
                using (var wri = new StreamWriter(fs, Encoding.UTF8))
                {
                    wri.WriteLine("//Java script file for Serbench Web output. Table '{0}'".Args(table.Key));
                    wri.WriteLine("var data_{0} = ".Args(table.Key));
                    JSONWriter.Write(table.Value, wri, JSONWritingOptions.PrettyPrintRowsAsMap);
                    wri.WriteLine(";");
                }
        }
Ejemplo n.º 4
0
        public virtual void Serialize(Stream stream)
        {
            if (!m_Built)
            {
                throw new MLException("Node is not built");
            }

            var body = new JSONDataMap();

            body.Add("type", this.GetType().AssemblyQualifiedName);
            body.Add("name", Name);
            body.Add("index", Index);
            body.Add("is-input", IsInput);
            body.Add("is-output", IsOutput);
            body.Add("is-trainable", IsTrainable);
            body.Add("param-count", ParamCount);

            var inputs  = m_Inputs ?? new _ComputingNode <TVal> [0];
            var outputs = m_Outputs ?? new _ComputingNode <TVal> [0];

            body.Add("inputs", new JSONDataArray(inputs));
            body.Add("outputs", new JSONDataArray(outputs));

            DoSerialize(body);

            // TODO: store parameters separately in HD5 or CDF?
            var paramBytes = new byte[ParamCount * sizeof(double)];

            Buffer.BlockCopy(Parameters, 0, paramBytes, 0, paramBytes.Length);
            var parameters = Convert.ToBase64String(paramBytes);

            body.Add("parameters", parameters);
            // TODO: store parameters separately in HD5 or CDF?

            var root = new JSONDataMap {
                { "node", body }
            };

            JSONWriter.Write(root, stream);
        }
Ejemplo n.º 5
0
        private static void run(IConfigSectionNode args)
        {
            var pretty         = args["pp", "pretty"].Exists;
            var noEntropy      = args["ne", "noentropy"].Exists;
            var scoreThreshold = args["st", "score"].AttrByIndex(0).ValueAsInt(80);

            if (scoreThreshold < 20)
            {
                scoreThreshold = 20;
            }
            if (scoreThreshold > 100)
            {
                scoreThreshold = 100;
            }
            var strength = args["lvl", "level"].AttrByIndex(0).ValueAsEnum <PasswordStrengthLevel>(PasswordStrengthLevel.Default);

            ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Welcome.txt"));

            if (args["?", "h", "help"].Exists)
            {
                ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Help.txt"));
                return;
            }

            ConsoleUtils.Info("Score Threshold: {0}%".Args(scoreThreshold));
            ConsoleUtils.Info("Stength level: {0}".Args(strength));

            if (!noEntropy)
            {
                var count = ExternalRandomGenerator.Instance.NextScaledRandomInteger(47, 94);
                ConsoleUtils.Info("Acquiring entropy from user...");
                Console.WriteLine();
                ConsoleUtils.WriteMarkupContent(
                    @"<push>
<f color=magenta>Please make <f color=white>{0}<f color=magenta> random keystrokes
Do not hit the same key and try to space key presses in time:<pop>
".Args(count));

                var pnow = Stopwatch.GetTimestamp();

                Console.WriteLine();
                for (var i = 0; i < count; i++)
                {
                    var k = Console.ReadKey(true).KeyChar;
                    if (k < 0x20)
                    {
                        continue;
                    }
                    var now     = Stopwatch.GetTimestamp();
                    var elapsed = (int)(39621 * (k - 0x19) * (now - pnow));
                    pnow = now;
                    ExternalRandomGenerator.Instance.FeedExternalEntropySample(elapsed);
                    Console.Write("\r{0}  {1} characters to go ...", elapsed, count - i - 1);
                }
                ConsoleUtils.Info("OK. Entropy key entered");
                Console.WriteLine("-----------------------");
                System.Threading.Thread.Sleep(3000);
                while (Console.KeyAvailable)
                {
                    Console.ReadKey(true);
                }
            }

            SecureBuffer password = null;

            while (true)
            {
                Console.WriteLine("Please type-in your password and press <enter>:");
                password = ConsoleUtils.ReadPasswordToSecureBuffer('*');
                var score = App.SecurityManager.PasswordManager.CalculateStrenghtPercent(PasswordFamily.Text, password);
                var pass  = score >= scoreThreshold;
                Console.WriteLine();
                var t = "Password score: {0}% is {1} strong".Args(score, pass ? "sufficiently" : "insufficiently");
                if (pass)
                {
                    ConsoleUtils.Info(t);
                    break;
                }

                ConsoleUtils.Error(t);
                Console.WriteLine();
            }

            Console.WriteLine();

            while (true)
            {
                Console.WriteLine("Please re-type your password and press <enter>:");
                using (var p2 = ConsoleUtils.ReadPasswordToSecureBuffer('*'))
                    if (password.Content.MemBufferEquals(p2.Content))
                    {
                        break;
                    }
                ConsoleUtils.Error("Passwords do not match");
            }

            Console.WriteLine();
            Console.WriteLine();

            var hashed = App.SecurityManager.PasswordManager.ComputeHash(
                NFX.Security.PasswordFamily.Text,
                password,
                strength);

            password.Dispose();

            var toPrint = JSONWriter.Write(hashed, pretty ? JSONWritingOptions.PrettyPrintASCII : JSONWritingOptions.CompactASCII);

            Console.WriteLine("Hashed Password:");
            Console.WriteLine();

            Console.WriteLine(toPrint);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Saves JSON configuration to string
        /// </summary>
        public string SaveToString(JSONWritingOptions options = null)
        {
            var data = ToConfigurationJSONDataMap();

            return(JSONWriter.Write(data, options));
        }
Ejemplo n.º 7
0
 public virtual void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
 {
     JSONWriter.Write(this.ObjectValue, wri, options);
 }
Ejemplo n.º 8
0
        public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
        {
            var data = new { js = Code, doc = Scope };

            JSONWriter.Write(data, wri, options);
        }
Ejemplo n.º 9
0
 public void Process(List <NECResultDataModel> data)
 {
     JSONWriter.Write(data, @"../SmICSWebApp/Resources/nec/json", DateTime.Now.ToString("yyyy-MM-dd"));
 }
Ejemplo n.º 10
0
 public override void Serialize(object serializable, Stream outputStream)
 {
     JSONWriter.Write(serializable, outputStream, JSONWritingOptions.Compact);
 }
Ejemplo n.º 11
0
 public override string Serialize(object serializable)
 {
     return(JSONWriter.Write(serializable, JSONWritingOptions.Compact));
 }
Ejemplo n.º 12
0
 private void WriteToJSON(string fileDir)
 {
     CurrentParser.Close();
     JSONWriter.Write(this, fileDir);
 }
Ejemplo n.º 13
0
 public override void Serialize(object serializable, Stream outputStream)
 {
     JSONWriter.Write(serializable, outputStream);
 }
Ejemplo n.º 14
0
 public override void ParallelSerialize(object root, Stream stream)
 {
     JSONWriter.Write(root, stream, m_Options);
 }
Ejemplo n.º 15
0
 private void writeJSON(KeyValuePair <string, List <Row> > table)
 {
     using (var fs = new FileStream(Path.Combine(m_RunSessionPath, table.Key + ".json"), FileMode.Create, FileAccess.Write, FileShare.None, 256 * 1024))
         JSONWriter.Write(table.Value, fs, JSONWritingOptions.PrettyPrintRowsAsMap);
 }