public static CountryIpIntervalCollection Load(string fileName)
        {
            var serializer = SerializerManager.GetByFileName(fileName);
            var list       = serializer.DeserializeFromFile <List <CountryIpInterval> >(fileName);

            return(new CountryIpIntervalCollection(list));
        }
Exemple #2
0
        private static void Init()
        {
            if (_init)
            {
                return;
            }
            _init = true;

            var queueSettings = Core.GetSettings <QueueConfigurationSettings>();

            if (string.IsNullOrEmpty(queueSettings.ConfigFile))
            {
                Core.Log.Warning("The queues configuration file wasn't setted.");
                return;
            }
            queueSettings.ServerName = queueSettings.ServerName ?? Core.ApplicationName;

            var queuesConfigFile = queueSettings.ConfigFile;

            queuesConfigFile = queuesConfigFile?.Replace("{EnvironmentName}", Core.EnvironmentName);
            queuesConfigFile = queuesConfigFile?.Replace("{MachineName}", Core.MachineName);
            queuesConfigFile = queuesConfigFile?.Replace("{ApplicationName}", Core.ApplicationName);
            queuesConfigFile = queuesConfigFile?.Replace("{InstanceId}", Core.InstanceIdString);
            queuesConfigFile = Factory.ResolveLowLowFilePath(queuesConfigFile);
            Core.Log.InfoBasic("Loading queues configuration: {0}", queuesConfigFile);

            try
            {
                var value = queuesConfigFile.ReadTextFromFile();
                value = Core.ReplaceSettingsTemplate(value);
                value = Core.ReplaceEnvironmentTemplate(value);
                var serializer = SerializerManager.GetByFileName <ITextSerializer>(queuesConfigFile);
                _queues = serializer.DeserializeFromString <MQueuesConfiguration>(value);
            }
            catch (Exception ex)
            {
                throw new Exception($"The Queues config file: {queuesConfigFile} can't be deserialized.", ex);
            }

            if (_queues is null)
            {
                Core.Log.Warning("The Queues configuration file is null or empty.");
                return;
            }

            if (_queues.Items?.Contains(queueSettings.ServerName) == true)
            {
                _queueServer = _queues.Items[queueSettings.ServerName];
            }
        }
Exemple #3
0
        private static void Init()
        {
            if (_init)
            {
                return;
            }
            _init = true;

            var cacheSettings = Core.GetSettings <CacheConfigurationSettings>();

            if (string.IsNullOrEmpty(cacheSettings.ConfigFile))
            {
                return;
            }

            //Cache configuration
            var cachesConfigFile = cacheSettings.ConfigFile;

            cachesConfigFile = cachesConfigFile.Replace("{EnvironmentName}", Core.EnvironmentName);
            cachesConfigFile = cachesConfigFile.Replace("{MachineName}", Core.MachineName);
            cachesConfigFile = cachesConfigFile.Replace("{ApplicationName}", Core.ApplicationName);
            cachesConfigFile = Factory.ResolveLowLowFilePath(cachesConfigFile);
            Core.Log.InfoBasic("Loading cache server configuration: {0}", cachesConfigFile);

            try
            {
                var value = cachesConfigFile.ReadTextFromFile();
                value = Core.ReplaceSettingsTemplate(value);
                value = Core.ReplaceEnvironmentTemplate(value);
                var serializer = SerializerManager.GetByFileName <ITextSerializer>(cachesConfigFile);
                _serverCacheSettings = serializer.DeserializeFromString <CacheSettings>(value);
            }
            catch (Exception ex)
            {
                throw new Exception($"The Cache config file: {cachesConfigFile} can't be deserialized.", ex);
            }

            if (_serverCacheSettings == null)
            {
                Core.Log.Warning("The Cache configuration file is null or empty.");
                return;
            }

            _defaultCacheConfiguration = _serverCacheSettings.Caches?.FirstOrDefault((c, cSettings) => c.Name == (cSettings.ServerName ?? Core.ApplicationName), cacheSettings);
            _defaultServerOptions      = _defaultCacheConfiguration?.ServerOptionsList?.FirstOf(
                c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true && c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true,
                c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true,
                c => c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true,
                c => c.EnvironmentName.IsNullOrWhitespace());
        }
