예제 #1
0
 /// <summary>
 /// A class used for application logging.
 /// </summary>
 /// <param name="logger">The log function.</param>
 /// <param name="timestamp">Whether to put a timestamp on all logs.</param>
 /// <param name="timeformat">The format of the timestamp.</param>
 public Logger(LogFunction logger, bool timestamp = true, string timeformat = "HH:mm:ss: ")
 {
     this.LoggerFunction = logger;
     this.Timestamp = timestamp;
     this.Timeformat = timeformat;
     this.Enabled = true;
 }
예제 #2
0
        /// <summary>
        /// Log object constructor.
        /// </summary>
        /// <param name="type">The type of the event being logged.</param>
        /// <param name="function">The function executing when the event occured.</param>
        /// <param name="action">The action being performed when the event occured.</param>
        /// <param name="Message">A specific message associated with the event being logged.</param>
        /// <param name="user">The user of the system when the event occured.</param>
        /// <param name="timestamp">The date and time when the event was logged (set in DB).</param>
        public LogEntry(LogType type, LogFunction function, LogAction action, DateTime timestamp, long id, string message, Person user)
        {
            Type = type;
            Function = function;
            Action = action;

            ID = id;
            Timestamp = timestamp;
            Message = message;
            User = user;
        }
예제 #3
0
 /*
  * Public Methods
  */
 /// <summary>
 /// Set the log function to use
 /// </summary>
 /// <param name="logWriter">User defined log function</param>
 public void SetLogger(LogFunction logWriter)
 {
     Logger = logWriter;
 }
