public void OnOpenProjectEntity(ProjectEntityType type, string name) { // Open your schema and other document types here by entity name DocumentView view = null; switch (type) { case ProjectEntityType.Schema: foreach (DocumentView doc in documentViews) { if (doc is SchemaView) { if (doc.DocumentName == name) { doc.Activate(); return; } } } view = new SchemaView(); if ((view == null) || (view as SchemaView).LoadDocument(name) == false) { System.Windows.MessageBox.Show(DialogMessages.CannotLoadSchema, DialogMessages.ErrorCaption, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); return; } break; case ProjectEntityType.VariableList: foreach (DocumentView doc in documentViews) { if (doc is VariablesView) { doc.Activate(); return; } } view = new VariablesView(); if ((view == null)) { System.Windows.MessageBox.Show(DialogMessages.CannotLoadVariables, DialogMessages.ErrorCaption, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); return; } break; } documentViews.Add(view); view.FormClosing += new FormClosingEventHandler(OnDocumentWindowClosing); view.Show(dockPanel, DockState.Document); currentDocument = (DocumentView)dockPanel.ActiveDocument; }
/// <summary> /// Checks if the project contains given entity /// </summary> /// <param name="type">Entity type</param> /// <param name="name">Entity name</param> /// <returns>return array of entities</returns> public bool ContainsEntity(ProjectEntityType type, string name) { if (type == ProjectEntityType.Schema) { return(System.Array.IndexOf(GetEntities(type), name) >= 0); } else { return(data.ContainsKey(GetFullEntityName(type, name))); } }
public string GenerateUniqueName(ProjectEntityType type, string prefix) { int number = 1; string newName; do { newName = string.Format("{0}{1}", prefix, number); number++; }while(ContainsEntity(type, newName) == true); return(newName); }
/// <summary> /// Returns internal name of given entity type /// </summary> public string GetEntityTypeInternalName(ProjectEntityType type) { switch (type) { case ProjectEntityType.Image: return("images"); case ProjectEntityType.Script: return("scripts"); case ProjectEntityType.Settings: return("settings"); case ProjectEntityType.Schema: return("Schemas"); default: throw new NotImplementedException(); } }
/// <summary> /// Return given entity from the project /// </summary> /// <param name="type">Entity type</param> /// <param name="name">Entity name</param> public bool RemoveEntity(ProjectEntityType type, string name) { if (ContainsEntity(type, name) == false) { return(false); } List <string> keysToRemove = new List <string>(); foreach (string entity in data.Keys) { string entityStartPath = Path.Combine(GetEntityTypeInternalName(type), name); if (entity.StartsWith(entityStartPath, StringComparison.InvariantCultureIgnoreCase)) { keysToRemove.Add(entity); } } if (keysToRemove.Count == 0) { return(false); } foreach (string key in keysToRemove) { data.Remove(key); } modifiedFlag = true; if (type == ProjectEntityType.Schema && ContainsEntity(ProjectEntityType.Script, name)) { RemoveEntity(ProjectEntityType.Script, name); } if (EntitySetChanged != null) { EntitySetChanged(this, new EventArgs()); } return(true); }
/// <summary> /// Return all entities of given type /// </summary> /// <param name="type">Entity type</param> /// <returns>return array of entities</returns> public string[] GetEntities(ProjectEntityType type) { if (type == ProjectEntityType.Schema) { return(GetSchemas()); } else { List <string> entities = new List <string>(); foreach (string key in data.Keys) { if (key.StartsWith(GetEntityTypeInternalName(type))) { string tmp = key.Remove(0, GetEntityTypeInternalName(type).Length + 1); entities.Add(tmp); } } return(entities.ToArray()); } }
public void OnOpenProjectEntity(ProjectEntityType type, string name) { // Open your schema and other document types here by entity name DocumentView view = null; switch (type) { case ProjectEntityType.Schema: foreach (DocumentView doc in documentViews) { if (doc is SchemaView) { if (doc.DocumentName == name) { doc.Activate(); return; } } } view = new SchemaView(name); view.FormClosing += new FormClosingEventHandler(OnDocumentWindowClosing); documentViews.Add(view); view.Show(dockPanel, DockState.Document); break; case ProjectEntityType.Archiver: ShowArchiverSettings(); break; case ProjectEntityType.Script: OnOpenScript(this, name); break; // etc.... default: break; } }
public IEnumerable<BCModel.CompanyProfile> SearchCompanyProfiles(int projectEntityId, ProjectEntityType type) { IEnumerable<CompanyProfile> result; GeoLocator locator = new GeoLocator(); // call up the locator BidPackage theBp; DbGeography searchPoint; int projectIdforLocation = 0; switch (type) { case ProjectEntityType.bidPackage: theBp = _repo.FindBidPackage(projectEntityId); projectIdforLocation = theBp.ProjectId; searchPoint = _repo.FindProject(projectIdforLocation).GeoLocation; int[] bpScopes = theBp.Scopes.Where(s => s.Scope.Children == null).Select(s => s.ScopeId).ToArray(); result = from c in _repo.Query() where c.Scopes.Any(s => bpScopes.Contains(s.ScopeId)) && (c.GeoLocation.Distance(searchPoint).Value * 0.00062137) <= c.OperatingDistance select c; return result.ToList(); case ProjectEntityType.project: projectIdforLocation = projectEntityId; searchPoint = _repo.FindProject(projectIdforLocation).GeoLocation; result = from c in _repo.Query() where (c.GeoLocation.Distance(searchPoint).Value * 0.00062137) <= c.OperatingDistance select c; return result.ToList(); default: throw new Exception("unknown entity type"); } }
/// <summary> /// Renames entities in the project /// </summary> /// <param name="type">Entity type</param> /// <param name="oldName">Old entity name</param> /// <param name="newName">New entity name</param> /// <returns>Returns true if successed</returns> public bool RenameEntity(ProjectEntityType type, string oldName, string newName) { if (ContainsEntity(type, oldName) == false) { return(false); } if (ContainsEntity(type, newName) == true) { return(false); } if (type == ProjectEntityType.Schema) { List <string> keysToRemove = new List <string>(); Dictionary <string, byte[]> keysToAdd = new Dictionary <string, byte[]>(); foreach (string entity in data.Keys) { Regex rx = new Regex(@"^schemas[\\/]+(?<name>.*)[\\/]+.*", RegexOptions.Compiled | RegexOptions.IgnoreCase); Match match = rx.Match(entity); if (match.Success) { if (match.Groups["name"].Value == oldName) { keysToRemove.Add(entity); keysToAdd.Add(entity.Replace(oldName, newName), data[entity]); } } } if (keysToRemove.Count != keysToAdd.Count || keysToAdd.Count == 0) { return(false); } foreach (string key in keysToRemove) { data.Remove(key); } foreach (string key in keysToAdd.Keys) { data[key] = keysToAdd[key]; } if (ContainsEntity(ProjectEntityType.Script, oldName)) { RenameEntity(ProjectEntityType.Script, oldName, newName); } modifiedFlag = true; if (EntitySetChanged != null) { EntitySetChanged(this, new EventArgs()); } return(true); } else { List <string> keysToRemove = new List <string>(); Dictionary <string, byte[]> keysToAdd = new Dictionary <string, byte[]>(); foreach (string entity in data.Keys) { string entityStartPath = Path.Combine(GetEntityTypeInternalName(type), oldName); if (entity.StartsWith(entityStartPath)) { keysToRemove.Add(entity); keysToAdd.Add(entity.Replace(oldName, newName), data[entity]); } } if (keysToRemove.Count != keysToAdd.Count || keysToAdd.Count == 0) { return(false); } foreach (string key in keysToRemove) { data.Remove(key); } foreach (string key in keysToAdd.Keys) { data[key] = keysToAdd[key]; } modifiedFlag = true; if (EntitySetChanged != null) { EntitySetChanged(this, new EventArgs()); } return(true); } }
/// <summary> /// Returns full internal name of given entity /// </summary> public string GetFullEntityName(ProjectEntityType type, string name) { return(Path.Combine(GetEntityTypeInternalName(type), name)); }
/// <summary> /// Writes a tmp_buff into the project. Automatically sets IsModified property. /// </summary> /// <param name="type">Entity type</param> /// <param name="name">Entity name</param> /// <param name="data_block">Data block for saving</param> public void SetData(ProjectEntityType type, string name, Stream data_block) { SetData(GetFullEntityName(type, name), data_block); }
/// <summary> /// Return read only stream for specified entity /// </summary> /// <param name="type">Entity type</param> /// <param name="name">Entity name</param> /// <returns>Return Stream instance or null if there is no entity</returns> public Stream GetData(ProjectEntityType type, string name) { return(GetData(GetFullEntityName(type, name))); }
public BaseEntityNode(ProjectEntityType entityType, string entityName) { this.entityType = entityType; this.entityName = entityName; }