Exemple #4
0
        private static void Init()
        {
            if (_init)
            {
                return;
            }
            _init = true;

            var cacheSettings = Core.GetSettings <CacheConfigurationSettings>();

            if (string.IsNullOrEmpty(cacheSettings.ConfigFile))
            {
                return;
            }

            //Cache configuration
            var cachesConfigFile = cacheSettings.ConfigFile;

            cachesConfigFile = cachesConfigFile.Replace("{EnvironmentName}", Core.EnvironmentName);
            cachesConfigFile = cachesConfigFile.Replace("{MachineName}", Core.MachineName);
            cachesConfigFile = cachesConfigFile.Replace("{ApplicationName}", Core.ApplicationName);
            cachesConfigFile = Factory.ResolveLowLowFilePath(cachesConfigFile);
            Core.Log.InfoBasic("Loading cache client configuration: {0}", cachesConfigFile);

            try
            {
                var value = cachesConfigFile.ReadTextFromFile();
                value = Core.ReplaceSettingsTemplate(value);
                value = Core.ReplaceEnvironmentTemplate(value);
                var serializer = SerializerManager.GetByFileName <ITextSerializer>(cachesConfigFile);
                _settings = serializer.DeserializeFromString <CacheSettings>(value);
            }
            catch (Exception ex)
            {
                throw new Exception($"The Cache config file: {cachesConfigFile} can't be deserialized.", ex);
            }

            if (_settings != null)
            {
                return;
            }
            Core.Log.Warning("The Cache configuration file is null or empty.");
        }
Exemple #5
0
        protected override void OnHandler(ParameterHandlerInfo info)
        {
            Core.Log.Warning("Starting Serializer TEST");

            if (info.Arguments?.Contains("/complex") == true)
            {
                var file       = "c:\\temp\\complex.test.nbin.gz";
                var serializer = SerializerManager.GetByFileName(file);

                AssemblyResolverManager.RegisterDomain(new[] { @"C:\AGSW_GIT\Travel\src\Flights\Engines\Services\Agsw.Travel.Flights.Engines.Service\bin\Release\netcoreapp2.2" });
                //AssemblyResolverManager.RegisterDomain(new[] { @"C:\Repo\AgswGit\Travel\src\Flights\Engines\Services\Agsw.Travel.Flights.Engines.Service\bin\Release\netcoreapp2.2" });

                object value = null;
                try
                {
                    value = serializer.DeserializeFromFile <object>(file);
                    //value = rMsg.Body.GetValue();
                }
                catch (DeserializerException exGO)
                {
                    var jsonSerializer = new JsonTextSerializer {
                        Indent = true
                    };
                    jsonSerializer.SerializeToFile(exGO.Value, "c:\\temp\\complexObject-GenericObject.json");

                    var val = exGO.Value["Products"][5];
                }

                RunTestEx(value, 500, null);
                //GC.Collect();
                //GC.WaitForFullGCComplete();
                //RunTestEx(value, 200, new GZipCompressor());
                //GC.Collect();
                //GC.WaitForFullGCComplete();
                //RunTestEx(value, 200, new DeflateCompressor());

                return;
            }

            var sTest = new STest
            {
                FirstName = "Daniel",
                LastName  = "Redondo",
                Age       = 33,
                value     = 166
            };

            var collection = new List <List <STest> >();

            for (var i = 0; i <= 10; i++)
            {
                var colSTest = new List <STest>
                {
                    sTest, sTest, sTest, sTest, sTest, sTest,
                    sTest, sTest, sTest, sTest, sTest, sTest,
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 0, Age = 1, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 1, Age = 2, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 2, Age = 3, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 3, Age = 4, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 4, Age = 5, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 5, Age = 6, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 6, Age = 7, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 7, Age = 8, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 8, Age = 9, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 9, Age = 10, Brother = sTest
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 10, Age = 11
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 11, Age = 12
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 12, Age = 13
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 13, Age = 14
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 14, Age = 15
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 15, Age = 16
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 16, Age = 17
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 17, Age = 18
                    },
                    new STest {
                        FirstName = "Person", LastName = "Person" + i + "." + i + 18, Age = 19
                    },
                    //new STest2 { FirstName = "Person" , LastName = "Person" + i + "." + i+19, Age = 20, New = "This is a test" }
                };
                collection.Add(colSTest);
            }

            var lt = new List <STest>
            {
                new STest {
                    FirstName = "Name1", LastName = "LName1", Age = 11
                },
                //new STest2 { FirstName = "Name2" , LastName = "LName2", Age = 20, New = "This is a test" }
            };

            var lt2 = new List <Test3>
            {
                new Test3 {
                    Values = new List <int> {
                        2, 3, 4, 5
                    }
                },
                new Test3 {
                    Values = new List <int> {
                        10, 11, 12, 13
                    }
                }
            };

            var dct = new Dictionary <string, int>
            {
                ["Value1"] = 1,
                ["Value2"] = 2,
                ["Value3"] = 3,
            };

            var colClone = collection[0].DeepClone();
            var clone    = collection.DeepClone();



            if (info.Arguments?.Contains("/parallel") == true)
            {
                RunSingleTest(collection[0], 2, false);
                Core.Log.InfoBasic("Press ENTER to Start:");
                Console.ReadLine();
                Task.WaitAll(
                    Enumerable.Range(0, 8).Select(i => Task.Run(() => RunSingleTest(collection[0], 200_000, false))).ToArray()
                    );
                Console.ReadLine();
                return;
            }

            RunTest(collection[0], 200_000, false);
        }
