protected static void OpenSingleWindow() { InitTitle(); InitSize(); FocusAndShow(); void InitTitle() { var titleAttribute = WindowType.GetSingleAttribute <MenuWindowTitleAttribute>(); var titleString = titleAttribute == null? MultiLanguageString.Create(WindowType.Name, WindowType.Name) : titleAttribute.TitleString; SingleWindow.Value.titleContent = new GUIContent(titleString.Text); } void InitSize() { var sizeAttribute = WindowType.GetSingleAttribute <MenuWindowSizeAttirbute>(); // ?. NULL检查运算符 ?? 空合并运算符 var min = sizeAttribute?.Min ?? 300; var max = sizeAttribute?.Max ?? 600; Vector2 initSize = new Vector2(min, max); SingleWindow.Value.minSize = initSize; } void FocusAndShow() { SingleWindow.Value.Focus(); SingleWindow.Value.Show(); } }
public static EkTransactionProduct FromProduct(EkProduct product, MultiLanguageString description, int quantity) { Assure.ArgumentNotNull(product, nameof(product)); return(new EkTransactionProduct() { Key = product.Key, Source = product.Source, SourceId = product.SourceId, BrandName = product.BrandName, PartNumber = product.PartNumber, CategoryId = product.CategoryId, Name = product.Name, Description = description, ThumbnailUrl = product.GetThumbnailUrl(), BasePrice = product.BasePrice, BasePriceCurrencyCode = product.BasePriceCurrencyCode, DeliveryPrice = product.DeliveryPrice, Price = product.Price, PriceCurrencyCode = product.PriceCurrencyCode, PriceCalculationInfo = product.PriceCalculationInfo, State = product.State, Quantity = quantity, }); }
public VotingData(MultiLanguageString title, MultiLanguageString description, MultiLanguageString url) { Title = title; Descrption = description; Url = url; Questions = new List<Question>(); }
public void Initialize(Type enumType) { if (isInitialized) { return; } isInitialized = true; // to avoid to change placesGetValues, use GetFields var list = new List <int>(); var fields = enumType.GetFields(); //var iconBitmaps = new List<Bitmap>(); //bool hasIcon = false; foreach (var f in fields) { if (f.FieldType != enumType) { continue; } var attributes = f.GetCustomAttributes(false); object name = f.ToString(); var key = KeyAttribute.GetKey(attributes); var nameKey = key + "_Name"; if (string.IsNullOrEmpty(key)) { nameKey = f.FieldType.ToString() + "_" + f.ToString() + "_Name"; } if (MultiLanguageTextProvider.HasKey(nameKey)) { name = new MultiLanguageString(nameKey); } else { name = NameAttribute.GetName(attributes); if (name.ToString() == string.Empty) { name = f.ToString(); } //System.IO.File.AppendAllText("kv.csv", nameKey + "," + name.ToString() + "\r\n"); } var iconAttribute = IconAttribute.GetIcon(attributes); if (iconAttribute != null) { name = iconAttribute.code + name; } list.Add((int)f.GetValue(null)); FieldNames.Add(name); } enums = list.ToArray(); }
/// <summary> /// Create a new voting with test parameters. /// </summary> /// <remarks> /// Must only be used for testing. /// </remarks> /// <param name="primeBits">Number of bits of the safe prime.</param> /// <param name="dataPath">Path where application data is stored.</param> private VotingParameters() { VotingId = Guid.NewGuid(); Title = new MultiLanguageString("Test"); Description = new MultiLanguageString(string.Empty); VotingBeginDate = DateTime.Now; VotingEndDate = DateTime.Now.AddDays(1); }
/// <summary> /// Create a new option. /// </summary> /// <param name="id">Id of the group.</param> /// <param name="name">Name of the group.</param> public Group(int id, MultiLanguageString name) { if (name == null) throw new ArgumentNullException("text"); Id = id; Name = name; }
/// <summary> /// Creates a new voting result. /// </summary> /// <remarks> /// Don't forget adding option and envelopes results. /// </remarks> /// <param name="votingId">Id of the voting procedure.</param> /// <param name="votingParameters">Parameters of the voting in question.</param> public VotingResult(Guid votingId, VotingParameters votingParameters) { this.votingId = votingId; this.title = votingParameters.Title; this.description = votingParameters.Description; this.questions = new List<QuestionResult>(); this.voters = new List<EnvelopeResult>(); }
public void ToString_ThrowsLanguageNotSupportedException_WhenUnknownLanguageIsProvided() { //Arrange & Act var sut = new MultiLanguageString("English", "French", "Dutch"); //Assert Assert.ThrowsException <LanguageNotSupportedException>(() => sut.ToString((Language)50)); }
/// <summary> /// Creates a new option decriptor. /// </summary> /// <param name="option">Option to decscribe.</param> public OptionDescriptor(Option option) { if (option == null) throw new ArgumentException("option"); this.text = option.Text; this.description = option.Description; this.url = option.Url; }
internal void ReportParsedDeckData(WeissSchwarzDeck newDeck) { report = report with { Percentage = 10, ReportMessage = new MultiLanguageString { EN = $"Found Deck [{newDeck.Name}] [{newDeck.Remarks}]" } }; progress.Report(report); }
internal void ReportParseStart(string url) { report = report with { Percentage = 0, ReportMessage = new MultiLanguageString { EN = $"Parsing DeckLog Deck: [{url}]" } }; progress.Report(report); }
internal void ReportMissingSets(List <string> missingSets) { this.missingSets = missingSets; report = report with { Percentage = 10, ReportMessage = new MultiLanguageString { EN = $"Found Missing Sets; Parsing using EncoreDecks: [{missingSets.ConcatAsString(",")}" } }; progress.Report(report); }
public void CTOR_ShouldInitTranslatedFields_WhenValidTranslationIsProvided() { //Arrange & Act var sut = new MultiLanguageString("English", "French", "Dutch"); //Assert Assert.AreEqual("English", sut.English); Assert.AreEqual("French", sut.French); Assert.AreEqual("Dutch", sut.Dutch); }
public void ToString_ShouldReturnTranslatedFields_WhenValidLanguageIsProvided() { //Arrange & Act var sut = new MultiLanguageString("English", "French", "Dutch"); //Assert Assert.AreEqual("English", sut.ToString(Language.English)); Assert.AreEqual("French", sut.ToString(Language.French)); Assert.AreEqual("Dutch", sut.ToString(Language.Dutch)); }
/// <summary> /// Create a new option. /// </summary> /// <param name="text">Text of option.</param> /// <param name="description">Description of option.</param> /// <param name="url">Url of the discussion of the option.</param> public Option(MultiLanguageString text, MultiLanguageString description, MultiLanguageString url) { if (text == null) throw new ArgumentNullException("text"); if (description == null) throw new ArgumentNullException("description"); Text = text; Description = description; Url = url; }
/// <summary> /// Creates a new question descriptor. /// </summary> /// <param name="question">Question to describe.</param> public QuestionDescriptor(Question question) { if (question == null) throw new ArgumentNullException("question"); this.text = question.Text; this.description = question.Description; this.url = question.Url; this.maxOptions = question.MaxVota; this.options = new List<OptionDescriptor>(); question.Options.Foreach(option => this.options.Add(new OptionDescriptor(option))); }
public void ToString_ThrowsLanguageNotSupportedException_WhenUnknownLanguageIsProvided() { //Arrange var mockILogger = TestHelper.MockILogger(); LoggedException.Logger = mockILogger.Object; //Act var sut = new MultiLanguageString("English", "French", "Dutch"); //Assert Assert.ThrowsException <LanguageNotSupportedException>(() => sut.ToString((Language)50)); mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Once); }
public static T FillFromMultiLanguageString <T>(this T ToFill, MultiLanguageString multiLanguageString) where T : IMultiLanguageNameFields { if (multiLanguageString is null) { throw new ArgumentNullException(nameof(multiLanguageString)); } ToFill.NameEnglish = multiLanguageString.English; ToFill.NameFrench = multiLanguageString.French; ToFill.NameDutch = multiLanguageString.Dutch; return(ToFill); }
/// <summary> /// Creates a new question. /// </summary> /// <param name="question">Text of the question.</param> /// <param name="description">Description of the question.</param> /// <param name="maxVota">Maximum number of options a voter can select.</param> /// <param name="url">Url of the discussion of the option.</param> public Question(MultiLanguageString question, MultiLanguageString description, MultiLanguageString url, int maxVota) { if (question == null) throw new ArgumentNullException("question"); if (description == null) throw new ArgumentNullException("description"); if (!maxVota.InRange(1, 100)) throw new ArgumentException("maxVota out of range."); Description = description; Text = question; Url = url; MaxVota = maxVota; this.options = new List<Option>(); }
private Menu SetupExportSubMenu(MultiLanguageString output) { var exportMenu = new Menu(output, Icons.Empty); for (int c = 0; c < Core.ExportScripts.Count; c++) { var item = new MenuItem(); var script = Core.ExportScripts[c]; item.Label = script.Title; item.Clicked += () => Export(script); exportMenu.Controls.Add(item); } return(exportMenu); }
public void IsCorrectTranslation_ThrowsIsNullOrWhiteSpaceException_WhenMultiLanguageStringIsNULL() { //ARRANGE var mockILogger = TestHelper.MakeILogger(); var mockITRSTranslationService = TestHelper.MakeITRSTranslationService(); LoggedException.Logger = mockILogger.Object; var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object); MultiLanguageString MLSToCheck = null; //ACT & ASSERT Assert.Throws <LoggedException>(() => translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.Dutch)); mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.Never); mockILogger.Verify(x => x.Error(It.IsAny <ArgumentNullException>(), It.IsAny <string>()), Times.Once); }
public void IsCorrectTranslation_ThrowsIsNullOrWhiteSpaceException_WhenSourceStringToTranslateIsNotProvided() { //ARRANGE var mockILogger = TestHelper.MakeILogger(); var mockITRSTranslationService = TestHelper.MakeITRSTranslationService(); LoggedException.Logger = mockILogger.Object; var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object); var MLSToCheck = new MultiLanguageString("Not a good translation", "Some wrong DutchString", " "); //ACT & ASSERT Assert.Throws <IsNullOrWhiteSpaceException>(() => translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.Dutch)); mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.Never); mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Once); }
public static Tuple <Language, string>[] ToTupleLanguages(this MultiLanguageString multiLanguageString) { if (multiLanguageString is null) { throw new LoggedException(new ArgumentNullException($"{nameof(multiLanguageString)} is null @ MultiLanguageStringExtensions.ToTupleLanguages")); } var ReturnValues = new List <Tuple <Language, string> > { new Tuple <Language, string>(Language.English, multiLanguageString.ToString(Language.English)), new Tuple <Language, string>(Language.French, multiLanguageString.ToString(Language.French)), new Tuple <Language, string>(Language.Dutch, multiLanguageString.ToString(Language.Dutch)) }; return(ReturnValues.ToArray()); }
public override void Execute(Rect rect) { var drawRect = GetIconRect(rect.width + rect.x - IconSize, rect.y); var tip = MultiLanguageString.Create("Open" + " csharp scaffold", "´ò¿ªCshap½ÅÊÖ¼Ü"); var guiContent = new GUIContent(csharpScaffoldIcon.Icon, tip.Text); if (!GUI.Button(drawRect, guiContent, GUIStyle.none)) { return; } EditorPrefs.SetString(CsharpScaffold.OutputDirectoryPrefsKey , Path); FunctionCenterWindow.OpneTargetMenu(typeof(CsharpScaffold)); }
public void IsCorrectTranslation_ThrowsNecessaryDataException_WhenAPIKeyIsNotProvided() { //ARRANGE var mockILogger = TestHelper.MakeILogger(); var mockITRSTranslationService = TestHelper.MakeITRSTranslationService(); LoggedException.Logger = mockILogger.Object; var translationUC = new OnlineServicesSystem(mockILogger.Object, mockITRSTranslationService.Object); var DutchSource = "Dutch Source String"; var MLSToCheck = new MultiLanguageString("Not a good translation", "Some wrong DutchString", DutchSource); //ACT & ASSERT Assert.Throws <NecessaryDataException>(() => translationUC.IsCorrectTranslation(null, MLSToCheck, Language.Dutch)); mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.Never); mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Once); }
public void IsCorrectTranslation_CallsOnceTranslator_When2LanguageNOTWellTranslated_PerformanceTest() { //ARRANGE var mockILogger = TestHelper.MakeILogger(); var mockITRSTranslationService = TestHelper.MakeITRSTranslationService(); var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object); var FrenchSource = "French Source String"; var MLSToCheck = new MultiLanguageString("blah blah blah...", FrenchSource, "blah blah blah..."); //ACT var translated = translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.French); //ASSERT Assert.False(translated); mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.Once); }
private Menu SetupRecoverSubMenu(MultiLanguageString menuTitle) { var recoverMenu = new Menu(menuTitle, Icons.Empty); var lastSession = new MenuItem(); lastSession.Label = new MultiLanguageString("Recover_LastSession"); lastSession.Clicked += () => Commands.RestoreLastSession(); recoverMenu.Controls.Add(lastSession); var autoSave = new MenuItem(); autoSave.Label = new MultiLanguageString("Recover_AutoSave"); autoSave.Clicked += () => Commands.RestoreLastAutoSave(); recoverMenu.Controls.Add(autoSave); return(recoverMenu); }
public void IsCorrectTranslation_ReturnsFalse_When_FRENCH_IsNOT_WellTranslated() { //ARRANGE var mockILogger = TestHelper.MakeILogger(); var mockITRSTranslationService = TestHelper.MakeITRSTranslationService(); var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object); var FrenchSource = "French Source String"; var MLSToCheck = new MultiLanguageString(TestHelper.EnglishTranslated, FrenchSource, "Some wrong DutchString"); //ACT var translated = translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.French); //ASSERT Assert.False(translated); mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.AtMost(Enum.GetNames(typeof(Language)).Count() - 1)); mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Never); }
public void IsCorrectTranslation_ReturnsTrue_When_DUTCH_IS_WellTranslated() { //ARRANGE var mockILogger = TestHelper.MakeILogger(); var mockITRSTranslationService = TestHelper.MakeITRSTranslationService(); var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object); var DutchSource = "Dutch Source String"; var MLSToCheck = new MultiLanguageString(TestHelper.EnglishTranslated, TestHelper.FrenchTranslated, DutchSource); //ACT var translated = translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.Dutch); //ASSERT Assert.True(translated); mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.Once); mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Never); }
public TemplateData( string id, string timestamp, string snomedVersion, string snomedBranch, string defaultLanguage, MultiLanguageString title, string etl ) { if (string.IsNullOrEmpty(snomedVersion)) { throw new ArgumentException($"'{nameof(snomedVersion)}' cannot be null or empty", nameof(snomedVersion)); } if (string.IsNullOrEmpty(snomedBranch)) { throw new ArgumentException($"'{nameof(snomedBranch)}' cannot be null or empty", nameof(snomedBranch)); } if (string.IsNullOrEmpty(defaultLanguage)) { throw new ArgumentException($"'{nameof(defaultLanguage)}' cannot be null or empty", nameof(defaultLanguage)); } if (string.IsNullOrEmpty(etl)) { throw new ArgumentException($"'{nameof(etl)}' cannot be null or empty", nameof(etl)); } if (title == null) { throw new ArgumentNullException(nameof(title)); } if (!title.IsTranslatedFor(defaultLanguage)) { throw new ArgumentException($"'{nameof(title)}' should be translated for the default language."); } Id = id; DefaultLanguage = defaultLanguage; Title = title; TimeStamp = timestamp; SnomedVersion = snomedVersion.Trim(); SnomedBranch = snomedBranch.Trim(); Etl = etl.Trim(); }
/// <summary> /// Create a new voting. /// </summary> /// <param name="dataPath">Path where application data is stored.</param> /// <param name="title">Title of this voting.</param> /// <param name="description">Description of this voting.</param> /// <param name="url">Url of the discussion of the voting.</param> /// <param name="votingBeginDate">Date at which voting begins.</param> /// <param name="votingEndDate">Date a which voting ends.</param> /// <param name="groupId">Id of the group in which the voting takes place.</param> public VotingParameters( MultiLanguageString title, MultiLanguageString description, MultiLanguageString url, DateTime votingBeginDate, DateTime votingEndDate, int groupId) { if (title == null) throw new ArgumentNullException("title"); if (description == null) throw new ArgumentNullException("description"); VotingId = Guid.NewGuid(); Title = title; Description = description; Url = url; VotingBeginDate = votingBeginDate; VotingEndDate = votingEndDate; GroupId = groupId; }
/// <summary> /// Creates a new voting descriptor from offline files. /// </summary> /// <param name="offlinePath">Path to the offline files.</param> public VotingDescriptor(string offlinePath) { string materialFileName = Path.Combine(offlinePath, Files.VotingMaterialFileName); if (!File.Exists(materialFileName)) throw new ArgumentException("Offline voting material file not found."); DirectoryInfo offlineDirectory = new DirectoryInfo(offlinePath); VotingMaterial material = Serializable.Load<VotingMaterial>(materialFileName); VotingParameters parameters = material.Parameters.Value; this.offlinePath = offlinePath; this.id = parameters.VotingId; this.title = parameters.Title; this.descripton = parameters.Description; this.url = parameters.Url; this.status = VotingStatus.Offline; this.authoritiesDone = null; this.voteFrom = parameters.VotingBeginDate; this.voteUntil = parameters.VotingEndDate; this.authorityCount = parameters.AuthorityCount; this.envelopeCount = offlineDirectory.GetFiles(Files.EnvelopeFilePattern).Count(); this.questions = new List<QuestionDescriptor>(); this.questions.AddRange(parameters.Questions.Select(question => new QuestionDescriptor(question))); this.groupId = parameters.GroupId; this.authoritiesDone = new List<Guid>(); for (int authorityIndex = 1; authorityIndex < parameters.AuthorityCount + 1; authorityIndex++) { string partialDecipherFileName = Path.Combine(offlinePath, string.Format(Files.PartialDecipherFileString, authorityIndex)); if (File.Exists(partialDecipherFileName)) { var partialDecipher = Serializable.Load<Signed<PartialDecipherList>>(partialDecipherFileName); this.authoritiesDone.Add(partialDecipher.Certificate.Id); } } }
/// <summary> /// List all groups in database. /// </summary> /// <returns>List of groups.</returns> public List<Group> GetGroups() { MySqlDataReader reader = DbConnection .ExecuteReader("SELECT Id, NameEnglish, NameGerman, NameFrench, NameItalien FROM votinggroup"); List<Group> groupList = new List<Group>(); while (reader.Read()) { MultiLanguageString name = new MultiLanguageString(); name.Set(Language.English, reader.GetString(1)); name.Set(Language.German, reader.GetString(2)); name.Set(Language.French, reader.GetString(3)); name.Set(Language.Italien, reader.GetString(4)); groupList.Add(new Group(reader.GetInt32(0), name)); } reader.Close(); return groupList; }
/// <summary> /// Create a new voting descriptor. /// </summary> /// <param name="parameters">Parameters of voting to describe.</param> /// <param name="status">Status of the voting.</param> /// <param name="authoritiesDone">List of authorities that have completed the current step if applicable.</param> public VotingDescriptor(VotingParameters parameters, VotingStatus status, List<Guid> authoritiesDone, int envelopeCount) { this.id = parameters.VotingId; this.title = parameters.Title; this.descripton = parameters.Description; this.url = parameters.Url; this.status = status; this.authoritiesDone = authoritiesDone; this.voteFrom = parameters.VotingBeginDate; this.voteUntil = parameters.VotingEndDate; this.authorityCount = status == VotingStatus.Deciphering ? parameters.Thereshold + 1 : parameters.AuthorityCount; this.envelopeCount = envelopeCount; this.questions = new List<QuestionDescriptor>(); this.questions.AddRange(parameters.Questions.Select(question => new QuestionDescriptor(question))); this.groupId = parameters.GroupId; }
/// <summary> /// Deserializes binary data to object. /// </summary> /// <param name="context">Context for deserialization</param> protected override void Deserialize(DeserializeContext context, byte version) { base.Deserialize(context, version); Id = context.ReadInt32(); Name = context.ReadMultiLanguageString(); }
/// <summary> /// Deserializes binary data to object. /// </summary> /// <param name="context">Context for deserialization</param> protected override void Deserialize(DeserializeContext context, byte version) { base.Deserialize(context, version); Text = context.ReadMultiLanguageString(); Description = context.ReadMultiLanguageString(); Url = context.ReadMultiLanguageString(); MaxVota = context.ReadInt32(); this.options = context.ReadObjectList<Option>(); }
/// <summary> /// Creates a new voting option result object. /// </summary> /// <param name="text">Text of option.</param> /// <param name="description">Descrption of option.</param> /// <param name="result">Votes for this option.</param> public OptionResult(MultiLanguageString text, MultiLanguageString description, int result) { this.text = text; this.description = description; this.result = result; }
/// <summary> /// Creates a result from a question. /// </summary> /// <param name="question">Question in question.</param> public QuestionResult(Question question) { this.text = question.Text; this.options = new List<OptionResult>(); }
public static Option CreateAbstention() { MultiLanguageString text = new MultiLanguageString(); text.Set(Language.English, LibraryResources.OptionAbstainEnglish); text.Set(Language.German, LibraryResources.OptionAbstainGerman); text.Set(Language.French, LibraryResources.OptionAbstainFrench); return new Option( text, MultiLanguageString.AllEmpty, MultiLanguageString.AllEmpty); }
protected override void Deserialize(DeserializeContext context, byte version) { base.Deserialize(context, version); Title = context.ReadMultiLanguageString(); Descrption = context.ReadMultiLanguageString(); Url = context.ReadMultiLanguageString(); Questions = context.ReadObjectList<Question>(); }
/// <summary> /// Deserializes binary data to object. /// </summary> /// <param name="context">Context for deserialization</param> protected override void Deserialize(DeserializeContext context, byte version) { base.Deserialize(context, version); Text = context.ReadMultiLanguageString(); Description = context.ReadMultiLanguageString(); Url = context.ReadMultiLanguageString(); }