예제 #4
0
        static void Main(string[] args)
        {
            //var set = new SettlementProcess_MEB();
            //var crD = new DateTime(2018,08,05);
            //var trD = new DateTime(2018, 06, 05);
            //using (var con = new RepoBase().OpenConnection("Data Source=.;Initial Catalog=SettlementMaster;User Id=sa;password=(oneGod)"))
            //{

            // set.LogErrorMessage(12, "12345", "1234", DateTime.Now, "Test", crD, trD, "abc123",23456, con);
            //}
            //var df = DateTime.Compare(DateTime.Now.Date, new DateTime(2018,01,02));



            //connect.TranxEnquiry();
            //var obj = new requestPaymentObj()
            //{
            // Beneficiary = "Usman Yusuf Olawale",
            // AccountNumber = "0015204612",
            // Amount = "30000",
            // Narration = "OKOK",
            // SortCode = "033"
            //};
            //var obj2 = new requestPaymentObj()
            //{
            // Beneficiary = "Usman Yusuf Olawale",
            // AccountNumber = "0015204612",
            // Amount = "30000",
            // Narration = "OKOK",
            // SortCode = "033"
            //};
            //var gh = new jsonAuthKey()
            //{
            // AppUser = "******",
            // Password = "******",
            // FileName = "FilenameUploaded",
            // ScheduleId = "488449399393",
            // DebitSortCode = "050",
            // DebitAccountNumber = "0123456789"
            //};
            //var dList = new List<requestPaymentObj>();
            //dList.Add(obj);
            //dList.Add(obj2);
            //var jsonPay = JsonConvert.SerializeObject(dList);
            //var resp = @"{""?xml"":{""@version"":""1.0"",""@encoding"":""UTF - 8""},""PaymentResponse"":{""Header"":{""ScheduleId"":""48844938989879086789078798888799388"",""ClientId"":""NIBSS_V2001"",""DebitSortCode"":""050"",""DebitAccountNumber"":""0123456789"",""Status"":""16""},""HashValue"":""""}}";
            //var objreq = JsonConvert.DeserializeObject<PayResponse>(resp);

            //var jsonAuth = JsonConvert.SerializeObject(gh);
            //var objreq2 = JsonConvert.DeserializeObject<jsonAuthKey>(jsonAuth);
            //Console.ReadLine();
            //PostNaps();
            //AspNetUser rec = new AspNetUser()
            //{
            // DeptCode = "SFT",
            // UserName = "******",
            // DeptName = "",
            // FirstName = "Yusuf",
            // LastName = "Usman",
            // CreateDate = DateTime.Now,
            // Email = "*****@*****.**",

            //};
            //AuditHelper.PostAudit(null, rec, "I", "test", "test2", DateTime.Now,"key", "AspNetUsers", 1);

            //
            //var d = new DateTime(2018, 01, 2);
            //var rpt = new Naps();
            //var rst = rpt.GenerateNaps(d, "1234", "A", "12345");
            //var d = new DateTime(2017,10, 4);
            //var currentDay = d.Day;
            //var daysInMonth = DateTime.DaysInMonth(d.Year, d.Month);
            //var SETTLEMENTDATE = d.AddDays((daysInMonth - currentDay));
            //var daysAdded = 0;
            //for (int i = 1; i <= daysInMonth; i++)
            //{
            // //if(WeekendList SETTLEMENTDATE.DayOfWeek)
            // if (daysAdded == 2)
            // {
            // break;
            // }
            // var hj = GetWeekendList();
            // SETTLEMENTDATE = SETTLEMENTDATE.AddDays(1);
            // if (hj.Contains(SETTLEMENTDATE.DayOfWeek))
            // {
            // continue;
            // }
            // daysAdded++;
            // //sett
            //}
            //13 - 19
            //var d = new DateTime(2017, 11, 19);
            //var currentDay = (int)d.DayOfWeek;
            //int daysAdded = 0;
            //if (currentDay != 0)
            //{
            // daysAdded = (7 - currentDay) + 1;
            //}
            //else
            //{
            // daysAdded = 1;
            //}
            //var hh = d.AddDays(daysAdded);
            //var curDay = hh.DayOfWeek;
            /*---DOWNLOAD REPORT*/
            // var dtMain = rptSett.generateDS(null,"","ALL", "U", null, "2018-01-02", null, null);
            // var excelBytes = ExcelHelper.ExportDataSet(dtMain);
            /*---REPORT GENERATION TEST*/
            //string reportPath = !string.IsNullOrEmpty(ConfigurationManager.AppSettings["ReportPath"]) ? Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ReportPath"]) : string.Empty;
            //string logopath = !string.IsNullOrEmpty(ConfigurationManager.AppSettings["LogoPath"]) ? Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["LogoPath"]) : string.Empty;
            //IMainReport _repoSETT = new MainReport();
            //var setDate = new DateTime(2017, 11, 20);
            //string sett = _repoSETT.RPT_GenSettlementMASTER(setDate, reportPath, logopath, null);
            /*---END OF REPORT GENERATION---*/

            //////try
            //////{
            ////// var connect = new NapsConnect();
            ////// connect.PostNapsXPEApi();
            //////}
            //////catch (Exception ex)
            //////{
            ////// var test = ex.Message;
            ////// throw;
            //////}

            string destDb = ConfigurationManager.AppSettings["DEST_DB"].ToString();

            //using (var con = new RepoBase().OpenConnection(destDb))
            //{
            // var opdate = DateTime.Now;
            // var p1 = new DynamicParameters();
            // p1.Add("@P_DATE", opdate, DbType.Date);
            // var sql = "proc_set_PostToSettlementDetail";
            // var rec = con.Execute(sql, p1,commandTimeout:0, commandType: CommandType.StoredProcedure);
            //}
            LogFunction           lgfn        = new LogFunction();
            MEBCollectionClass    TLAStarter  = new MEBCollectionClass();
            SettlementProcess_MEB TLAStarter2 = new SettlementProcess_MEB();

            NapsConnect connect = new NapsConnect();

            // string dtFrom2 = DateTime.Today.ToString("dd-MMM-yyyy");
            // //If Scheduled Time is passed set Schedule for the next day.
            lgfn.loginfoMSG(DateTime.Now.ToString() + " [POS PROCESS] INFO Timer Initializing", null, null);


            try
            {
                //TLAStarter.MEBProcess();
                var    random      = new Random((int)DateTime.Now.Ticks);
                var    randomValue = random.Next(1000000, 9999999);
                string batchno     = randomValue.ToString();

                // new NapsConnect().TranxEnquiryApi();
                //////Parallel.Invoke(() =>
                //////{
                //////    new SettlementProcess_MEB().SettProcess(batchno, "2019-05-20");
                //////});

                // TLAStarter.ProcessSettlement(batchno);
                ///new SettProcess_POS().SettProcessPOS(batchno, "2019-06-10");
                //Process RuN

                //pull from DWHOUSE
                //TLAStarter.ProcessSettlement(batchno);

                ////pull from Traxmaster
                Console.WriteLine("Enter Process Date");
                var dt = Console.ReadLine();
                TLAStarter2.SettProcess(batchno, dt);

                ///NEFTData Posting
                //connect.PostNapsXPEApiNeft();
                ////////connect.TranxEnquiryApiNeft();
                ///

                ///NAPSData Posting
                //connect.PostNapsXPEApi();
                //connect.TranxEnquiryApi();


                //TLAStarter.ProcessSettlement(batchno);
                // Parallel.Invoke(() =>
                // {
                //     //new SettlementProcess_MEBVALU().SETTProcess(batchno, dtFrom);
                // },
                //() =>
                //{
                //    //new SettlementProcess_MEBVALU2().SETTProcess(batchno, dtFrom);
                //});
            }

            catch (Exception ex)
            {
                lgfn.loginfoMSG(DateTime.Now.ToString() + " [POS PROCESS] ERROR " + ex.Message, null, null);
            }

            //try
            //{
            // SettlementProcess_MEB gg = new SettlementProcess_MEB();
            // gg.SettProcess("124", "2017-09-29");
            //}
            //catch (Exception ex)
            //{

            //}
        }
