/// <summary> /// Reads an XmlSubtree an a law and prepares a GUI (with windows) to /// represent the Law. /// </summary> /// <param name="reader"></param> /// <param name="law"></param> public void prepareGui(XmlReader reader, Law law) { // TODO: Only one window and many widget? GameObject gowin = WindowManager.openEmptyWindow(law.id + "_window"); GameObject go = Instantiate(dynamicWidgetPrototype); WindowWidget window = gowin.GetComponent <WindowWidget>(); window.content = go; if (go.GetComponent <DynamicXmlWidget>() == null) { Debug.LogError("Missing DynamicXMlWindow component."); return; } DynamicXmlWidget law_widget = go.GetComponent <DynamicXmlWidget>(); //proto.moveToCanvas(); go.name = law.id + "_widget"; law_widget.target = law; law_widget.buildGui(reader); window.minimumSize = law_widget.minimumSize + WindowWidget.margin; lawGUIs[law.id] = go; }
private void LoadLaws(ExcelWorksheet reader, List <Law> lawsList, string language, int row) { List <Law> result = new List <Law>(); var laws = ProcessLaws(GetString(reader, 6, row)); var lawLinks = ProcessLaws(GetString(reader, 7, row)); if (laws == null) { return; } while (laws.Count > 0) { var link = lawLinks?.Dequeue(); var reference = link; Law law = new Law(); result.Add(law); law.Names.Add(new LanguageLabel(laws.Dequeue(), language)); if (link != null) { law.Links.Add(new LanguageLabel(link, language)); } law.LawReference = reference ?? law.Names.First().Label; } lawsList?.AddRange(result); }
public void UnitPriceInvalidCountCompanyValidTest() { double minUnitPrice = 0; double maxUnitPrice = 100; int minCount = 50; double wholeValue = 7500; string goodName = "gun"; string company = "googoolParvar"; double weight = 100; double unitPrice = 150; int count = 50; DateTime issuanceDate = new DateTime(2015, 1, 20); List <string> merchandises = new List <string>(); List <string> companies = new List <string>(); List <string> licenseNeeded = new List <string>(); companies.Add("googoolParvar"); bool expected = false; //drivers Law lawTest = new Law(DateTime.MinValue, DateTime.MaxValue, minUnitPrice, maxUnitPrice, minCount, "", "", double.MinValue, merchandises, companies, licenseNeeded); Statement statement = new Statement(); statement.SetParameters(issuanceDate, wholeValue, "", ""); MerchandiseInStatement MIS = new MerchandiseInStatement(goodName, company, weight, count, unitPrice); statement.AddNewMerchandise(MIS); Assert.AreEqual(lawTest.IsValidWithoutMerchandise(statement), expected, "Wrong Check in "); }
public void PopulatedListMonadLaw(Law <TestArgs <ListF, string, int, long> > law) { var args = TestArgs.Default <ListF>(); args.LiftedA = new List <string> { args.A }.K(); args.LiftedB = new List <int> { args.B }.K(); args.LiftedFuncAtoB = new List <Func <string, int> > { args.FuncAtoB }.K(); args.LiftedFuncBtoC = new List <Func <int, long> > { args.FuncBtoC }.K(); args.FuncAtoLiftedB = a => new List <int> { args.FuncAtoB(a) }.K(); args.FuncBtoLiftedC = b => new List <long> { args.FuncBtoC(b) }.K(); law.TestLaw(args).ShouldBe(true); }
public void EqLaw(Law <List <string> > law) { law.TestLaw(new List <string>()).ShouldBe(true); law.TestLaw(new List <string> { "1" }).ShouldBe(true); }
public static void repeal(User user, string guid) { if (guid != "") { Law law = Legislation.Laws.GetLawByGuid(guid); if (law is Law) { Legislation.Laws.RemoveLaw(Guid.Parse(guid)); } else { send_pm( "<color=#FF4444>ERROR: Invalid LAWID, please double check it exists.</color>", user.Player, ChatCategory.Info, DefaultChatTags.Government ); } } else { send_pm( "<color=#FF4444>ERROR: This command takes a string LAWID as an argument.</color>", user.Player, ChatCategory.Info, DefaultChatTags.Government ); } }
/// <summary> /// 设置列表项下载状态文字(法规、阅读历史、下载共用) /// </summary> /// <param name="law"></param> /// <param name="text"></param> public void setLawStateText(Type type, Law law, string text) { if (Global.online) { var controlsHost = new Control(); if (type == typeof(LawListItem)) { controlsHost = flp_lawLibrary; } else if (type == typeof(ViewHistoryListItem)) { controlsHost = flp_viewHistory; } else if (type == typeof(DownloadListItem)) { controlsHost = flp_downloadTask; } foreach (Control c in controlsHost.Controls) { if (c is BaseListItem) { var item = c as BaseListItem; if (item.law.lawId == law.lawId) { item.setDownloadState(text); return; } } } } }
public void GivenAllNotNullElements_ReturnsError() { var testCollection = new[] { "subject1", "subject2" }; var result = Law.CreateNotNullElements(string.Empty, testCollection).Evaluate(); Assert.True(result.IsSuccess()); }
public void check_low_with_two_unvalid_merchandise_in_statement() { List <string> merchandises = new List <string>(); merchandises.Add("berenj"); merchandises.Add("gandom"); List <string> companies = new List <string>(); companies.Add("tabarok"); companies.Add("golestan"); List <string> licenseNeeded = new List <string>(); DateTime issuanceDate = new DateTime(2015, 1, 18); //stub bool expected = false; //drivers Law lawTest = new Law(DateTime.MinValue, DateTime.MaxValue, 200, 5000, 200 , "", "", double.MinValue, merchandises, companies, licenseNeeded); Statement statement = new Statement(); statement.SetParameters(issuanceDate, 200000, "", ""); MerchandiseInStatement mis = new MerchandiseInStatement("berenj", "tabarok", 0, 1000, 100); MerchandiseInStatement mis2 = new MerchandiseInStatement("gandom", "golestan", 0, 100, 1000); statement.AddNewMerchandise(mis); statement.AddNewMerchandise(mis2); Assert.AreEqual(lawTest.IsValidPerMerchandise(statement), expected, "low with tow unvalid merchandise in statement isn't correctly coded!"); }
/// <summary> /// 清除某法规的本地图片 /// </summary> /// <param name="law"></param> private void clearLocalImg(Law law) { try { string path = Path.Combine(Environment.CurrentDirectory, "Image", Global.user.Id, law.lawId); if (!Directory.Exists(path)) { return; } DirectoryInfo dir = new DirectoryInfo(path); FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录 foreach (FileSystemInfo i in fileinfo) { if (i is DirectoryInfo) //判断是否文件夹 { DirectoryInfo subdir = new DirectoryInfo(i.FullName); subdir.Delete(true); //删除子目录和文件 } else { File.Delete(i.FullName); //删除指定文件 } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public ActionResult New(Law law) { try { if (!ModelState.IsValid) { return(View(law)); } else { CivLDbContext dbCivL = GetCivLDbContext(); dbCivL.Laws.Add(law); dbCivL.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { ErrorDTO errorDTO = new ErrorDTO() { Message = "An error occurred while creating a new law.", MessageDetail = ex.Message }; return(View("Error", errorDTO)); } }
private string getTitle(string id) { List <string> list = new List <string>(); foreach (string s in id.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { if (s.Contains("@"))//如果含@,是法规@章节,显示章节标题 { Node node = db.getNodeById(s.Substring(s.IndexOf("@") + 1)); if (node != null) { if (!string.IsNullOrEmpty(node.Id)) { list.Add(node.title); } } } else//如果不含@,是法规,显示法规标题 { Law law = db.getLawById(s); if (law != null) { if (!string.IsNullOrEmpty(law.lawId)) { list.Add(law.title); } } } } return(string.Join(Environment.NewLine, list)); }
public List <Law> ConvertToLaws() { List <Law> laws = new List <Law>(); foreach (listItem list in this.data.list) { Law law = new Law(); law.Id = Guid.NewGuid().ToString(); law.userId = Global.user.Id; law.lawId = list.id.ToString(); law.title = list.title; law.version = list.version; law.digest = list.abs; law.weijie = list.bookType; law.buhao = list.buhao; law.effectiveDate = UTC.ConvertIntDatetime(list.startDate).ToString("yyyy-MM-dd HH:mm:ss"); law.expiryDate = UTC.ConvertIntDatetime(list.endDate).ToString("yyyy-MM-dd HH:mm:ss"); law.linghao = list.linghao; law.siju = list.managerOrg; law.status = list.status; law.lastversion = list.lastversion; law.zefa = list.punish; law.yilai = list.related; law.banwendanwei = list.release; law.userLabel = list.tag; //string.Join(",", list.tagList.Select(t => t.desc)); law.yewu = list.biz; //string.Join(",", list.bizList.Select(b => b.desc)); law.isLocal = "0"; laws.Add(law); } return(laws); }
public void LoadAllLaws() { // Get files with the xml extension string[] files = Directory.GetFiles(Application.streamingAssetsPath + "/Laws", "*.xml"); for (int i = 0; i < files.Length; i++) { try { Law tmplaw = XmlSerializerHelper <Law> .DeserializeXmlFile(files[i]); m_allGameLaws.Add(tmplaw); } catch (Exception e) { // Trigger a breakpoint if Visual is attached to UNITY #if UNITY_EDITOR if (Debugger.IsAttached) { Debugger.Break(); } #endif UnityEngine.Debug.Log(e.Message); } } }
/// <summary> /// 删除已选任务 /// </summary> public void deleteSelectedTask() { bool hasChecked = false; foreach (Control c in flp_downloadTask.Controls) { if (c is DownloadListItem) { DownloadListItem item = c as DownloadListItem; if (item.isChecked) { hasChecked = true; Law law = item.law; if (law.isLocal == "1") { law.downloadPercent = null; law.downloadNodeCount = null; } else { law.isLocal = "0"; law.downloadPercent = null; law.downloadNodeCount = null; } db.saveLaw(law); } } if (hasChecked) { reloadDownloadList(); reloadLawList(); } } }
public void GivenNull_ReturnsError() { var result = Law.CreateNotNull <object>("subjectName", null).Evaluate(); Assert.False(result.IsSuccess()); Assert.Equal("'subjectName' should not be null.", result.GetError()); }
void loadLawPrototypes(string path) { lawPrototypes = new Dictionary <string, Law>(); XmlReaderSettings settings = new XmlReaderSettings(); XmlReader reader = XmlReader.Create(path, settings); reader.MoveToContent(); while (reader.Read()) { XmlNodeType nodeType = reader.NodeType; switch (nodeType) { case XmlNodeType.Element: //Debug.Log(reader.Name); if (reader.Name.Equals("Law")) { //Debug.Log(reader.Name); Law law = new Law(); XmlReader subtree = reader.ReadSubtree(); law.ReadXml(subtree); lawPrototypes[law.id] = law; subtree.Close(); //currentGovernment = gov; } break; case XmlNodeType.EndElement: default: //Debug.Log(reader.Name as string); break; } } }
public void Evaluate_GivenFailingPredicate_ReturnsErrorMessage() { const string expectedErrorMessage = "errorMessage"; var result = new Law(_falsePredicate, expectedErrorMessage).Evaluate(); Assert.Equal(expectedErrorMessage, result.GetError()); }
public void AddNewLaw(Law law) { string merchadises = String.Join("#", law.GetMerchandiseList().ToArray()); string companies = String.Join("#", law.GetCompanies().ToArray()); string licenses = String.Join("#", law.GetLicenses().ToArray()); //for (int i = 0; i < law.GetMerchandiseList().Count; i++) //{ // merchadises += law.GetMerchandiseList()[i]; // if (i != law.GetMerchandiseList().Count - 1) // merchadises += '#'; //} //for (int i = 0; i < law.GetCompanies().Count; i++) //{ // companies += law.GetCompanies()[i]; // if (i != law.GetCompanies().Count - 1) // companies += '#'; //} //for (int i = 0; i < law.GetLicenses().Count; i++) //{ // licenses += law.GetLicenses()[i]; // if (i != law.GetLicenses().Count - 1) // licenses += '#'; //} string query = "insert into dbo.Law values" + "('" + Convert.ToString(law.GetStartDate()) + "', '" + Convert.ToString(law.GetFinishDate()) + "', '" + Convert.ToString(law.GetMinUnitPrice()) + "', '" + Convert.ToString(law.GetMaxUnitPrice()) + "', '" + Convert.ToString(law.GetMinCount()) + "', N'" + Convert.ToString(law.GetCountry()) + "', N'" + Convert.ToString(law.GetImportType()) + "', '" + Convert.ToString(law.GetMinTotalPrice()) + "', N'" + merchadises + "', N'" + companies + "', N'" + licenses + "')"; MessageBox.Show("in in LawDAO: new law added successfully"); }
private void checkUserPreload() { User user = db.getUserById(Global.user.Id); if (user != null) { if (user.Preload != "1") { List <string> lawIds = RemoteWorker.getPreloadLaw();//获取预下载的法规id列表 lawIds = new List <string>() { }; //todo 预下载接口还未完成,可用后删除此行代码 foreach (string lawId in lawIds) { List <Node> nodes = RemoteWorker.getBookContent(lawId);//依次下载法规及内容,下载完成后,更新法规的下载状态 if (RemoteWorker.getNodeDetail(nodes.Select(n => n.Id).ToList(), downloadImage:true)) { Law law = db.getLawById(lawId); law.isLocal = "1"; law.downloadPercent = 100; law.downloadDate = DateTime.Now.ToString("yyyy-MM-dd"); law.downloadNodeCount = nodes.Count; db.saveLaw(law); } } Global.user.Preload = "1"; } } }
private IDocument CreateDocument(DataRow row) { int iType = Convert.ToInt32(row["DocTypeId"]); IDocument doc; switch (iType) { case 5000: // zakon doc = new Law(); break; case 6200: // odluka doc = new CaseLaw(); break; case 8000: // članak doc = new Article(); break; default: doc = new Law(); break; } doc.DocTitle = row["DocTitle"].ToString(); doc.SOPI = row["SOPI"].ToString(); doc.DocTypeID = iType; return(doc); }
public void ErrorInvariantLaw(Law <TestArgs <ResultOkF <bool>, string, int, long> > law) { var args = TestArgs.Default <ResultOkF <bool> >(); args.LiftedA = Error(false).K <string, bool>(); law.TestLaw(args).ShouldBe(true); }
public void SomeFunctorLaw(Law <TestArgs <OptionF, string, int, long> > law) { var args = TestArgs.Default <OptionF>(); args.LiftedA = Some(args.A); law.TestLaw(args).ShouldBe(true); }
public void NoneInvariantLaw(Law <TestArgs <OptionF, string, int, long> > law) { var args = TestArgs.Default <OptionF>(); args.LiftedA = None.K <string>(); law.TestLaw(args).ShouldBe(true); }
public void SuccessFunctorLaw(Law <TestArgs <TryF, string, int, long> > law) { var args = TestArgs.Default <TryF>(); args.LiftedA = new Success <string>(args.A); law.TestLaw(args).ShouldBe(true); }
public void GivenAllNullElements_ReturnsError() { var collectionWithNullValue = new object[] { null, null }; var result = Law.CreateNotNullElements("subjectName", collectionWithNullValue).Evaluate(); Assert.False(result.IsSuccess()); Assert.Equal("'subjectName' should contain not null elements.", result.GetError()); }
public void OkFunctorLaw(Law <TestArgs <ResultOkF <bool>, string, int, long> > law) { var args = TestArgs.Default <ResultOkF <bool> >(); args.LiftedA = Ok(args.A).K <string, bool>(); law.TestLaw(args).ShouldBe(true); }
public void FailureFunctorLaw(Law <TestArgs <TryF, string, int, long> > law) { var args = TestArgs.Default <TryF>(); args.LiftedA = GetFailure <string>().K(); law.TestLaw(args).ShouldBe(true); }
public ActionResult DeleteConfirmed(int id) { Law law = db.Laws.Find(id); db.Laws.Remove(law); db.SaveChanges(); return(RedirectToAction("Index")); }
public void updateLaw(Law law) { if (db.saveLaw(law)) { reloadDownloadList(); reloadLawList(); } }