예제 #1
0
        // <summary>
        //
        // </summary>
        /// <summary>
        /// Create a new, fresh, empty Node from a node type.  Properties are filled in, but Property Values are not. !!POSTS CHANGES!!
        /// </summary>
        /// <param name="NodeTypeId">Primary Key of Nodetype</param>
        /// <param name="IsTemp">If true, the node is a temp node, though still saved to the database</param>
        /// <param name="OnAfterMakeNode">Event that occurs after creating the node but before saving it for the first time</param>
        /// <param name="OverrideUniqueValidation">If true, allow this node to be created even if it violates uniqueness rules</param>
        /// <returns>The new node. !!POSTS CHANGES!!</returns>
        public CswNbtNode makeNodeFromNodeTypeId(Int32 NodeTypeId, Action <CswNbtNode> OnAfterMakeNode = null, bool IsTemp = false, bool OverrideUniqueValidation = false, bool IsCopy = false, bool OverrideMailReportEvents = false)
        {
            CswNbtNode Node = new CswNbtNode(_CswNbtResources, _CswNbtNodeWriter, NodeTypeId, CswEnumNbtNodeSpecies.Plain, null, _NodeHash.Count, null, IsTemp: true);   // temp here for auditing, but see below

            //Node.OnAfterSetNodeId += new CswNbtNode.OnSetNodeIdHandler( OnAfterSetNodeIdHandler );
            Node.fillFromNodeTypeId();

            _CswNbtNodeWriter.makeNewNodeEntry(Node);
            _CswNbtNodeWriter.setDefaultPropertyValues(Node);

            if (null != OnAfterMakeNode)
            {
                OnAfterMakeNode(Node);
            }

            // We need to hash the Int32.MinValue keys for the Add form to work
            // But we can simply override what's in the hash if we make another new node
            NodeHashKey Hashkey = new NodeHashKey(Node.NodeId, Node.NodeSpecies);

            _NodeHash[Hashkey] = Node;

            ICswNbtNodePersistStrategy NodePersistStrategy;

            if (false == IsTemp)
            {
                NodePersistStrategy          = new CswNbtNodePersistStrategyPromoteReal(_CswNbtResources);
                NodePersistStrategy.Creating = true;
            }
            else
            {
                NodePersistStrategy = new CswNbtNodePersistStrategyCreateTemp(_CswNbtResources);
            }

            // only override the defaults on these if they are true
            if (OverrideUniqueValidation)
            {
                NodePersistStrategy.OverrideUniqueValidation = true;
            }
            if (IsCopy)
            {
                NodePersistStrategy.IsCopy = true;
            }
            if (OverrideMailReportEvents)
            {
                NodePersistStrategy.OverrideMailReportEvents = true;
            }

            NodePersistStrategy.postChanges(Node);

            return(Node);
        }//makeNodeFromNodeTypeId()