예제 #5
0
        public async Task Log(int?PageId, int?ModuleId, int?UserId, string category, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args)
        {
            Log log = new Log();

            log.SiteId   = sitestate.Alias.SiteId;
            log.PageId   = PageId;
            log.ModuleId = ModuleId;
            log.UserId   = UserId;
            log.Url      = NavigationManager.Uri;
            log.Category = category;
            log.Feature  = feature;
            log.Function = Enum.GetName(typeof(LogFunction), function);
            log.Level    = Enum.GetName(typeof(LogLevel), level);
            if (exception != null)
            {
                log.Exception = exception.ToString();
            }
            log.Message         = message;
            log.MessageTemplate = "";
            log.Properties      = JsonSerializer.Serialize(args);
            await http.PostJsonAsync(this.ApiUrl, log);
        }
예제 #6
0
        public void Log(int siteId, LogLevel level, object @class, LogFunction function, Exception exception, string message, params object[] args)
        {
            Log log = new Log();

            log.SiteId = siteId;
            if (log.SiteId == -1)
            {
                var alias = _tenantManager.GetAlias();
                if (alias != null)
                {
                    log.SiteId = alias.SiteId;
                }
            }
            if (log.SiteId == -1)
            {
                return;                   // logs must be site specific
            }
            log.PageId   = null;
            log.ModuleId = null;
            log.UserId   = null;
            User user = _userPermissions.GetUser();

            if (user != null)
            {
                log.UserId = user.UserId;
            }
            log.Url = "";
            if (_accessor.HttpContext != null)
            {
                HttpRequest request = _accessor.HttpContext.Request;
                if (request != null)
                {
                    log.Url = $"{request.Scheme}://{request.Host}{request.Path}{request.QueryString}";
                }
            }

            Type type = Type.GetType(@class.ToString());

            if (type != null)
            {
                log.Category = type.AssemblyQualifiedName;
                log.Feature  = Utilities.GetTypeNameLastSegment(log.Category, 0);
            }
            else
            {
                log.Category = @class.ToString();
                log.Feature  = log.Category;
            }
            log.Function = Enum.GetName(typeof(LogFunction), function);
            log.Level    = Enum.GetName(typeof(LogLevel), level);
            if (exception != null)
            {
                log.Exception = exception.ToString();
            }
            log.Message         = message;
            log.MessageTemplate = "";
            try
            {
                log.Properties = JsonSerializer.Serialize(args);
            }
            catch // serialization error occurred
            {
                log.Properties = "";
            }
            Log(log);
        }
