Beispiel #1
0
        public async Task <List <TodoListModel> > GetAllLists()
        {
            try
            {
                var lists = await database.QueryAsync <TodoListModel>("SELECT * FROM TodoList");

                foreach (TodoListModel list in lists)
                {
                    var todoItems = await GetTodoItems(list.Id);

                    if (todoItems != null && todoItems.Count > 0)
                    {
                        list.TodoItems = new List <TodoItemModel>(todoItems);
                    }
                    else
                    {
                        list.TodoItems = new List <TodoItemModel>();
                    }
                }

                return(lists);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(null);
            }
        }
        /// <summary>
        /// Navigates to the specified view with parameters and closes the current view.
        /// </summary>
        /// <param name="navModel">The nav model.</param>
        public virtual void NavigateWithClose(INavModel navModel)
        {
            var message = $"Navigating to {navModel.ViewName} with the following parameters:\n";

            message = navModel.NavigationParameters.Aggregate(message, (current, o) => current + $"{o.Key} - {o.Value}\n");
            Logger.Log(LogLevel.Info, message);
            try
            {
                RegionManager.RequestNavigate(Regions.MainRegion, navModel.ViewName, NavigationCallback,
                                              navModel.NavigationParameters);
                var vm = navModel.ViewModel as NavigationBaseViewModel;
                if (vm == null)
                {
                    Debug.WriteLine("VM NULL!!");
                    return;
                }
                navModel.ViewId = vm.ViewId;
                Close(navModel);
            }
            catch (Exception ex)
            {
                ErrorTracker.LogError(new ErrorModel(ex, Environment.UserName,
                                                     "NavigationBaseViewModel.NavigateWithClose"));
                Logger.Log(LogLevel.Error, "Failed to navigate to view. Location: NavigationBaseViewModel.NavigateWithClose");
                Logger.Log(LogLevel.Error, ex, ex.Message.Trim(), ex.StackTrace);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a Mod Script lexer for the given code, using the given error tracker.
        /// </summary>
        /// <param name="p_strCode">The code be lexed.</param>
        /// <param name="p_ertErrorTracker">The error tracker to use to log
        /// lexing errors.</param>
        /// <returns>A Mod Script lexer for the given code.</returns>
        public AntlrLexerBase CreateLexer(string p_strCode, ErrorTracker p_ertErrorTracker)
        {
            ModScriptLexer lexLexer = new ModScriptLexer(new ANTLRStringStream(p_strCode));

            lexLexer.ErrorTracker = p_ertErrorTracker;
            return(lexLexer);
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            var eTracker = new ErrorTracker(errorProviderLoginForm);

            if (string.IsNullOrWhiteSpace(txtUserName.Text))
            {
                eTracker.SetError(txtUserName, "Geçersiz alan");
            }

            if (string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                eTracker.SetError(txtPassword, "Geçersiz alan");
            }

            if (eTracker.Count != 0)
            {
                return;
            }

            if (UserService.IsValidLogin(txtUserName.Text, txtPassword.Text))
            {
                Logger.I("Succesfully logged in");
                Hide();
                var formHome = new MainForm();
                formHome.ShowDialog();

                Environment.Exit(0);
            }
            else
            {
                Logger.I("Invalid login");
                MessageBox.Show(Resources.invalid_credidentials);
            }
        }
Beispiel #5
0
        public async Task <bool> ChangeListActiveState(TodoListModel list)
        {
            try
            {
                list.Active = !list.Active;

                if (list.Active)
                {
                    var allLists = await database.QueryAsync <TodoListModel>("SELECT * FROM TodoList");

                    foreach (TodoListModel todolist in allLists)
                    {
                        todolist.Active = false;
                        await database.UpdateAsync(todolist);
                    }
                }

                await database.UpdateAsync(list);

                return(true);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(false);
            }
        }
Beispiel #6
0
        public async Task PackImagesIntoData(string[] inFiles, string outFile)
        {
            try
            {
                _syncContext.Post((s) => ErrorTracker.CurrentError = "Finding Images", null);
                var reader = new LunaDataWinReader(outFile);
                var images = GetOffsets(reader);

                _syncContext.Post((s) => ErrorTracker.CurrentError = "Packing Images", null);
                var writer = new LunaDataWinWriter(outFile);
                foreach (var file in inFiles)
                {
                    var imageDef = images.FirstOrDefault(x => string.Equals(x.FileName, Path.GetFileNameWithoutExtension(file), StringComparison.InvariantCultureIgnoreCase));
                    if (imageDef == null)
                    {
                        _syncContext.Post((s) => ErrorTracker.CurrentError = $"Could not find image match for {Path.GetFileName(file)}", null);
                        return;
                    }
                    await writer.WriteFile(imageDef, file);
                }
                var packedMsg = "Images Packed";
                _syncContext.Post((s) => ErrorTracker.CurrentError = packedMsg, null);
                _ = ErrorTracker.DelayClearError(packedMsg, 10000);
            }
            catch (Exception ex)
            {
                _syncContext.Post((s) => ErrorTracker.CurrentError = ex.Message, null);
            }
        }
        /// <summary>
        /// Closes the specified view.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="viewId">The view identifier.</param>
        public virtual void Close(dynamic viewModel, string viewId)
        {
            var region = RegionManager.Regions[Regions.MainRegion];

            for (var i = 0; i < region.Views.Count(); i++)
            {
                var v = (UserControl)region.Views.ElementAt(i);
                var d = v?.DataContext;
                if (d == null)
                {
                    continue;
                }
                if (d.GetType() != viewModel.GetType())
                {
                    continue;
                }
                if (((NavigationBaseViewModel)d).ViewId != viewId)
                {
                    continue;
                }
                try
                {
                    var fe = (FrameworkElement)v;
                    region.Remove(fe);
                }
                catch (Exception ex)
                {
                    ErrorTracker.LogError(new ErrorModel(ex, Environment.UserName, "NavigationBaseViewModel.Close"));
                    Logger.Log(LogLevel.Error, ex.Message.Trim(), ex.Data);
                }
            }
        }
Beispiel #8
0
        private bool ValidateTextboxes()
        {
            bool isValidated = true;

            foreach (Control control in this.Controls)
            {
                if (control is MetroTextBox)
                {
                    MetroTextBox textbox = control as MetroTextBox;

                    if (control.Text == string.Empty)
                    {
                        textbox.WithError = true;
                        textbox.BackColor = Color.FromArgb(255, 235, 238);

                        isValidated = false;
                        ErrorTracker.SetError(textbox, this.errorProvider);
                    }
                    else
                    {
                        textbox.BackColor = Color.White;
                        textbox.WithError = false;

                        ErrorTracker.RemoveError(textbox);
                    }
                }
            }

            ErrorTracker.DisplayError("This field cannot be empty.");

            return(isValidated);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            tvKayit.ExpandAll();
            RaporKontrol();

            _eTracker = new ErrorTracker(errorProviderHomePage);
        }
        /// <summary>
        /// Creates a CPL lexer for the given code, using the given error tracker.
        /// </summary>
        /// <param name="p_strCode">The code be lexed.</param>
        /// <param name="p_ertErrorTracker">The error tracker to use to log
        /// lexing errors.</param>
        /// <returns>A CPL lexer for the given code.</returns>
        public AntlrLexerBase CreateLexer(string p_strCode, ErrorTracker p_ertErrorTracker)
        {
            FONVCplLexer lexLexer = new FONVCplLexer(new ANTLRStringStream(p_strCode));

            lexLexer.SetErrorTracker(p_ertErrorTracker);
            return(lexLexer);
        }
Beispiel #11
0
        public async Task <TodoListModel> GetList(Guid listId)
        {
            try
            {
                var list = await database.QueryAsync <TodoListModel>("SELECT * FROM TodoList WHERE Id = ?", listId);

                if (list != null && list.Count > 0)
                {
                    var todoItems = await GetTodoItems(list[0].Id);

                    if (todoItems != null && todoItems.Count > 0)
                    {
                        list[0].TodoItems = new List <TodoItemModel>(todoItems);
                    }
                    else
                    {
                        list[0].TodoItems = new List <TodoItemModel>();
                    }
                    var listTodoItems = await GetTodoItems(list[0].Id);

                    return(list[0]);
                }

                return(null);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(null);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Creates a Mod Script parser for the given code, using the given error tracker.
        /// </summary>
        /// <param name="p_strCode">The code be parsed.</param>
        /// <param name="p_ertErrorTracker">The error tracker to use to log
        /// parsing errors.</param>
        /// <returns>A Mod Script parser for the given code.</returns>
        public AntlrParserBase CreateParser(string p_strCode, ErrorTracker p_ertErrorTracker)
        {
            AntlrLexerBase    lexLexer  = CreateLexer(p_strCode, p_ertErrorTracker);
            CommonTokenStream ctsTokens = new CommonTokenStream(lexLexer);
            ModScriptParser   prsParser = new ModScriptParser(ctsTokens);

            prsParser.ErrorTracker = p_ertErrorTracker;
            return(prsParser);
        }
        /// <summary>
        /// Creates a CPL parser for the given code, using the given error tracker.
        /// </summary>
        /// <param name="p_strCode">The code be parsed.</param>
        /// <param name="p_ertErrorTracker">The error tracker to use to log
        /// parsing errors.</param>
        /// <returns>A CPL parser for the given code.</returns>
        public AntlrParserBase CreateParser(string p_strCode, ErrorTracker p_ertErrorTracker)
        {
            AntlrLexerBase    lexLexer  = CreateLexer(p_strCode, p_ertErrorTracker);
            CommonTokenStream ctsTokens = new CommonTokenStream(lexLexer);
            FONVCplParser     prsParser = new FONVCplParser(ctsTokens, "");

            prsParser.SetErrorTracker(p_ertErrorTracker);
            return(prsParser);
        }
        public string UnloadVehicle(string storageName, int garageSlot)
        {
            Storage storage = this.storageRegistry.FirstOrDefault(x => x.Name == storageName);
            Vehicle vehicle = storage.GetVehicle(garageSlot);

            ErrorTracker.EmptyGarageSlot(vehicle);
            int unloadedProductsCount = storage.UnloadVehicle(garageSlot);

            return($"Unloaded {unloadedProductsCount}/{vehicle.Trunk.Count} products at {storageName}");
        }
Beispiel #15
0
 public virtual async Task RefreshTodoLists()
 {
     try
     {
         TodoLists = await cachingService.GetAllLists();
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #16
0
 public void OnNavigatedTo(INavigationParameters parameters)
 {
     try
     {
         Task.Run(async() => await RefreshTodoLists());
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
        /// <summary>
        /// Enables simple "using" syntax to easily detect <see cref="LogLevel.Fatal"/> or <see cref="LogLevel.Error"/>.
        /// </summary>
        /// <param name="this">This <see cref="IActivityMonitor"/>.</param>
        /// <param name="onFatal">An action that is called whenever a Fatal error occurs.</param>
        /// <param name="onError">An action that is called whenever an Error occurs.</param>
        /// <returns>A <see cref="IDisposable"/> object used to manage the scope of this handler.</returns>
        public static IDisposable OnError(this IActivityMonitor @this, Action onFatal, Action onError)
        {
            if (onFatal == null || onError == null)
            {
                throw new ArgumentNullException();
            }
            ErrorTracker tracker = new ErrorTracker(onFatal, onError);

            @this.Output.RegisterClient(tracker);
            return(Util.CreateDisposableAction(() => @this.Output.UnregisterClient(tracker)));
        }
Beispiel #18
0
        public HttpResponseMessage DeleteAllErrorTracker(HttpRequestMessage request, [FromBody] int errorTrackerId)
        {
            return(GetHttpResponse(request, () =>
            {
                var errorTracker = new ErrorTracker();

                _CoreService.DeleteAllErrorTracker();

                return request.CreateResponse <CodeEntities.ErrorTracker>(HttpStatusCode.OK, errorTracker);
            }));
        }
Beispiel #19
0
 public TodoItemView()
 {
     try
     {
         InitializeComponent();
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #20
0
 public static void RegisterServices(IContainerRegistry containerRegistry)
 {
     try
     {
         containerRegistry.RegisterSingleton <ICacheService, CacheService>();
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #21
0
 public TodoViewModel(ICacheService cacheService, INavigationService navigationService)
 {
     try
     {
         this.cachingService    = cacheService;
         this.navigationService = navigationService;
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #22
0
 protected override void RegisterTypes(IContainerRegistry containerRegistry)
 {
     try
     {
         IoCServices.RegisterServices(containerRegistry);
         IoCNavigation.RegisterViewsAndViewModels(containerRegistry);
     }
     catch (System.Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #23
0
        /// <summary>
        /// Parses the given CPL into an AST.
        /// </summary>
        /// <param name="p_strCplCode">The CPL to convert.</param>
        /// <returns>The AST built from the given CPL.</returns>
        private ITree GenerateAst(string p_strCplCode)
        {
            ErrorTracker    ertErrors = new ErrorTracker();
            AntlrParserBase cpbParser = ParserFactory.CreateParser(p_strCplCode, ertErrors);
            ITree           astCPL    = cpbParser.Parse();

            if (ertErrors.HasErrors)
            {
                throw new ArgumentException("Invalid CPL:" + Environment.NewLine + ertErrors.ToString(), "p_strCplCode");
            }
            return(astCPL);
        }
Beispiel #24
0
    public override object StringToField(string from)
    {
        //if you can't convert to date time.. .return null
        DateTime date;

        if (!DateTime.TryParse(from, out date))
        {
            ErrorTracker.Add(string.Format("Failed to parse date {0}.", from));
            return(null);
        }
        return(date);
    }
        public string SendVehicleTo(string sourceName, int sourceGarageSlot, string destinationName)
        {
            Storage sourceStorage      = this.storageRegistry.FirstOrDefault(x => x.Name == sourceName);
            Storage destinationStorage = this.storageRegistry.FirstOrDefault(x => x.Name == destinationName);

            ErrorTracker.SourceStorage(sourceStorage);
            ErrorTracker.DestinationStorage(destinationStorage);
            int     destinationGarageSlot = sourceStorage.SendVehicleTo(sourceGarageSlot, destinationStorage);
            Vehicle vehicle = sourceStorage.GetVehicle(sourceGarageSlot);

            return($"Sent {vehicle.GetType().Name} to {destinationName} (slot {destinationGarageSlot})");
        }
Beispiel #26
0
 public void OnNavigatedTo(INavigationParameters parameters)
 {
     try
     {
         TodoList = parameters.GetValue <TodoListModel>("todolist");
         Task.Run(async() => await RefreshTodoLists());
     }
     catch (Exception ex)
     {
         ErrorTracker.ReportError(ex);
     }
 }
Beispiel #27
0
    static void Main(string[] args)
    {
        var engine = new FileHelperEngine <ModelClass>();

        ErrorTracker.Clear();
        var productRecords = engine.ReadFile(@"C:\whatever.txt");

        foreach (var errorMessage in ErrorTracker.ErrorList)
        {
            Console.WriteLine(errorMessage);
        }
        Console.ReadKey();
    }
Beispiel #28
0
        /// <summary>
        /// Parses the given Mod Script into an AST.
        /// </summary>
        /// <param name="p_strModScriptCode">The Mod Script to compile.</param>
        /// <param name="p_booCompileTest">Whether the prograsm is just checking if the script compiles.</param>
        /// <returns>The AST built from the given Mod Script.</returns>
        private ITree GenerateAst(string p_strModScriptCode, bool p_booCompileTest)
        {
            ErrorTracker ertErrors = new ErrorTracker();
            string       strCode   = p_strModScriptCode;

            //unescape characters
            Regex                       rgxStrings          = new Regex("[^\\\\](\"(\"|(.*?[^\\\\]\")))", RegexOptions.Multiline);
            MatchCollection             colStrings          = rgxStrings.Matches(strCode);
            Dictionary <string, string> dicProtectedStrings = new Dictionary <string, string>();

            for (Int32 i = colStrings.Count - 1; i >= 0; i--)
            {
                string strShieldText = "<SHIELD" + i + ">";
                strCode = strCode.Replace(colStrings[i].Groups[1].Value, strShieldText);
                dicProtectedStrings[strShieldText] = colStrings[i].Value;
            }
            strCode = strCode.Replace(@"\""", @"""").Replace(@"\\", @"\");
            foreach (string strKey in dicProtectedStrings.Keys)
            {
                strCode = strCode.Replace(strKey, dicProtectedStrings[strKey]);
            }

            //clean code
            colStrings = rgxStrings.Matches(strCode);
            dicProtectedStrings.Clear();
            for (Int32 i = colStrings.Count - 1; i >= 0; i--)
            {
                string strShieldText = "<SHIELD" + i + ">";
                strCode = strCode.Replace(colStrings[i].Value, strShieldText);
                dicProtectedStrings[strShieldText] = colStrings[i].Value;
            }

            //strip comments
            Regex rgxComments = new Regex(";.*$", RegexOptions.Multiline);

            strCode = rgxComments.Replace(strCode, "");
            foreach (string strKey in dicProtectedStrings.Keys)
            {
                strCode = strCode.Replace(strKey, dicProtectedStrings[strKey]);
            }

            AntlrParserBase cpbParser    = CreateParser(strCode, ertErrors);
            ITree           astModSCript = cpbParser.Parse();

            if ((ertErrors.HasErrors) && !p_booCompileTest)
            {
                m_sicContext.FunctionProxy.ExtendedMessageBox("Invalid Mod Script", "Error", ertErrors.ToHtml(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
            return(astModSCript);
        }
Beispiel #29
0
        public async Task <TodoItemModel> GetTodoItem(Guid todoId)
        {
            try
            {
                var item = await database.QueryAsync <TodoItemModel>("SELECT * FROM TodoItem WHERE Id = ?", todoId);

                return(item[0] ?? null);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(null);
            }
        }
Beispiel #30
0
        public async Task <List <TodoItemModel> > GetTodoItems(Guid todoListId)
        {
            try
            {
                var todoItems = await database.QueryAsync <TodoItemModel>($"SELECT * FROM TodoItem where ListId = ?", todoListId);

                return(todoItems ?? null);
            }
            catch (Exception ex)
            {
                ErrorTracker.ReportError(ex);
                return(null);
            }
        }