/// <summary>
        /// Saves key bindings to a file
        /// </summary>
        /// <returns></returns>
        public bool SaveKeyBindings(string filename = null)
        {
            if (filename == null)
            {
                filename = KeyBindingsFilename;
            }

            return(JsonSerializationUtils.SerializeToFile(KeyBindings, filename, false, true));
        }
Beispiel #2
0
        public void JsonSerializeToFile()
        {
            var config = new AutoConfigFileConfiguration();

            bool   result   = JsonSerializationUtils.SerializeToFile(config, "serialized.config", true, true);
            string filetext = File.ReadAllText("serialized.config");

            Console.WriteLine(filetext);
        }
        public bool Save(string filename = "~/LocalizationConfigurations.json")
        {
            if (filename.StartsWith("~/"))
            {
                filename = HttpContext.Current.Server.MapPath(filename);
            }


            return(JsonSerializationUtils.SerializeToFile(Configurations, filename, false, true));
        }
Beispiel #4
0
        /// <summary>
        /// Write configuration to XmlConfigurationFile location
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public override bool Write(AppConfiguration config)
        {
            EncryptFields(config);

            bool result = JsonSerializationUtils.SerializeToFile(config, JsonConfigurationFile, false, true);

            // Have to decrypt again to make sure the properties are readable afterwards
            DecryptFields(config);

            return(result);
        }
Beispiel #5
0
        public void DeserializeFromFileTest()
        {
            string fname = "serialized.config";

            var config = new AutoConfigFileConfiguration();

            config.ApplicationName = "New App";
            config.DebugMode       = DebugModes.DeveloperErrorMessage;
            bool result = JsonSerializationUtils.SerializeToFile(config, fname, true, true);

            Assert.IsTrue(result);

            config = null;

            config = JsonSerializationUtils.DeserializeFromFile(fname, typeof(AutoConfigFileConfiguration)) as
                     AutoConfigFileConfiguration;

            Assert.IsNotNull(config);
            Assert.IsTrue(config.ApplicationName == "New App");
            Assert.IsTrue(config.DebugMode == DebugModes.DeveloperErrorMessage);
        }
Beispiel #6
0
 public static bool SaveUsersToJsonFile(List <UserEntry> users, string filename)
 {
     return(JsonSerializationUtils.SerializeToFile(users, filename, throwExceptions: true, formatJsonOutput: true));
 }
Beispiel #7
0
        public override void Write(HttpRequestData result)
        {
            // don't log request detail data for non errors over a certain no of requests
            if (!result.IsError && RequestsProcessed > 30000)
            {
                // always clear response
                result.ResponseContent = null;

                // detail data only if we explicitly requested
                if (_stressTester.Options.CaptureMinimalResponseData)
                {
                    result.Headers         = null;
                    result.ResponseHeaders = null;
                    result.FullRequest     = null;
                    result.RequestContent  = null;
                }
            }

            bool writeOut     = false;
            var  savedResults = Results;
            int  savedCount   = 0;

            lock (InsertLock)
            {
                Results.Add(result);
                RequestsProcessed++;
                if (result.IsError)
                {
                    RequestsFailed++;
                }

                if (Results.Count >= MaxCollectionItems)
                {
                    FileCount++;
                    savedCount = FileCount;
                    writeOut   = true;

                    Results = null;
                    Results = new List <HttpRequestData>();
                }
            }

            if (writeOut)
            {
                //Console.WriteLine();
                ThreadPool.QueueUserWorkItem((parm) =>
                {
                    //Console.WriteLine("QUWI Thread: " + Thread.CurrentThread.ManagedThreadId);
                    FileWriteParms parms = (FileWriteParms)parm;

                    var file = Path.Combine(TempFolderName, BaseFilename + parms.FileCount + ".json");
                    JsonSerializationUtils.SerializeToFile(parms.Requests, file, false);

                    //SerializationUtils.SerializeObject(parms.Requests, file, true);

                    //if (ResultsList == null)
                    //    ResultsList = new List<List<HttpRequestData>>();

                    //ResultsList.Add(parms.Requests);
                    ////ResultsList.Add(null);
                    //ResultsList[ResultsList.Count-1] = parms.Requests;

                    //var r = parms.Requests;
                    //Console.WriteLine("Queued Item " + parms.FileCount  + " " + r.Count);

                    //IFormatter formatter = new BinaryFormatter();
                    //Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None);
                    //formatter.Serialize(stream, parms.Requests);
                    //stream.Close();
                }, new FileWriteParms {
                    FileCount = savedCount, Requests = savedResults
                });

                //Console.WriteLine("Queue Use Worker Item time: " + swatch.ElapsedTicks.ToString("N0") + " " + Thread.CurrentThread.ManagedThreadId);
            }
        }
        public string Export(string name, List <HttpRequestData> requests, StressTesterConfiguration config, string filename = null)
        {
            var pm = new PostmanCollection();

            foreach (var request in requests)
            {
                pm.info._postman_id = Guid.NewGuid().ToString();
                if (!string.IsNullOrEmpty(name))
                {
                    pm.info.name = name;
                }
                else
                {
                    pm.info.name = "Collection-" + DataUtils.GenerateUniqueId(8);
                }
                pm.info.schema = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json";

                var item = new Item();
                pm.item.Add(item);

                item.name = request.Url;

                var req = new Request();
                item.request = req;

                req.url    = new Url();
                req.method = request.HttpVerb;

                var body = new Body();
                req.body  = body;
                body.mode = "raw";
                body.raw  = request.RequestContent;

                // don't copy over credentials explicitly
                //if (!string.IsNullOrEmpty(config.Username))
                //{
                //    req.auth = new Auth();
                //    req.auth.type = "ntlm";
                //    var ntlm = new List<Ntlm>();
                //    req.auth.ntlm = ntlm;
                //    ntlm.Add(new Ntlm {key = "username", value = config.Username});
                //    ntlm.Add(new Ntlm {key = "password", value = ""});
                //}

                foreach (var header in request.Headers)
                {
                    req.header.Add(new Header
                    {
                        key = header.Name, name = header.Name, value = header.Value, type = "text"
                    });
                }

                req.url.raw      = request.Url;
                req.url.protocol = "http";
                req.url.host.Add(request.Host);
            }

            if (!string.IsNullOrEmpty(filename))
            {
                if (JsonSerializationUtils.SerializeToFile(pm, filename, false, true))
                {
                    return("OK");
                }

                return(null);
            }

            return(JsonSerializationUtils.Serialize(pm, false, formatJsonOutput: true));
        }