예제 #7
0
 public void Log(LogLevel level, object @class, LogFunction function, Exception exception, string message, params object[] args)
 {
     Log(-1, level, @class.GetType().AssemblyQualifiedName, function, exception, message, args);
 }
예제 #8
0
 public ServerDecider(LogFunction l)
 {
     _logger = l;
 }
예제 #9
0
 public RegistryReader(LogFunction logFunction)
 {
     this.LogFunc = logFunction;
 }
예제 #10
0
        public void Log(int SiteId, LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args)
        {
            Log log = new Log();

            if (SiteId == -1)
            {
                log.SiteId = null;
                Alias alias = TenantResolver.GetAlias();
                if (alias != null)
                {
                    log.SiteId = alias.SiteId;
                }
            }
            else
            {
                log.SiteId = SiteId;
            }
            log.PageId   = null;
            log.ModuleId = null;
            log.UserId   = null;
            User user = UserPermissions.GetUser();

            if (user != null)
            {
                log.UserId = user.UserId;
            }
            HttpRequest request = Accessor.HttpContext.Request;

            if (request != null)
            {
                log.Url = request.Scheme.ToString() + "://" + request.Host.ToString() + request.Path.ToString() + request.QueryString.ToString();
            }

            Type type = Type.GetType(Class.ToString());

            if (type != null)
            {
                log.Category = type.AssemblyQualifiedName;
                log.Feature  = Utilities.GetTypeNameLastSegment(log.Category, 0);
            }
            else
            {
                log.Category = Class.ToString();
                log.Feature  = log.Category;
            }
            log.Function = Enum.GetName(typeof(LogFunction), Function);
            log.Level    = Enum.GetName(typeof(LogLevel), Level);
            if (Exception != null)
            {
                log.Exception = Exception.ToString();
            }
            log.Message         = Message;
            log.MessageTemplate = "";
            try
            {
                log.Properties = JsonSerializer.Serialize(Args);
            }
            catch // serialization error occurred
            {
                log.Properties = "";
            }
            Log(log);
        }
예제 #11
0
 void ShutDown(string Reason)
 {
     DisConnectServer();
     Console.WriteLine($"ServerShutDown:{Reason}");
     LogFunction.WriteLog(sLogFilePath, $"Meagges:Server Shut Down\"{ Reason}\".");
 }
예제 #12
0
 /// <summary>
 /// Create a new logger with a specified Sink and a specified Minimum Log Level. Both
 /// may be null.
 /// </summary>
 /// <param name="_sink"></param>
 /// <param name="_level"></param>
 public static void Create(ILogSink _sink = null, ELogLevel _level = ELogLevel.Debug) => Logger = new LogFunction(_sink, _level);
예제 #13
0
 /// <summary>
 /// Remove the logger. Allows null-conditional operator to bypass all logging string
 /// formatting.
 /// </summary>
 public static void Delete() => Logger = null;
예제 #14
0
 public async Task LogCritical(LogFunction function, string message, params object[] args)
 {
     await _moduleBase.Log(null, LogLevel.Critical, function, null, message, args);
 }
예제 #15
0
 public async Task LogInformation(LogFunction function, string message, params object[] args)
 {
     await _moduleBase.Log(null, LogLevel.Information, function, null, message, args);
 }