Exemple #6
0
        public async Task <ActionResult> UploadFile()
        {
            try
            {
                if (!Request.Query.TryGetValue("name", out var name))
                {
                    throw new Exception("You must specify a name of the file.");
                }

                if (Request.ContentLength.HasValue && Request.ContentLength.Value > 2097152)
                {
                    throw new Exception("The file is too large.");
                }

                object      obj;
                SessionData sessionData;

                var isSerializedObject = ((string)name).IndexOf(SerializedObject.FileExtension, StringComparison.OrdinalIgnoreCase) > -1;

                var serializer = SerializerManager.GetByFileName(name);
                if (isSerializedObject || (serializer != null && serializer.SerializerType == SerializerType.Binary))
                {
                    if (isSerializedObject)
                    {
                        Core.Log.InfoBasic("SerializedObject found, deserializing...");
                        obj = SerializedObject.FromStream(Request.Body);
                    }
                    else
                    {
                        Core.Log.InfoBasic("Serializer {0} found, deserializing...", serializer.ToString());
                        obj = serializer.Deserialize(Request.Body, typeof(object));
                    }
                    sessionData            = HttpContext.Session.GetSessionData();
                    sessionData.FilePath   = name;
                    sessionData.FileObject = obj;
                    HttpContext.Session.SetSessionData(sessionData);
                    Core.Log.InfoBasic("File {0} was loaded.", name);
                    return(new ObjectResult(new FileLoadedStatus
                    {
                        FilePath = sessionData.FilePath,
                        ObjectType = sessionData.FileObject?.GetType().Name
                    }));
                }

                Core.Log.Warning("The serializer for file {0} wasn't found.", name);
                var extension = Path.GetExtension(name);

                if (string.Equals(extension, ".txt", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".html", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".htm", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".js", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".ini", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".srt", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".css", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".ts", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".vue", StringComparison.OrdinalIgnoreCase) ||
                    serializer?.SerializerType == SerializerType.Text)
                {
                    obj = await Request.Body.TextReadToEndAsync();

                    sessionData            = HttpContext.Session.GetSessionData();
                    sessionData.FilePath   = name;
                    sessionData.FileObject = obj;
                    HttpContext.Session.SetSessionData(sessionData);
                    Core.Log.InfoBasic("File {0} was loaded as text data.", name);
                    return(new ObjectResult(new FileLoadedStatus
                    {
                        FilePath = sessionData.FilePath,
                        ObjectType = sessionData.FileObject?.GetType().Name
                    }));
                }

                obj                    = (await Request.Body.ReadAllBytesAsync()).AsArray();
                sessionData            = HttpContext.Session.GetSessionData();
                sessionData.FilePath   = name;
                sessionData.FileObject = obj;
                HttpContext.Session.SetSessionData(sessionData);
                Core.Log.InfoBasic("File {0} was loaded as bytes data.", name);
                return(new ObjectResult(new FileLoadedStatus
                {
                    FilePath = sessionData.FilePath,
                    ObjectType = sessionData.FileObject?.GetType().Name
                }));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(new SerializableException(ex)));
            }
        }
