Exemplo n.º 1
0
        public async void Update(object source, RoutedEventArgs eventArgs)
        {
            if (!ValidateUpdate())
            {
                return;
            }

            try
            {
                SetLoading(Visibility.Visible);
                var languageResources = ExcelService.Read(UpdateSelectedExcel);
                await I18nService.Update(UpdateI18nFolder, languageResources);

                var i18nKeys = await I18nService.GetAllKeys(UpdateI18nFolder);

                var excelKeys = new List <string>();
                foreach (var item in languageResources)
                {
                    excelKeys.AddRange(item.Values.Keys);
                    excelKeys = excelKeys.Distinct().ToList();
                }

                var(NotInA, NotInB) = CompareHelper.GetDifference(excelKeys, i18nKeys);

                KeysNotInExcel = new ObservableCollection <string>(NotInA);
                KeysNotInI18n  = new ObservableCollection <string>(NotInB);

                SetLoading(Visibility.Hidden);
            }
            catch (Exception ex)
            {
                ExceptionHandler(ex);
            }
        }
Exemplo n.º 2
0
        private void InsertEndpointView()
        {
            Console.WriteLine(I18nService.GetTranslate("INSERT_NEW_ENDPOINT"));
            Console.Write(I18nService.GetTranslate("SERIAL_NUMBER") + ": ");
            var serialNumber = Console.ReadLine();

            Console.Write(I18nService.GetTranslate("METER_MODEL_ID") + string.Format(" ({0} | {1} | {2} | {3}): ", ModelId.NSX1P2W, ModelId.NSX1P3W, ModelId.NSX1P4W, ModelId.NSX1P5W));
            var modelId = Console.ReadLine();

            Console.Write(I18nService.GetTranslate("METER_NUMBER") + ": ");
            var meterNumber = Console.ReadLine();

            Console.Write(I18nService.GetTranslate("METER_FIRMWARE_VERSION") + ": ");
            var firmwareVersion = Console.ReadLine();

            Console.Write(I18nService.GetTranslate("SWITCH_STATE") + string.Format(" ({0} | {1} | {2}): ", SwitchState.Disconnected, SwitchState.Connected, SwitchState.Armed));
            var switchState = Console.ReadLine();

            var newEndpoint = new EndpointVO()
            {
                serialNumber         = serialNumber,
                meterModelId         = modelId,
                meterNumber          = meterNumber,
                meterFirmwareVersion = firmwareVersion,
                switchState          = switchState
            };

            var endpoint = endpointController.Create(newEndpoint);

            Console.WriteLine(I18nService.GetTranslate("SUCCESSLY_CREATED_ENDPOINT"));
            PressAnyKeyToContinue();
        }
Exemplo n.º 3
0
        private void DeleteEndpointView()
        {
            Console.WriteLine(I18nService.GetTranslate("DELETE_ENDPOINT"));
            Console.Write(I18nService.GetTranslate("SERIAL_NUMBER") + ": ");
            var identifier = Console.ReadLine();

            endpointController.Delete(identifier);
            Console.WriteLine(I18nService.GetTranslate("SUCCESSLY_DELETED_ENDPOINT"));
            PressAnyKeyToContinue();
        }
Exemplo n.º 4
0
        public Endpoint Delete(string identifier)
        {
            if (string.IsNullOrEmpty(identifier))
            {
                throw new AppException(I18nService.GetTranslate("INVALID_SERIAL_NUMBER"));
            }
            var deleteEndpointService = new DeleteEndpointService();

            return(deleteEndpointService.Execute(identifier));
        }
Exemplo n.º 5
0
        private void FindEndpointView()
        {
            Console.WriteLine(I18nService.GetTranslate("FIND_ENDPOINT"));
            Console.Write(I18nService.GetTranslate("SERIAL_NUMBER") + ": ");
            var identifier = Console.ReadLine();
            var endpoint   = endpointController.FindOne(identifier);

            Console.WriteLine(endpoint.ToString());
            PressAnyKeyToContinue();
        }