예제 #16
0
        /// <summary>
        /// Tries to create an Leviathan Function expression if the function Uri correseponds to a supported Leviathan Function
        /// </summary>
        /// <param name="u">Function Uri</param>
        /// <param name="args">Function Arguments</param>
        /// <param name="scalarArgs">Scalar Arguments</param>
        /// <param name="expr">Generated Expression</param>
        /// <returns>Whether an expression was successfully generated</returns>
        public bool TryCreateExpression(Uri u, List <ISparqlExpression> args, Dictionary <String, ISparqlExpression> scalarArgs, out ISparqlExpression expr)
        {
            //If any Scalar Arguments are present then can't possibly be a Leviathan Function
            if (scalarArgs.Count > 0)
            {
                expr = null;
                return(false);
            }

            String func = u.ToString();

            if (func.StartsWith(LeviathanFunctionFactory.LeviathanFunctionsNamespace))
            {
                func = func.Substring(LeviathanFunctionFactory.LeviathanFunctionsNamespace.Length);
                ISparqlExpression lvnFunc = null;

                switch (func)
                {
                case LeviathanFunctionFactory.All:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new AllAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new AllAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for Leviathan all() aggregate");
                    }
                    break;

                case LeviathanFunctionFactory.Any:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new AnyAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new AnyAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for Leviathan any() aggregate");
                    }
                    break;

                case LeviathanFunctionFactory.Cartesian:
                    if (args.Count == 4)
                    {
                        lvnFunc = new CartesianFunction(args[0], args[1], args[2], args[3]);
                    }
                    else if (args.Count == 6)
                    {
                        lvnFunc = new CartesianFunction(args[0], args[1], args[2], args[3], args[4], args[5]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for Leviathan cartesian() function");
                    }
                    break;

                case LeviathanFunctionFactory.Cube:
                    if (args.Count == 1)
                    {
                        lvnFunc = new CubeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan cube() function");
                    }
                    break;

                case LeviathanFunctionFactory.DegreesToRadians:
                    if (args.Count == 1)
                    {
                        lvnFunc = new DegreesToRadiansFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan degrees-to-radians() function");
                    }
                    break;

                case LeviathanFunctionFactory.E:
                    if (args.Count == 1)
                    {
                        lvnFunc = new EFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan e() function");
                    }
                    break;

                case LeviathanFunctionFactory.Factorial:
                    if (args.Count == 1)
                    {
                        lvnFunc = new FactorialFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan factorial() function");
                    }
                    break;

                case LeviathanFunctionFactory.Ln:
                    if (args.Count == 1)
                    {
                        lvnFunc = new LeviathanNaturalLogFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan ln() function");
                    }
                    break;

                case LeviathanFunctionFactory.Log:
                    if (args.Count == 1)
                    {
                        lvnFunc = new LogFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        lvnFunc = new LogFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan log() function");
                    }
                    break;

                case LeviathanFunctionFactory.MD5Hash:
                    if (args.Count == 1)
                    {
                        lvnFunc = new MD5HashFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan md5hash() function");
                    }
                    break;

                case LeviathanFunctionFactory.Median:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new MedianAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new MedianAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan median() aggregate");
                    }
                    break;

                case LeviathanFunctionFactory.Mode:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new ModeAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new ModeAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan mode() aggregate");
                    }
                    break;

                case LeviathanFunctionFactory.None:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new NoneAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new NoneAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan none() aggregate");
                    }
                    break;

                case LeviathanFunctionFactory.NumericMax:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new NumericMaxAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new NumericMaxAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan nmax() aggregate");
                    }
                    break;

                case LeviathanFunctionFactory.NumericMin:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new NumericMinAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new NumericMinAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan nmin() aggregate");
                    }
                    break;

                case LeviathanFunctionFactory.Power:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SquareFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        lvnFunc = new PowerFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan pow() function");
                    }
                    break;

                case LeviathanFunctionFactory.Pythagoras:
                    if (args.Count == 2)
                    {
                        lvnFunc = new PythagoreanDistanceFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan pythagoras() function");
                    }
                    break;

                case LeviathanFunctionFactory.RadiansToDegrees:
                    if (args.Count == 1)
                    {
                        lvnFunc = new RadiansToDegreesFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan radians-to-degrees() function");
                    }
                    break;

                case LeviathanFunctionFactory.Random:
                    if (args.Count == 0)
                    {
                        lvnFunc = new RandomFunction();
                    }
                    else if (args.Count == 1)
                    {
                        lvnFunc = new RandomFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        lvnFunc = new RandomFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan rnd() function");
                    }
                    break;

                case LeviathanFunctionFactory.Reciprocal:
                    if (args.Count == 1)
                    {
                        lvnFunc = new ReciprocalFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan reciprocal() function");
                    }
                    break;

                case LeviathanFunctionFactory.Root:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SquareRootFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        lvnFunc = new RootFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan root() function");
                    }
                    break;

                case LeviathanFunctionFactory.Sha256Hash:
                    if (args.Count == 1)
                    {
                        lvnFunc = new Sha256HashFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan sha256hash() function");
                    }
                    break;

                case LeviathanFunctionFactory.Square:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SquareFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan sq() function");
                    }
                    break;

                case LeviathanFunctionFactory.SquareRoot:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SquareRootFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan sqrt() function");
                    }
                    break;

                case LeviathanFunctionFactory.Ten:
                    if (args.Count == 1)
                    {
                        lvnFunc = new TenFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan ten() function");
                    }
                    break;

                case LeviathanFunctionFactory.TrigCos:
                case LeviathanFunctionFactory.TrigCosInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new CosineFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigCosInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case LeviathanFunctionFactory.TrigCosec:
                case LeviathanFunctionFactory.TrigCosecInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new CosecantFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigCosecInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case LeviathanFunctionFactory.TrigCotan:
                case LeviathanFunctionFactory.TrigCotanInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new CotangentFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigCotanInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case LeviathanFunctionFactory.TrigSec:
                case LeviathanFunctionFactory.TrigSecInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SecantFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigSecInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case LeviathanFunctionFactory.TrigSin:
                case LeviathanFunctionFactory.TrigSinInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SineFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigSinInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case LeviathanFunctionFactory.TrigTan:
                case LeviathanFunctionFactory.TrigTanInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new TangentFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigTanInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;
                }

                if (lvnFunc != null)
                {
                    expr = lvnFunc;
                    return(true);
                }
            }
            expr = null;
            return(false);
        }
