Exemple #1
0
        public void TestCheckTrue()
        {
            RuleMain calculate = new RuleMain("MMCMMIII");
            var      output    = calculate.Check();

            Assert.AreEqual(true, output);
        }
Exemple #2
0
        public void TestCheckFalse()
        {
            RuleMain calculate = new RuleMain("MCMXLIVV");
            var      output    = calculate.Check();

            Assert.AreEqual(false, output);
        }
        public void NumberCalculate()
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach (var item in GalaxyNumber)
            {
                stringBuilder.Append(GalaxyNumberMapper[item].ToString());
            }
            string   romanStr = stringBuilder.ToString();
            RuleMain ruleMain = new RuleMain(romanStr);

            if (ruleMain.Check())
            {
                var _calculateSymbolList = romanStr.ToList();
                for (int i = 0; i < _calculateSymbolList.Count; i++)
                {
                    int nextIndex    = i + 1;
                    var currentPrice = (decimal)Tool.ToRomanNumeral(_calculateSymbolList[i].ToString());
                    var nextPrice    = nextIndex < _calculateSymbolList.Count ? (decimal)Tool.ToRomanNumeral(_calculateSymbolList[nextIndex].ToString()) : 0M;
                    if (currentPrice < nextPrice)
                    {
                        GalaxyNumberPrice += nextPrice - currentPrice;
                        i++;
                    }
                    else
                    {
                        GalaxyNumberPrice += currentPrice;
                    }
                }
            }
            else
            {
                throw new NotImplementedException("Check失败");
            }
        }
Exemple #4
0
        private static void RuleManualListToFile_1(RuleMain rm, List <RuleManuFile_1> RuleManualList)
        {
            var rml = rm.Content as RuleManualList;

            RuleManualList.Add(new RuleManuFile_1()
            {
                Format          = rm.Format,
                Name            = rm.Name,
                Description     = rm.Description,
                Contents        = XMLSerializer.DictionaryToXml(rml.ContentList),
                SelectedContent = rml.SelectedContent
            });
        }
Exemple #5
0
        private static void RuleTimeToFile_1(RuleMain rm, List <RuleTimeFile_1> RuleTimeList)
        {
            var rt = rm.Content as RuleTime;

            RuleTimeList.Add(new RuleTimeFile_1()
            {
                Format      = rm.Format,
                Name        = rm.Name,
                Description = rm.Description,
                Contents    = new RuleTimeFile_1.RTContent
                {
                    Pattern = rt.Pattern
                }
            });
        }
Exemple #6
0
        public RuleEditorViewModel(IRegionManager regionManager, ObservableCollection <RuleMain> originalRuleList, RuleMain originalRule)
        {
            RegionManager = regionManager;
            RegionManager.Regions[RegionNames.RuleCommon].RemoveAll();
            RegionManager.Regions[RegionNames.RuleContent].RemoveAll();
            RegionManager.Regions[RegionNames.RuleButton].RemoveAll();
            RegionManager.Regions[RegionNames.RuleButton].RemoveAll();

            // Initialize Rule Properties
            OriginalRuleList       = originalRuleList;
            OriginalRuleBeforeEdit = originalRule;

            RuleInputListWithoutOriginalRule = new List <RuleInput>();
            foreach (var r in OriginalRuleList)
            {
                if (r.Content is RuleInput && r != OriginalRuleBeforeEdit)
                {
                    RuleInputListWithoutOriginalRule.Add(r.Content as RuleInput);
                }
            }

            EditingRule        = originalRule.Clone as RuleMain;
            SelectedRuleFormat = EditingRule.Format;

            // Initialize View
            var topView = new RuleCommonView();

            topView.DataContext = this;
            RegionManager.Regions[RegionNames.RuleCommon].Add(topView, null, true);

            var botView = new EditOrDeleteButtonView();

            botView.DataContext = this;
            RegionManager.Regions[RegionNames.RuleButton].Add(botView, null, true);

            PrintExample = new DelegateCommand(GetExample);

            AddToList      = new DelegateCommand(AddToManualList);
            UpdateList     = new DelegateCommand(UpdateManualList);
            RemoveFromList = new DelegateCommand(RemoveFromManualList);

            Edit   = new DelegateCommand(IntoEditMode);
            Delete = new DelegateCommand(DeleteRule);

            Complete = new DelegateCommand(EditComplete);
            Cancle   = new DelegateCommand(EditCancle);
        }
