} // restore() /// <summary> /// Makes a new batch operation instance in the database /// </summary> public static CswNbtObjClassBatchOp makeNew(CswNbtResources CswNbtResources, CswEnumNbtBatchOpName BatchOpName, string BatchData, CswPrimaryKey UserId = null, Double Priority = Double.NaN) { CswNbtObjClassBatchOp BatchNode = null; CswNbtMetaDataObjectClass BatchOpOC = CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.BatchOpClass); if (BatchOpOC != null) { CswNbtMetaDataNodeType BatchOpNT = BatchOpOC.getNodeTypes().First(); if (BatchOpNT != null) { CswNbtNode Node = CswNbtResources.Nodes.makeNodeFromNodeTypeId(BatchOpNT.NodeTypeId); BatchNode = Node; BatchNode.BatchData.Text = BatchData; BatchNode.CreatedDate.DateTimeValue = DateTime.Now; BatchNode.OpName.Text = BatchOpName.ToString(); if (false == Double.IsNaN(Priority)) { BatchNode.Priority.Value = Priority; } BatchNode.Status.Value = CswEnumNbtBatchOpStatus.Pending.ToString(); BatchNode.User.RelatedNodeId = UserId ?? CswNbtResources.CurrentNbtUser.UserId; BatchNode.postChanges(true); } } return(BatchNode); } // makeNew()
/// <summary> /// WCF method to fulfill a Move Containers request /// </summary> public static void fulfillContainerMoveRequest(ICswResources CswResources, CswNbtRequestDataModel.CswRequestReturn Ret, CswNbtRequestDataModel.RequestFulfill Request) { CswNbtResources NbtResources = _validate(CswResources); CswNbtObjClassRequestItem RequestItem = NbtResources.Nodes[Request.RequestItemId]; if (null != RequestItem) { Int32 ContainersMoved = moveContainers(NbtResources, RequestItem, Request); Ret.Data.Succeeded = ContainersMoved > 0; if (Ret.Data.Succeeded) { if (CswTools.IsDouble(RequestItem.TotalMoved.Value)) { RequestItem.TotalMoved.Value += ContainersMoved; } else { RequestItem.TotalMoved.Value = ContainersMoved; } RequestItem.Status.Value = CswNbtObjClassRequestItem.Statuses.Moved; RequestItem.FulfillmentHistory.AddComment("Moved " + ContainersMoved + " containers to " + CswNbtNode.getNodeLink(RequestItem.Location.SelectedNodeId, RequestItem.Location.CachedFullPath)); RequestItem.postChanges(ForceUpdate: false); } } }
private CswNbtView _siLocationsListView(bool ReInit) { CswNbtView Ret = _getSystemView(CswEnumNbtSystemViewName.SILocationsList); if (null == Ret) { CswNbtNode ChemSwAdminRoleNode = _CswNbtResources.Nodes.makeRoleNodeFromRoleName(CswNbtObjClassRole.ChemSWAdminRoleName); Ret = new CswNbtView(_CswNbtResources); Ret.saveNew(CswEnumNbtSystemViewName.SILocationsList.ToString(), CswEnumNbtViewVisibility.Role, ChemSwAdminRoleNode.NodeId); Ret.Category = SiViewCategory; Ret.ViewMode = CswEnumNbtViewRenderingMode.List; ReInit = true; } if (ReInit) { Ret.Root.ChildRelationships.Clear(); CswNbtMetaDataObjectClass LocationOc = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.LocationClass); CswNbtViewRelationship LocationVr = Ret.AddViewRelationship(LocationOc, true); CswNbtMetaDataObjectClassProp LocationLocationOcp = LocationOc.getObjectClassProp(CswNbtObjClassLocation.PropertyName.Location); CswNbtViewProperty LocationLocationVp = Ret.AddViewProperty(LocationVr, LocationLocationOcp); LocationLocationVp.SortBy = true; Ret.save(); } return(Ret); }
public override void update() { CswNbtNode CisproRequestFulfillerRole = _CswNbtSchemaModTrnsctn.Nodes.makeRoleNodeFromRoleName( "CISPro_Request_Fulfiller" ); if( null != CisproRequestFulfillerRole ) { LandingPageData PageData = _CswNbtSchemaModTrnsctn.getLandingPageTable().getLandingPageItems( new LandingPageData.Request { RoleId = CisproRequestFulfillerRole.NodeId.ToString(), ActionId = null } ); Collection<Int32> DoomedIds = new Collection<int>(); foreach( LandingPageData.LandingPageItem PageItem in PageData.LandingPageItems ) { if( PageItem.Text == "Pending Requests" ) { _CswNbtSchemaModTrnsctn.getLandingPageTable().addLandingPageItem( new LandingPageData.Request { Type = CswEnumNbtLandingPageItemType.Link, RoleId = CisproRequestFulfillerRole.NodeId.ToString(), Text = "Submitted Requests", NodeViewId = PageItem.ViewId, PkValue = PageItem.ViewId, ButtonIcon = "cart.png", ViewType = CswEnumNbtViewType.View.ToString() } ); DoomedIds.Add( CswConvert.ToInt32( PageItem.LandingPageId ) ); } } foreach( int DoomedId in DoomedIds ) { _CswNbtSchemaModTrnsctn.getLandingPageTable().deleteLandingPageItem( new LandingPageData.Request { LandingPageId = DoomedId } ); } } foreach( CswEnumNbtObjectClass Member in CswNbtPropertySetRequestItem.Members() ) { CswNbtMetaDataObjectClass MemberOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( Member ); foreach( CswNbtMetaDataNodeType NodeType in MemberOc.getLatestVersionNodeTypes() ) { CswNbtMetaDataNodeTypeProp CommentsNtp = NodeType.getNodeTypePropByObjectClassProp( CswNbtPropertySetRequestItem.PropertyName.Comments ); CommentsNtp.updateLayout( CswEnumNbtLayoutType.Add, false ); if( null != CisproRequestFulfillerRole ) { _CswNbtSchemaModTrnsctn.Permit.set( CswEnumNbtNodeTypePermission.Edit, NodeType, CisproRequestFulfillerRole, true ); } } } CswNbtMetaDataObjectClass RequestOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.RequestClass ); foreach( CswNbtMetaDataNodeType RequestNt in RequestOc.getNodeTypes() ) { RequestNt.NameTemplateValue = ""; RequestNt.addNameTemplateText( CswNbtObjClassRequest.PropertyName.Name ); RequestNt.addNameTemplateText( CswNbtObjClassRequest.PropertyName.SubmittedDate ); } } // update()
public static void getMolImg(ICswResources CswResources, MolDataReturn Return, MolData ImgData) { string molData = ImgData.molString; string nodeId = ImgData.nodeId; string base64String = ""; CswNbtResources NbtResources = (CswNbtResources)CswResources; if (String.IsNullOrEmpty(molData) && false == String.IsNullOrEmpty(nodeId)) //if we only have a nodeid, get the mol text from the mol property if there is one { CswPrimaryKey pk = CswConvert.ToPrimaryKey(nodeId); CswNbtNode node = NbtResources.Nodes[pk]; CswNbtMetaDataNodeTypeProp molNTP = node.getNodeType().getMolProperty(); if (null != molNTP) { molData = node.Properties[molNTP].AsMol.getMol(); } } if (false == String.IsNullOrEmpty(molData)) { //If the Direct Structure Search module is enabled, use the AcclDirect methods to generate an image. Otherwise, use the legacy code. byte[] bytes = (NbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.DirectStructureSearch) ? NbtResources.AcclDirect.GetImage(molData) : CswStructureSearch.GetImage(molData)); base64String = Convert.ToBase64String(bytes); } ImgData.molImgAsBase64String = base64String; ImgData.molString = molData; Return.Data = ImgData; }
public static void getQuota(ICswResources Resources, CswNbtQuotaResponse Response, QuotaRequest Request) { if (null != Resources) { CswNbtResources NbtResources = (CswNbtResources)Resources; CswNbtActQuotas ActQuotas = new CswNbtActQuotas(NbtResources); int NodeTypeId = Request.NodeTypeId; int ObjectClassId = Request.ObjectClassId; if (NodeTypeId <= 0) { CswNbtNodeKey Key = wsNBT.getNodeKey(Request.NodeKey); if (null != Key) { NodeTypeId = Key.NodeTypeId; ObjectClassId = Key.ObjectClassId; } } if (NodeTypeId <= 0) { CswNbtNode Node = NbtResources.Nodes[Request.NodeId]; if (null != Node) { NodeTypeId = Node.NodeTypeId; ObjectClassId = Node.getObjectClassId(); } } Response.Data = ActQuotas.CheckQuota(NodeTypeId, ObjectClassId); } }
public void addSingleNodeProp(CswNbtNode Node, JObject PropObj, CswNbtMetaDataNodeTypeTab Tab) { CswPropIdAttr PropIdAttr = new CswPropIdAttr(CswConvert.ToString(PropObj["id"])); CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(PropIdAttr.NodeTypePropId); if (null != MetaDataProp) { CswNbtMetaDataNodeType NodeType = MetaDataProp.getNodeType(); if (_CswNbtResources.Permit.canNodeType(Security.CswEnumNbtNodeTypePermission.Edit, NodeType) || _CswNbtResources.Permit.canTab(Security.CswEnumNbtNodeTypePermission.Edit, NodeType, Tab) || _CswNbtResources.Permit.isPropWritable(Security.CswEnumNbtNodeTypePermission.Edit, MetaDataProp, Tab)) { Node.Properties[MetaDataProp].ReadJSON(PropObj, null, null); // Recurse on sub-props if (null != PropObj["subprops"]) { JObject SubPropsObj = (JObject)PropObj["subprops"]; if (SubPropsObj.HasValues) { foreach (JObject ChildPropObj in SubPropsObj.Properties() .Where(ChildProp => null != ChildProp.Value && ChildProp.Value.HasValues) .Select(ChildProp => (JObject)ChildProp.Value) .Where(ChildPropObj => ChildPropObj.HasValues)) { addSingleNodeProp(Node, ChildPropObj, Tab); } } } } //if user has permission to edit the property } //if not null } // addSingleNodeProp()
public void Create(CswNbtResource Return, CswNbtAPIGenericRequest GenericRequest) { if (hasPermission(GenericRequest, Return)) { try { CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(GenericRequest.MetaDataName); CswNbtNode NewNode = _CswNbtResources.Nodes.makeNodeFromNodeTypeId(NodeType.NodeTypeId, IsTemp : GenericRequest.Properties.Count > 0, OnAfterMakeNode : delegate(CswNbtNode node) { foreach (CswNbtWcfProperty WcfProp in GenericRequest.Properties) { ReadPropertyData(node, WcfProp); } }); Return.NodeId = NewNode.NodeId; Return.NodeName = NewNode.NodeName; Return.NodeType = NewNode.getNodeType().NodeTypeName; Return.ObjectClass = NewNode.ObjClass.ObjectClass.ObjectClassName; Return.URI = BuildURI(NodeType.NodeTypeName, NewNode.NodeId.PrimaryKey); Return.PropertyData = GetPropertyData(NewNode); Return.Status = HttpStatusCode.Created; } catch (Exception) { Return.Status = HttpStatusCode.InternalServerError; } } else { Return.Status = HttpStatusCode.Forbidden; } }
/// <summary> /// Convenience function for hiding Role nodes. Entering 'cispro' for the modulename param will hide all Roels with 'cispro' in the name. /// </summary> /// <param name="hidden">True if the nodes should be hidden</param> /// <param name="modulename">The module of the nodes to hide</param> public void ToggleRoleNodes(bool hidden, string modulename) { CswNbtMetaDataObjectClass roleOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.RoleClass); CswNbtMetaDataObjectClassProp nameOCP = roleOC.getObjectClassProp(CswNbtObjClassRole.PropertyName.Name); CswNbtView rolesView = new CswNbtView(_CswNbtResources); CswNbtViewRelationship parent = rolesView.AddViewRelationship(roleOC, false); rolesView.AddViewPropertyAndFilter(parent, MetaDataProp: nameOCP, Value: modulename, SubFieldName: CswNbtFieldTypeRuleText.SubFieldName.Text, FilterMode: CswEnumNbtFilterMode.Contains); ICswNbtTree cisproUsersTree = _CswNbtResources.Trees.getTreeFromView(rolesView, false, true, true); int count = cisproUsersTree.getChildNodeCount(); for (int i = 0; i < count; i++) { cisproUsersTree.goToNthChild(i); CswNbtNode userNode = cisproUsersTree.getNodeForCurrentPosition(); userNode.Hidden = hidden; userNode.postChanges(false); cisproUsersTree.goToParentNode(); } }
public override void update() { // Adapted from CswNbtSessionDataMgr.removeAllSessionData() CswTableSelect NodesSelect = _CswNbtSchemaModTrnsctn.makeCswTableSelect( "30983_nodes_select", "nodes" ); DataTable NodesTable = NodesSelect.getTable( new CswCommaDelimitedString { "nodeid" }, "where istemp = '1'" ); if( NodesTable.Rows.Count > 0 ) { Collection<CswNbtNode> DoomedNodes = new Collection<CswNbtNode>(); foreach( DataRow Row in NodesTable.Rows ) { CswPrimaryKey NodeId = new CswPrimaryKey( "nodes", CswConvert.ToInt32( Row["nodeid"] ) ); if( CswTools.IsPrimaryKey( NodeId ) ) { CswNbtNode TempNode = _CswNbtSchemaModTrnsctn.Nodes[NodeId]; if( null != TempNode ) { DoomedNodes.Add( TempNode ); } } } foreach( CswNbtNode DoomedNode in DoomedNodes ) { DoomedNode.delete( DeleteAllRequiredRelatedNodes: true, OverridePermissions: true ); } } //there are nodes rows } // update()
private CswNbtView _getSiInspectionUserView(bool ReInit) { CswNbtView Ret = _getSystemView(CswEnumNbtSystemViewName.SIInspectionsbyUser); if (null == Ret) { CswNbtNode ChemSwAdminRoleNode = _CswNbtResources.Nodes.makeRoleNodeFromRoleName(CswNbtObjClassRole.ChemSWAdminRoleName); Ret = new CswNbtView(_CswNbtResources); Ret.saveNew(CswEnumNbtSystemViewName.SIInspectionsbyUser.ToString(), CswEnumNbtViewVisibility.Role, ChemSwAdminRoleNode.NodeId); Ret.Category = SiViewCategory; Ret.ViewMode = CswEnumNbtViewRenderingMode.List; ReInit = true; } if (ReInit) { Ret.Root.ChildRelationships.Clear(); CswNbtMetaDataObjectClass InspectionDesignOc = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.InspectionDesignClass); CswNbtViewRelationship InspectionDesignVr = Ret.AddViewRelationship(InspectionDesignOc, true); _addDefaultInspectionDesignViewPropsAndFilters(Ret, InspectionDesignVr, InspectionDesignOc); CswNbtMetaDataObjectClassProp InspectorOcp = InspectionDesignOc.getObjectClassProp(CswNbtObjClassInspectionDesign.PropertyName.Inspector); Ret.AddViewPropertyAndFilter(InspectionDesignVr, InspectorOcp, "me"); Ret.save(); } return(Ret); }
} // _getSearchNodes private void _runTreeNodesRecursive(ICswNbtTree Tree, JObject ParentJsonO) { for (Int32 c = 0; c < Tree.getChildNodeCount(); c++) { Tree.goToNthChild(c); CswNbtNode ThisNode = Tree.getNodeForCurrentPosition(); CswNbtNodeKey ThisNodeKey = Tree.getNodeKeyForCurrentPosition(); if (Tree.getNodeShowInTreeForCurrentPosition()) { bool RunProps = (_ForMobile && Tree.getChildNodeCount() == 0 && NodeSpecies.More != ThisNodeKey.NodeSpecies); // is a leaf JProperty ThisJProp = _getNode(ThisNode, RunProps, ThisNodeKey.NodeSpecies); ParentJsonO.Add(ThisJProp); if (Tree.getChildNodeCount() > 0) { JObject ThisNodeObj = (JObject)ThisJProp.Value; JObject NodesObj = new JObject(); ThisNodeObj["nodes"] = NodesObj; _runTreeNodesRecursive(Tree, NodesObj); } } // if( Tree.getNodeShowInTreeForCurrentPosition() ) else { _runTreeNodesRecursive(Tree, ParentJsonO); } Tree.goToParentNode(); } } // _runTreeNodesRecursive()
} // runBatchOp() #region Private Helper Methods #region Helper Methods private CswNbtNode _getNodeFromBarcode(string barcode, CswEnumNbtObjectClass objClassType, string barcodePropertyName, bool IncludeDefaultFilters = true) { CswNbtNode returnNode = null; CswNbtView objClassView = new CswNbtView(_CswNbtResources); CswNbtMetaDataObjectClass objClass = _CswNbtResources.MetaData.getObjectClass(objClassType); CswNbtMetaDataObjectClassProp barcodeOCP = objClass.getObjectClassProp(barcodePropertyName); CswNbtViewRelationship parent = objClassView.AddViewRelationship(objClass, IncludeDefaultFilters); objClassView.AddViewPropertyAndFilter(parent, MetaDataProp: barcodeOCP, Value: barcode, FilterMode: CswEnumNbtFilterMode.Equals); ICswNbtTree Tree = _CswNbtResources.Trees.getTreeFromView(objClassView, false, true, true); Tree.goToRoot(); for (int i = 0; i < Tree.getChildNodeCount(); i++) { Tree.goToNthChild(i); returnNode = Tree.getNodeForCurrentPosition(); Tree.goToParentNode(); } return(returnNode); }
public static void Initialize(ICswResources CswResources, CswNbtExplorerReturn Return, CswNbtExplorerRequest Request) { CswNbtResources NbtResources = (CswNbtResources)CswResources; CswPrimaryKey NodeId = CswConvert.ToPrimaryKey(Request.NodeId); if (Request.Depth <= 4 || Request.Depth > 0) //We never want a request higher than 4 and 0 doesn't make sense { MAX_DEPTH = Request.Depth; } FilterVal = new CswCommaDelimitedString(); if (String.IsNullOrEmpty(Request.FilterVal)) { FilterVal.FromString(CswNbtArborGraph._setDefaultFilterVal(NbtResources)); } else { FilterVal.FromString(Request.FilterVal); } StartingNode = NbtResources.Nodes[NodeId]; CswNbtMetaDataNodeType startingNT = StartingNode.getNodeType(); //Add the initial node to the graph _addToGraph(Return, StartingNode.NodeName, string.Empty, NodeId.ToString(), startingNT.IconFileName, 0, "Instance", NodeId.ToString(), startingNT.NodeTypeName, Int32.MinValue); _recurseForRelatingNodes(NbtResources, Return, StartingNode, 1, NodeId.ToString()); _recurseForRelatedNTs(NbtResources, Return, StartingNode.NodeTypeId, 1, NodeId.ToString()); }
public void dispenseIntoChildContainersTestDispenseTwo() { double Expected = 1.0; CswNbtMetaDataNodeType ContainerNT = TestData.CswNbtResources.MetaData.getNodeType("Container"); string ContainerNodeTypeId = ContainerNT.NodeTypeId.ToString(); CswNbtNode LiterNode = TestData.Nodes.createUnitOfMeasureNode("Volume", "Liters", 1.0, 0, CswEnumTristate.True); CswNbtNode MilliliterNode = TestData.Nodes.createUnitOfMeasureNode("Volume", "Milliliters", 1.0, -3, CswEnumTristate.True); CswNbtNode ContainerNode = TestData.Nodes.createContainerNode("Container", 2.0, LiterNode); CswNbtActDispenseContainer wiz = new CswNbtActDispenseContainer(TestData.CswNbtResources, ContainerNode.NodeId.ToString()); string DispenseRow1 = "{ \"containerNo\":\"1\", \"quantity\":\"0.5\", \"unitid\":\"" + LiterNode.NodeId.ToString() + "\" }"; string DispenseRow2 = "{ \"containerNo\":\"1\", \"quantity\":\"500\", \"unitid\":\"" + MilliliterNode.NodeId.ToString() + "\" }"; string DispenseGrid = "[" + DispenseRow1 + "," + DispenseRow2 + "]"; JObject obj = wiz.dispenseIntoChildContainers(ContainerNodeTypeId, DispenseGrid, String.Empty); Assert.IsNotNull(obj); List <CswNbtObjClassContainer> NewContainers = _getNewContainers(ContainerNode.NodeId); foreach (CswNbtObjClassContainer NewContainer in NewContainers) { Assert.IsTrue((NewContainer.Quantity.Quantity == 500 && NewContainer.Quantity.UnitId == MilliliterNode.NodeId) || (NewContainer.Quantity.Quantity == 0.5 && NewContainer.Quantity.UnitId == LiterNode.NodeId)); } Assert.AreEqual(2, NewContainers.Count); Assert.AreEqual(Expected, _getNewSourceContainerQuantity(ContainerNode.NodeId)); }
private static void _recurseForRelatingNodes(CswNbtResources NbtResources, CswNbtExplorerReturn Return, CswNbtNode Node, int Level, string OwnerIdStr) { CswNbtMetaDataNodeType TargetNodeType = Node.getNodeType(); foreach (CswNbtMetaDataNodeTypeProp RelNTP in TargetNodeType.getNodeTypeProps(CswEnumNbtFieldType.Relationship)) //TODO: Locations are just like relationships, we should be able to handle them { CswNbtNodePropRelationship RelProp = Node.Properties[RelNTP]; string Icon = _getIconFromRelationshipProp(NbtResources, RelNTP); if (CswTools.IsPrimaryKey(RelProp.RelatedNodeId)) { CswNbtNode TargetNode = NbtResources.Nodes[RelProp.RelatedNodeId]; CswNbtMetaDataNodeType TargetNT = TargetNode.getNodeType(); if (FilterVal.Contains("NT_" + TargetNode.NodeTypeId) || FilterVal.Contains("OC_" + TargetNode.getObjectClassId())) { string targetIdStr = OwnerIdStr + "_" + RelProp.RelatedNodeId.ToString(); _addToGraph(Return, RelProp.PropName + ": " + RelProp.CachedNodeName, Node.NodeId.ToString(), RelProp.RelatedNodeId.ToString(), Icon, Level, "Instance", RelProp.RelatedNodeId.ToString(), TargetNT.NodeTypeName, RelNTP.PropId); if (Level + 1 <= MAX_DEPTH) { _recurseForRelatedNTs(NbtResources, Return, TargetNode.NodeTypeId, 1, RelProp.RelatedNodeId.ToString()); } if (Level + 1 <= MAX_DEPTH) { _recurseForRelatingNodes(NbtResources, Return, TargetNode, Level + 1, targetIdStr); } } } } }
} // update() private void _fixBadScheudlesAndTasks() { ICswNbtTree BadSchedulesTree = _CswNbtSchemaModTrnsctn.getTreeFromView( _getBadSchedulesAndTasksView(), false ); BadSchedulesTree.goToRoot(); for( int i = 0; i < BadSchedulesTree.getChildNodeCount(); i++ ) { BadSchedulesTree.goToNthChild( i ); CswNbtObjClassGenerator ScheduleNode = BadSchedulesTree.getNodeForCurrentPosition(); int TargetTypeId = ScheduleNode.NodeTypeId == AssemblyScheduleNT.NodeTypeId ? AssemblyTaskNT.NodeTypeId : EquipmentTaskNT.NodeTypeId; ScheduleNode.TargetType.SelectedNodeTypeIds.Clear(); ScheduleNode.TargetType.SelectedNodeTypeIds.Add( CswConvert.ToString( TargetTypeId ) ); ScheduleNode.postChanges( false ); for( int j = 0; j < BadSchedulesTree.getChildNodeCount(); j++ ) { BadSchedulesTree.goToNthChild( j ); CswNbtNode OldTaskNode = BadSchedulesTree.getNodeForCurrentPosition(); CswNbtObjClassTask NewTaskNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( TargetTypeId, CswEnumNbtMakeNodeOperation.WriteNode ); NewTaskNode.Node.copyPropertyValues( OldTaskNode ); NewTaskNode.Owner.RelatedNodeId = ScheduleNode.Owner.RelatedNodeId; OldTaskNode.delete(); NewTaskNode.postChanges( false ); BadSchedulesTree.goToParentNode(); } BadSchedulesTree.goToParentNode(); } }
} // applyMergeChoices() public void _applyMergeChoicesToNode(MergeInfoData Choices, MergeInfoData.MergeInfoNodePair nodePair, CswNbtNode resultNode) { CswNbtNode Node1 = _CswNbtResources.Nodes[nodePair.Node1Id]; CswNbtNode Node2 = _CswNbtResources.Nodes[nodePair.Node2Id]; if (null != Node1 && null != Node2) { /* * Copy all the values from Node2 into the result and then copy any properties from Node1 into the result that were selected * This is to ensure we copy property values we didn't have to merge. */ resultNode.copyPropertyValuesGeneric(Node2); foreach (MergeInfoData.MergeInfoProperty mergeProp in nodePair.Properties.Where(mergeProp => mergeProp.Choice == 1)) { resultNode.Properties[mergeProp.NodeTypePropId].copyGeneric(Node1.Properties[mergeProp.NodeTypePropId]); } // Set references to new merged node if (Int32.MinValue != nodePair.NodeReferencePropId) { // Find the new nodeid for the value of the reference ICswNbtNodePropNodeReference NodeReferenceProp = resultNode.Properties[nodePair.NodeReferencePropId].AsNodeReference; CswPrimaryKey oldNodeId = NodeReferenceProp.ReferencedNodeId; MergeInfoData.MergeInfoNodePair otherNodePair = Choices.NodePairs.FirstOrDefault(np => np.Node1Id == oldNodeId.ToString() || np.Node2Id == oldNodeId.ToString()); if (null != otherNodePair) { // Set the reference to point to the new merged node NodeReferenceProp.ReferencedNodeId = CswConvert.ToPrimaryKey(otherNodePair.Node2Id); } } // if( Int32.MinValue != nodePair.NodeReferencePropId ) } // if( null != Node1 && null != Node2 ) } // _applyMergeChoicesToNode()
} // _getUniqueKeysDict() public MergeInfoData applyMergeChoices(MergeInfoData Choices) { foreach (MergeInfoData.MergeInfoNodePair nodePair in Choices.NodePairs) { // Apply the changes to a temp node, so that they can be previewed CswNbtNode tempNode; if (false == string.IsNullOrEmpty(nodePair.NodeTempId)) { tempNode = _CswNbtResources.Nodes[nodePair.NodeTempId]; _applyMergeChoicesToNode(Choices, nodePair, tempNode); tempNode.postChanges(ForceUpdate: false, IsCopy: false, OverrideUniqueValidation: true); } else { CswNbtNode Node1 = _CswNbtResources.Nodes[nodePair.Node1Id]; if (null != Node1) { tempNode = _CswNbtResources.Nodes.makeNodeFromNodeTypeId(Node1.NodeTypeId, IsTemp : true, OverrideUniqueValidation : true, OnAfterMakeNode : delegate(CswNbtNode newNode) { _applyMergeChoicesToNode(Choices, nodePair, newNode); }); nodePair.NodeTempId = tempNode.NodeId.ToString(); nodePair.NodeTempName = tempNode.NodeName; } } } // foreach( MergeInfoData.MergeInfoNodePair nodePair in Choices.NodePairs ) return(Choices); } // applyMergeChoices()
public override void CommitOperation(ref OperationData OpData) { bool succeeded = false; string statusMsg = null; CswNbtObjClassUser newTransferOwner = _getNodeByBarcode(CswEnumNbtObjectClass.UserClass, OpData.Field1.Value, true); CswNbtNode node = _CswNbtResources.Nodes[OpData.Field2.NodeId]; CswNbtMetaDataNodeType NodeType = node.getNodeType(); string itemName = NodeType.NodeTypeName; ICswNbtKioskModeTransferable AsTransferable = (ICswNbtKioskModeTransferable)node.ObjClass; if (AsTransferable.CanTransfer(out statusMsg)) { AsTransferable.Transfer(newTransferOwner); succeeded = true; } if (null != node && succeeded) { node.postChanges(false); CswNbtObjClassLocation newLocationNode = _CswNbtResources.Nodes[newTransferOwner.DefaultLocationId]; OpData.Log.Add(DateTime.Now + " - Transferred " + itemName + " " + OpData.Field2.Value + " ownership to " + newTransferOwner.Username + " (" + OpData.Field1.Value + ") at " + newLocationNode.Name.Text); base.CommitOperation(ref OpData); } else { statusMsg = statusMsg ?? "You do not have permission to edit " + itemName + " (" + OpData.Field2.Value + ")"; OpData.Field2.StatusMsg = statusMsg; OpData.Field2.ServerValidated = false; OpData.Log.Add(DateTime.Now + " - ERROR: " + statusMsg); } }
private CswPrimaryKey _HandleReference(string LocationNodeIdStr, string LocationBarcode) //, Dictionary<Int32, Int32> NodeMap ) { CswPrimaryKey LocationNodeId = new CswPrimaryKey(); if (!string.IsNullOrEmpty(LocationNodeIdStr)) { LocationNodeId.FromString(LocationNodeIdStr); if (LocationNodeId.PrimaryKey == Int32.MinValue && LocationBarcode != string.Empty) { // Find the location with this barcode value CswNbtMetaDataObjectClass LocationObjectClass = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.LocationClass); CswNbtMetaDataObjectClassProp BarcodeObjectClassProp = LocationObjectClass.getObjectClassProp(CswNbtObjClassLocation.PropertyName.Barcode); CswNbtView LocationView = new CswNbtView(_CswNbtResources); // All locations.. CswNbtViewRelationship LocationRelationship = LocationView.AddViewRelationship(LocationObjectClass, false); // ..with barcodes CswNbtViewProperty BarcodeViewProperty = LocationView.AddViewProperty(LocationRelationship, BarcodeObjectClassProp); // ..equal to the given barcode CswNbtViewPropertyFilter BarcodeViewPropertyFilter = LocationView.AddViewPropertyFilter(BarcodeViewProperty, CswNbtFieldTypeRuleBarCode.SubFieldName.Barcode, CswEnumNbtFilterMode.Equals, LocationBarcode, false); ICswNbtTree LocationTree = _CswNbtResources.Trees.getTreeFromView(_CswNbtResources.CurrentNbtUser, LocationView, true, false, false); if (LocationTree.getChildNodeCount() > 0) { LocationTree.goToNthChild(0); CswNbtNode LocationNode = LocationTree.getNodeForCurrentPosition(); LocationNodeId = LocationNode.NodeId; } } } // if(!string.IsNullOrEmpty(LocationNodeIdStr)) return(LocationNodeId); } // _HandleReference()
public void threadCallBack(ICswResources CswResources) { _LogicRunStatus = CswEnumScheduleLogicRunStatus.Running; CswNbtResources CswNbtResources = (CswNbtResources)CswResources; CswNbtResources.AuditContext = "Scheduler Task: " + RuleName; if (CswEnumScheduleLogicRunStatus.Stopping != _LogicRunStatus) { try { // Find which nodes are out of date CswArbitrarySelect OutOfDateNodesQuerySelect = getValuesToUpdate(CswNbtResources); DataTable OutOfDateNodes = null; Int32 NodesPerCycle = CswConvert.ToInt32(CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumConfigurationVariableNames.NodesProcessedPerCycle)); if (NodesPerCycle <= 0) { NodesPerCycle = 25; } OutOfDateNodes = OutOfDateNodesQuerySelect.getTable(0, NodesPerCycle, false); NodesPerCycle = OutOfDateNodes.Rows.Count; //in case we didn't actually retrieve that amount Int32 ErroneousNodeCount = 0; string ErroneousNodes = "The following Nodes failed to update:\n"; for (Int32 idx = 0; (idx < NodesPerCycle); idx++) { CswPrimaryKey nodeid = new CswPrimaryKey("nodes", CswConvert.ToInt32(OutOfDateNodes.Rows[idx]["nodeid"].ToString())); try//Case 29526 - if updating the node fails for whatever reason, log it and move on { CswNbtNode Node = CswNbtResources.Nodes[nodeid]; CswNbtActUpdatePropertyValue CswNbtActUpdatePropertyValue = new CswNbtActUpdatePropertyValue(CswNbtResources); CswNbtActUpdatePropertyValue.UpdateNode(Node, false); // Case 28997: Node.postChanges(ForceUpdate: true); } catch (Exception ex) { if (false == ErroneousNodes.Contains(CswConvert.ToString(nodeid))) { ErroneousNodeCount++; ErroneousNodes += nodeid + " - " + ex.Message + ex.StackTrace + "\n\n"; } } }//if we have nodes to process _CswScheduleLogicDetail.StatusMessage = 0 == ErroneousNodeCount ? "Completed without error" : ErroneousNodes; _LogicRunStatus = CswEnumScheduleLogicRunStatus.Succeeded; //last line } catch (Exception Exception) { CswNbtResources.logError(Exception); _CswScheduleLogicDetail.StatusMessage = "CswScheduleLogicNbtUpdtPropVals exception: " + Exception.Message + "; " + Exception.StackTrace; _LogicRunStatus = CswEnumScheduleLogicRunStatus.Failed;//last line } }//if we're not shutting down }//threadCallBack()
} // getPercentDone() /// <summary> /// Run the next iteration of this batch operation /// </summary> public void runBatchOp(CswNbtObjClassBatchOp BatchNode) { try { if (BatchNode != null && BatchNode.OpNameValue == CswEnumNbtBatchOpName.MultiEdit) { BatchNode.start(); MultiEditBatchData BatchData = new MultiEditBatchData(BatchNode.BatchData.Text); if (BatchData.SourceNodeId != null && BatchData.CopyNodeIds.Count > 0 && BatchData.NodeTypePropIds.Count > 0) { CswNbtNode SourceNode = _CswNbtResources.Nodes[BatchData.SourceNodeId]; if (SourceNode != null) { string NodeIdStr = BatchData.CopyNodeIds.First.ToString(); CswPrimaryKey CopyToNodePk = new CswPrimaryKey(); CopyToNodePk.FromString(NodeIdStr); if (Int32.MinValue != CopyToNodePk.PrimaryKey) { CswNbtNode CopyToNode = _CswNbtResources.Nodes[CopyToNodePk]; if (CopyToNode != null && _CswNbtResources.Permit.isNodeWritable(CswEnumNbtNodeTypePermission.Edit, CopyToNode.getNodeType(), CopyToNode.NodeId)) { foreach (CswNbtMetaDataNodeTypeProp NodeTypeProp in BatchData.NodeTypePropIds.Select(PropId => _CswNbtResources.MetaData.getNodeTypeProp(CswConvert.ToInt32(PropId)))) { CopyToNode.Properties[NodeTypeProp].copy(SourceNode.Properties[NodeTypeProp]); } CopyToNode.postChanges(false); //BatchNode.appendToLog( "Copied values for: " + CopyToNode.NodeName + " (" + CopyToNode.NodeId.PrimaryKey.ToString() + ")" ); } // if( CopyToNode != null ) } // if( Int32.MinValue != CopyToNodePk.PrimaryKey ) // Setup for next iteration BatchData.CopyNodeIds.RemoveAt(0); BatchNode.BatchData.Text = BatchData.ToString(); BatchNode.PercentDone.Value = getPercentDone(BatchNode); } // if( SourceNode != null ) else { BatchNode.finish(); } } else { BatchNode.finish(); } BatchNode.postChanges(false); } // if( BatchNode != null && BatchNode.OpNameValue == NbtBatchOpName.MultiEdit ) } catch (Exception ex) { BatchNode.error(ex); } } // runBatchOp()
public void setChangedValue() { CswNbtNode NodeInstance = _CswNbtSchemaModTrnsctn.Nodes[_NodePrimaryKey]; CswNbtMetaDataNodeTypeProp NodeTypeProp = _CswNbtSchemaModTrnsctn.MetaData.getNodeTypeProp(_NodeTypeId, _TestNodeTypePropName); NodeInstance.Properties[NodeTypeProp].AsMemo.Text = _PropValChanged; NodeInstance.postChanges(true); } //setChagnedValue
} //write() private string _makeDefaultNodeName(CswNbtNode Node) { string ReturnVal = ""; ReturnVal = Node.getNodeType().NodeTypeName + " " + Node.NodeId.PrimaryKey.ToString(); return(ReturnVal); }//_makeDefaultNodeName
private CswNbtObjClassRole _createRole( CswNbtMetaDataNodeType RoleNodeType, string RoleName ) { CswNbtNode RoleNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( RoleNodeType.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode ); CswNbtObjClassRole NodeAsRole = RoleNode; NodeAsRole.Name.Text = RoleName; NodeAsRole.Timeout.Value = 30; return NodeAsRole; }
private CswNbtView _getSystemView(CswEnumNbtSystemViewName ViewName) { List <CswNbtView> Views = _CswNbtResources.ViewSelect.restoreViews(ViewName.ToString(), CswEnumNbtViewVisibility.Unknown, Int32.MinValue); CswNbtNode ChemSwAdminRoleNode = _CswNbtResources.Nodes.makeRoleNodeFromRoleName(CswNbtObjClassRole.ChemSWAdminRoleName); return(Views.FirstOrDefault(View => View.Visibility == CswEnumNbtViewVisibility.Role && View.VisibilityRoleId == ChemSwAdminRoleNode.NodeId)); }
public void promoteTempToRealTestTempStateRemoved() { CswNbtNode TestNode = TestData.Nodes.createTempNode(); Assert.IsTrue(TestNode.IsTemp); TestNode.PromoteTempToReal(); Assert.IsFalse(TestNode.IsTemp); }
internal CswNbtNode createContainerWithRecords(string NodeTypeName = "Container", double Quantity = 1.0, CswNbtNode UnitOfMeasure = null, CswNbtNode Material = null, CswPrimaryKey LocationId = null, DateTime?DateCreated = null, string UseType = null) { CswNbtNode ret = createContainerNode(NodeTypeName, Quantity, UnitOfMeasure, Material, LocationId, UseType); createContainerDispenseTransactionNode(ret, DateCreated); createContainerLocationNode(ret, LocationId: LocationId, NullableScanDate: DateCreated); return(ret); }
} // getPercentDone() /// <summary> /// Run the next iteration of this batch operation /// </summary> public void runBatchOp(CswNbtObjClassBatchOp BatchNode) { try { if (BatchNode != null && BatchNode.OpNameValue == CswEnumNbtBatchOpName.SyncLocation) { BatchNode.start(); SyncLocationBatchData BatchData = new SyncLocationBatchData(BatchNode.BatchData.Text); if (BatchData.NodePks.Count > 0) { int NodesProcessedPerIteration = CswConvert.ToInt32(_CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumConfigurationVariableNames.NodesProcessedPerCycle)); for (int i = 0; i < NodesProcessedPerIteration && BatchData.NodePks.Count > 0; i++) { CswNbtNode Node = _CswNbtResources.Nodes[CswConvert.ToString(BatchData.NodePks[0])]; BatchData.NodePks.RemoveAt(0); bool LocationUpdated = false; if (null != Node) { CswNbtMetaDataNodeType NodeType = Node.getNodeType(); if (null != NodeType) { CswNbtMetaDataNodeTypeProp LocationNTP = NodeType.getLocationProperty(); if (null != LocationNTP) { CswNbtNodePropLocation LocationProp = Node.Properties[LocationNTP]; if (null != LocationProp) { LocationProp.SelectedNodeId = BatchData.LocationId; Node.postChanges(false); LocationUpdated = true; } } } }//if( null != Node ) if (false == LocationUpdated) { BatchNode.appendToLog("Unable to update the location of: " + Node.NodeName + " (" + Node.NodeId.ToString() + ")"); } }//for( int i = 0; i < NodesProcessedPerIteration && BatchData.NodePks.Count > 0; i++ ) } else { BatchNode.finish(); } BatchNode.PercentDone.Value = getPercentDone(BatchNode); BatchNode.BatchData.Text = BatchData.ToString(); BatchNode.postChanges(false); } } catch (Exception ex) { BatchNode.error(ex); } } // runBatchOp()