예제 #17
0
 public void Log(LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args)
 {
     Log(Level, Class.GetType().AssemblyQualifiedName, Function, null, Message, Args);
 }
예제 #18
0
        public async Task Log(Alias alias, int?pageId, int?moduleId, int?userId, string category, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args)
        {
            Log log = new Log();

            if (alias == null)
            {
                log.SiteId = _siteState.Alias.SiteId;
            }
            else
            {
                log.SiteId = alias.SiteId;
            }
            log.PageId   = pageId;
            log.ModuleId = moduleId;
            log.UserId   = userId;
            log.Url      = _navigationManager.Uri;
            log.Category = category;
            log.Feature  = feature;
            log.Function = Enum.GetName(typeof(LogFunction), function);
            log.Level    = Enum.GetName(typeof(LogLevel), level);
            if (exception != null)
            {
                log.Exception = exception.ToString();
            }
            log.Message         = message;
            log.MessageTemplate = "";
            log.Properties      = JsonSerializer.Serialize(args);
            await PostJsonAsync(Apiurl, log);
        }
예제 #19
0
 public LogEntry(LogType type, LogFunction function, LogAction action) : this(type, function, action, DateTime.Now, 0, "NA", new Person())
 {
 }
예제 #20
0
        /// <summary>
        /// Loads a project in the Editor, creating one experiment view model for every experiment in the project
        /// </summary>
        /// <param name="experiments">The list of experiments where loaded experiments are added</param>
        /// <param name="appDefinitions">The application definitions</param>
        /// <param name="log">The log function used to log messages</param>
        /// <param name="filename">The filename of the input project</param>
        static public void LoadExperiments(ref BindableCollection <ExperimentViewModel> experiments,
                                           Dictionary <string, string> appDefinitions, LogFunction log, string filename = null)
        {
            if (filename == null)
            {
                bool isOpen = OpenFileDialog(ref filename, ProjectDescription, ProjectFilter);
                if (!isOpen)
                {
                    return;
                }
            }

            XmlDocument badgerDoc = new XmlDocument();

            badgerDoc.Load(filename);
            XmlElement fileRoot = badgerDoc.DocumentElement;

            if (fileRoot.Name != XMLTags.BadgerNodeTag)
            {
                Data.CaliburnUtility.ShowWarningDialog("Malformed XML in experiment badger project file.", "ERROR");
                log("ERROR: malformed XML in experiment badger project file.");
                return;
            }

            XmlNode configNode;

            foreach (XmlNode experiment in fileRoot.ChildNodes)
            {
                if (experiment.Name == XMLTags.ExperimentNodeTag && experiment.ChildNodes.Count > 0)
                {
                    configNode = experiment.FirstChild;
                    experiments.Add(new ExperimentViewModel(appDefinitions[configNode.Name],
                                                            configNode, experiment.Attributes[XMLTags.nameAttribute].Value));
                }
                else
                {
                    Data.CaliburnUtility.ShowWarningDialog("Malformed XML in experiment queue file.", "ERROR");
                    log("ERROR: malformed XML in experiment queue file.");
                }
            }
        }
