Esempio n. 1
0
        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            string treeId = this.GetBinding <string>("SelectedTreeId");

            Tree tree = TreeFacade.GetTree(treeId);

            DynamicDataItemAttachmentPoint dataItemAttachmentPoint = (DynamicDataItemAttachmentPoint)tree.GetAttachmentPoints(this.EntityToken).Single();

            TreeFacade.RemovePersistedAttachmentPoint(treeId, dataItemAttachmentPoint.InterfaceType, dataItemAttachmentPoint.KeyValue);

            this.RefreshCurrentEntityToken();
        }
        private void InitializeTreeAttachmentPoints()
        {
            lock (_reloadAttachmentPointsSyncRoot)
            {
                ClearAttachmentPoints <DynamicDataItemAttachmentPoint>();

                IEnumerable <IDataItemTreeAttachmentPoint> attachmentPoints = DataFacade.GetData <IDataItemTreeAttachmentPoint>().Evaluate();

                foreach (IDataItemTreeAttachmentPoint attachmentPoint in attachmentPoints)
                {
                    Tree tree = GetTree(attachmentPoint.TreeId);
                    if (tree == null)
                    {
                        string treePath = Path.Combine(TreeDefinitionsFolder, attachmentPoint.TreeId);
                        if (!C1File.Exists(treePath)) // This ensures that invalid, but existing trees does not remove these attachment points
                        {
                            if (DataFacade.WillDeleteSucceed(attachmentPoint))
                            {
                                Log.LogWarning("TreeFacade", "A data item attachment points is referring a non existing tree '{0}' and is deleted", attachmentPoint.TreeId);

                                // Preventing events so this method won't call itself recursively
                                DataFacade.Delete(attachmentPoint, true, CascadeDeleteType.Allow);
                            }
                        }

                        continue;
                    }

                    Type   interfaceType = TypeManager.GetType(attachmentPoint.InterfaceType);
                    object keyValue      = ValueTypeConverter.Convert(attachmentPoint.KeyValue, interfaceType.GetKeyProperties()[0].PropertyType);

                    var position = (ElementAttachingProviderPosition)Enum.Parse(typeof(ElementAttachingProviderPosition), attachmentPoint.Position);

                    var dataItemTreeAttachmentPoint = new DynamicDataItemAttachmentPoint
                    {
                        InterfaceType = interfaceType,
                        KeyValue      = keyValue,
                        Position      = position
                    };

                    // Log.LogVerbose("TreeFacade", string.Format("Tree with id '{0}' is dynamically attached to the data type '{1}' with key value of '{2}'", attachmentPoint.TreeId, interfaceType, keyValue));

                    tree.AttachmentPoints.Add(dataItemTreeAttachmentPoint);

                    DataEventSystemFacade.SubscribeToDataDeleted(interfaceType, OnDataItemDeleted, false);
                }


                using (_resourceLocker.ReadLocker)
                {
                    foreach (var kvp in _resourceLocker.Resources.PersistentAttachmentPoints)
                    {
                        Tree tree = GetTree(kvp.Key);
                        if (tree == null)
                        {
                            continue;
                        }

                        tree.AttachmentPoints.AddRange(kvp.Value);
                    }
                }
            }
        }