public TimingModule() { _ServerStartTimer = new CswTimer(); // _LogFileStream = File.CreateText( @"D:/vault/dn/logs/httplog.txt" ); _CswSetupVbls = new CswSetupVbls(CswEnumSetupMode.NbtWeb); _CswLogger = new CswAppStatusReporter(null, _CswSetupVbls, CswEnumAppType.Nbt); }//ctor()
public void OnEndOfPageLifeCycle(CswTimer Timer) { if (_RecordStatistics) { if (null != Timer) { // Store numbers to determine average page lifecycle double ElapsedTime = Timer.ElapsedDurationInMilliseconds; CswNbtStatisticsEntry.Stats_servertime_total += ElapsedTime; CswNbtStatisticsEntry.Stats_servertime_count++; } } }
}//makeNodeFromNodeTypeId() /// <summary> /// Fetches a User Node from the Username, using a View and a TreeLoader. /// </summary> /// <remarks> /// not sure if this belongs here in CswNbtNodeCollection /// </remarks> /// <param name="Username">Username of User</param> /// <param name="RequireViewPermissions"></param> public CswNbtNode makeUserNodeFromUsername(string Username, bool RequireViewPermissions = true) { CswTimer Timer = new CswTimer(); CswNbtNode UserNode = null; CswNbtMetaDataObjectClass User_ObjectClass = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.UserClass); CswNbtMetaDataObjectClassProp UserName_ObjectClassProp = User_ObjectClass.getObjectClassProp(CswNbtObjClassUser.PropertyName.Username); _CswNbtResources.logTimerResult("makeUserNodeFromUsername 1", Timer); // generate the view CswNbtView View = new CswNbtView(_CswNbtResources); View.ViewName = "CswNbtNodes.makeUserNodeFromUsername(" + Username + ")"; CswNbtViewRelationship UserRelationship = View.AddViewRelationship(User_ObjectClass, false); CswNbtViewProperty Prop = View.AddViewProperty(UserRelationship, UserName_ObjectClassProp); CswNbtViewPropertyFilter Filter = View.AddViewPropertyFilter(Prop, CswNbtFieldTypeRuleText.SubFieldName.Text, CswEnumNbtFilterMode.Equals, Username, false); _CswNbtResources.logTimerResult("makeUserNodeFromUsername 2", Timer); // generate the tree ICswNbtTree UserTree = _CswNbtResources.Trees.getTreeFromView(View, RequireViewPermissions, true, IncludeHiddenNodes: true); _CswNbtResources.logTimerResult("makeUserNodeFromUsername 3", Timer); // get user node UserTree.goToRoot(); if (UserTree.getChildNodeCount() > 0) { UserTree.goToNthChild(0); _CswNbtResources.logTimerResult("makeUserNodeFromUsername 4", Timer); UserNode = UserTree.getNodeForCurrentPosition(); } //else //{ // foreach( CswNbtMetaDataNodeType UserNodeTypes in User_ObjectClass.NodeTypes ) // { // foreach( CswNbtNode user in UserNodeTypes.getNodes( true, false ) ) // { // if( user.Properties[UserName_ObjectClassProp.PropName].AsText.Text == Username ) // { // UserNode = user; // break; // } // } // } _CswNbtResources.logTimerResult("makeUserNodeFromUsername 5", Timer); return(UserNode); }
}//delete() public void fill() { if (NodeSpecies == CswEnumNbtNodeSpecies.Plain) { //bool NodeInfoFetched = false; if (CswTools.IsPrimaryKey(NodeId) && (NodeTypeId <= 0 || NodeName == String.Empty)) { DataTable NodesTable = null; if (CswTools.IsDate(_Date)) { string NodesSql = "select * from " + CswNbtAuditTableAbbreviation.getAuditTableSql(_CswNbtResources, "nodes", _Date, NodeId.PrimaryKey); CswArbitrarySelect NodesTableSelect = _CswNbtResources.makeCswArbitrarySelect("fetchNodeInfo_Select", NodesSql); NodesTable = NodesTableSelect.getTable(); } else { CswTableSelect NodesTableSelect = _CswNbtResources.makeCswTableSelect("CswNbtNode.fill_nodes", "nodes"); NodesTable = NodesTableSelect.getTable("nodeid", NodeId.PrimaryKey); } if (NodesTable.Rows.Count > 0) { read(NodesTable.Rows[0]); RelationalId = new CswPrimaryKey(NodesTable.Rows[0]["relationaltable"].ToString(), CswConvert.ToInt32(NodesTable.Rows[0]["relationalid"])); } CswTimer Timer = new CswTimer(); if (getNodeType() != null) { Properties.fill(false); } _CswNbtResources.logTimerResult("Filled in node property data for node (" + NodeId.ToString() + "): " + NodeName, Timer.ElapsedDurationInSecondsAsString); if (CswTools.IsDate(_Date)) { setReadOnly(value: true, SaveToDb: false); } } } _NodeModificationState = CswEnumNbtNodeModificationState.Unchanged; }//fill()
/// <remark> /// We need a NodeTypeId because the NodeId is missing from the HashKey if this is a new node we're about to add /// </remark> private CswNbtNode _getExistingNode(NodeHashKey HashKey, Int32 NodeTypeId, CswDateTime Date) { CswTimer Timer = new CswTimer(); CswNbtNode Node = new CswNbtNode(_CswNbtResources, _CswNbtNodeWriter, NodeTypeId, CswEnumNbtNodeSpecies.Plain, HashKey.NodeId, _NodeHash.Count, Date); //bz # 7816 -- only add to the collection if the node got filled Node.fill(); if (Node.Filled) { if (!_NodeHash.ContainsKey(HashKey)) { _NodeHash.Add(HashKey, Node); } _CswNbtResources.logTimerResult("CswNbtNodeCollection.makeNode on NodeId (" + HashKey.NodeId.ToString() + ")", Timer.ElapsedDurationInSecondsAsString); } else { Node = null; } return(Node); }
} // _makeSafeSearchTerm() public override void load(bool RequireViewPermissions, Int32 ResultsLimit = Int32.MinValue) { _CswNbtTree.makeRootNode("", false); _CswNbtTree.goToRoot(); if (string.Empty != _SearchTerm) { DataTable NodesTable = new DataTable(); string Sql = _makeNodeSql(); CswArbitrarySelect ResultSelect = _CswNbtResources.makeCswArbitrarySelect("TreeLoader_select", Sql); CswTimer SqlTimer = new CswTimer(); try { NodesTable = ResultSelect.getTable(); } catch (Exception ex) { throw new CswDniException(CswEnumErrorType.Error, "Invalid View", "_getNodes() attempted to run invalid SQL: " + Sql, ex); } if (SqlTimer.ElapsedDurationInSeconds > 2) { _CswNbtResources.logMessage("Tree View SQL required longer than 2 seconds to run: " + Sql); } Int32 PriorNodeId = Int32.MinValue; Collection <CswNbtNodeKey> NewNodeKeys = null; Int32 RowCount = 1; foreach (DataRow NodesRow in NodesTable.Rows) { Int32 ThisNodeId = CswConvert.ToInt32(NodesRow["nodeid"]); Int32 ThisNodeTypeId = CswConvert.ToInt32(NodesRow["nodetypeid"]); CswPrimaryKey ThisPermGrpId = null; // Verify permissions // this could be a performance problem CswNbtMetaDataNodeType ThisNodeType = _CswNbtResources.MetaData.getNodeType(ThisNodeTypeId); if (false == RequireViewPermissions || _CswNbtResources.Permit.canAnyTab(CswEnumNbtNodeTypePermission.View, ThisNodeType)) { Int32 ThisNTPId = Int32.MinValue; if (NodesTable.Columns.Contains("nodetypepropid")) { ThisNTPId = CswConvert.ToInt32(NodesRow["nodetypepropid"]); } if (NodesTable.Columns.Contains("permissiongroupid")) { ThisPermGrpId = new CswPrimaryKey("nodes", CswConvert.ToInt32(NodesRow["permissiongroupid"])); } bool ThisNodeFavorited = false == String.IsNullOrEmpty(NodesRow["userid"].ToString()); // donb't include properties in search results to which the user has no permissions if (false == RequireViewPermissions || (_canViewNode(ThisPermGrpId, ThisNodeType) && (Int32.MinValue == ThisNTPId || _canViewProp(ThisNTPId, ThisPermGrpId)))) { // Handle property multiplexing // This assumes that property rows for the same nodeid are next to one another if (ThisNodeId != PriorNodeId) { PriorNodeId = ThisNodeId; NewNodeKeys = _CswNbtTree.loadNodeAsChildFromRow(null, NodesRow, false, string.Empty, true, true, CswEnumNbtViewAddChildrenSetting.None, RowCount, Favorited: ThisNodeFavorited); RowCount++; } // if( ThisNodeId != PriorNodeId ) if (NewNodeKeys != null && ThisNTPId != Int32.MinValue) { foreach (CswNbtNodeKey NewNodeKey in NewNodeKeys) { _CswNbtTree.makeNodeCurrent(NewNodeKey); _CswNbtTree.addProperty(ThisNTPId, CswConvert.ToInt32(NodesRow["objectclasspropid"]), CswConvert.ToInt32(NodesRow["jctnodepropid"]), NodesRow["propname"].ToString(), NodesRow["objectclasspropname"].ToString(), NodesRow["gestalt"].ToString(), CswConvert.ToString(NodesRow["fieldtype"]), CswConvert.ToString(NodesRow["field1"]), CswConvert.ToString(NodesRow["field2"]), CswConvert.ToInt32(NodesRow["field1_fk"]), CswConvert.ToInt32(NodesRow["field1_numeric"]), CswConvert.ToBoolean(NodesRow["hidden"]), CswConvert.ToString(NodesRow["field1_big"])); } // foreach( CswNbtNodeKey NewNodeKey in NewNodeKeys ) } // if( NewNodeKeys != null && ThisNTPId != Int32.MinValue ) _CswNbtTree.goToRoot(); } // if( _canViewNode( ThisNodeType, ThisNodeId ) && } // if( _CswNbtResources.Permit.can( CswEnumNbtNodeTypePermission.View, ThisNodeTypeId ) ) } // foreach(DataRow NodesRow in NodesTable.Rows) // case 24678 - Mark truncated results if (RowCount > _CswNbtResources.TreeViewResultLimit) { // Mark root truncated _CswNbtTree.goToRoot(); _CswNbtTree.setCurrentNodeChildrenTruncated(true); } _CswNbtTree.goToRoot(); } } // load()
void context_BeginRequest(object sender, EventArgs e) { _RequestTimer = new CswTimer(); _logEvent(((System.Web.HttpApplication)(sender)).Request, "HTTP_BeginRequest"); }
} // load() private void loadRelationshipRecursive(CswNbtViewRelationship Relationship, bool RequireViewPermissions, bool GroupBySiblings, IEnumerable <CswPrimaryKey> ParentNodeIds = null, Int32 ResultsLimit = Int32.MinValue) { CswNbtNodeKey PriorCurrentNodeKey = _CswNbtTree.getNodeKeyForCurrentPosition(); // Nodes and Properties DataTable NodesTable = new DataTable(); CswArbitrarySelect ResultSelect = _makeNodeSql(Relationship, ParentNodeIds); Int32 thisResultLimit = _CswNbtResources.TreeViewResultLimit; if (ResultsLimit != Int32.MinValue) { thisResultLimit = ResultsLimit; } if (Relationship.Properties.Count > 0) { thisResultLimit = thisResultLimit * Relationship.Properties.Count; } CswTimer SqlTimer = new CswTimer(); try { NodesTable = ResultSelect.getTable(0, thisResultLimit, false); } catch (Exception ex) { throw new CswDniException(CswEnumErrorType.Error, "Invalid View", "_getNodes() attempted to run invalid SQL: " + ResultSelect.Sql, ex); } _CswNbtResources.CswLogger.TreeLoaderSQLTime += SqlTimer.ElapsedDurationInMilliseconds; if (SqlTimer.ElapsedDurationInSeconds > 2) { _CswNbtResources.logMessage("Tree View SQL required longer than 2 seconds to run: " + ResultSelect.Sql); } Int32 PriorNodeId = Int32.MinValue; Int32 PriorParentNodeId = Int32.MinValue; Collection <CswPrimaryKey> KeysThisLevel = new Collection <CswPrimaryKey>(); Collection <CswNbtNodeKey> NewNodeKeys = new Collection <CswNbtNodeKey>(); Collection <CswNbtNodeKey> ParentNodeKeys = null; foreach (DataRow NodesRow in NodesTable.Rows) { Int32 ThisNodeId = CswConvert.ToInt32(NodesRow["nodeid"]); CswPrimaryKey ThisNodePk = new CswPrimaryKey("nodes", ThisNodeId); Int32 ThisParentNodeId = Int32.MinValue; if (NodesTable.Columns.Contains("parentnodeid")) { ThisParentNodeId = CswConvert.ToInt32(NodesRow["parentnodeid"]); } Int32 ThisNodeTypeId = CswConvert.ToInt32(NodesRow["nodetypeid"]); bool ThisNodeFavorited = false == String.IsNullOrEmpty(NodesRow["userid"].ToString()); // Verify permissions // this could be a performance problem CswNbtMetaDataNodeType ThisNodeType = _CswNbtResources.MetaData.getNodeType(ThisNodeTypeId); if (false == RequireViewPermissions || (_CswNbtResources.Permit.canAnyTab(CswEnumNbtNodeTypePermission.View, ThisNodeType, _RunAsUser) && _CswNbtResources.Permit.isNodeWritable(CswEnumNbtNodeTypePermission.View, ThisNodeType, ThisNodePk, _RunAsUser))) { // Handle property multiplexing // This assumes that property rows for the same nodeid are next to one another if (ThisNodeId != PriorNodeId || ThisParentNodeId != PriorParentNodeId) { PriorNodeId = ThisNodeId; PriorParentNodeId = ThisParentNodeId; NewNodeKeys = new Collection <CswNbtNodeKey>(); Collection <CswNbtNodeKey> ThisNewNodeKeys = new Collection <CswNbtNodeKey>(); ParentNodeKeys = new Collection <CswNbtNodeKey>(); // Handle ResultMode.Disabled on filters bool Included = true; foreach (DataColumn Column in NodesRow.Table.Columns) { if (Column.ColumnName.StartsWith("INCLUDED")) { string Conjunction = Column.ColumnName.Substring("INCLUDED".Length); if (Conjunction.StartsWith("OR")) { Included = Included || CswConvert.ToBoolean(NodesRow[Column]); } else { Included = Included && CswConvert.ToBoolean(NodesRow[Column]); } } } bool UseGroupBy = Relationship.GroupByPropId != Int32.MinValue; string GroupName = string.Empty; if (UseGroupBy) { GroupName = CswConvert.ToString(NodesRow["groupname"]); if (GroupName == string.Empty) { GroupName = "[blank]"; } } else if (GroupBySiblings) { UseGroupBy = true; GroupName = CswConvert.ToString(NodesRow["nodetypename"]); } if (NodesTable.Columns.Contains("parentnodeid")) { CswPrimaryKey ParentNodePk = new CswPrimaryKey("nodes", CswConvert.ToInt32(NodesRow["parentnodeid"])); // We can't use getNodeKeyByNodeId, because there may be more instances of this node at different places in the tree //ParentNodeKey = _CswNbtTree.getNodeKeyByNodeId( ParentNodeId ); ParentNodeKeys = _CswNbtTree.getNodeKeysByNodeIdAndViewNode(ParentNodePk, Relationship.Parent); if (ParentNodeKeys.Count == 0) { // If the parent isn't in the tree, don't add the child PriorNodeId = Int32.MinValue; // case 24788 } else { foreach (CswNbtNodeKey ParentNodeKey in ParentNodeKeys) { _CswNbtTree.makeNodeCurrent(ParentNodeKey); Int32 ChildCount = _CswNbtTree.getChildNodeCount(); ThisNewNodeKeys = _CswNbtTree.loadNodeAsChildFromRow(ParentNodeKey, NodesRow, UseGroupBy, GroupName, Relationship, ChildCount + 1, Included, ThisNodeFavorited); foreach (CswNbtNodeKey ThisNewNodeKey in ThisNewNodeKeys) { NewNodeKeys.Add(ThisNewNodeKey); KeysThisLevel.Add(ThisNewNodeKey.NodeId); } } // foreach( CswNbtNodeKey ParentNodeKey in ParentNodeKeys ) } } // if( NodesTable.Columns.Contains( "parentnodeid" ) ) else { Int32 ChildCount = _CswNbtTree.getChildNodeCount(); ThisNewNodeKeys = _CswNbtTree.loadNodeAsChildFromRow(null, NodesRow, UseGroupBy, GroupName, Relationship, ChildCount + 1, Included, ThisNodeFavorited); foreach (CswNbtNodeKey ThisNewNodeKey in ThisNewNodeKeys) { NewNodeKeys.Add(ThisNewNodeKey); KeysThisLevel.Add(ThisNewNodeKey.NodeId); } } // if( AddChild ) } // if( ThisNodeId != PriorNodeId ) // This assumes that property rows for the same nodeid are next to one another // It also assumes that loadNodeAsChildFromRow() made the node current if (NewNodeKeys.Count > 0 && NodesTable.Columns.Contains("jctnodepropid")) { foreach (CswNbtNodeKey NewNodeKey in NewNodeKeys) { _CswNbtTree.makeNodeCurrent(NewNodeKey); _CswNbtTree.addProperty(CswConvert.ToInt32(NodesRow["nodetypepropid"]), CswConvert.ToInt32(NodesRow["objectclasspropid"]), CswConvert.ToInt32(NodesRow["jctnodepropid"]), NodesRow["propname"].ToString(), NodesRow["objectclasspropname"].ToString(), NodesRow["gestalt"].ToString(), CswConvert.ToString(NodesRow["fieldtype"]), CswConvert.ToString(NodesRow["field1"]), CswConvert.ToString(NodesRow["field2"]), CswConvert.ToInt32(NodesRow["field1_fk"]), CswConvert.ToDouble(NodesRow["field1_numeric"]), CswConvert.ToBoolean(NodesRow["hidden"]), CswConvert.ToString(NodesRow["field1_big"])); } // foreach( CswNbtNodeKey NewNodeKey in NewNodeKeys ) if (ParentNodeKeys.Count > 0) { _CswNbtTree.makeNodeCurrent(ParentNodeKeys[0]); } else { _CswNbtTree.goToRoot(); } } // if( NewNodeKeys != null && NodesTable.Columns.Contains( "jctnodepropid" ) ) } // if( false == RequireViewPermissions || _CswNbtResources.Permit.can( CswEnumNbtNodeTypePermission.View, ThisNodeType, true, null, _RunAsUser ) ) } // foreach(DataRow NodesRow in NodesTable.Rows) if (KeysThisLevel.Count > 0) // only recurse if there are results { // Recurse foreach (CswNbtViewRelationship ChildRelationship in Relationship.ChildRelationships) { bool ContinueGroupingBySibling = (_View.GroupBySiblings && Relationship.ChildRelationships.Count > 1); loadRelationshipRecursive(ChildRelationship, RequireViewPermissions, ContinueGroupingBySibling, KeysThisLevel); } // case 24678 - Mark truncated results if (KeysThisLevel.Count == thisResultLimit) { //if( ParentNodeKeys != null && ParentNodeKeys.Count > 0 ) //{ // foreach( CswNbtNodeKey ParentNodeKey in ParentNodeKeys ) // { // // assume truncation on every potential parent // _CswNbtTree.makeNodeCurrent( ParentNodeKey ); // _CswNbtTree.goToParentNode(); // for( Int32 c = 0; c < _CswNbtTree.getChildNodeCount(); c++ ) // { // _CswNbtTree.goToNthChild( c ); // _CswNbtTree.setCurrentNodeChildrenTruncated( true ); // _CswNbtTree.goToParentNode(); // } // } //} //else //{ _CswNbtTree.goToRoot(); _CswNbtTree.setCurrentNodeChildrenTruncated(true); //} } // if( NodesTable.Rows.Count == thisResultLimit ) } // if( NodesTable.Rows.Count > 0 ) _CswNbtTree.makeNodeCurrent(PriorCurrentNodeKey); } // loadRelationshipRecursive()
public JObject getMenu(CswNbtView View, string SafeNodeKey, Int32 NodeTypeId, string PropIdAttr, bool ReadOnly, string NodeId) { CswTimer MainMenuTimer = new CswTimer(); JObject Ret = new JObject(); CswPrimaryKey RelatedNodeId = new CswPrimaryKey(); string RelatedNodeName = string.Empty; CswNbtNode Node = null; if (false == String.IsNullOrEmpty(SafeNodeKey)) { CswNbtNodeKey NbtNodeKey = new CswNbtNodeKey(SafeNodeKey); Node = _CswNbtResources.Nodes[NbtNodeKey]; } else if (false == String.IsNullOrEmpty(NodeId)) { CswPrimaryKey NodePk = CswConvert.ToPrimaryKey(NodeId); Node = _CswNbtResources.Nodes[NodePk]; } if (null != Node) { RelatedNodeId = Node.NodeId; RelatedNodeName = Node.NodeName; } // MORE if (_MenuItems.Contains("More")) { JObject MoreObj = new JObject(); if (null == View && Int32.MinValue != NodeTypeId) { // ADD for Searches if (_MenuItems.Contains("Add") && false == ReadOnly) { JObject AddObj = new JObject(); CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(NodeTypeId); if (null != NodeType && _CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, NodeType) && NodeType.getObjectClass().CanAdd) { AddObj[NodeType.NodeTypeName] = makeAddMenuItem(NodeType, RelatedNodeId, RelatedNodeName); AddObj["haschildren"] = true; Ret["Add"] = AddObj; } } // if( _MenuItems.Contains( "Add" ) && false == ReadOnly ) } // if( null == View && Int32.MinValue != NodeTypeId ) if (null != View) { // ADD for Views if (_MenuItems.Contains("Add") && false == ReadOnly) { JObject AddObj = new JObject(); // case 21672 CswNbtViewNode ParentNode = View.Root; bool LimitToFirstLevelRelationships = (View.ViewMode == CswEnumNbtViewRenderingMode.Grid); if (LimitToFirstLevelRelationships && View.Visibility == CswEnumNbtViewVisibility.Property) { if (null == Node) { ICswNbtTree Tree = _CswNbtResources.Trees.getTreeFromView(View, false, false, false); if (Tree.getChildNodeCount() > 0) { Tree.goToNthChild(0); CswNbtNodeKey NodeKey = Tree.getNodeKeyForCurrentPosition(); Node = _CswNbtResources.Nodes[NodeKey]; if (null != Node) { RelatedNodeId = Node.NodeId; RelatedNodeName = Node.NodeName; } } } if (View.Root.ChildRelationships.Count > 0) { ParentNode = View.Root.ChildRelationships[0]; } } foreach (JProperty AddNodeType in ParentNode.AllowedChildNodeTypes(LimitToFirstLevelRelationships) .Select(Entry => new JProperty(Entry.NodeType.NodeTypeName, makeAddMenuItem(Entry.NodeType, RelatedNodeId, RelatedNodeName)))) { AddObj.Add(AddNodeType); } if (AddObj.HasValues) { AddObj["haschildren"] = true; Ret["Add"] = AddObj; } } // COPY if ( _MenuItems.Contains("Copy") && false == ReadOnly && null != Node && Node.NodeSpecies == CswEnumNbtNodeSpecies.Plain && View.ViewMode != CswEnumNbtViewRenderingMode.Grid && _CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, Node.getNodeType()) && Node.getObjectClass().CanAdd //If you can't Add the node, you can't Copy it either ) { MoreObj["Copy"] = new JObject(); MoreObj["Copy"]["copytype"] = _getActionType(Node.getNodeType()); MoreObj["Copy"]["action"] = CswEnumNbtMainMenuActions.CopyNode.ToString(); MoreObj["Copy"]["nodeid"] = Node.NodeId.ToString(); MoreObj["Copy"]["nodename"] = Node.NodeName; MoreObj["Copy"]["nodetypeid"] = Node.NodeTypeId.ToString(); } // DELETE if (_MenuItems.Contains("Delete") && false == ReadOnly && false == string.IsNullOrEmpty(SafeNodeKey) && null != Node && View.ViewMode != CswEnumNbtViewRenderingMode.Grid && Node.NodeSpecies == CswEnumNbtNodeSpecies.Plain && _CswNbtResources.Permit.isNodeWritable(CswEnumNbtNodeTypePermission.Delete, Node.getNodeType(), Node.NodeId)) { MoreObj["Delete"] = new JObject(); MoreObj["Delete"]["action"] = CswEnumNbtMainMenuActions.DeleteNode.ToString(); MoreObj["Delete"]["nodeid"] = Node.NodeId.ToString(); MoreObj["Delete"]["nodename"] = Node.NodeName; } // SAVE VIEW AS if (_MenuItems.Contains("Save View As") && false == View.ViewId.isSet() && _CswNbtResources.Permit.can(_CswNbtResources.Actions[CswEnumNbtActionName.Edit_View])) { View.SaveToCache(false); MoreObj["Save View As"] = new JObject(); MoreObj["Save View As"]["action"] = CswEnumNbtMainMenuActions.SaveViewAs.ToString(); MoreObj["Save View As"]["viewid"] = View.SessionViewId.ToString(); MoreObj["Save View As"]["viewmode"] = View.ViewMode.ToString(); } JObject PrintObj = null; // PRINT LABEL bool ValidForTreePrint = (false == string.IsNullOrEmpty(SafeNodeKey) && View.ViewMode != CswEnumNbtViewRenderingMode.Grid && null != Node && null != Node.getNodeType() && Node.getNodeType().HasLabel); bool ValidForGridPrint = false; bool TryValidForGridPrint = (View.ViewMode == CswEnumNbtViewRenderingMode.Grid); Int32 MultiPrintNodeTypeId = Int32.MinValue; if (TryValidForGridPrint) { CswNbtViewRelationship TryRel = null; if (View.Visibility != CswEnumNbtViewVisibility.Property && View.Root.ChildRelationships.Count == 1) { TryRel = View.Root.ChildRelationships[0]; } else if (View.Visibility == CswEnumNbtViewVisibility.Property && View.Root.ChildRelationships.Count == 1 && View.Root.ChildRelationships[0].ChildRelationships.Count == 1) { TryRel = View.Root.ChildRelationships[0].ChildRelationships[0]; } if (null != TryRel) { ICswNbtMetaDataDefinitionObject MdDef = TryRel.SecondMetaDataDefinitionObject(); if (null != MdDef) { if (MdDef.HasLabel) { //This assumes that only NodeTypes will implement this property MultiPrintNodeTypeId = MdDef.UniqueId; ValidForGridPrint = true; } } } } if (_MenuItems.Contains("Print") && (ValidForTreePrint || ValidForGridPrint)) { PrintObj = PrintObj ?? new JObject(new JProperty("haschildren", true)); PrintObj["Print Label"] = new JObject(); PrintObj["Print Label"]["action"] = CswEnumNbtMainMenuActions.PrintLabel.ToString(); if (ValidForTreePrint) { PrintObj["Print Label"]["nodeid"] = Node.NodeId.ToString(); PrintObj["Print Label"]["nodetypeid"] = Node.NodeTypeId; PrintObj["Print Label"]["nodename"] = Node.NodeName; } else if (ValidForGridPrint) { PrintObj["Print Label"]["nodetypeid"] = MultiPrintNodeTypeId; } } // PRINT if (_MenuItems.Contains("Print") && View.ViewMode == CswEnumNbtViewRenderingMode.Grid) { View.SaveToCache(false); PrintObj = PrintObj ?? new JObject(new JProperty("haschildren", true)); PrintObj["Print View"] = new JObject(); PrintObj["Print View"]["action"] = CswEnumNbtMainMenuActions.PrintView.ToString(); } if (null != PrintObj) { MoreObj["Print"] = PrintObj; } // EXPORT if (_MenuItems.Contains("Export")) { if (CswEnumNbtViewRenderingMode.Grid == View.ViewMode) { JObject ExportObj = new JObject(); MoreObj["Export"] = ExportObj; View.SaveToCache(false); ExportObj["CSV"] = new JObject(); string ExportLink = "wsNBT.asmx/gridExportCSV?ViewId=" + View.SessionViewId + "&SafeNodeKey='"; if (CswEnumNbtViewVisibility.Property == View.Visibility) { ExportLink += SafeNodeKey; } ExportLink += "'"; ExportObj["CSV"]["popup"] = ExportLink; ExportObj["haschildren"] = true; } } } // if( null != View ) // EDIT VIEW if (_MenuItems.Contains("Edit View") && _CswNbtResources.Permit.can(CswEnumNbtActionName.Edit_View) && (null == View || (false == View.IsSystem || CswNbtObjClassUser.ChemSWAdminUsername == _CswNbtResources.CurrentNbtUser.Username))) { MoreObj["Edit View"] = new JObject(); MoreObj["Edit View"]["action"] = CswEnumNbtMainMenuActions.editview.ToString(); } if (_MenuItems.Contains("Multi-Edit") && false == ReadOnly && null != View && _CswNbtResources.Permit.can(CswEnumNbtActionName.Multi_Edit) && // Per discussion with David, for the short term eliminate the need to validate the selection of nodes across different nodetypes in Grid views. // Case 21701: for Grid Properties, we need to look one level deeper // Case 29032: furthermore (for Grids), we need to exclude ObjectClass relationships (which can also produce the multi-nodetype no-no (View.ViewMode != CswEnumNbtViewRenderingMode.Grid || ((View.Root.ChildRelationships.Count == 1 && View.Root.ChildRelationships[0].SecondType == CswEnumNbtViewRelatedIdType.NodeTypeId) && (View.Visibility != CswEnumNbtViewVisibility.Property || (View.Root.ChildRelationships[0].ChildRelationships.Count == 1 && View.Root.ChildRelationships[0].ChildRelationships[0].SecondType == CswEnumNbtViewRelatedIdType.NodeTypeId)))) ) { MoreObj["Multi-Edit"] = new JObject(); MoreObj["Multi-Edit"]["action"] = CswEnumNbtMainMenuActions.multiedit.ToString(); } if (_MenuItems.Contains("Bulk Edit") && false == ReadOnly && null != View && _CswNbtResources.Permit.can(CswEnumNbtActionName.Bulk_Edit)) { MoreObj["Bulk Edit"] = new JObject(); MoreObj["Bulk Edit"]["action"] = CswEnumNbtMainMenuActions.bulkedit.ToString(); } if (MoreObj.Count > 0) { MoreObj["haschildren"] = true; Ret["More"] = MoreObj; } } // if( _MenuItems.Contains( "More" ) ) _CswNbtResources.logTimerResult("CswNbtWebServiceMainMenu.getMenu()", MainMenuTimer.ElapsedDurationInSecondsAsString); return(Ret); } // getMenu()
protected void CswViewTree_DataBinding(object sender, EventArgs e) { try { CswTimer DataBindTimer = new CswTimer(); _CswNbtResources.logTimerResult("CswViewListTree.DataBind() started", DataBindTimer.ElapsedDurationInSecondsAsString); EnsureChildControls(); // don't bother databinding on postback -- this prevents losing the currently selected node if (TreeView.SelectedNode == null) { // BZ 8686 if (Page.Session[SessionCachedXmlName] != null && Page.Session[SessionCachedXmlName].ToString() != string.Empty) { TreeView.LoadXml(Page.Session[SessionCachedXmlName].ToString()); } else { XmlDocument XmlDoc = new XmlDocument(); XmlNode DocRoot = XmlDoc.CreateElement("Tree"); XmlDoc.AppendChild(DocRoot); // Views Dictionary <CswNbtViewId, CswNbtView> Views = _CswNbtResources.ViewSelect.getVisibleViews("lower(NVL(v.category, v.viewname)), lower(v.viewname)", false); foreach (CswNbtView View in Views.Values) { // BZ 10121 // This is a performance hit, but since this view list is cached, it's ok CswNbtView CurrentView = new CswNbtView(_CswNbtResources); CurrentView.LoadXml(View.ToXml()); CurrentView.ViewId = View.ViewId; // if( CurrentView.IsFullyEnabled() ) -- Case 20452: getVisibleViews() does this already XmlNode CategoryNode = _getCategoryNode(DocRoot, View.Category); bool ThisSearchable = View.ToXml().ToString().Contains("<Filter"); CategoryNode.AppendChild(_makeTreeViewXmlNode(XmlDoc, CurrentView.ViewId.ToString(), ViewType.View, CurrentView.ViewName, CurrentView.IconFileName, true, ThisSearchable)); } // Actions foreach (CswNbtAction Action in _CswNbtResources.Actions) { if (Action.ShowInList && (_CswNbtResources.ConfigVbls.getConfigVariableValue("loc_use_images") != "0") && _CswNbtResources.Permit.can(Action.Name)) { XmlNode CategoryNode = _getCategoryNode(DocRoot, Action.Category); CategoryNode.AppendChild(_makeTreeViewXmlNode(XmlDoc, Action.ActionId.ToString(), ViewType.Action, Action.Name.ToString().Replace('_', ' '), CswNbtMetaDataObjectClass.IconPrefix16 + "wizard.png", true, false)); } } // Reports CswNbtView ReportView = new CswNbtView(_CswNbtResources); ReportView.ViewName = "CswViewTree.DataBinding.ReportView"; CswNbtMetaDataObjectClass ReportMetaDataObjectClass = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.ReportClass); CswNbtViewRelationship ReportRelationship = ReportView.AddViewRelationship(ReportMetaDataObjectClass, true); ICswNbtTree ReportTree = _CswNbtResources.Trees.getTreeFromView(_CswNbtResources.CurrentNbtUser, ReportView, true, false, false); for (int i = 0; i < ReportTree.getChildNodeCount(); i++) { ReportTree.goToNthChild(i); CswNbtObjClassReport ReportNode = (CswNbtObjClassReport)ReportTree.getNodeForCurrentPosition(); XmlNode CategoryNode = _getCategoryNode(DocRoot, ReportNode.Category.Text); CategoryNode.AppendChild(_makeTreeViewXmlNode(XmlDoc, ReportNode.NodeId.PrimaryKey.ToString(), ViewType.Report, ReportNode.ReportName.Text, "Images/view/report.gif", true, false)); ReportTree.goToParentNode(); } TreeView.LoadXml(XmlDoc.InnerXml); Page.Session.Add(SessionCachedXmlName, XmlDoc.InnerXml); } // if-else( Page.Session[SessionCachedXmlName] != null && Page.Session[SessionCachedXmlName].ToString() != string.Empty ) } // if(TreeView.SelectedNode == null) _CswNbtResources.logTimerResult("CswViewListTree.DataBind() finished", DataBindTimer.ElapsedDurationInSecondsAsString); } catch (Exception ex) { HandleError(ex); } }
protected override void OnInit(EventArgs e) { try { CswTimer Timer = new CswTimer(); LogTimerResult("MainLayout.OnInit() started", Timer.ElapsedDurationInSecondsAsString); Master.OnError += new CswErrorHandler(HandleError); //StatusImage = new CswImageButton( CswImageButton.ButtonType.SaveStatus ); //StatusImage.ID = "StatusImage"; //StatusImagePH.Controls.Add( StatusImage ); //SearchLink = new LinkButton(); //SearchLink.Text = "Search"; //SearchLink.Click += new EventHandler( SearchLink_Click ); //SearchPlaceHolder.Controls.Add( SearchLink ); //SearchLinkStatusHF = new HiddenField(); //SearchLinkStatusHF.ID = "SearchLinkStatusHF"; //SearchLinkStatusHF.Value = "0"; //SearchPlaceHolder.Controls.Add( SearchLinkStatusHF ); //SearchLiteral = new CswLiteralNbsp(); //SearchPlaceHolder.Controls.Add( SearchLiteral ); MainMenu = new CswMainMenu(Master.CswNbtResources); MainMenu.ID = "mainmenu"; MainMenu.OnError += new CswErrorHandler(Master.HandleError); MainMenu.AllowBatch = false; MainMenu.AllowMobile = false; MainMenu.AllowEditView = false; MainMenu.AllowChangeView = true; MenuPlaceHolder.Controls.Add(MainMenu); HiddenChangeViewButton = new Button(); HiddenChangeViewButton.ID = "HiddenChangeViewButton"; HiddenChangeViewButton.Style.Add(HtmlTextWriterStyle.Display, "none"); HiddenChangeViewButton.Click += new EventHandler(HiddenChangeViewButton_Click); MenuPlaceHolder.Controls.Add(HiddenChangeViewButton); HiddenChangeViewId = new HiddenField(); HiddenChangeViewId.ID = "HiddenChangeViewId"; MenuPlaceHolder.Controls.Add(HiddenChangeViewId); if (Master.CswNbtResources.CurrentUser != null) { _QuickLaunch = new CswQuickLaunch(Master.CswNbtResources); _QuickLaunch.OnError += new CswErrorHandler(Master.HandleError); _QuickLaunch.OnActionLinkClick += new CswQuickLaunch.ActionLinkClickEvent(_QuickLaunch_OnActionLinkClick); _QuickLaunch.OnSessionViewLinkClick += new CswQuickLaunch.SessionViewLinkClickEvent(_QuickLaunch_OnSessionViewLinkClick); _QuickLaunch.OnViewLinkClick += new CswQuickLaunch.ViewLinkClickEvent(_QuickLaunch_OnViewLinkClick); quicklaunchplaceholder.Controls.Add(_QuickLaunch); } if (Master.CswNbtResources.ConfigVbls.getConfigVariableValue("showloadbox") != "1") { ProgressDiv.Visible = false; } else { ProgressDiv.Visible = true; } LogTimerResult("MainLayout.OnInit() finished", Timer.ElapsedDurationInSecondsAsString); } catch (Exception ex) { HandleError(ex); } base.OnInit(e); }
/// <summary> /// Get a Collection of all views visible to the current user, and the DataTable /// </summary> public Dictionary <CswNbtViewId, CswNbtView> getVisibleViews(string OrderBy, ICswNbtUser User, bool IncludeEmptyViews, bool MobileOnly, bool SearchableOnly, CswEnumNbtViewRenderingMode ViewRenderingMode, out DataTable ViewsTable, CswCommaDelimitedString LimitToViews = null, bool ForEdit = false) { CswTimer VisibleViewsTimer = new CswTimer(); ViewsTable = null; Dictionary <CswNbtViewId, CswNbtView> Ret = new Dictionary <CswNbtViewId, CswNbtView>(); if (null != User && CswTools.IsPrimaryKey(User.UserId) && CswTools.IsPrimaryKey(User.RoleId)) { if (null == LimitToViews || LimitToViews.Count > 0) { CswStaticSelect ViewsSelect = _CswNbtResources.makeCswStaticSelect("getVisibleViews_select", "getVisibleViewInfo"); ViewsSelect.S4Parameters.Add("getroleid", new CswStaticParam("getroleid", User.RoleId.PrimaryKey.ToString())); ViewsSelect.S4Parameters.Add("getuserid", new CswStaticParam("getuserid", User.UserId.PrimaryKey.ToString())); string AddClause = " "; if (MobileOnly) { AddClause += "and formobile = '" + CswConvert.ToDbVal(true) + "'"; } if (ViewRenderingMode != CswEnumNbtViewRenderingMode.Any) { AddClause += "and viewmode = '" + ViewRenderingMode.ToString() + "'"; } if (null != LimitToViews) { AddClause += "and nodeviewid in (" + LimitToViews.ToString() + ")"; } ViewsSelect.S4Parameters.Add("addclause", new CswStaticParam("addclause", AddClause, true)); if (OrderBy != string.Empty) { ViewsSelect.S4Parameters.Add("orderbyclause", new CswStaticParam("orderbyclause", OrderBy)); } else { ViewsSelect.S4Parameters.Add("orderbyclause", new CswStaticParam("orderbyclause", "lower(v.viewname)")); } ViewsTable = ViewsSelect.getTable(); _CswNbtResources.logTimerResult("CswNbtView.getVisibleViews() data fetched", VisibleViewsTimer.ElapsedDurationInSecondsAsString); Collection <DataRow> RowsToRemove = new Collection <DataRow>(); foreach (DataRow Row in ViewsTable.Rows) { CswNbtView ThisView = new CswNbtView(_CswNbtResources); ThisView.LoadXml(Row["viewxml"].ToString()); if (isVisible(ThisView, User, IncludeEmptyViews, SearchableOnly, ForEdit)) { Ret.Add(ThisView.ViewId, ThisView); } else { RowsToRemove.Add(Row); } } // foreach( DataRow Row in ViewsTable.Rows ) foreach (DataRow Row in RowsToRemove) { ViewsTable.Rows.Remove(Row); } } // if( null == LimitToViews || LimitToViews.Count > 0 ) } // if( null != User && CswTools.IsPrimaryKey( User.UserId ) && CswTools.IsPrimaryKey( User.RoleId ) ) _CswNbtResources.logTimerResult("CswNbtView.getVisibleViews() finished", VisibleViewsTimer.ElapsedDurationInSecondsAsString); return(Ret); }