private IEnumerable <Diag> AnalyzeMethodEnsures() { // find all symbols that are part of a Contract.Ensures(...), e.g. Contract.Ensures(Contract.Result<T>() != null) const ContractCategory contractCategory = ContractCategory.Ensures; var ensuresExpressions = _invocationExpressionSyntaxNodes .Where(item => (item.Expression as MemberAccessExpressionSyntax).IsContractExpression(contractCategory)) // find all "Contract.Ensures(...)" .Where(item => item.IsContractResultExpression()); var methodsWithContractEnsures = ensuresExpressions .Select(ensuresExpression => ensuresExpression.Ancestors().OfType <MemberDeclarationSyntax>().FirstOrDefault() as MethodDeclarationSyntax) .Select(method => method?.FindDeclaringMemberOnBaseClass(_semanticModel, _root)) .Where(method => method != null); var methodsWithNotNullAnnotation = _methodDeclarationSyntaxNodes .Where(CanAddContracts) .Where(method => method.AttributeLists.ContainsNotNullAttribute()); var methodsWithMissingContractEnsures = methodsWithNotNullAnnotation .Except(methodsWithContractEnsures); foreach (var methodSyntax in methodsWithMissingContractEnsures) { yield return(GetDiagnostic(methodSyntax, contractCategory)); } }
private IEnumerable <Diag> AnalyzeMethodParameters() { const ContractCategory contractCategory = ContractCategory.Requires; var requiresExpressions = _invocationExpressionSyntaxNodes .Where(item => (item.Expression as MemberAccessExpressionSyntax).IsContractExpression(contractCategory)); // find all "Contract.Requires(...)" var parametersWithNotNullContract = requiresExpressions .GetNotNullArgumentIdentifierSyntaxNodes() .Select(syntax => _semanticModel.GetSymbolInfo(syntax).Symbol as IParameterSymbol) // get the parameter symbol .Select(symbol => symbol?.GetTargetSymbolForAnnotation()) .Select(symbol => _root.GetSyntaxNode <ParameterSyntax>(symbol)) .Where(parameter => parameter != null); var parametersWithNotNullAnnotation = _methodDeclarationSyntaxNodes .Where(CanAddContracts) .SelectMany(node => node.ParameterList.Parameters) .Where(parameter => parameter.AttributeLists.ContainsNotNullAttribute()); var parametersWithMissingContracts = parametersWithNotNullAnnotation.Except(parametersWithNotNullContract, new DelegateEqualityComparer <ParameterSyntax>(p => p.GetLocation())); foreach (var parameterSyntax in parametersWithMissingContracts) { yield return(GetDiagnostic(parameterSyntax, contractCategory)); } }
public virtual void ParseInfo(Hashtable info) { m_Id = info.GetValue <string>((int)SPC.Id, string.Empty); m_State = (ContractState)info.GetValue <int>((int)SPC.ContractState, (int)ContractState.unknown); m_Stage = info.GetValue <int>((int)SPC.ContractStage, -1); m_SourceWorld = info.GetValue <string>((int)SPC.SourceWorld, string.Empty); m_Category = (ContractCategory)info.GetValue <int>((int)SPC.ContractCategory, (int)ContractCategory.unknown); }
public BaseContract GetProposedContract(ContractCategory category) { if (HasProposedContract(category)) { return(proposedContracts[category]); } return(null); }
public ActionResult DeleteConfirmed(int id) { ContractCategory contractCategory = db.ContractCategories.Find(id); db.ContractCategories.Remove(contractCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
private static Diag GetDiagnostic(ParameterSyntax syntax, ContractCategory contractCategory) { if (syntax?.AttributeLists.ContainsNotNullAttribute() != false) { return(null); } return(new Diag(syntax.Identifier.GetLocation(), syntax.Identifier.Text, contractCategory)); }
private static Diag GetDiagnostic(ParameterSyntax syntax, ContractCategory contractCategory) { if (syntax == null) { return(null); } return(new Diag(syntax.Identifier.GetLocation(), syntax.Identifier.Text, contractCategory)); }
public ActionResult Edit([Bind(Include = "Id,Name")] ContractCategory contractCategory) { if (ModelState.IsValid) { db.Entry(contractCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contractCategory)); }
public BaseContract GetActiveContract(ContractCategory category) { foreach (var pac in activeContracts) { if (pac.Value.category == category) { return(pac.Value); } } return(null); }
public bool HasActiveContract(ContractCategory category) { foreach (var pac in activeContracts) { if (pac.Value.category == category) { return(true); } } return(false); }
private static Diag GetDiagnostic(VariableDeclaratorSyntax syntax, ContractCategory contractCategory) { var fieldDeclarationSyntax = syntax?.Ancestors().OfType <FieldDeclarationSyntax>().FirstOrDefault(); if (fieldDeclarationSyntax?.AttributeLists.ContainsNotNullAttribute() != false) { return(null); } return(new Diag(fieldDeclarationSyntax.GetLocation(), syntax.ToString(), contractCategory)); }
public ActionResult Create([Bind(Include = "Id,Name")] ContractCategory contractCategory) { if (ModelState.IsValid) { db.ContractCategories.Add(contractCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contractCategory)); }
public ActionResult Edit([Bind(Include = "ID,Name,ContractID")] ContractCategory contractCategory) { if (ModelState.IsValid) { db.Entry(contractCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ContractID = new SelectList(db.Contracts, "ID", "Name", contractCategory.ContractID); return(View(contractCategory)); }
public ActionResult Create([Bind(Include = "ID,Name,ContractID")] ContractCategory contractCategory) { if (ModelState.IsValid) { db.ContractCategories.Add(contractCategory); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ContractID = new SelectList(db.Contracts, "ID", "Name", contractCategory.ContractID); return(View(contractCategory)); }
private static Diag GetDiagnostic(BaseMethodDeclarationSyntax syntax, ContractCategory contractCategory) { if (syntax == null) { return(null); } return(syntax.TryCast().Returning <Diag>() .When <MethodDeclarationSyntax>(s => new Diag(s.Identifier.GetLocation(), s.Identifier.Text, contractCategory)) .When <ConstructorDeclarationSyntax>(s => new Diag(s.Identifier.GetLocation(), s.Identifier.Text, contractCategory)) .Result); }
public static ContractWorkload StatisYearCategoryRegularLoad(int year, ContractCategory category) { MySqlConnection con = DBTools.GetMySqlConnection(); MySqlCommand cmd; ContractWorkload workload = null; try { con.Open(); cmd = con.CreateCommand(); cmd.CommandText = STATIS_YEAR_CATEGORY_REGULARLOAD_STR; cmd.Parameters.AddWithValue("@Year", year); cmd.Parameters.AddWithValue("@CategoryId", category.Id); MySqlDataReader sqlRead = cmd.ExecuteReader(); cmd.Dispose(); while (sqlRead.Read()) { workload = new ContractWorkload(); workload.ContractId = STATIS_KIND.STATIS_YEAR_CATEGORY_REGULARLOAD.ToString(); workload.Work = double.Parse(sqlRead["works"].ToString()); workload.Expense = double.Parse(sqlRead["expenses"].ToString()); /// BUG ContractItem item = new ContractItem(); item.Id = -1; workload.Item = item; } con.Close(); con.Dispose(); } catch (Exception) { throw; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } return(workload); }
private List <ContractData> GetContracts(ContractCategory category) { List <ContractData> categoryContracts = new List <ContractData>(); foreach (var pc in m_Contracts) { if (pc.Value.category == category) { categoryContracts.Add(pc.Value); } } return(categoryContracts); }
public BaseContract(string id, int stage, string sourceWorld, ContractCategory category, ContractManager contractOwner) { m_Id = id; m_State = ContractState.proposed; m_Stage = stage; m_SourceWorld = sourceWorld; m_Category = category; m_ContractOwner = contractOwner; }
public List <ContractData> GetContracts(ContractCategory category, int level) { List <ContractData> categoryContracts = GetContracts(category); List <ContractData> leveledContracts = new List <ContractData>(); foreach (var c in categoryContracts) { if (level >= c.minLevel) { leveledContracts.Add(c); } } return(leveledContracts); }
// GET: ContractCategories/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ContractCategory contractCategory = db.ContractCategories.Find(id); if (contractCategory == null) { return(HttpNotFound()); } return(View(contractCategory)); }
// GET: ContractCategories/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ContractCategory contractCategory = db.ContractCategories.Find(id); if (contractCategory == null) { return(HttpNotFound()); } ViewBag.ContractID = new SelectList(db.Contracts, "ID", "Name", contractCategory.ContractID); return(View(contractCategory)); }
private Diag GetDiagnostic(PropertyDeclarationSyntax syntax, ContractCategory contractCategory) { if (syntax == null) { return(null); } syntax = syntax.FindDeclaringMemberOnBaseClass(_semanticModel, _root); if (syntax.AttributeLists.ContainsNotNullAttribute()) { return(null); } return(new Diag(syntax.Identifier.GetLocation(), syntax.Identifier.Text, contractCategory)); }
public static List <ContractCategory> QuerySDepartmentContractCategory(int departmentId) { MySqlConnection con = DBTools.GetMySqlConnection(); MySqlCommand cmd; List <ContractCategory> categorys = new List <ContractCategory>(); try { con.Open(); cmd = con.CreateCommand(); cmd.CommandText = QUERY_SDEPARTMENT_CONTRACTCATEGORY_STR; cmd.Parameters.AddWithValue("@DepartmentId", departmentId); MySqlDataReader sqlRead = cmd.ExecuteReader(); cmd.Dispose(); while (sqlRead.Read()) { ContractCategory category = new ContractCategory(); category.Id = int.Parse(sqlRead["id"].ToString()); category.Category = sqlRead["category"].ToString(); category.CategoryShortCall = sqlRead["categoryshortcall"].ToString(); categorys.Add(category); } con.Close(); con.Dispose(); } catch (Exception) { throw; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } return(categorys); }
private IEnumerable <Diag> AnalyzeEnsures() { // find all symbols that are part of a Contract.Ensures(...), e.g. Contract.Ensures(Contract.Result<T>() != null) const ContractCategory contractCategory = ContractCategory.Ensures; var ensuresExpressions = _invocationExpressionSyntaxNodes .Where(item => item.Expression.IsContractExpression(contractCategory)) // find all "Contract.Ensures(...)" .Where(item => item.IsContractResultExpression()); return(ensuresExpressions .Select(ensuresExpression => ensuresExpression.Ancestors().OfType <MemberDeclarationSyntax>().FirstOrDefault()) .Select(outerMember => outerMember.TryCast().Returning <Diag>() .When <MethodDeclarationSyntax>(syntax => GetDiagnostic(syntax, contractCategory)) .When <PropertyDeclarationSyntax>(syntax => GetDiagnostic(syntax, contractCategory)) .Result)); }
public ContractData GetRandom(ContractCategory category) { List <ContractData> dataList = new List <ContractData>(); foreach (var pc in m_Contracts) { if (pc.Value.category == category) { dataList.Add(pc.Value); } } if (dataList.Count > 0) { return(dataList.AnyElement()); } return(null); }
public static ContractCategory GetCategory(string categoryShortCall) { MySqlConnection con = DBTools.GetMySqlConnection(); MySqlCommand cmd; ContractCategory category = new ContractCategory(); try { con.Open(); cmd = con.CreateCommand(); cmd.CommandText = GET_CATEGORY_BY_SHORTCALL_STR; cmd.Parameters.AddWithValue("@CategoryShortCall", categoryShortCall); MySqlDataReader sqlRead = cmd.ExecuteReader(); cmd.Dispose(); while (sqlRead.Read()) { category.Id = int.Parse(sqlRead["id"].ToString()); category.Category = sqlRead["category"].ToString(); category.CategoryShortCall = sqlRead["shortcall"].ToString(); } con.Close(); con.Dispose(); } catch (Exception) { throw; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } return(category); }
private IEnumerable <Diag> AnalyzeInvariants() { // find all symbols that are part of a Contract.Invariant(...), e.g. Contract.Invariant(x != null) => x const ContractCategory contractCategory = ContractCategory.Invariant; var invariantExpressions = _invocationExpressionSyntaxNodes .Where(item => (item.Expression as MemberAccessExpressionSyntax).IsContractExpression(contractCategory)); // find all "Contract.Invariant(...)" var notNullSyntaxNodes = invariantExpressions.GetNotNullArgumentIdentifierSyntaxNodes() .Select(syntax => _semanticModel.GetSymbolInfo(syntax).Symbol) // get the parameter symbol .Select(notNullParameterSymbol => _root.GetSyntaxNode <SyntaxNode>(notNullParameterSymbol)); return(notNullSyntaxNodes .Select(syntaxNode => syntaxNode.TryCast().Returning <Diag>() .When <PropertyDeclarationSyntax>(syntax => GetDiagnostic(syntax, contractCategory)) .When <VariableDeclaratorSyntax>(syntax => GetDiagnostic(syntax, contractCategory)) .Result)); }
//public Hashtable CompleteContract(string id) { // ContractManager contractManager = player.GetComponent<ContractManager>(); // bool success = contractManager.CompleteContract(id); // Hashtable hash = CreateResponse(Common.RPCErrorCode.Ok); // hash.Add(SPCKEY(SPC.Status), success); // return hash; //} public Hashtable ProposeContract(int icategory) { ContractCategory category = (ContractCategory)icategory; ContractManager contractManager = player.GetComponent <ContractManager>(); if (contractManager.HasActiveContract(category)) { Hashtable resp = CreateResponse(RPCErrorCode.AlreadyHasAcceptedContractWithSuchCategory); resp.Add((int)SPC.ContractCategory, icategory); return(resp); } var generator = ContractGenerator.Create(category); if (generator == null) { Hashtable resp = CreateResponse(RPCErrorCode.ContractGeneratorNotFound); resp.Add((int)SPC.ContractCategory, icategory); return(resp); } var playerRaceable = player.GetComponent <RaceableObject>(); var playerCharacter = player.GetComponent <CharacterObject>(); var contract = generator.Generate((Race)playerRaceable.race, playerCharacter.level, (player.World as MmoWorld).Name, contractManager, player.resource); if (contract == null) { Hashtable resp = CreateResponse(RPCErrorCode.NoValidContract); return(resp); } if (false == contractManager.ProposeContract(contract)) { return(CreateResponse(RPCErrorCode.UnableProposeContract)); } Hashtable result = CreateResponse(RPCErrorCode.Ok); result.Add((int)SPC.Contract, contract.GetInfo()); return(result); }
/// <summary> /// 向工作队列中添加一个统计信息 /// 每当完成一个单子之后其实就可以统计这个单子所属的工作量的信息 /// 任务为统计当前年份year, 当前类Category别下的会签单信息 /// </summary> /// <param name="contractId"></param> public void AddStatisticWork(string contractId) { // 会签单信息已经完成,直接生成会签单信息 int year = DALHDJContract.GetYearFromContractId(contractId); // 从编号中取出年份信息 // 此处其实有性能的缺失 string categoryShortCall = DALHDJContract.GetCatgoryShortCallFromContractId(contractId).ToString(); // 从会签单中取出简称 ContractCategory category = DALContractIdCategory.GetCategory(categoryShortCall); MSOfficeThreadWork work = new MSOfficeThreadWork { WorkKind = WORK_KIND.CREATE_STATISTC_REQUEST, Year = year, CategoryId = category.Id, }; lock (m_worksQueue) { m_worksQueue.Enqueue(work); } }
private void MoveActiveContractToTrash(ContractCategory category) { List <string> ids = new List <string>(); foreach (var pac in m_ActiveContracts) { if (pac.Value.category == category) { ids.Add(pac.Key); } } foreach (string id in ids) { BaseContract old; if (m_ActiveContracts.TryRemove(id, out old)) { AddOrReplaceCompletedContract(old); } } }