Exemplo n.º 6
0
        public Endpoint Edit(EndpointVO endpointVo)
        {
            if (string.IsNullOrEmpty(endpointVo.serialNumber))
            {
                throw new AppException(I18nService.GetTranslate("INVALID_SERIAL_NUMBER"));
            }

            var editEndpointService = new EditEndpointService();

            return(editEndpointService.Execute(endpointVo));
        }
Exemplo n.º 7
0
        public Endpoint FindOne(string identifier)
        {
            if (string.IsNullOrEmpty(identifier))
            {
                throw new AppException(I18nService.GetTranslate("INVALID_SERIAL_NUMBER"));
            }

            var findEndpointBySerialNumberService = new FindEndpointBySerialNumberService();

            return(findEndpointBySerialNumberService.Execute(identifier));
        }
Exemplo n.º 8
0
        private void ListAllEndpointView()
        {
            var endpointList = endpointController.ListAll();

            Console.WriteLine(I18nService.GetTranslate("LIST_ALL_ENDPOINT"));
            foreach (var endpoint in endpointList)
            {
                Console.WriteLine(endpoint.ToString());
            }
            PressAnyKeyToContinue();
        }
Exemplo n.º 9
0
        public override string ToString()
        {
            ModelId     meterModelIdLabel = (ModelId)meterModelId;
            SwitchState switchStateLabel  = (SwitchState)switchState;

            return(string.Format("{0}: {1} | " +
                                 "{2}: {3} | " +
                                 "{4}: {5} | " +
                                 "{6}: {7} | " +
                                 "{8}: {9}",
                                 I18nService.GetTranslate("SERIAL_NUMBER"), serialNumber,
                                 I18nService.GetTranslate("METER_MODEL_ID"), meterModelIdLabel,
                                 I18nService.GetTranslate("METER_NUMBER"), meterNumber,
                                 I18nService.GetTranslate("METER_FIRMWARE_VERSION"), meterFirmwareVersion,
                                 I18nService.GetTranslate("SWITCH_STATE"), switchStateLabel));
        }
Exemplo n.º 10
0
 public static void ValidateSwitchState(string switchState, Endpoint endpoint)
 {
     if (switchState.ToLower() == SwitchState.Disconnected.ToString().ToLower())
     {
         endpoint.switchState = (int)SwitchState.Disconnected;
     }
     else if (switchState.ToLower() == SwitchState.Connected.ToString().ToLower())
     {
         endpoint.switchState = (int)SwitchState.Connected;
     }
     else if (switchState.ToLower() == SwitchState.Armed.ToString().ToLower())
     {
         endpoint.switchState = (int)SwitchState.Armed;
     }
     else
     {
         throw new AppException(I18nService.GetTranslate("INVALID_SWITCH_STATE_INPUT"));
     }
 }
Exemplo n.º 11
0
        private void EditEndpointView()
        {
            Console.WriteLine(I18nService.GetTranslate("EDIT_ENDPOINT"));
            Console.Write(I18nService.GetTranslate("SERIAL_NUMBER") + ": ");
            var serialNumber = Console.ReadLine();

            Console.Write(I18nService.GetTranslate("SWITCH_STATE") + string.Format(" ({0} | {1} | {2}): ", SwitchState.Disconnected, SwitchState.Connected, SwitchState.Armed));
            var switchState = Console.ReadLine();

            var newEndpoint = new EndpointVO()
            {
                serialNumber = serialNumber,
                switchState  = switchState,
            };

            var endpoint = endpointController.Edit(newEndpoint);

            Console.WriteLine(I18nService.GetTranslate("SUCCESSLY_EDITED_ENDPOINT"));
            PressAnyKeyToContinue();
        }
Exemplo n.º 12
0
        public async void Generate(object source, RoutedEventArgs eventArgs)
        {
            if (!ValidateGenerate())
            {
                return;
            }

            try
            {
                SetLoading(Visibility.Visible);
                var languageResources = ExcelService.Read(GenerateSelectedExcel);
                await I18nService.Create(GenerateSaveFolder, languageResources);

                SetLoading(Visibility.Hidden);
            }
            catch (Exception ex)
            {
                ExceptionHandler(ex);
            }
        }
