public TridionLinkProvider() { if (componentLink == null) { componentLink = new ComponentLink(PublicationId); } }
public T Add <T>(int componentIndex) where T : ComponentEcs, new() { if (IsReserved) { throw new Exception(string.Format("Unable to add {0} to reserved entity", componentIndex)); } if (Has(componentIndex)) { Debug.LogException(new Exception(string.Format("Component {0} is Already Added to the Entity (id: {1}) ", componentIndex, ID))); return(null); } var component = (T)storages[componentIndex].ActivateAtIndex(ID); component._InternalOnValueChange = (fieldID) => { OnComponentValueChange(ID, fieldID, componentIndex); }; ComponentLinks[ComponentsCount++] = new ComponentLink(componentIndex); OnComponentAdd(ID); if (ComponentLinks.Length == ComponentsCount) { Array.Resize(ref ComponentLinks, ComponentsCount << 1); } #if UNITY_EDITOR && NANOECS_DEBUG ComponentObservers.Add(new ComponentObserver() { Component = component, IsFoldout = true }); #endif return(component); }
public TridionLinkFactoryBase() { if (componentLink == null) { componentLink = new ComponentLink(PublicationId); } }
/// <summary> /// Creates a new Link instance and returnes this as a string /// </summary> /// <param name="title">Attribute to include in the link as string</param> /// //example<a href="..">title</a> /// <param name="tcmuri">tcmUri of the Component as string</param> /// <returns>url string</returns> public static string ComponentLinkMethod(string tcmuri) { MI4TLogger.WriteLog(ELogLevel.INFO, "Entering method TridionDataHelper.ComponentLinkMethod"); ComponentLink componentLink = null; Link link = null; int publicationID; String linkUrl = string.Empty; try { publicationID = TridionDataHelper.GetContentRepositoryId(tcmuri); MI4TLogger.WriteLog(ELogLevel.DEBUG, "Publication ID: " + publicationID); componentLink = new ComponentLink(publicationID); link = componentLink.GetLink(tcmuri); MI4TLogger.WriteLog(ELogLevel.DEBUG, "ComponentLink: " + link); if (link.IsResolved) { linkUrl = link.Url; } MI4TLogger.WriteLog(ELogLevel.INFO, "Link URL : " + linkUrl); } catch (Exception ex) { MI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace); } finally { componentLink.Dispose(); componentLink = null; link = null; } MI4TLogger.WriteLog(ELogLevel.INFO, "Exiting method TridionDataHelper.ComponentLinkMethod"); return(linkUrl); }
public Entity Update(Spread <EntityComponent> components) { // Quick change check if (components != this.components) { this.components = components; } else { return(entity); } // Synchronize our entity links var @array = components._array; for (int i = 0; i < array.Length; i++) { var link = links.ElementAtOrDefault(i); if (link == null) { link = new ComponentLink(entity); links.Add(link); } link.Component = array[i]; } for (int i = links.Count - 1; i >= array.Length; i--) { var link = links[i]; link.Dispose(); links.RemoveAt(i); } return(entity); }
private static string ResolveComponentLink(TcmUri tcmUri, int localizationId = 0) { int publicationId = localizationId == 0 ? tcmUri.PublicationId : localizationId; ComponentLink linker = new ComponentLink(publicationId); Link link = linker.GetLink(tcmUri.ItemId); return link.IsResolved ? link.Url : null; }
public TridionLinkFactory() { if (componentLink == null) { componentLink = new ComponentLink(PublicationId); } }
/// <summary> /// Gets exist one or adds new component to entity. /// </summary> /// <param name="entity">Entity.</param> /// <param name="isNew">Is component was added in this call?</param> public T EnsureComponent <T> (int entity, out bool isNew) where T : class, new () { EcsHelpers.Assert(entity >= 0 && entity < _entitiesCount, string.Format("Invalid entity: {0}", entity)); var entityData = _entities[entity]; EcsHelpers.Assert(!entityData.IsReserved, string.Format("\"{0}\" component cant be added to removed entity {1}", typeof(T).Name, entity)); var pool = EcsComponentPool <T> .Instance; for (var i = 0; i < entityData.ComponentsCount; i++) { if (entityData.Components[i].Pool == pool) { isNew = false; return((T)entityData.Components[i].Pool.GetExistItemById(entityData.Components[i].ItemId)); } } var link = new ComponentLink(pool, pool.RequestNewId()); if (entityData.ComponentsCount == entityData.Components.Length) { Array.Resize(ref entityData.Components, entityData.ComponentsCount << 1); } entityData.Components[entityData.ComponentsCount++] = link; AddDelayedUpdate(DelayedUpdate.Op.AddComponent, entity, pool, link.ItemId); #if DEBUG var component = pool.Items[link.ItemId]; for (var ii = 0; ii < _debugListeners.Count; ii++) { _debugListeners[ii].OnComponentAdded(entity, component); } #endif isNew = true; return(pool.Items[link.ItemId]); }
private static string ResolveComponentLink(Tridion.ContentManager.TcmUri tcmUri, Localization localization) { ComponentLink linker = new ComponentLink(GetPublicationUri(tcmUri, localization)); Link link = linker.GetLink(tcmUri.ItemId); return(link.IsResolved ? link.Url : null); }
private static string ResolveComponentLink(TcmUri tcmUri, int localizationId = 0) { int publicationId = localizationId == 0 ? tcmUri.PublicationId : localizationId; ComponentLink linker = new ComponentLink(publicationId); Link link = linker.GetLink(tcmUri.ItemId); return(link.IsResolved ? link.Url : null); }
/// <summary> /// Gets exist one or adds new component to entity. /// </summary> /// <param name="entity">Entity.</param> /// <param name="isNew">Is component was added in this call?</param> public T EnsureComponent <T> (int entity, out bool isNew) where T : class, new () { #if DEBUG if (entity < 0 || entity >= _entitiesCount) { throw new Exception(string.Format("Invalid entity: {0}", entity)); } if (_entities[entity].IsReserved) { throw new Exception(string.Format("\"{0}\" component cant be added to removed entity {1}", typeof(T).Name, entity)); } #endif var entityData = _entities[entity]; var pool = EcsComponentPool <T> .Instance; for (var i = 0; i < entityData.ComponentsCount; i++) { if (entityData.Components[i].Pool == pool) { isNew = false; return(pool.Items[entityData.Components[i].ItemId]); } } // create separate filter for one-frame components. if (pool.IsOneFrame) { if (!_oneFrameFilters.ContainsKey(pool.GetComponentTypeIndex())) { _oneFrameFilters[pool.GetComponentTypeIndex()] = GetFilter(typeof(EcsFilter <T>)); } } var link = new ComponentLink(pool, pool.RequestNewId()); if (entityData.ComponentsCount == entityData.Components.Length) { Array.Resize(ref entityData.Components, entityData.ComponentsCount << 1); } entityData.Components[entityData.ComponentsCount++] = link; AddDelayedUpdate(DelayedUpdate.Op.AddComponent, entity, pool, link.ItemId); #if DEBUG var dbgCmpt = pool.Items[link.ItemId]; for (var ii = 0; ii < _debugListeners.Count; ii++) { _debugListeners[ii].OnComponentAdded(entity, dbgCmpt); } #endif #if LEOECS_ENABLE_WORLD_EVENTS var evtCmpt = pool.Items[link.ItemId]; for (var ii = 0; ii < _eventListeners.Count; ii++) { _eventListeners[ii].OnComponentAdded(entity, evtCmpt); } #endif isNew = true; return(pool.Items[link.ItemId]); }
static void Main(string[] args) { Regex regex = new Regex(@"href=\""(?<url>.*?)\""", RegexOptions.IgnoreCase | RegexOptions.Multiline); foreach (String uri in Utilities.LinkUris) { try { using (ComponentLink componentLink = new ComponentLink()) { String url = componentLink.GetLinkAsString("tcm:0-0-0", uri, "tcm:0-0-0", String.Empty, String.Empty, false, false); if (!String.IsNullOrEmpty(url)) { Match match = regex.Match(url); if (match.Success) Utilities.OutputLink(uri, match.Groups["url"].Value); else Console.WriteLine("Error resolving component link for {0}: Invalid url {1}.", uri, url); } else { Console.WriteLine("Error resolving component link for {0}: Link is null or not resolved.", uri); } } } catch (Exception ex) { Console.WriteLine("Error resolving component link for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } foreach (String uri in Utilities.BrokerUris) { try { using (ComponentPresentationFactory factory = new ComponentPresentationFactory()) { ComponentPresentation presentation = factory.GetComponentPresentationWithHighestPriority(uri); if (presentation != null) Utilities.OutputDCP(uri, presentation.Content); else Console.WriteLine("Error retrieving dynamic component presentation for {0}: Presentation is null.", uri); } } catch (Exception ex) { Console.WriteLine("Error retrieving dynamic component presentation for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
protected virtual void Dispose(bool isDisposed) { if (!isDisposed) { if (componentLink != null) { componentLink.Dispose(); componentLink = null; } } }
protected virtual void Dispose(bool isDisposed) { if (isDisposed) { return; } if (_componentLink != null) { _componentLink.Dispose(); _componentLink = null; } foreach (ComponentLink cl in _componentLinks.Values) { cl?.Dispose(); } _componentLinks.Clear(); }
protected virtual void Dispose(bool isDisposed) { if (!isDisposed) { if (componentLink != null) { componentLink.Dispose(); componentLink = null; } foreach (ComponentLink cl in _componentLinks.Values) { if (cl != null) { cl.Dispose(); } } _componentLinks.Clear(); } }
/// <summary> /// Adds component to entity. /// </summary> /// <param name="entity">Entity.</param> /// <param name="componentId">Component index. If equals to "-1" - will try to find registered type.</param> public T AddComponent <T> (int entity, int componentId = -1) where T : class, IEcsComponent { if (componentId == -1) { componentId = GetComponentIndex <T> (); } var entityData = _entities[entity]; var pool = _componentPools[componentId]; ComponentLink link; // direct initialization - faster than constructor call. link.ItemId = -1; link.PoolId = -1; var i = entityData.ComponentsCount - 1; for (; i >= 0; i--) { link = entityData.Components[i]; if (link.PoolId == componentId) { break; } } if (i != -1) { // already exists. return(pool.Items[link.ItemId] as T); } _delayedUpdates.Add(new DelayedUpdate(DelayedUpdate.Op.AddComponent, entity, componentId)); link.PoolId = componentId; link.ItemId = pool.GetIndex(); if (entityData.ComponentsCount == entityData.Components.Length) { var newComponents = new ComponentLink[entityData.ComponentsCount << 1]; Array.Copy(entityData.Components, newComponents, entityData.ComponentsCount); entityData.Components = newComponents; } entityData.Components[entityData.ComponentsCount++] = link; return(pool.Items[link.ItemId] as T); }
/// <summary> /// Adds component to entity. Will throw exception if component already exists. /// </summary> /// <param name="entity">Entity.</param> public T AddComponent <T> (int entity) where T : class, new () { var entityData = _entities[entity]; var pool = EcsComponentPool <T> .Instance; #if DEBUG if (entityData.IsReserved) { throw new Exception(string.Format("\"{0}\" component cant be added to removed entity {1}", typeof(T).Name, entity)); } var i = entityData.ComponentsCount - 1; for (; i >= 0; i--) { if (entityData.Components[i].Pool == pool) { break; } } if (i != -1) { throw new Exception(string.Format("\"{0}\" component already exists on entity {1}", typeof(T).Name, entity)); } #endif var link = new ComponentLink(pool, pool.RequestNewId()); if (entityData.ComponentsCount == entityData.Components.Length) { Array.Resize(ref entityData.Components, entityData.ComponentsCount << 1); } entityData.Components[entityData.ComponentsCount++] = link; AddDelayedUpdate(DelayedUpdate.Op.AddComponent, entity, pool, link.ItemId); #if DEBUG var component = pool.Items[link.ItemId]; for (var ii = 0; ii < _debugListeners.Count; ii++) { _debugListeners[ii].OnComponentAdded(entity, component); } #endif return(pool.Items[link.ItemId]); }
static void Main(string[] args) { Regex regex = new Regex(@"href=\""(?<url>.*?)\""", RegexOptions.IgnoreCase | RegexOptions.Multiline); foreach (String uri in Utilities.LinkUris) { try { using (ComponentLink componentLink = new ComponentLink()) { String url = componentLink.GetLinkAsString("tcm:0-0-0", uri, "tcm:0-0-0", String.Empty, String.Empty, false, false); if (!String.IsNullOrEmpty(url)) { Match match = regex.Match(url); if (match.Success) { Utilities.OutputLink(uri, match.Groups["url"].Value); } else { Console.WriteLine("Error resolving component link for {0}: Invalid url {1}.", uri, url); } } else { Console.WriteLine("Error resolving component link for {0}: Link is null or not resolved.", uri); } } } catch (Exception ex) { Console.WriteLine("Error resolving component link for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } foreach (String uri in Utilities.BrokerUris) { try { using (ComponentPresentationFactory factory = new ComponentPresentationFactory()) { ComponentPresentation presentation = factory.GetComponentPresentationWithHighestPriority(uri); if (presentation != null) { Utilities.OutputDCP(uri, presentation.Content); } else { Console.WriteLine("Error retrieving dynamic component presentation for {0}: Presentation is null.", uri); } } } catch (Exception ex) { Console.WriteLine("Error retrieving dynamic component presentation for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
static void Main(String[] args) { try { IJvmLoader loader = JvmLoader.GetJvmLoader(); Console.WriteLine("CodeMesh using Java: {0}", loader.JvmPath); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine("Java virtual machine could not be loaded\n{0}", Utilities.FormatException(ex)); Console.ReadKey(); return; } foreach (String uri in Utilities.LinkUris) { try { using (ComponentLink componentLink = new ComponentLink(Utilities.PublicationUri)) { Link link = componentLink.GetLink(uri); if (link != null && link.IsResolved) Utilities.OutputLink(uri, link.Url); else Console.WriteLine("Error resolving component link for {0}: Link is null or not resolved.", uri); } } catch (Exception ex) { Console.WriteLine("Error resolving component link for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } foreach (String uri in Utilities.BrokerUris) { try { using (ComponentPresentationFactory factory = new ComponentPresentationFactory(Utilities.PublicationUri)) { ComponentPresentation presentation = factory.GetComponentPresentationWithHighestPriority(uri); if (presentation != null) { Utilities.OutputDCP(uri, presentation.Content); } else { Console.Write("Error retrieving dynamic component presentation for {0}: Presentation is null.", uri); } } } catch (Exception ex) { Console.WriteLine("Error retrieving dynamic component presentation for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public static void SeedData1() { var repo = new ComponentsRepo(); repo.ComponentLinks.SlowTruncateTable(); repo.Components.SlowTruncateTable(); var c1 = new Component { Name = "Горячие клавиши", IsTopLevel = true }; var c2 = new Component { Name = "Загрузить тестовые наборы данных" }; var c3 = new Component { Name = "Набор 1 (Ctrl + 1)" }; var c4 = new Component { Name = "Набор 2 (Ctrl + 2)" }; var c5 = new Component { Name = "Набор 3 (Ctrl + 3)" }; var c6 = new Component { Name = "Редактирование графа компонентов" }; var c7 = new Component { Name = "Новый компонент верхнего уровня (Ctrl + Shift + N)" }; var c8 = new Component { Name = "Новый вложенный компонент (Ctrl + N)" }; var c9 = new Component { Name = "Переименовать (F2)" }; var c10 = new Component { Name = "Удалить (Del)" }; var c11 = new Component { Name = "Отчёты" }; var c12 = new Component { Name = "Отчёт о сводном составе (Ctrl + R)" }; var l1 = new ComponentLink { ParentComponent = c1, ChildComponent = c2, Quantity = 1 }; var l2 = new ComponentLink { ParentComponent = c2, ChildComponent = c3, Quantity = 1 }; var l3 = new ComponentLink { ParentComponent = c2, ChildComponent = c4, Quantity = 1 }; var l4 = new ComponentLink { ParentComponent = c2, ChildComponent = c5, Quantity = 1 }; var l5 = new ComponentLink { ParentComponent = c1, ChildComponent = c6, Quantity = 1 }; var l6 = new ComponentLink { ParentComponent = c6, ChildComponent = c7, Quantity = 1 }; var l7 = new ComponentLink { ParentComponent = c6, ChildComponent = c8, Quantity = 1 }; var l8 = new ComponentLink { ParentComponent = c6, ChildComponent = c9, Quantity = 1 }; var l9 = new ComponentLink { ParentComponent = c6, ChildComponent = c10, Quantity = 1 }; var l10 = new ComponentLink { ParentComponent = c1, ChildComponent = c11, Quantity = 1 }; var l11 = new ComponentLink { ParentComponent = c11, ChildComponent = c12, Quantity = 1 }; repo.ComponentLinks.AddRange( new List <ComponentLink> { l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11 }); }
private static string ResolveComponentLink(string uri, int localizationId = 0) { //TODO should we have a single (static) link object? var linker = new ComponentLink(localizationId==0 ? GetPublicationIdFromUri(uri) : localizationId); var link = linker.GetLink(GetItemIdFromUri(uri)); return link.IsResolved ? link.Url : null; }
public ProductPrice() { Product = new ComponentLink(); }
public static void SeedData3() { var repo = new ComponentsRepo(); repo.ComponentLinks.SlowTruncateTable(); repo.Components.SlowTruncateTable(); var c1 = new Component { Name = "Блок 1", IsTopLevel = true }; var c2 = new Component { Name = "Блок 2", IsTopLevel = true }; //var c3 = new Component { Name = "Блок 3", IsTopLevel = true }; var c4 = new Component { Name = "Блок 4" }; var c5 = new Component { Name = "Блок 5" }; var c6 = new Component { Name = "Блок 6" }; var c7 = new Component { Name = "Блок 7" }; var c8 = new Component { Name = "Блок 8" }; var c9 = new Component { Name = "Блок 9" }; var l1 = new ComponentLink { ParentComponent = c1, ChildComponent = c4, Quantity = 1 }; var l2 = new ComponentLink { ParentComponent = c1, ChildComponent = c5, Quantity = 1 }; var l3 = new ComponentLink { ParentComponent = c1, ChildComponent = c6, Quantity = 2 }; var l4 = new ComponentLink { ParentComponent = c2, ChildComponent = c5, Quantity = 4 }; var l5 = new ComponentLink { ParentComponent = c2, ChildComponent = c6, Quantity = 1 }; var l6 = new ComponentLink { ParentComponent = c2, ChildComponent = c7, Quantity = 2 }; //var l7 = new ComponentLink { ParentComponent = c3, ChildComponent = c4, Quantity = 1 }; //var l8 = new ComponentLink { ParentComponent = c3, ChildComponent = c7, Quantity = 4 }; var l11 = new ComponentLink { ParentComponent = c4, ChildComponent = c8, Quantity = 1 }; var l12 = new ComponentLink { ParentComponent = c4, ChildComponent = c9, Quantity = 1 }; var l13 = new ComponentLink { ParentComponent = c8, ChildComponent = c9, Quantity = 2 }; var l14 = new ComponentLink { ParentComponent = c1, ChildComponent = c8, Quantity = 2 }; var l15 = new ComponentLink { ParentComponent = c9, ChildComponent = c6, Quantity = 2 }; var l16 = new ComponentLink { ParentComponent = c5, ChildComponent = c9, Quantity = 2 }; repo.ComponentLinks.AddRange( new List <ComponentLink> { l1, l2, l3, /*l4, l5, l6, l7, l8,*/ l11, /*l12,*/ l13, l14, l15, l16 }); }
private static void TestTask(bool output, bool loop) { int start = Environment.TickCount; int cycle = start; for (int i = 0; i < 10000; i++) { if (i % 100 == 0) { if (i > 0 && output) { Console.WriteLine("Execution cycle #{0}\tCycle Time: {1} secs.\tTotal Time: {2} secs.", i, (Environment.TickCount - cycle) / 1000, (Environment.TickCount - start) / 1000); } cycle = Environment.TickCount; } String componentlink = ComponentLink.Get("tcm:233-193779"); if (output) { Console.WriteLine("ComponentLink #1: {0}", componentlink); } componentlink = ComponentLink.Get("tcm:233-11111-64", "tcm:233-193779", "tcm:233-1222111-32", true); if (output) { Console.WriteLine("ComponentLink #2: {0}", componentlink); } String binaryLink = BinaryLink.Get("tcm:233-703376", null, "anchor"); if (output) { Console.WriteLine("BinaryLink: {0}", binaryLink); } String pageLink = PageLink.Get("tcm:233-192225-64"); if (output) { Console.WriteLine("PageLink #1: {0}", pageLink); } pageLink = PageLink.Get("tcm:233-192225-64", "anchor", "parameters"); if (output) { Console.WriteLine("PageLink #2: {0}", pageLink); } ComponentPresentation componentPresentation = TcmCDService.Remoting.DynamicContent.ComponentPresentation.GetHighestPriority("tcm:233-685281"); if (output) { Console.WriteLine("Presentation #1: {0}", componentPresentation != null); Console.WriteLine("JSON:\n{0}", ToJSON(componentPresentation)); } componentPresentation = TcmCDService.Remoting.DynamicContent.ComponentPresentation.GetHighestPriority(233, 685281); if (output) { Console.WriteLine("Presentation #2: {0}", componentPresentation != null); } componentPresentation = TcmCDService.Remoting.DynamicContent.ComponentPresentation.Get("tcm:233-685281", "tcm:233-355892-32"); if (output) { Console.WriteLine("Presentation #3: {0}", componentPresentation != null); } componentPresentation = TcmCDService.Remoting.DynamicContent.ComponentPresentation.Get("tcm:233-685281", 355892); if (output) { Console.WriteLine("Presentation #4: {0}", componentPresentation != null); } componentPresentation = TcmCDService.Remoting.DynamicContent.ComponentPresentation.Get(233, 685281, 355892); if (output) { Console.WriteLine("Presentation #5: {0}", componentPresentation != null); } ComponentMeta componentMeta = TcmCDService.Remoting.Meta.ComponentMeta.Get("tcm:233-685281"); if (output) { Console.WriteLine("ComponentMeta #1: {0}", componentMeta != null); Console.WriteLine("JSON:\n{0}", ToJSON(componentMeta)); } componentMeta = TcmCDService.Remoting.Meta.ComponentMeta.Get(233, 685281); if (output) { Console.WriteLine("ComponentMeta #2: {0}", componentMeta != null); } Byte[] binary = TcmCDService.Remoting.DynamicContent.BinaryData.Get("tcm:233-684746"); if (output) { Console.WriteLine("Binary #1: {0}", binary.Length); } String pageContent = TcmCDService.Remoting.DynamicContent.PageContent.Get("tcm:233-192225-64"); if (output) { Console.WriteLine("PageContent #1: {0}", pageContent.Length); } IEnumerable <String> taxonomies = TcmCDService.Remoting.Taxonomies.Keyword.GetTaxonomies("tcm:0-233-1"); if (output) { Console.WriteLine("Taxonomies: {0}", String.Join(", ", taxonomies)); } Keyword keyword = TcmCDService.Remoting.Taxonomies.Keyword.GetKeywords("tcm:233-42180-512"); if (output) { Console.WriteLine("Keyword: {0}", ToXml(keyword)); } /* * keyword = TcmCDService.Remoting.Taxonomies.Keyword.GetKeywords("tcm:233-42180-512", new TaxonomyFilter() * { * DepthFilteringLevel = 10, * DepthFilteringDirection = TaxonomyFilterDirecton.Down * }); */ if (!loop) { break; } } }
private void RemoveComponent_Click(object sender, EventArgs e) { var selectedNode = MainView.SelectedNode; if (selectedNode == null) { MessageBox.Show("Ни один компонент не выбран.", "Ошибка"); return; } var repo = new ComponentsRepo(); var selectedNodeId = (int)selectedNode.Tag; var selectedComponent = repo.Components.Find(c => c.Id == selectedNodeId); if (selectedComponent == null) { return; } if (!selectedComponent.IsTopLevel) { var parentNodeId = (int)selectedNode.Parent.Tag; var parentComponent = repo.Components.Get(parentNodeId); var result = InputDialogs.RemoveChoice( "Хотите ли вы разорвать связь между текущим компонентом (" + selectedComponent + ") и его родителем (" + parentComponent + ") " + "или только удалить текущий узел?"); if (result == DialogResult.Cancel) { return; } if (result == DialogResult.Yes) { var linkToBroke = repo.ComponentLinks .Find(cl => cl.ParentComponentId == parentComponent.Id && cl.ChildComponentId == selectedComponent.Id ); if (linkToBroke != null) { repo.ComponentLinks.Delete(linkToBroke); } } } RemoveSubComponents(selectedComponent); var componentCount = GetComponentCountInTree(selectedComponent); if (componentCount == 1) { var uplink = repo.ComponentLinks .Find(cl => cl.ChildComponentId == selectedComponent.Id); if (uplink != null) { repo.ComponentLinks.Delete(uplink); } repo.Components.Delete(selectedComponent); } else { TreeNode parentNode = selectedNode.Parent; var componentsChain = new List <Component>(); do { var parentComponent = repo.Components.Get((int)parentNode.Tag); var parentCount = GetComponentCountInTree(parentComponent); componentsChain.Add(parentComponent); if (parentCount == 1) { break; } parentNode = parentNode.Parent; } while (true); var newComponentsChain = new List <Component>(); for (int i = 0; i < componentsChain.Count - 1; i++) { var oldComponent = componentsChain[i]; var newComponent = new Component { Name = oldComponent.Name, IsTopLevel = oldComponent.IsTopLevel }; repo.Components.Add(newComponent); newComponentsChain.Add(newComponent); } if (componentsChain.Count == 1) { var parentId = componentsChain[0].Id; var childId = selectedComponent.Id; var link = repo.ComponentLinks .Find(cl => cl.ParentComponentId == parentId && cl.ChildComponentId == childId ); if (link != null) { repo.ComponentLinks.Delete(link); } } else { var chainRootId = componentsChain[componentsChain.Count - 1].Id; var chainFirstChildId = componentsChain[componentsChain.Count - 2].Id; var linkToUpdate = repo.ComponentLinks. Find(cl => cl.ParentComponentId == chainRootId && cl.ChildComponentId == chainFirstChildId); if (linkToUpdate != null) { linkToUpdate.ChildComponentId = newComponentsChain[newComponentsChain.Count - 1].Id; } for (int i = componentsChain.Count - 1; i >= 1; i--) { if (i != componentsChain.Count - 1) { var oldLinkParentId = componentsChain[i].Id; var oldLinkChildId = componentsChain[i - 1].Id; var oldLink = repo.ComponentLinks .Find(cl => cl.ParentComponentId == oldLinkParentId && cl.ChildComponentId == oldLinkChildId ); var oldLinkQuantity = -1; if (oldLink != null) { oldLinkQuantity = oldLink.Quantity; } var newChainLink = new ComponentLink { ParentComponentId = newComponentsChain[i].Id, ChildComponentId = newComponentsChain[i - 1].Id, Quantity = oldLinkQuantity }; repo.ComponentLinks.Add(newChainLink); } var restoreExceptionId = (i == 1) ? selectedComponent.Id : componentsChain[i - 2].Id; var oldParentId = componentsChain[i - 1].Id; var oldChildrenLinks = repo.ComponentLinks .FindAll(cl => cl.ParentComponentId == oldParentId && cl.ChildComponentId != restoreExceptionId) .ToList(); foreach (var oldChildLink in oldChildrenLinks) { var restoredOldLink = new ComponentLink { ParentComponentId = newComponentsChain[i - 1].Id, ChildComponentId = oldChildLink.ChildComponentId, Quantity = oldChildLink.Quantity }; repo.ComponentLinks.Add(restoredOldLink); } } } } RefreshView(); }
private void NewEmbeddedComponentButton_Click(object sender, EventArgs e) { var selectedNode = MainView.SelectedNode; if (selectedNode == null) { MessageBox.Show("Ни один компонент не выбран.", "Ошибка"); return; } string input = ""; int componentId; decimal quantity = 0; var repo = new ComponentsRepo(); var embeddedComponents = repo.Components.FindAll(c => !c.IsTopLevel).ToList(); var selectedComponentId = (int)selectedNode.Tag; var selectedComponent = repo.Components .Find(c => c.Id == selectedComponentId); DialogResult result; bool circularLinkFound = false; do { componentId = -1; result = InputDialogs.ComponentNameAndQuantity( ref input, ref componentId, ref quantity, "Введите имя компонента и количество", embeddedComponents); if (result == DialogResult.OK) { circularLinkFound = componentId != -1 && CheckUplinks(selectedComponentId, componentId); } if ((result == DialogResult.OK) && circularLinkFound) { MessageBox.Show("Обнаружено рекурсиное вложение компонентов", "Ошибка"); } } while (result == DialogResult.OK && circularLinkFound); if (result == DialogResult.OK) { ComponentLink existingLink = null; Component newComponent; if (componentId == -1) { newComponent = new Component { Name = input }; repo.Components.Add(newComponent); } else { newComponent = repo.Components.Find(c => c.Id == componentId); existingLink = repo.ComponentLinks .Find(cl => cl.ParentComponentId == selectedComponentId && cl.ChildComponentId == componentId); } if (existingLink != null) { existingLink.Quantity += (int)quantity; } else { if ((selectedComponent != null) && (newComponent != null)) { var newLink = new ComponentLink { ParentComponentId = selectedComponent.Id, ChildComponentId = newComponent.Id, Quantity = (int)quantity }; repo.ComponentLinks.Add(newLink); } } RefreshView(); } }
static void Main(String[] args) { try { IJvmLoader loader = JvmLoader.GetJvmLoader(); Console.WriteLine("CodeMesh using Java: {0}", loader.JvmPath); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine("Java virtual machine could not be loaded\n{0}", Utilities.FormatException(ex)); Console.ReadKey(); return; } foreach (String uri in Utilities.LinkUris) { try { using (ComponentLink componentLink = new ComponentLink(Utilities.PublicationUri)) { Link link = componentLink.GetLink(uri); if (link != null && link.IsResolved) { Utilities.OutputLink(uri, link.Url); } else { Console.WriteLine("Error resolving component link for {0}: Link is null or not resolved.", uri); } } } catch (Exception ex) { Console.WriteLine("Error resolving component link for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } foreach (String uri in Utilities.BrokerUris) { try { using (ComponentPresentationFactory factory = new ComponentPresentationFactory(Utilities.PublicationUri)) { ComponentPresentation presentation = factory.GetComponentPresentationWithHighestPriority(uri); if (presentation != null) { Utilities.OutputDCP(uri, presentation.Content); } else { Console.Write("Error retrieving dynamic component presentation for {0}: Presentation is null.", uri); } } } catch (Exception ex) { Console.WriteLine("Error retrieving dynamic component presentation for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public static void SeedData2() { var repo = new ComponentsRepo(); repo.ComponentLinks.SlowTruncateTable(); repo.Components.SlowTruncateTable(); var c1 = new Component { Name = "Двигатель 2106", IsTopLevel = true }; var c2 = new Component { Name = "Блок цилиндров" }; var c3 = new Component { Name = "Коленвал" }; var c4 = new Component { Name = "Распредвал" }; var c5 = new Component { Name = "Поршень в сборе" }; var c6 = new Component { Name = "Поршень" }; var c7 = new Component { Name = "Компрессионное кольцо" }; var c8 = new Component { Name = "Маслосъёмное кольцо" }; var c9 = new Component { Name = "Шатун" }; var c11 = new Component { Name = "Двигатель 2103", IsTopLevel = true }; var l1 = new ComponentLink { ParentComponent = c1, ChildComponent = c2, Quantity = 1 }; var l2 = new ComponentLink { ParentComponent = c1, ChildComponent = c3, Quantity = 1 }; var l3 = new ComponentLink { ParentComponent = c1, ChildComponent = c4, Quantity = 2 }; var l4 = new ComponentLink { ParentComponent = c1, ChildComponent = c5, Quantity = 4 }; var l5 = new ComponentLink { ParentComponent = c5, ChildComponent = c6, Quantity = 1 }; var l6 = new ComponentLink { ParentComponent = c5, ChildComponent = c7, Quantity = 2 }; var l7 = new ComponentLink { ParentComponent = c5, ChildComponent = c8, Quantity = 1 }; var l8 = new ComponentLink { ParentComponent = c1, ChildComponent = c9, Quantity = 4 }; var l11 = new ComponentLink { ParentComponent = c11, ChildComponent = c2, Quantity = 1 }; var l12 = new ComponentLink { ParentComponent = c11, ChildComponent = c3, Quantity = 1 }; var l13 = new ComponentLink { ParentComponent = c11, ChildComponent = c4, Quantity = 2 }; var l14 = new ComponentLink { ParentComponent = c11, ChildComponent = c5, Quantity = 4 }; var l18 = new ComponentLink { ParentComponent = c11, ChildComponent = c9, Quantity = 4 }; repo.ComponentLinks.AddRange( new List <ComponentLink> { l1, l2, l3, l4, l5, l6, l7, l8, l11, l12, l13, l14, l18, }); }