public static void HandleAirReaction(ElementItem elementItem) { DetermineAlikaliAirReactionCompound(elementItem, out Compound compound, out int hydrogensSpawned, out int compoundsSpawned); SpawnItemsFromReaction(elementItem, compound, hydrogensSpawned, compoundsSpawned); }
static void Main(string[] args) { using (var sourceContext = new BackboneContext("SourceContext")) { using (var targetContext = new BackboneContext("TargetContext")) { // Init Security.LoginAs(-1, "Administrator"); sourceContext.Configuration.AutoDetectChangesEnabled = false; targetContext.Database.CreateIfNotExists(); targetContext.Configuration.AutoDetectChangesEnabled = false; // Roles if (!targetContext.Roles.Any()) { var sourceRoles = sourceContext.Roles.AsEnumerable(); foreach (var sourceRole in sourceRoles) { var targetRole = new Role { Name = sourceRole.Name, CreatedOn = sourceRole.CreatedOn, ModifiedOn = sourceRole.ModifiedOn, DeletedOn = sourceRole.DeletedOn, }; targetContext.Roles.Add(targetRole); } } // Users var sourceUsers = sourceContext.Users .Include(x => x.Logins) .Include(x => x.Roles) .AsEnumerable(); foreach (var sourceUser in sourceUsers) { Console.WriteLine($"User: {sourceUser.Id}"); var targetUser = new User { UserName = sourceUser.UserName, Email = sourceUser.Email, EmailConfirmed = sourceUser.EmailConfirmed, EmailConfirmationSentOn = sourceUser.EmailConfirmationSentOn, HasPassword = sourceUser.HasPassword, PasswordHash = sourceUser.PasswordHash, SecurityStamp = sourceUser.SecurityStamp, SingleUseToken = sourceUser.SingleUseToken, FirstName = sourceUser.FirstName, MiddleName = sourceUser.MiddleName, LastName = sourceUser.LastName, Notes = sourceUser.Notes, CreatedOn = sourceUser.CreatedOn, ModifiedOn = sourceUser.ModifiedOn, DeletedOn = sourceUser.DeletedOn, }; targetContext.Users.Add(targetUser); // User roles var sourceUserRoles = sourceUser.Roles; foreach (var sourceUserRole in sourceUserRoles) { // Console.WriteLine($"User role {sourceUserRole.UserId} - {sourceUserRole.RoleId}"); var targetUserRole = new UserRole { User = targetUser, RoleId = sourceUserRole.RoleId, CreatedOn = sourceUserRole.CreatedOn, ModifiedOn = sourceUserRole.ModifiedOn, DeletedOn = sourceUserRole.DeletedOn, }; targetUser.Roles.Add(targetUserRole); } // User logins var sourceUserLogins = sourceUser.Logins; foreach (var sourceUserLogin in sourceUserLogins) { // Console.WriteLine("user login " + userLogin.LoginProvider); var targetUserLogin = new UserLogin { User = targetUser, LoginProvider = sourceUserLogin.LoginProvider, ProviderKey = sourceUserLogin.ProviderKey, CreatedOn = sourceUserLogin.CreatedOn, ModifiedOn = sourceUserLogin.ModifiedOn, DeletedOn = sourceUserLogin.DeletedOn, }; targetUser.Logins.Add(targetUserLogin); } } // Projects var projects = sourceContext.Project .Include(x => x.User) .Include(x => x.ElementSet) .ToList(); foreach (var sourceProject in projects) { Console.WriteLine($"Project: {sourceProject.Name}"); var targetProject = new Project { User = targetContext.Users.Local.Single(x => x.UserName == sourceProject.User.UserName), Name = sourceProject.Name, Origin = sourceProject.Origin, Description = sourceProject.Description, RatingCount = sourceProject.RatingCount, CreatedOn = sourceProject.CreatedOn, ModifiedOn = sourceProject.ModifiedOn, DeletedOn = sourceProject.DeletedOn, }; targetContext.Project.Add(targetProject); // Elements var elements = sourceProject.ElementSet; foreach (var sourceElement in elements) { // Console.WriteLine($"Element {sourceElement.Name}"); var targetElement = new Element { Project = targetProject, Name = sourceElement.Name, CreatedOn = sourceElement.CreatedOn, ModifiedOn = sourceElement.ModifiedOn, DeletedOn = sourceElement.DeletedOn, }; targetContext.Element.Add(targetElement); // Fields var sourceFields = sourceContext.ElementField .Include(x => x.UserElementFieldSet) .Where(x => x.ElementId == sourceElement.Id) .AsEnumerable(); foreach (var sourceField in sourceFields) { var targetField = new ElementField { Element = targetElement, Name = sourceField.Name, DataType = sourceField.DataType, UseFixedValue = sourceField.UseFixedValue, RatingEnabled = sourceField.RatingEnabled, SortOrder = sourceField.SortOrder, RatingTotal = sourceField.RatingTotal, RatingCount = sourceField.RatingCount, CreatedOn = sourceField.CreatedOn, ModifiedOn = sourceField.ModifiedOn, DeletedOn = sourceField.DeletedOn, }; // Selected element if (sourceField.SelectedElement != null) { targetField.SelectedElement = targetContext.Element .Local .Single(x => x.Project == targetProject && x.Name == sourceField.SelectedElement.Name); } targetContext.ElementField.Add(targetField); // User fields var userFieldSet = sourceField.UserElementFieldSet; foreach (var sourceUserField in userFieldSet) { var targetUserElementField = new UserElementField { User = targetContext.Users.Local.Single(x => x.UserName == sourceUserField.User.UserName), ElementField = targetField, Rating = sourceUserField.Rating, CreatedOn = sourceUserField.CreatedOn, ModifiedOn = sourceUserField.ModifiedOn, DeletedOn = sourceUserField.DeletedOn, }; targetContext.UserElementField.Add(targetUserElementField); } } // Items var sourceItems = sourceContext.ElementItem .Include(x => x.ElementCellSet.Select(e => e.UserElementCellSet)) .Where(x => x.ElementId == sourceElement.Id) .AsEnumerable(); foreach (var sourceItem in sourceItems) { var targetItem = new ElementItem { Element = targetElement, Name = sourceItem.Name, CreatedOn = sourceItem.CreatedOn, ModifiedOn = sourceItem.ModifiedOn, DeletedOn = sourceItem.DeletedOn, }; targetContext.ElementItem.Add(targetItem); // Cells var sourceCells = sourceItem.ElementCellSet; foreach (var sourceCell in sourceCells) { var targetCell = new ElementCell { ElementField = targetContext.ElementField.Local.Single(x => x.Element == targetItem.Element && x.Name == sourceCell.ElementField.Name), ElementItem = targetItem, StringValue = sourceCell.StringValue, DecimalValueTotal = sourceCell.DecimalValueTotal, DecimalValueCount = sourceCell.DecimalValueCount, CreatedOn = sourceCell.CreatedOn, ModifiedOn = sourceCell.ModifiedOn, DeletedOn = sourceCell.DeletedOn, }; // Selected item if (sourceCell.SelectedElementItem != null) { targetCell.SelectedElementItem = targetContext.ElementItem .Local .Single(x => x.Element.Project == targetProject && x.Name == sourceCell.SelectedElementItem.Name); } targetContext.ElementCell.Add(targetCell); // User cells var sourceUserCells = sourceCell.UserElementCellSet; foreach (var sourceUserCell in sourceUserCells) { var targetUserCell = new UserElementCell { User = targetContext.Users.Local.Single(x => x.UserName == sourceUserCell.User.UserName), ElementCell = targetCell, DecimalValue = sourceUserCell.DecimalValue, CreatedOn = sourceUserCell.CreatedOn, ModifiedOn = sourceUserCell.ModifiedOn, DeletedOn = sourceUserCell.DeletedOn, }; targetContext.UserElementCell.Add(targetUserCell); } } } } } // Save targetContext.SaveChanges(); } } Console.WriteLine(""); Console.WriteLine(" - Finito! - "); Console.ReadKey(); }
internal override string GetOuterXml(ElementItem FragmentRoot) { return("<?" + this.Name + " " + this.GetValue() + "?>"); }
public void LogGenerate(ElementItem gridElement, OwnerType ownerType) { GenerateItem(new StepMessageData(GetMessageText(gridElement), ownerType)); _scrollRect.verticalNormalizedPosition = -0.2f; }
// 由path得到Item // parameters: // itemRoot 根item // strPath path // item out参数,返回item // return: // -1 error // 0 succeed public static int Path2Item(ElementItem itemRoot, string strPath, out Item item) { item = null; if (itemRoot == null) { return(-1); } if (itemRoot.children == null) { return(-1); } if (strPath == "") { return(-1); } int nPosition = strPath.IndexOf('/'); string strLeft = ""; string strRight = ""; if (nPosition >= 0) { strLeft = strPath.Substring(0, nPosition); strRight = strPath.Substring(nPosition + 1); } else { strLeft = strPath; } //得到序号 int nIndex = getNo(strLeft); //得到名称 nPosition = strLeft.IndexOf("["); string strName = strLeft.Substring(0, nPosition); int i = 0; foreach (Item child in itemRoot.children) { if (child.Name == strName) { //递归 if (i == nIndex) { if (strRight == "") { item = child; break; } else { if (!(child is ElementItem)) { return(-1); // text类型节点再也无法继续向下找儿子了 } Debug.Assert(child is ElementItem); return(Path2Item((ElementItem)child, strRight, out item)); } } else { i++; } } } return(0); }
// 由item得到path // parameters: // itemRoot 根item // item 给定的item // strPath out参数,返回item的path // return: // -1 出错 // 0 成功 public static int Item2Path(ElementItem itemRoot, Item item, out string strPath) { strPath = ""; if (itemRoot == null) { return(-1); } if (item == null) { return(-1); } Item itemMyself; Item itemTemp; int nIndex; //当为属性节点时,加了属性path字符串 string strAttr = ""; if (item is AttrItem) { strAttr = "/@" + item.Name; item = item.parent; } while (item != null) { //与根节点相等 if (item.Equals(itemRoot) == true) { break; } itemMyself = item; item = item.parent; if (item == null) { break; } itemTemp = null; if (item is ElementItem && ((ElementItem)item).children != null) { itemTemp = ((ElementItem)item).children[0]; } nIndex = 1; while (itemTemp != null) { if (itemTemp.Equals(itemMyself) == true) { if (strPath != "") { strPath = "/" + strPath; } strPath = itemMyself.Name + "[" + System.Convert.ToString(nIndex) + "]" + strPath; break; } if (itemTemp.Name == itemMyself.Name) { nIndex += 1; } itemTemp = itemTemp.GetNextSibling(); } } strPath = strPath + strAttr; if (strPath == "") { return(0); } else { return(1); } }
public void SpawnAndEquipElement(ElementItem ElementToEquip) { ElementItem tempEle = Instantiate(ElementToEquip); EquipElement(tempEle); }
internal override string GetOuterXml(ElementItem FragmentRoot) { return("<!--" + this.GetValue() + "-->"); }
internal override string GetOuterXml(ElementItem FragmentRoot) { return("&" + this.Name + ";"); }
public override void InitialVisual() { ElementItem item = (ElementItem)this.GetItem(); if (item == null) { return; } // 收缩态 if (item.m_attrsExpand == ExpandStyle.Collapse) { this.childrenVisual = null; this.MyText.container = this.container; this.MyText.Name = "attributes"; this.MyText.Text = "尚未初始化"; //item.strAttrsValue; // 把this.MyText加进本对象的父亲中,把this从父亲中删除 ((Box)this.container).AddChildVisual(this.MyText); ((Box)this.container).childrenVisual.Remove(this); item.Flush(); } else if (item.m_attrsExpand == ExpandStyle.Expand) { foreach (AttrItem attr in item.attrs) { Debug.Assert(attr.GetValue() != null, "准备值不能为null"); attr.m_paraValue1 = attr.GetValue(); } if (this.childrenVisual != null) { this.childrenVisual.Clear(); } // 竖向排列 this.LayoutStyle = LayoutStyle.Vertical; foreach (AttrItem attr in item.attrs) { // 设子元素的style样式与父亲相同 attr.LayoutStyle = item.LayoutStyle; // 把child加到content里作为ChildVisual attr.container = this; this.AddChildVisual(attr); // 此处 Debug.Assert(attr.m_paraValue1 != null, "此时不应为null"); // 实现嵌归 attr.InitialVisual(); //elementStyle); } } else { Debug.Assert(false, ""); } }
internal override string GetOuterXml(ElementItem FragmentRoot) { return(StringUtil.GetXmlStringSimple(this.GetValue())); }
// parameter: // FragmentRoot 是否带名字空间,该参数仅对ElementItem有意义 internal virtual string GetOuterXml(ElementItem FragmentRoot) { return(""); }
public void SetPlayerElement(int id, ElementItem element) { PlayerDataSelectedElements[id - 1] = element; }
public async Task <int> AddElementItemAsync(ElementItem entity) { _elementItemStore.Add(entity); return(await _context.SaveChangesAsync()); }
internal override string GetOuterXml(ElementItem FragmentRoot) { return("<!DOCTYPE " + this.Name + " [" + this.GetValue() + "]>"); }
// 分支版本。不适合外部直接调用。 // 从指定位置向上(祖先),有一个以上元素的属性是收缩状态,这样就没法 // 利用我们自己的DOM对象体系来搜集名字空间信息,只能模拟一个XML局部字符串来借用 // .net DOM来帮助搜集名字空间信息 public static NamespaceItemCollection GatherOuterNamespacesByDotNetDom( ElementItem element) { string strXml = ""; NamespaceItemCollection nsColl = new NamespaceItemCollection(); ElementItem current = (ElementItem)element; while (true) { if (current == null || current is VirtualRootItem) { break; } strXml = "<" + current.Name + current.GetAttrsXml() + ">" + strXml + "</" + current.Name + ">"; current = (ElementItem)current.parent; } if (strXml == "") { return(nsColl); } XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strXml); } catch (Exception ex) { throw (new Exception("GatherOuterNamespacesByDotNetDom()加载模拟xml代码出错: " + ex.Message)); } // 先确定起点 XmlNode currentNode = dom.DocumentElement; while (true) { if (currentNode.ChildNodes.Count == 0) { break; } currentNode = currentNode.ChildNodes[0]; } Debug.Assert(currentNode != null, ""); // 开始搜集信息 while (true) { if (currentNode == null) { break; } foreach (XmlAttribute attr in currentNode.Attributes) { if (attr.Prefix != "xmlns" && attr.LocalName != "xmlns") { continue; } if (attr.LocalName == "xmlns") { nsColl.Add("", attr.Value, true); // 只要prefix重就不加入 } else { nsColl.Add(attr.LocalName, attr.Value, true); // 只要prefix重就不加入 } } currentNode = currentNode.ParentNode; if (currentNode is XmlDocument) // 这样就算到根以上了 { break; } } return(nsColl); }
internal override string GetOuterXml(ElementItem FragmentRoot) { return("<![CDATA[" + this.GetValue() + "]]>"); }