Exemplo n.º 13
0
        public Endpoint Create(EndpointVO endpointVo)
        {
            if (string.IsNullOrEmpty(endpointVo.serialNumber))
            {
                throw new AppException(I18nService.GetTranslate("INVALID_SERIAL_NUMBER"));
            }
            if (string.IsNullOrEmpty(endpointVo.meterFirmwareVersion))
            {
                throw new AppException(I18nService.GetTranslate("INVALID_METER_FIRMWARE_VERSION"));
            }
            int number;

            if (string.IsNullOrEmpty(endpointVo.meterNumber) || !int.TryParse(endpointVo.meterNumber, out number))
            {
                throw new AppException(I18nService.GetTranslate("INVALID_METER_NUMBER"));
            }

            var createEndpointService = new CreateEndpointService();

            return(createEndpointService.Execute(endpointVo));
        }
Exemplo n.º 14
0
        private void ApplyChanges()
        {
            _data = new SortedDictionary <string, LocalizationRecord>();
            foreach (var keyValuePair in _mixedData)
            {
                if (keyValuePair.Value.Status != PairStatus.Removed)
                {
                    _data.Add(keyValuePair.Key, keyValuePair.Value);
                }
            }

            var rawData = new List <string[]>();

            foreach (var item in _data)
            {
                item.Value.Status = PairStatus.NoneChanged;

                rawData.Add(new[] {
                    item.Key,
                    I18nService.Screen(string.IsNullOrEmpty(item.Value.Value) ? item.Key + "_Value" : item.Value.Value),
                    I18nService.Screen(item.Value.Hint),
                    item.Value.Source.ToString()
                });
            }

            var source = I18nHelpers.BuildCSV(rawData);

            source = I18nService.UnScreen(source);

            var writer = new StreamWriter(PathToFile, false);

            writer.Write(source);
            writer.Close();

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            RevertChanges();
        }
Exemplo n.º 15
0
        public async void Export(object source, RoutedEventArgs eventArgs)
        {
            if (!ValidateExport())
            {
                return;
            }


            try
            {
                SetLoading(Visibility.Visible);
                var excelData = await I18nService.ConvertToExcelData(exportSourceFolder);

                var excelPath = Path.Combine(ExportSaveFolder, $"{ExportExcelName}.xlsx");
                ExcelService.Export(excelData, excelPath);
                SetLoading(Visibility.Hidden);
            }
            catch (Exception ex)
            {
                ExceptionHandler(ex);
            }
        }
Exemplo n.º 16
0
 public static void ValidateModelId(string modelId, Endpoint endpoint)
 {
     if (modelId.ToUpper() == ModelId.NSX1P2W.ToString().ToUpper())
     {
         endpoint.meterModelId = (int)ModelId.NSX1P2W;
     }
     else if (modelId.ToUpper() == ModelId.NSX1P3W.ToString().ToUpper())
     {
         endpoint.meterModelId = (int)ModelId.NSX1P3W;
     }
     else if (modelId.ToUpper() == ModelId.NSX1P4W.ToString().ToUpper())
     {
         endpoint.meterModelId = (int)ModelId.NSX1P4W;
     }
     else if (modelId.ToUpper() == ModelId.NSX1P5W.ToString().ToUpper())
     {
         endpoint.meterModelId = (int)ModelId.NSX1P5W;
     }
     else
     {
         throw new AppException(I18nService.GetTranslate("INVALID_METER_MODE_INPUT"));
     }
 }