Exemple #7
0
        public async Task <ActionResult> LoadFile()
        {
            try
            {
                object      obj;
                SessionData sessionData;
                Type        fileType = null;

                if (Request.Query.TryGetValue("type", out var type))
                {
                    fileType = Core.GetType(type);
                }
                if (!Request.Query.TryGetValue("path", out var path))
                {
                    return(new ObjectResult(new FileLoadedStatus {
                        Loaded = false
                    }));
                }
                if (string.IsNullOrWhiteSpace(path))
                {
                    return(new ObjectResult(new FileLoadedStatus {
                        Loaded = false
                    }));
                }
                path = Path.GetFullPath(path);
                if (!System.IO.File.Exists(path))
                {
                    return(new ObjectResult(new FileLoadedStatus {
                        FilePath = path, Loaded = false
                    }));
                }

                var isSerializedObject = ((string)path).IndexOf(SerializedObject.FileExtension, StringComparison.OrdinalIgnoreCase) > -1;

                var serializer = SerializerManager.GetByFileName(path);
                if (isSerializedObject || (serializer != null && (serializer.SerializerType == SerializerType.Binary || fileType != null)))
                {
                    try
                    {
                        if (isSerializedObject)
                        {
                            Core.Log.InfoBasic("SerializedObject found, deserializing...");
                            obj = await SerializedObject.FromFileAsync(path);
                        }
                        else
                        {
                            Core.Log.InfoBasic("Serializer {0} found, deserializing...", serializer.ToString());
                            obj = serializer.DeserializeFromFile(fileType, path);
                        }
                        sessionData            = HttpContext.Session.GetSessionData();
                        sessionData.FilePath   = path;
                        sessionData.FileObject = obj;
                        HttpContext.Session.SetSessionData(sessionData);
                        Core.Log.InfoBasic("File {0} was loaded.", path);
                        return(new ObjectResult(new FileLoadedStatus
                        {
                            FilePath = sessionData.FilePath,
                            ObjectType = sessionData.FileObject?.GetType().Name
                        }));
                    }
                    catch (Exception ex)
                    {
                        Core.Log.Write(ex);
                        if (!isSerializedObject)
                        {
                            Core.Log.InfoBasic("Trying to deserialize from a continous stream...");
                            using (var fs = System.IO.File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                            {
                                var lstObj = new List <object>();
                                while (fs.Position != fs.Length)
                                {
                                    var item = serializer.Deserialize <object>(fs);
                                    if (item != null)
                                    {
                                        lstObj.Add(item);
                                    }
                                }
                                obj                    = lstObj;
                                sessionData            = HttpContext.Session.GetSessionData();
                                sessionData.FilePath   = path;
                                sessionData.FileObject = obj;
                                HttpContext.Session.SetSessionData(sessionData);
                                Core.Log.InfoBasic("File {0} was loaded.", path);
                                return(new ObjectResult(new FileLoadedStatus
                                {
                                    FilePath = sessionData.FilePath,
                                    ObjectType = sessionData.FileObject?.GetType().Name
                                }));
                            }
                        }
                    }
                }

                Core.Log.Warning("The serializer for file {0} wasn't found.", path);
                var extension = Path.GetExtension(path);

                if (string.Equals(extension, ".txt", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".html", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".htm", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".js", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".log", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".ini", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".srt", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".css", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".ts", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(extension, ".vue", StringComparison.OrdinalIgnoreCase) ||
                    serializer?.SerializerType == SerializerType.Text)
                {
                    using (var fs = System.IO.File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        using (var sr = new StreamReader(fs))
                            obj = sr.ReadToEnd();
                    sessionData            = HttpContext.Session.GetSessionData();
                    sessionData.FilePath   = path;
                    sessionData.FileObject = obj;
                    HttpContext.Session.SetSessionData(sessionData);
                    Core.Log.InfoBasic("File {0} was loaded as text data.", path);
                    return(new ObjectResult(new FileLoadedStatus
                    {
                        FilePath = sessionData.FilePath,
                        ObjectType = sessionData.FileObject?.GetType().Name
                    }));
                }

                using (var fs = System.IO.File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (var sr = new BinaryReader(fs))
                        obj = sr.ReadBytes((int)fs.Length);
                sessionData            = HttpContext.Session.GetSessionData();
                sessionData.FilePath   = path;
                sessionData.FileObject = obj;
                HttpContext.Session.SetSessionData(sessionData);
                Core.Log.InfoBasic("File {0} was loaded as bytes data.", path);
                return(new ObjectResult(new FileLoadedStatus
                {
                    FilePath = sessionData.FilePath,
                    ObjectType = sessionData.FileObject?.GetType().Name
                }));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(new SerializableException(ex)));
            }
        }