Exemple #7
0
        private static void RuleInputCombineFile_1(RuleMain rm, List <RuleInputCombineFile_1> RuleInputCombineList)
        {
            var ric = rm.Content as RuleInputCombine;

            RuleInputCombineList.Add(new Files.RuleInputCombineFile_1()
            {
                Format      = rm.Format,
                Name        = rm.Name,
                Description = rm.Description,
                Contents    = new RuleInputCombineFile_1.RICContent
                {
                    Seperator  = ric.Seperator,
                    StartIndex = ric.StartIndex,
                    Length     = ric.Length,
                    InputList  = ric.InputList
                }
            });
        }
Exemple #8
0
        private static void RuleInputListToFile_1(RuleMain rm, List <RuleInputFile_1> RuleInputList)
        {
            var ri = rm.Content as RuleInput;

            RuleInputList.Add(new RuleInputFile_1()
            {
                Format      = rm.Format,
                Name        = rm.Name,
                Description = rm.Description,
                Contents    = new RuleInputFile_1.RIContent
                {
                    Order      = ri.Order,
                    StartIndex = ri.StartIndex,
                    CharLength = ri.CharLength,
                    InputData  = ri.InputData
                }
            });
        }
Exemple #9
0
        private static void RuleSequentialNumToFile_1(RuleMain rm, List <RuleSequFile_1> RuleSequentialNumList)
        {
            var rsn = rm.Content as RuleSequentialNum;

            RuleSequentialNumList.Add(new RuleSequFile_1()
            {
                Format      = rm.Format,
                Name        = rm.Name,
                Description = rm.Description,
                Contents    = new RuleSequFile_1.RSContent
                {
                    NumLength    = rsn.NumLength,
                    MinNum       = rsn.MinNum,
                    MaxNum       = rsn.MaxNum,
                    CurrNum      = rsn.CurrNum,
                    Increment    = rsn.Increment,
                    OnZeroFiller = rsn.OnZeroFiller,
                }
            });
        }
Exemple #10
0
        private void CreateNewRule()
        {
            var    newRule = new RuleMain();
            string newName = "NewRule";
            int    addNum  = 1;

            foreach (var r in RuleList)
            {
                if (r.Name.Equals(newName + "_" + addNum.ToString()))
                {
                    addNum++;
                }
            }
            newRule.Name   = newName + "_" + addNum.ToString();
            newRule.Format = RuleRegulation.RuleFormat.SEQUENTIAL_NUM;

            new RuleEditorViewModel(RegionManager, RuleList, newRule)
            {
                IsEditMode = true
            };
        }
Exemple #11
0
        private void EditComplete()
        {
            if (ErrorMsg != null)
            {
                DialogService.ShowSimpleTextDialog("Warning", ErrorMsg);
            }
            else
            {
                var index = OriginalRuleList.Count;
                if (OriginalRuleList.Contains(OriginalRuleBeforeEdit))
                {
                    index = OriginalRuleList.IndexOf(OriginalRuleBeforeEdit);
                    OriginalRuleList.RemoveAt(index);
                }
                OriginalRuleList.Insert(index, EditingRule);
                OriginalRuleBeforeEdit           = EditingRule;
                OriginalRuleBeforeEdit.IsChanged = true;

                EditingRule = OriginalRuleBeforeEdit.Clone as RuleMain;;
                IsEditMode  = false;
            }
        }