Exemplo n.º 17
0
        public NotesListsViewModel(IEventAggregator eventAggregator, INoteService noteService, IAppearanceService appearanceService, IJumpListService jumpListService, ISearchService searchService, IDialogService dialogService, I18nService i18nService, IBackupService backupService)
        {
            // Injection
            this.eventAggregator   = eventAggregator;
            this.noteService       = noteService;
            this.appearanceService = appearanceService;
            this.jumpListService   = jumpListService;
            this.searchService     = searchService;
            this.dialogService     = dialogService;
            this.i18nService       = i18nService;
            this.backupService     = backupService;

            // PubSub events
            this.eventAggregator.GetEvent <TriggerLoadNoteAnimationEvent>().Subscribe((_) =>
            {
                this.TriggerRefreshNotesAnimation = false;
                this.TriggerRefreshNotesAnimation = true;
            });

            this.eventAggregator.GetEvent <SettingChangeStorageLocationFromMainChangedEvent>().Subscribe((_) => OnPropertyChanged(() => this.ShowChangeStorageLocationButton));
            this.eventAggregator.GetEvent <RefreshJumpListEvent>().Subscribe((_) => this.jumpListService.RefreshJumpListAsync(this.noteService.GetRecentlyOpenedNotes(SettingsClient.Get <int>("Advanced", "NumberOfNotesInJumpList")), this.noteService.GetFlaggedNotes()));

            this.eventAggregator.GetEvent <OpenNoteEvent>().Subscribe(noteTitle =>
            {
                if (!string.IsNullOrEmpty(noteTitle))
                {
                    this.SelectedNote = new NoteViewModel {
                        Title = noteTitle
                    }
                }
                ;
                this.OpenSelectedNote();
            });

            // Event handlers
            this.i18nService.LanguageChanged        += LanguageChangedHandler;
            this.noteService.FlagUpdated            += async(noteId, isFlagged) => { await this.UpdateNoteFlagAsync(noteId, isFlagged); };
            this.noteService.StorageLocationChanged += (_, __) => this.RefreshNotebooksAndNotes();
            this.backupService.BackupRestored       += (_, __) => this.RefreshNotebooksAndNotes();
            this.noteService.NotesChanged           += (_, __) => Application.Current.Dispatcher.Invoke(() => { this.RefreshNotes(); });
            this.searchService.Searching            += (_, __) => TryRefreshNotesOnSearch();

            this.NoteFilter = ""; // Must be set before RefreshNotes()

            // Initialize notebooks
            this.RefreshNotebooksAndNotes();

            // Commands
            this.DeleteNoteCommand             = new DelegateCommand <object>(async(obj) => await this.DeleteNoteAsync(obj));
            this.ToggleNoteFlagCommand         = new DelegateCommand <object>((obj) => this.ToggleNoteFlag(obj));
            this.DeleteNotebookCommand         = new DelegateCommand <object>((obj) => this.DeleteNotebook(obj));
            this.EditNotebookCommand           = new DelegateCommand <object>((obj) => this.EditNotebook(obj));
            this.DeleteSelectedNotebookCommand = new DelegateCommand(() => this.DeleteSelectedNotebook());
            this.EditSelectedNotebookCommand   = new DelegateCommand(() => this.EditSelectedNotebook());
            this.DeleteSelectedNoteCommand     = new DelegateCommand(async() => await this.DeleteSelectedNoteAync());
            this.ChangeStorageLocationCommand  = new DelegateCommand(async() => await this.ChangeStorageLocationAsync(false));
            this.ResetStorageLocationCommand   = new DelegateCommand(async() => await this.ChangeStorageLocationAsync(true));

            this.NewNotebookCommand = new DelegateCommand <string>((_) => this.NewNotebook());
            Common.Prism.ApplicationCommands.NewNotebookCommand.RegisterCommand(this.NewNotebookCommand);

            this.NewNoteCommand = new DelegateCommand <object>(param => this.NewNote(param));
            Common.Prism.ApplicationCommands.NewNoteCommand.RegisterCommand(this.NewNoteCommand);

            this.ImportNoteCommand = new DelegateCommand <string>((_) => this.ImportNote());
            Common.Prism.ApplicationCommands.ImportNoteCommand.RegisterCommand(this.ImportNoteCommand);

            this.NavigateBetweenNotesCommand = new DelegateCommand <object>(NavigateBetweenNotes);
            Common.Prism.ApplicationCommands.NavigateBetweenNotesCommand.RegisterCommand(this.NavigateBetweenNotesCommand);

            // Process jumplist commands
            this.ProcessJumplistCommands();
        }