예제 #21
0
 public void Log(int siteId, LogLevel level, object @class, LogFunction function, string message, params object[] args)
 {
     Log(siteId, level, @class.GetType().AssemblyQualifiedName, function, null, message, args);
 }
예제 #22
0
        /// <summary>
        ///     Save an experiment batch: the list of (possibly forked) experiments is saved a as set of experiments
        ///     without forks and a .exp-batch file in the root directory referencing them all and the forks/values
        ///     each one took.
        /// </summary>
        /// <param name="experiments"></param>
        /// <param name="batchFilename"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public static int SaveExperimentBatchFile(BindableCollection <ExperimentViewModel> experiments,
                                                  string batchFilename, LogFunction log, ProgressUpdateFunction progressUpdateFunction)
        {
            //set culture as invariant to write numbers as in english
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            int experimentalUnitsCount = 0;

            if (experiments.Count == 0)
            {
                return(-1);
            }

            //Validate the experiments
            foreach (ExperimentViewModel experiment in experiments)
            {
                if (!experiment.Validate())
                {
                    Data.CaliburnUtility.ShowWarningDialog("The configuration couldn't be validated in " + experiment.Name
                                                           + ". Please check it", "VALIDATION ERROR");

                    return(-1);
                }
                experimentalUnitsCount += experiment.getNumForkCombinations();
            }

            //Dialog window asking for an output name
            if (batchFilename == "")
            {
                //Save dialog -> returns the experiment batch file
                var sfd = SaveFileDialog(ExperimentBatchDescription, ExperimentBatchFilter);
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    //When using multiple extensions, they are duplicated
                    //To fix this behavior, we remove from the first extension, then add it back
                    if (sfd.FileName.Contains(Extensions.ExperimentBatch))
                    {
                        batchFilename = sfd.FileName.Substring(0, sfd.FileName.IndexOf(Extensions.ExperimentBatch)) + Extensions.ExperimentBatch;
                    }
                    else
                    {
                        batchFilename = sfd.FileName + Extensions.ExperimentBatch;
                    }
                }
                else
                {
                    log("Error saving the experiment queue");
                    return(-1);
                }
            }
            string relPathToBatchDir = batchFilename.Remove(batchFilename.LastIndexOf(Extensions.ExperimentBatch));
            string bareBatchName     = Herd.Utils.GetFilename(relPathToBatchDir);

            relPathToBatchDir = Herd.Utils.GetRelativePathTo(Directory.GetCurrentDirectory(), relPathToBatchDir);
            // Clean output directory if it exists
            if (Directory.Exists(relPathToBatchDir))
            {
                try { Directory.Delete(relPathToBatchDir, true); }
                catch
                {
                    Data.CaliburnUtility.ShowWarningDialog("It has not been possible to remove the directory: "
                                                           + relPathToBatchDir + ". Make sure that it's not been using for other app.", "ERROR");
                    log("Error saving the experiment queue");
                    return(-1);
                }
            }
            string relPathToBatchFile = relPathToBatchDir + Extensions.ExperimentBatch;

            progressUpdateFunction?.Invoke(0.0);
            int numExperimentalUnitsSaved = 0;

            using (StreamWriter batchFileWriter = new StreamWriter(relPathToBatchFile))
            {
                // Write batch file header (i.e. open 'EXPERIMENT-BATCH' tag)
                batchFileWriter.WriteLine("<" + XMLTags.ExperimentBatchNodeTag + ">");

                foreach (ExperimentViewModel experimentViewModel in experiments)
                {
                    batchFileWriter.WriteLine("  <" + XMLTags.ExperimentNodeTag + " "
                                              + XMLTags.nameAttribute + "=\"" + experimentViewModel.Name + "\">");

                    foreach (AppVersion appVersion in experimentViewModel.AppVersions)
                    {
                        batchFileWriter.WriteLine(appVersion.ToString());
                    }

                    // Save the fork hierarchy and values. This helps to generate reports easier
                    experimentViewModel.SaveToStream(batchFileWriter, SaveMode.ForkHierarchy, "  ");

                    int numCombinations = experimentViewModel.getNumForkCombinations();
                    for (int i = 0; i < numCombinations; i++)
                    {
                        // Save the combination of forks as a new experiment
                        string experimentName = experimentViewModel.setForkCombination(i);

                        string relPathToExpUnitDir = relPathToBatchDir + "/" + experimentName;
                        Directory.CreateDirectory(relPathToExpUnitDir);
                        string relPathToExpUnitFile = relPathToExpUnitDir + "/" + experimentName + Extensions.Experiment;
                        experimentViewModel.Save(relPathToExpUnitFile, SaveMode.AsExperimentalUnit);
                        string relPathToExpUnitFileFromBatchDir = bareBatchName + "/" + experimentName + "/" + experimentName + Extensions.Experiment;

                        // Save the experiment reference in the root batch file. Open 'EXPERIMENTAL-UNIT' tag
                        // with its corresponding attributes.
                        batchFileWriter.WriteLine("    <" + XMLTags.ExperimentalUnitNodeTag + " "
                                                  + XMLTags.nameAttribute + "=\"" + experimentName + "\" "
                                                  + XMLTags.pathAttribute + "=\"" + relPathToExpUnitFileFromBatchDir + "\">");
                        // Write fork values in between
                        experimentViewModel.SaveToStream(batchFileWriter, SaveMode.ForkValues, "\t");
                        // Close 'EXPERIMENTAL-UNIT' tag
                        batchFileWriter.WriteLine("    </" + XMLTags.ExperimentalUnitNodeTag + ">");

                        numExperimentalUnitsSaved++;
                        progressUpdateFunction?.Invoke(numExperimentalUnitsSaved / (double)experimentalUnitsCount);
                    }

                    // Close 'EXPERIMENT' tag
                    batchFileWriter.WriteLine("  </" + XMLTags.ExperimentNodeTag + ">");
                }
                // Write batch file footer (i.e. close 'EXPERIMENT-BATCH' tag)
                batchFileWriter.WriteLine("</" + XMLTags.ExperimentBatchNodeTag + ">");
                log("Succesfully saved " + experiments.Count + " experiments");
            }

            return(experimentalUnitsCount);
        }
예제 #23
0
 public async Task Log(int?pageId, int?moduleId, int?userId, string category, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args)
 {
     await Log(null, pageId, moduleId, userId, category, feature, function, level, exception, message, args);
 }
예제 #24
0
 public LogEntry(LogType type, LogFunction function, LogAction action)
     : this(type, function, action, DateTime.Now, 0, "NA", new Person())
 {
 }
예제 #25
0
 /*
  * Public Methods
  */
 /// <summary>
 /// Set the log function to use
 /// </summary>
 /// <param name="logWriter">User defined log function</param>
 public void SetLogger(LogFunction logWriter)
 {
     Logger = logWriter;
 }
예제 #26
0
 public TestBehavior(LogFunction f)
 {
     _f = f;
 }