Exemplo n.º 18
0
        private void ProcessSearchResult()
        {
            _mixedData = new SortedDictionary <string, LocalizationRecord>();

            ParseAndUpdateVariables(_foundedData);

            var translationsFromFile = _data;
            var newSearchedKeys      = _foundedData;

            foreach (var fromSavedFile in translationsFromFile)
            {
                var mergeResult = (LocalizationRecord)fromSavedFile.Value.Clone();

                _mixedData.Add(fromSavedFile.Key, mergeResult);

                if (!_searchSource.HasFlag(mergeResult.Source))
                {
                    mergeResult.Status = PairStatus.NoneChanged;
                    continue;
                }

                if (mergeResult.Source.HasFlag(Source.Variable))
                {
                    continue;
                }

                LocalizationRecord foundedLocalizationRecord;
                newSearchedKeys.TryGetValue(fromSavedFile.Key, out foundedLocalizationRecord);

                if (foundedLocalizationRecord != null)
                {
                    if (!_searchSource.HasFlag(foundedLocalizationRecord.Source))
                    {
                        continue;
                    }

                    if (foundedLocalizationRecord.Source == Source.Code || foundedLocalizationRecord.Source == Source.PrefabAndScene)
                    {
                        mergeResult.Source = foundedLocalizationRecord.Source;

                        if (mergeResult.Hint != I18nService.UnScreen(foundedLocalizationRecord.Hint))
                        {
                            mergeResult.Hint   = foundedLocalizationRecord.Hint;
                            mergeResult.Status = PairStatus.Changed;
                            foundedLocalizationRecord.Status = PairStatus.Changed;
                        }
                        continue;
                    }
                    else if (foundedLocalizationRecord.Source == Source.Config)
                    {
                        if (mergeResult.Value != foundedLocalizationRecord.Value || mergeResult.Hint != I18nService.UnScreen(foundedLocalizationRecord.Hint))
                        {
                            mergeResult.Value  = foundedLocalizationRecord.Value;
                            mergeResult.Hint   = foundedLocalizationRecord.Hint;
                            mergeResult.Status = PairStatus.Changed;
                        }
                    }

                    continue;
                }
                mergeResult.Status = PairStatus.Removed;
            }

            foreach (var founded in newSearchedKeys)
            {
                if (founded.Value.Status == PairStatus.Changed)
                {
                    continue;
                }

                if (!_searchSource.HasFlag(founded.Value.Source) && !(founded.Key.StartsWith("$") && founded.Key.EndsWith("_Name")))
                {
                    continue;
                }

                if (!translationsFromFile.ContainsKey(founded.Key))
                {
                    founded.Value.Status = PairStatus.New;
                    _mixedData.Add(founded.Key, founded.Value);
                }
            }
        }
Exemplo n.º 19
0
        public void TestProductCreateAndUpdate()
        {
            RunTestWithDbContext(async context =>
            {
                var i18NService     = new I18nService(context, new HttpContextAccessor(), Mock.Of <ILogger <I18nService> >());
                var imageService    = new ImageService(context, Mock.Of <ILogger <ImageService> >());
                var wishlistService = new WishlistService(context, Mock.Of <ILogger <WishlistService> >());
                var categoryService = new CategoryService(context, Mock.Of <ILogger <CategoryService> >());
                var productService  = new ProductService(context, i18NService,
                                                         Mock.Of <ILogger <ProductService> >(), imageService, wishlistService);

                // Add a category which is necessary for the product creation
                var category = new CategoryEntity
                {
                    Title = "Hard Rock"
                };

                await categoryService.AddAsync(category);

                Assert.Empty(await productService.GetAllAsync());

                // Create product
                var product = new ProductEntity
                {
                    Artist      = "Artist",
                    CategoryId  = category.Id,
                    Label       = "test",
                    ReleaseDate = DateTime.Today,
                    Image       = new ImageEntity
                    {
                        Base64String = "asf23523sdfk",
                        Description  = "Hard Rock image",
                        ImageType    = "jpg"
                    }
                };

                // Create product prices
                var productPriceEntities = new List <ProductPriceEntity>
                {
                    new ProductPriceEntity
                    {
                        CurrencyId = "EUR",
                        Price      = 9,
                        ProductId  = product.Id
                    },
                    new ProductPriceEntity
                    {
                        CurrencyId = "USD",
                        Price      = 20,
                        ProductId  = product.Id
                    }
                };

                // Create product translations
                var productTranslationEntities = new List <ProductTranslationEntity>
                {
                    new ProductTranslationEntity
                    {
                        Description      = "Deutsche Beschreibung",
                        DescriptionShort = "kurz",
                        LanguageId       = "de_DE",
                        ProductId        = product.Id,
                        Title            = "Deutsches Produkt"
                    },
                    new ProductTranslationEntity
                    {
                        Description      = "English Description",
                        DescriptionShort = "short",
                        LanguageId       = "en_US",
                        ProductId        = product.Id,
                        Title            = "English Product"
                    }
                };

                await productService.AddAsync(product, productPriceEntities, productTranslationEntities);

                //Test Products
                Assert.NotNull(await productService.GetByIdAsync(product.Id));
                Assert.Null(await productService.GetByIdAsync(new Guid()));
                Assert.Single(productService.GetAllAsync().Result);
                Assert.True(await productService.DoesProductExistByIdAsync(product.Id));

                Assert.NotNull(await imageService.GetByIdAsync(product.ImageId));
                Assert.True(categoryService.DoesCategoryNameExist(category.Title));
                Assert.Single(categoryService.GetAllAsync().Result);

                // Add a second category
                var secondCategory = new CategoryEntity
                {
                    Title = "Rock"
                };

                await categoryService.AddAsync(secondCategory);

                var updatedProduct        = product;
                updatedProduct.Id         = product.Id;
                updatedProduct.CategoryId = secondCategory.Id;
                await productService.UpdateAsync(updatedProduct);

                //Test Updated Product
                Assert.NotNull(await productService.GetByIdAsync(updatedProduct.Id));
                Assert.Null(await productService.GetByIdAsync(new Guid()));
                Assert.Single(productService.GetAllAsync().Result);
                Assert.True(await productService.DoesProductExistByIdAsync(updatedProduct.Id));

                Assert.True(categoryService.DoesCategoryNameExist(secondCategory.Title));
                Assert.Equal(2, categoryService.GetAllAsync().Result.Count);
                Assert.Equal("Rock", productService.GetByIdAsync(updatedProduct.Id).Result.Category.Title);
            });
        }
Exemplo n.º 20
0
        public void StartApp()
        {
            var input = ConsoleKey.NumPad0;

            do
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine(I18nService.GetTranslate("INSERT_NEW_ENDPOINT_MENU"));
                    Console.WriteLine(I18nService.GetTranslate("EDIT_ENDPOINT_MENU"));
                    Console.WriteLine(I18nService.GetTranslate("DELETE_ENDPOINT_MENU"));
                    Console.WriteLine(I18nService.GetTranslate("LIST_ALL_ENDPOINT_MENU"));
                    Console.WriteLine(I18nService.GetTranslate("FIND_ENDPOINT_MENU"));
                    Console.WriteLine(I18nService.GetTranslate("EXIT_MENU"));
                    input = Console.ReadKey().Key;
                    Console.Clear();
                    switch (input)
                    {
                    case ConsoleKey.D1:
                    case ConsoleKey.NumPad1:
                        InsertEndpointView();
                        break;

                    case ConsoleKey.D2:
                    case ConsoleKey.NumPad2:
                        EditEndpointView();
                        break;

                    case ConsoleKey.D3:
                    case ConsoleKey.NumPad3:
                        DeleteEndpointView();
                        break;

                    case ConsoleKey.D4:
                    case ConsoleKey.NumPad4:
                        ListAllEndpointView();
                        break;

                    case ConsoleKey.D5:
                    case ConsoleKey.NumPad5:
                        FindEndpointView();
                        break;

                    case ConsoleKey.D6:
                    case ConsoleKey.NumPad6:
                        break;

                    default:
                        Console.WriteLine(I18nService.GetTranslate("INVALID_INPUT_TRY_AGAIN"));
                        PressAnyKeyToContinue();
                        break;
                    }
                }
                catch (AppException e)
                {
                    Console.WriteLine(e.Message);
                    PressAnyKeyToContinue();
                }
            } while (input != ConsoleKey.NumPad6 && input != ConsoleKey.D6);
        }
Exemplo n.º 21
0
 private void PressAnyKeyToContinue()
 {
     Console.WriteLine(I18nService.GetTranslate("PRESS_ANY_KEY_TO_CONTINUE"));
     Console.ReadKey();
 }