private bool _doesMailReportRunNow(CswNbtObjClassMailReport CurrentMailReport) { bool RunNow = false; DateTime ThisDueDateValue = CurrentMailReport.NextDueDate.DateTimeValue; DateTime InitialDueDateValue = CurrentMailReport.DueDateInterval.getStartDate(); DateTime FinalDueDateValue = CurrentMailReport.FinalDueDate.DateTimeValue; DateTime NowDateValue = DateTime.Now; DateTime MinDateValue = DateTime.MinValue; if (DateTime.MinValue != ThisDueDateValue) { if (CswEnumRateIntervalType.Hourly != CurrentMailReport.DueDateInterval.RateInterval.RateType) // Ignore runtime for hourly reports { ThisDueDateValue = ThisDueDateValue.Date; InitialDueDateValue = InitialDueDateValue.Date; FinalDueDateValue = FinalDueDateValue.Date; MinDateValue = MinDateValue.Date; if (CurrentMailReport.RunTime.DateTimeValue != DateTime.MinValue) { ThisDueDateValue = ThisDueDateValue.AddTicks(CurrentMailReport.RunTime.DateTimeValue.TimeOfDay.Ticks); } } // if we're within the initial and final due dates, but past the current due date (- warning days) and runtime RunNow = (NowDateValue >= InitialDueDateValue) && (NowDateValue <= FinalDueDateValue || MinDateValue == FinalDueDateValue) && (NowDateValue >= ThisDueDateValue); } return(RunNow); }
} // getSubscriptions() public static void saveSubscriptions(ICswResources CswResources, CswWebSvcReturn Return, MailReportSubscriptions Request) { CswNbtResources CswNbtResources = (CswNbtResources)CswResources; CswPrimaryKey ThisUserPk = CswNbtResources.CurrentNbtUser.UserId; CswNbtMetaDataObjectClass MailReportOC = CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.MailReportClass); foreach (MailReportSubscriptions.Subscription sub in Request.Subscriptions) { if (sub.Modified) { CswPrimaryKey NodeId = new CswPrimaryKey(); NodeId.FromString(sub.NodeId); CswNbtObjClassMailReport MailReportNode = CswNbtResources.Nodes[NodeId]; if (sub.Subscribed) { MailReportNode.Recipients.AddUser(ThisUserPk); } else { MailReportNode.Recipients.RemoveUser(ThisUserPk); } MailReportNode.postChanges(false); } } } // saveSubscriptions()
public void threadCallBack(ICswResources CswResources) { _LogicRunStatus = CswEnumScheduleLogicRunStatus.Running; if (CswEnumScheduleLogicRunStatus.Stopping != _LogicRunStatus) { CswNbtResources CswNbtResources = (CswNbtResources)CswResources; try { _InnerErrorMessage = string.Empty; CswResources.AuditContext = "Scheduler Task: " + RuleName; Int32 MailReportLimit = CswConvert.ToInt32(CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumConfigurationVariableNames.NodesProcessedPerCycle)); if (MailReportLimit < 1) { MailReportLimit = 1; } Int32 TotalMailReportsProcessed = 0; while (TotalMailReportsProcessed < MailReportLimit && _MailReportIdsToRun.Count > 0 && (CswEnumScheduleLogicRunStatus.Stopping != _LogicRunStatus)) { CswNbtObjClassMailReport MailReportNode = CswNbtResources.Nodes[_MailReportIdsToRun[0]]; if (null != MailReportNode) { Collection <Int32> RecipientIds = MailReportNode.Recipients.SelectedUserIds.ToIntCollection(); if (RecipientIds.Count > 0) { processMailReport(CswNbtResources, MailReportNode); MailReportNode.postChanges(false); } } _MailReportIdsToRun.RemoveAt(0); TotalMailReportsProcessed++; } if (false == String.IsNullOrEmpty(_InnerErrorMessage)) { _CswScheduleLogicDetail.StatusMessage = "The following errors occurred during processing: " + _InnerErrorMessage; } else { _CswScheduleLogicDetail.StatusMessage = "Completed without error"; } _LogicRunStatus = CswEnumScheduleLogicRunStatus.Succeeded; //last line }//try catch (Exception Exception) { _CswScheduleLogicDetail.StatusMessage = "An exception occurred: " + Exception.Message + "; " + Exception.StackTrace; CswNbtResources.logError(new CswDniException(_CswScheduleLogicDetail.StatusMessage)); _LogicRunStatus = CswEnumScheduleLogicRunStatus.Failed; } //catch } //if we're not shutting down } //threadCallBack()
public override void update() { // Create a demo mail report (notification) CswNbtMetaDataObjectClass UserOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.UserClass ); CswNbtMetaDataObjectClass MailReportOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.MailReportClass ); CswNbtMetaDataNodeType MailReportNT = MailReportOC.FirstNodeType; CswNbtMetaDataNodeTypeProp MailReportNameNTP = MailReportNT.getNodeTypeProp( "Name" ); CswNbtMetaDataNodeType UserNT = UserOC.FirstNodeType; CswNbtMetaDataNodeTypeProp UserLockedNTP = UserNT.getNodeTypePropByObjectClassProp( CswNbtObjClassUser.PropertyName.AccountLocked ); if( null != MailReportNT && null != UserNT ) { CswNbtObjClassMailReport MailReportNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( MailReportNT.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode ); if( null != MailReportNameNTP ) { MailReportNode.Node.Properties[MailReportNameNTP].AsText.Text = "Locked Users Notification"; } MailReportNode.OutputFormat.Value = "link"; MailReportNode.Type.Value = CswNbtObjClassMailReport.TypeOptionView; MailReportNode.Event.Value = CswNbtObjClassMailReport.EventOption.Edit.ToString(); MailReportNode.TargetType.SelectedNodeTypeIds.Add( UserNT.NodeTypeId.ToString() ); MailReportNode.Message.Text = "The following user accounts have been locked:"; MailReportNode.Enabled.Checked = Tristate.False; MailReportNode.IsDemo = true; CswRateInterval HourlyRate = _CswNbtSchemaModTrnsctn.makeRateInterval(); HourlyRate.setHourly( 1, DateTime.Now ); MailReportNode.DueDateInterval.RateInterval = HourlyRate; CswNbtObjClassUser AdminUser = _CswNbtSchemaModTrnsctn.Nodes.makeUserNodeFromUsername( "admin" ); if( null != AdminUser ) { MailReportNode.Recipients.AddUser( AdminUser.UserId ); } MailReportNode.postChanges( true ); CswNbtView ReportView = _CswNbtSchemaModTrnsctn.restoreView( MailReportNode.ReportView.ViewId ); ReportView.Root.ChildRelationships.Clear(); CswNbtViewRelationship UserRel = ReportView.AddViewRelationship( UserNT, false ); ReportView.AddViewPropertyAndFilter( UserRel, UserLockedNTP, Tristate.True.ToString() ); ReportView.save(); } // if( null != MailReportNT ) }//Update()
}//_sendMailMessage() private string _makeEmailBody(CswNbtResources _CswNbtResources, CswNbtObjClassMailReport CurrentMailReport, string Link, Dictionary <CswPrimaryKey, string> NodeDict = null) { string ReturnVal = string.Empty; ReturnVal = CurrentMailReport.Message.Text.Replace("\r\n", "<br>") + "<br>"; if (null != NodeDict) { foreach (CswPrimaryKey NodeId in NodeDict.Keys) { ReturnVal += _makeNodeLink(_CswNbtResources, NodeId, NodeDict[NodeId]) + "<br>"; } } ReturnVal += "<br>" + Link + "<br>"; return(ReturnVal); }//_makeEmailBody()
} //processMailReport() private string _sendMailMessage(CswNbtResources _CswNbtResources, CswNbtObjClassMailReport CurrentMailReport, string MailReportMessage, string LastName, string FirstName, string UserName, string Subject, string CurrentEmailAddress, DataTable ReportTable) { string ReturnVal = string.Empty; CswMail CswMail = _CswNbtResources.CswMail; ReturnVal += "Recipients: "; CswMailMessage MailMessage = new CswMailMessage(); MailMessage.Recipient = CurrentEmailAddress; MailMessage.RecipientDisplayName = FirstName + " " + LastName; MailMessage.Subject = Subject; MailMessage.Content = MailReportMessage; MailMessage.Format = CswEnumMailMessageBodyFormat.HTML; if (null != ReportTable) { string TableAsCSV = ((CswDataTable)ReportTable).ToCsv(); byte[] Buffer = new System.Text.UTF8Encoding().GetBytes(TableAsCSV); System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream(Buffer, false); MailMessage.Attachment = MemoryStream; MailMessage.AttachmentDisplayName = CurrentMailReport.Node.NodeName + ".csv"; } if (CswMail.send(MailMessage)) { ReturnVal += UserName + " at " + CurrentEmailAddress + " (succeeded); "; } else { ReturnVal += UserName + " at " + CurrentEmailAddress + " (failed: " + CswMail.Status + "); "; } return(ReturnVal); }//_sendMailMessage()
public override void update() { CswNbtMetaDataObjectClass MailReportOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.MailReportClass ); CswNbtMetaDataNodeType MailReportNT = MailReportOC.FirstNodeType; CswNbtMetaDataNodeTypeProp MailReportNameNTP = MailReportNT.getNodeTypeProp( "Name" ); if( null != MailReportNT ) { if( _CswNbtSchemaModTrnsctn.Modules.IsModuleEnabled( CswNbtModuleName.SI ) ) { // Notification for Inspection status = Action Required CswNbtMetaDataObjectClass InspectionOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.InspectionDesignClass ); foreach( CswNbtMetaDataNodeType InspectionNT in InspectionOC.getNodeTypes() ) { CswNbtMetaDataNodeTypeProp InspectionStatusNTP = InspectionNT.getNodeTypePropByObjectClassProp( CswNbtObjClassInspectionDesign.PropertyName.Status ); // Make new mail report for old notification CswNbtObjClassMailReport MailReportNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( MailReportNT.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode ); if( null != MailReportNameNTP ) { MailReportNode.Node.Properties[MailReportNameNTP].AsText.Text = InspectionNT.NodeTypeName + " Action Required Notification"; } MailReportNode.OutputFormat.Value = "link"; MailReportNode.Type.Value = CswNbtObjClassMailReport.TypeOptionView; MailReportNode.Event.Value = CswNbtObjClassMailReport.EventOption.Edit.ToString(); MailReportNode.TargetType.SelectedNodeTypeIds.Add( InspectionNT.NodeTypeId.ToString() ); MailReportNode.Message.Text = "The following inspections have been marked Action Required:"; MailReportNode.Enabled.Checked = Tristate.True; MailReportNode.IsDemo = true; CswRateInterval HourlyRate = _CswNbtSchemaModTrnsctn.makeRateInterval(); HourlyRate.setHourly( 2, DateTime.Now ); MailReportNode.DueDateInterval.RateInterval = HourlyRate; if( "scu" == _CswNbtSchemaModTrnsctn.Accessid ) { // Subscribe existing user (id: 24917) MailReportNode.Recipients.AddUser( new CswPrimaryKey( "nodes", 24917 ) ); MailReportNode.Enabled.Checked = Tristate.True; } else { MailReportNode.Enabled.Checked = Tristate.False; } MailReportNode.postChanges( true ); CswNbtView ReportView = _CswNbtSchemaModTrnsctn.restoreView( MailReportNode.ReportView.ViewId ); ReportView.Root.ChildRelationships.Clear(); CswNbtViewRelationship InspRel = ReportView.AddViewRelationship( InspectionNT, false ); ReportView.AddViewPropertyAndFilter( InspRel, InspectionStatusNTP, CswNbtObjClassInspectionDesign.InspectionStatus.ActionRequired.ToString() ); ReportView.save(); } // foreach( CswNbtMetaDataNodeType InspectionNT in InspectionOC.getNodeTypes() ) } // if(_CswNbtSchemaModTrnsctn.Modules.IsModuleEnabled( CswNbtModuleName.SI) ) if( _CswNbtSchemaModTrnsctn.Modules.IsModuleEnabled( CswNbtModuleName.IMCS ) ) { // Notification for new Problems CswNbtMetaDataObjectClass ProblemOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.ProblemClass ); foreach( CswNbtMetaDataNodeType ProblemNT in ProblemOC.getNodeTypes() ) { CswNbtMetaDataNodeTypeProp ProblemClosedNTP = ProblemNT.getNodeTypePropByObjectClassProp( CswNbtObjClassProblem.PropertyName.Closed ); // Make new mail report for old notification CswNbtObjClassMailReport MailReportNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( MailReportNT.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode ); if( null != MailReportNameNTP ) { MailReportNode.Node.Properties[MailReportNameNTP].AsText.Text = "New " + ProblemNT.NodeTypeName + " Notification"; } MailReportNode.OutputFormat.Value = "link"; MailReportNode.Type.Value = CswNbtObjClassMailReport.TypeOptionView; MailReportNode.Event.Value = CswNbtObjClassMailReport.EventOption.Edit.ToString(); MailReportNode.TargetType.SelectedNodeTypeIds.Add( ProblemNT.NodeTypeId.ToString() ); MailReportNode.Message.Text = "The following problems have been opened:"; MailReportNode.IsDemo = true; CswRateInterval HourlyRate = _CswNbtSchemaModTrnsctn.makeRateInterval(); HourlyRate.setHourly( 2, DateTime.Now ); MailReportNode.DueDateInterval.RateInterval = HourlyRate; if( "cabot" == _CswNbtSchemaModTrnsctn.Accessid ) { // Subscribe existing user (id: 24786) MailReportNode.Recipients.AddUser( new CswPrimaryKey( "nodes", 24786 ) ); MailReportNode.Enabled.Checked = Tristate.True; } else { MailReportNode.Enabled.Checked = Tristate.False; } MailReportNode.postChanges( true ); CswNbtView ReportView = _CswNbtSchemaModTrnsctn.restoreView( MailReportNode.ReportView.ViewId ); ReportView.Root.ChildRelationships.Clear(); CswNbtViewRelationship ProbRel = ReportView.AddViewRelationship( ProblemNT, false ); ReportView.AddViewPropertyAndFilter( ProbRel, ProblemClosedNTP, Tristate.False.ToString() ); ReportView.save(); } // foreach( CswNbtMetaDataNodeType ProblemNT in ProblemOC.getNodeTypes() ) } // else if(_CswNbtSchemaModTrnsctn.Modules.IsModuleEnabled( CswNbtModuleName.IMCS) ) } // if( null != MailReportNT ) }//Update()
private void processMailReport(CswNbtResources _CswNbtResources, CswNbtObjClassMailReport CurrentMailReport) { string EmailReportStatusMessage = string.Empty; if (false == CurrentMailReport.Recipients.Empty) { Collection <Int32> RecipientIds = CurrentMailReport.Recipients.SelectedUserIds.ToIntCollection(); for (Int32 u = 0; u < RecipientIds.Count; u++) { Int32 UserId = CswConvert.ToInt32(RecipientIds[u].ToString()); if (Int32.MinValue != UserId) { CswNbtNode UserNode = _CswNbtResources.Nodes[new CswPrimaryKey("nodes", UserId)]; CswNbtObjClassUser UserNodeAsUser = (CswNbtObjClassUser)UserNode; string CurrentEmailAddress = UserNodeAsUser.Email.Trim(); if (CurrentEmailAddress != string.Empty) { DataTable ReportTable = null; CswNbtObjClassReport ReportObjClass = null; string EmailMessageSubject = CurrentMailReport.NodeName; string EmailMessageBody = string.Empty; bool SendMail = false; if ("View" == CurrentMailReport.Type.Value) { CswNbtViewId ViewId = CurrentMailReport.ReportView.ViewId; if (ViewId.isSet()) { CswNbtView ReportView = _CswNbtResources.ViewSelect.restoreView(ViewId); ICswNbtTree ReportTree = _CswNbtResources.Trees.getTreeFromView( RunAsUser: UserNodeAsUser as ICswNbtUser, View: ReportView, RequireViewPermissions: true, IncludeSystemNodes: false, IncludeHiddenNodes: false); //ICswNbtTree ReportTree = _CswNbtResources.Trees.getTreeFromView( UserNodeAsUser as ICswNbtUser, ReportView, true, true, false, false ); if (ReportTree.getChildNodeCount() > 0) { if (CswEnumNbtMailReportEventOption.Exists.ToString() != CurrentMailReport.Event.Value) { // case 27720 - check mail report events to find nodes that match the view results Dictionary <CswPrimaryKey, string> NodesToMail = new Dictionary <CswPrimaryKey, string>(); foreach (Int32 NodeId in CurrentMailReport.GetNodesToReport().ToIntCollection()) { CswPrimaryKey ThisNodeId = new CswPrimaryKey("nodes", NodeId); ReportTree.makeNodeCurrent(ThisNodeId); if (ReportTree.isCurrentNodeDefined()) { NodesToMail.Add(ThisNodeId, ReportTree.getNodeNameForCurrentPosition()); } } if (NodesToMail.Count > 0) { EmailMessageBody = _makeEmailBody(_CswNbtResources, CurrentMailReport, string.Empty, NodesToMail); SendMail = true; } } else { EmailMessageBody = _makeEmailBody(_CswNbtResources, CurrentMailReport, _makeViewLink(_CswNbtResources, ViewId, ReportView.ViewName)); SendMail = true; } } // if( ReportTree.getChildNodeCount() > 0 ) } // if( ViewId.isSet() ) else { EmailReportStatusMessage += "Unable to process email report " + CurrentMailReport.Node.NodeName + ": the associated view's ViewId is not set\r\n"; } } // if( "View" == CurrentMailReport.Type.Value ) else if ("Report" == CurrentMailReport.Type.Value) { ReportObjClass = (CswNbtObjClassReport)_CswNbtResources.Nodes[CurrentMailReport.Report.RelatedNodeId]; if (null != ReportObjClass) { string ReportSql = CswNbtObjClassReport.ReplaceReportParams(ReportObjClass.SQL.Text, ReportObjClass.ExtractReportParams(UserNode)); CswArbitrarySelect ReportSelect = _CswNbtResources.makeCswArbitrarySelect("MailReport_" + ReportObjClass.NodeId.ToString() + "_Select", ReportSql); ReportTable = ReportSelect.getTable(); if (ReportTable.Rows.Count > 0) { string ReportLink = string.Empty; CswEnumNbtMailReportFormatOptions MailRptFormat = CurrentMailReport.OutputFormat.Value; if (CswEnumNbtMailReportFormatOptions.Link == MailRptFormat) { ReportLink = _makeReportLink(_CswNbtResources, ReportObjClass); ReportTable = null; //so we don't end up attaching the CSV } EmailMessageBody = _makeEmailBody(_CswNbtResources, CurrentMailReport, ReportLink); SendMail = true; } } else { EmailReportStatusMessage += "Unable to process email report " + CurrentMailReport.Node.NodeName + ": the associated report's NodeId is not set\r\n"; } //if-else report's node id is present } // else if( "Report" == CurrentMailReport.Type.Value ) else { EmailReportStatusMessage += "Unable to process email report " + CurrentMailReport.Node.NodeName + ": the report type " + CurrentMailReport.Type.Value + " is unknown\r\n"; }//if-else-if on report type if (SendMail) { EmailReportStatusMessage += _sendMailMessage(_CswNbtResources, CurrentMailReport, EmailMessageBody, UserNodeAsUser.LastName, UserNodeAsUser.FirstName, UserNodeAsUser.Node.NodeName, EmailMessageSubject, CurrentEmailAddress, ReportTable) + "\r\n"; } } //if( Email Address != string.Empty ) } //if( Int32.MinValue != UserId ) } //for( Int32 u = 0; u < BatchData.RecipientIds.Count() && u < NodeLimit; u++ ) // case 27720, 28006, 31205, 30959 CurrentMailReport.ClearNodesToReport(); CurrentMailReport.LastProcessed.DateTimeValue = DateTime.Now; CurrentMailReport.RunStatus.AddComment(EmailReportStatusMessage); CurrentMailReport.postChanges(false); } //if( !CurrentMailReport.Recipients.Empty ) } //processMailReport()
private Collection <CswPrimaryKey> _getMailReportsToRun(CswNbtResources _CswNbtResources) { _CswScheduleLogicNodes = new CswScheduleLogicNodes(_CswNbtResources); Collection <CswNbtObjClassMailReport> MailReports = _CswScheduleLogicNodes.getMailReports(); Collection <CswPrimaryKey> MailReportIdsToRun = new Collection <CswPrimaryKey>(); for (Int32 idx = 0; (idx < MailReports.Count); idx++) { CswNbtObjClassMailReport CurrentMailReport = MailReports[idx]; if (null != CurrentMailReport) { try { if (CurrentMailReport.Recipients.SelectedUserIds.Count > 0) { // for notifications, make sure at least one node has changed if (CurrentMailReport.Type.Value != CswNbtObjClassMailReport.TypeOptionView || CurrentMailReport.Event.Value != CswEnumNbtMailReportEventOption.Edit.ToString() || false == String.IsNullOrEmpty(CurrentMailReport.NodesToReport.Text)) { if (false == CurrentMailReport.Type.Empty) { if (_doesMailReportRunNow(CurrentMailReport)) { // Process this mail report and increment (Case 29684) MailReportIdsToRun.Add(CurrentMailReport.NodeId); // Cycle the next due date so we don't make another batch op while this one is running CurrentMailReport.updateNextDueDate(ForceUpdate: true, DeleteFutureNodes: false); CurrentMailReport.postChanges(false); } } // if( false == CurrentMailReport.Type.Empty ) else { CurrentMailReport.RunStatus.AddComment("Report type is not specified"); CurrentMailReport.Enabled.Checked = CswEnumTristate.False; CurrentMailReport.postChanges(true); } } // if there's something to report else { CurrentMailReport.RunStatus.AddComment("No reportable changes made"); CurrentMailReport.updateNextDueDate(ForceUpdate: true, DeleteFutureNodes: false); CurrentMailReport.postChanges(false); } } // if( CurrentMailReport.Recipients.SelectedUserIds.Count > 0 ) else { CurrentMailReport.RunStatus.AddComment("No recipients selected"); CurrentMailReport.Enabled.Checked = CswEnumTristate.False; CurrentMailReport.postChanges(false); } } //try catch (Exception Exception) { _InnerErrorMessage += "An exception occurred: " + Exception.Message + "; "; CurrentMailReport.Enabled.Checked = CswEnumTristate.False; CurrentMailReport.RunStatus.AddComment(_InnerErrorMessage); CurrentMailReport.postChanges(true); } } // if( null != CurrentMailReport ) } // for( Int32 idx = 0; ( idx < MailReports.Count ) && ( LogicRunStatus.Stopping != _LogicRunStatus ); idx++ ) return(MailReportIdsToRun); }
} // update() private void _makeNameUnique( CswNbtMetaDataObjectClass MailReportOC, CswNbtMetaDataObjectClassProp NameOCP, CswNbtObjClassMailReport MailReport, string ProposedName, int Modifier ) { if( false == _findMailReportByName( MailReportOC, NameOCP, ProposedName ) ) { MailReport.Name.Text = ProposedName; MailReport.postChanges( false ); } else { Modifier++; string NewName = ProposedName + Modifier; _makeNameUnique( MailReportOC, NameOCP, MailReport, NewName, Modifier ); } }
public override void update() { #region OC Props CswNbtMetaDataObjectClass InventoryLevelOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.InventoryLevelClass ); CswNbtMetaDataObjectClassProp MaterialProp = InventoryLevelOC.getObjectClassProp( CswNbtObjClassInventoryLevel.PropertyName.Material ); CswNbtMetaDataObjectClassProp LocationProp = InventoryLevelOC.getObjectClassProp( CswNbtObjClassInventoryLevel.PropertyName.Location ); CswNbtMetaDataObjectClassProp TypeProp = InventoryLevelOC.getObjectClassProp( CswNbtObjClassInventoryLevel.PropertyName.Type ); CswNbtMetaDataObjectClassProp LevelProp = InventoryLevelOC.getObjectClassProp( CswNbtObjClassInventoryLevel.PropertyName.Level ); CswNbtMetaDataObjectClassProp CurrentQuantityProp = InventoryLevelOC.getObjectClassProp( CswNbtObjClassInventoryLevel.PropertyName.CurrentQuantity ); CswNbtMetaDataObjectClassProp StatusProp = InventoryLevelOC.getObjectClassProp( CswNbtObjClassInventoryLevel.PropertyName.Status ); CswNbtMetaDataObjectClass LocationOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.LocationClass ); CswNbtMetaDataObjectClassProp LocInventoryGroupProp = LocationOC.getObjectClassProp( CswNbtObjClassLocation.PropertyName.InventoryGroup ); CswNbtMetaDataObjectClass InventoryGroupPermissionOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.InventoryGroupPermissionClass ); CswNbtMetaDataObjectClassProp IGPInventoryGroupProp = InventoryGroupPermissionOC.getObjectClassProp( CswNbtObjClassInventoryGroupPermission.PropertyName.InventoryGroup ); CswNbtMetaDataObjectClassProp IGPWorkUnitProp = InventoryGroupPermissionOC.getObjectClassProp( CswNbtObjClassInventoryGroupPermission.PropertyName.WorkUnit ); CswNbtMetaDataObjectClassProp IGPRoleProp = InventoryGroupPermissionOC.getObjectClassProp( CswNbtObjClassInventoryGroupPermission.PropertyName.Role ); CswNbtMetaDataObjectClass UserOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.UserClass ); CswNbtMetaDataObjectClassProp WorkUnitProp = UserOC.getObjectClassProp( CswNbtObjClassUser.PropertyName.WorkUnit ); CswNbtMetaDataObjectClassProp RoleProp = UserOC.getObjectClassProp( CswNbtObjClassUser.PropertyName.Role ); #endregion OC Props #region SQL Query Template String SqlText = @" select il.op_{0} as Material, il.op_{1} as LOCATION, il.op_{2} as TYPE, il.op_{3} as inventorylevel, il.op_{4} as CurrentQuantity, il.op_{5} as Status from ocinventorylevelclass il inner join oclocationclass l on l.nodeid = il.op_{1}_fk inner join ocinventorygroupclass ig on ig.nodeid = l.op_{6}_fk inner join (select * from ocinventorygrouppermissioncl) igp on igp.op_{7}_fk = ig.nodeid inner join ocworkunitclass wu on wu.nodeid = igp.op_{8}_fk inner join (select * from ocuserclass) u on u.op_{9}_fk = wu.nodeid where il.op_{5} != 'Ok' and u.op_{11}_fk = igp.op_{10}_fk and u.nodeid = {12}"; #endregion SQL Query Template String SelectText = String.Format( SqlText, MaterialProp.PropId, LocationProp.PropId, TypeProp.PropId, LevelProp.PropId, CurrentQuantityProp.PropId, StatusProp.PropId, LocInventoryGroupProp.PropId, IGPInventoryGroupProp.PropId, IGPWorkUnitProp.PropId, WorkUnitProp.PropId, IGPRoleProp.PropId, RoleProp.PropId, "{userid}" ); CswNbtMetaDataObjectClass ReportOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.ReportClass ); CswNbtMetaDataNodeType ReportNT = ReportOC.FirstNodeType; if( null != ReportNT ) { CswNbtObjClassReport ReportNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( ReportNT.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode ); ReportNode.ReportName.Text = "Deficient Inventory Levels"; ReportNode.Category.Text = "Containers"; ReportNode.SQL.Text = SelectText; ReportNode.postChanges( false ); CswNbtMetaDataObjectClass MailReportOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.MailReportClass ); CswNbtMetaDataNodeType MailReportNT = MailReportOC.FirstNodeType; if( null != MailReportNT ) { CswNbtMetaDataNodeTypeProp MailReportNameNTP = MailReportNT.getNodeTypeProp( "Name" ); CswNbtObjClassMailReport MailReportNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( MailReportNT.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode ); if( null != MailReportNameNTP ) { MailReportNode.Node.Properties[MailReportNameNTP].AsText.Text = "Deficient Inventory Levels"; } MailReportNode.OutputFormat.Value = "link"; MailReportNode.Type.Value = CswNbtObjClassMailReport.TypeOptionReport; MailReportNode.Report.RelatedNodeId = ReportNode.NodeId; MailReportNode.Message.Text = "The following levels are above maximum inventory or below minimum inventory:"; MailReportNode.Enabled.Checked = Tristate.True; CswRateInterval DailyRate = _CswNbtSchemaModTrnsctn.makeRateInterval(); DailyRate.setHourly( 24, DateTime.Today ); MailReportNode.DueDateInterval.RateInterval = DailyRate; MailReportNode.postChanges( true ); } } }//Update()
public override void update() { // Set up label printing nodetypes CswNbtMetaDataObjectClass PrinterOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.PrinterClass ); CswNbtMetaDataObjectClass JobOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.PrintJobClass ); CswNbtMetaDataObjectClassProp JobCreatedDateOCP = JobOC.getObjectClassProp( CswNbtObjClassPrintJob.PropertyName.CreatedDate ); CswNbtMetaDataObjectClassProp JobJobNoOCP = JobOC.getObjectClassProp( CswNbtObjClassPrintJob.PropertyName.JobNo ); CswNbtMetaDataObjectClassProp JobJobStateOCP = JobOC.getObjectClassProp( CswNbtObjClassPrintJob.PropertyName.JobState ); CswNbtMetaDataObjectClassProp JobPrinterOCP = JobOC.getObjectClassProp( CswNbtObjClassPrintJob.PropertyName.Printer ); CswNbtMetaDataObjectClassProp JobRequestedByOCP = JobOC.getObjectClassProp( CswNbtObjClassPrintJob.PropertyName.RequestedBy ); CswNbtMetaDataObjectClassProp JobErrorOCP = JobOC.getObjectClassProp( CswNbtObjClassPrintJob.PropertyName.ErrorInfo ); CswNbtMetaDataObjectClassProp JobLabelOCP = JobOC.getObjectClassProp( CswNbtObjClassPrintJob.PropertyName.Label ); CswNbtMetaDataObjectClassProp JobEndedDateOCP = JobOC.getObjectClassProp( CswNbtObjClassPrintJob.PropertyName.EndedDate ); // Printer NodeType { CswNbtMetaDataNodeType PrinterNT = _CswNbtSchemaModTrnsctn.MetaData.makeNewNodeType( new CswNbtWcfMetaDataModel.NodeType( PrinterOC ) { NodeTypeName = "Printer", Category = "System" } ); PrinterNT.setNameTemplateText( CswNbtMetaData.MakeTemplateEntry( CswNbtObjClassPrinter.PropertyName.Name ) ); // Add a job grid CswNbtMetaDataNodeTypeTab JobGridTab = _CswNbtSchemaModTrnsctn.MetaData.makeNewTab( PrinterNT, "Jobs", 2 ); CswNbtMetaDataNodeTypeProp JobGridNTP = _CswNbtSchemaModTrnsctn.MetaData.makeNewProp( new CswNbtWcfMetaDataModel.NodeTypeProp( PrinterNT, _CswNbtSchemaModTrnsctn.MetaData.getFieldType( CswNbtMetaDataFieldType.NbtFieldType.Grid ), "Jobs" ) ); JobGridNTP.updateLayout( CswNbtMetaDataNodeTypeLayoutMgr.LayoutType.Edit, true, JobGridTab.TabId ); CswNbtView JobGridView = _CswNbtSchemaModTrnsctn.restoreView( JobGridNTP.ViewId ); JobGridView.Root.ChildRelationships.Clear(); CswNbtViewRelationship PrinterRel = JobGridView.AddViewRelationship( PrinterOC, true ); CswNbtViewRelationship JobRel = JobGridView.AddViewRelationship( PrinterRel, NbtViewPropOwnerType.Second, JobPrinterOCP, true ); CswNbtViewProperty JobNoVP = JobGridView.AddViewProperty( JobRel, JobJobNoOCP ); CswNbtViewProperty RequestedByVP = JobGridView.AddViewProperty( JobRel, JobRequestedByOCP ); CswNbtViewProperty CreatedDateVP = JobGridView.AddViewProperty( JobRel, JobCreatedDateOCP ); CswNbtViewProperty JobStateVP = JobGridView.AddViewProperty( JobRel, JobJobStateOCP ); CswNbtViewProperty JobLabelVP = JobGridView.AddViewProperty( JobRel, JobLabelOCP ); JobNoVP.Order = 1; RequestedByVP.Order = 2; CreatedDateVP.Order = 3; JobStateVP.Order = 4; JobLabelVP.Order = 5; JobGridView.save(); } // Print Job NodeType { CswNbtMetaDataNodeType JobNT = _CswNbtSchemaModTrnsctn.MetaData.makeNewNodeType( new CswNbtWcfMetaDataModel.NodeType( JobOC ) { NodeTypeName = "Print Job", Category = "System" } ); JobNT.setNameTemplateText( CswNbtMetaData.MakeTemplateEntry( CswNbtObjClassPrintJob.PropertyName.JobNo ) ); CswNbtMetaDataNodeTypeProp JobJobNoNTP = JobNT.getNodeTypePropByObjectClassProp( CswNbtObjClassPrintJob.PropertyName.JobNo ); Int32 SequenceId = _CswNbtSchemaModTrnsctn.makeSequence( new CswSequenceName( "printjob" ), "PJ", "", 4, 1 ); JobJobNoNTP.setSequence( SequenceId ); JobJobNoNTP.ReadOnly = true; // Notification: My print job failed { CswNbtMetaDataObjectClass MailReportOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.MailReportClass ); CswNbtMetaDataNodeType MailReportNT = MailReportOC.FirstNodeType; if( null != MailReportNT ) { CswNbtMetaDataNodeTypeProp NameNTP = MailReportNT.getNodeTypeProp( "Name" ); CswNbtObjClassMailReport PrintJobNotif = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( MailReportNT.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode ); if( null != NameNTP ) { PrintJobNotif.Node.Properties[NameNTP].AsText.Text = "My Print Job Failures"; } PrintJobNotif.Type.Value = CswNbtObjClassMailReport.TypeOptionView; PrintJobNotif.Enabled.Checked = Tristate.True; PrintJobNotif.Event.Value = CswNbtObjClassMailReport.EventOption.Edit.ToString(); PrintJobNotif.Message.Text = "One of your print jobs has failed."; PrintJobNotif.OutputFormat.Value = MailRptFormatOptions.Link.ToString(); PrintJobNotif.TargetType.SelectedNodeTypeIds.Add( JobNT.NodeTypeId.ToString() ); CswRateInterval Rate = _CswNbtSchemaModTrnsctn.makeRateInterval(); Rate.setHourly( 1, DateTime.Now ); PrintJobNotif.DueDateInterval.RateInterval = Rate; PrintJobNotif.postChanges( false ); CswNbtView NotifView = _CswNbtSchemaModTrnsctn.restoreView( PrintJobNotif.ReportView.ViewId ); // Print jobs... CswNbtViewRelationship JobRel = NotifView.AddViewRelationship( JobOC, false ); // ...where the state is error... NotifView.AddViewPropertyAndFilter( JobRel, JobJobStateOCP, Value: CswNbtObjClassPrintJob.StateOption.Error, FilterMode: CswNbtPropFilterSql.PropertyFilterMode.Equals ); // ...and the requestor was me... NotifView.AddViewPropertyAndFilter( JobRel, JobRequestedByOCP, Value: "me", FilterMode: CswNbtPropFilterSql.PropertyFilterMode.Equals ); NotifView.save(); } } } // Printers View { CswNbtView PrintersView = _CswNbtSchemaModTrnsctn.makeView(); PrintersView.saveNew( "Printers", NbtViewVisibility.Global ); PrintersView.Category = "System"; PrintersView.ViewMode = NbtViewRenderingMode.Tree; PrintersView.AddViewRelationship( PrinterOC, true ); PrintersView.save(); } // Print Job Errors View { CswNbtView ErrorsView = _CswNbtSchemaModTrnsctn.makeView(); ErrorsView.saveNew( "Print Job Errors", NbtViewVisibility.Global ); ErrorsView.Category = "System"; ErrorsView.ViewMode = NbtViewRenderingMode.Grid; CswNbtViewRelationship JobRel = ErrorsView.AddViewRelationship( JobOC, true ); CswNbtViewProperty JobNoVP = ErrorsView.AddViewProperty( JobRel, JobJobNoOCP ); CswNbtViewProperty RequestedByVP = ErrorsView.AddViewProperty( JobRel, JobRequestedByOCP ); //CswNbtViewProperty CreatedDateVP = ErrorsView.AddViewProperty( JobRel, JobCreatedDateOCP ); CswNbtViewProperty JobStateVP = ErrorsView.AddViewProperty( JobRel, JobJobStateOCP ); CswNbtViewProperty JobLabelVP = ErrorsView.AddViewProperty( JobRel, JobLabelOCP ); CswNbtViewProperty ErrorVP = ErrorsView.AddViewProperty( JobRel, JobErrorOCP ); CswNbtViewProperty EndedDateVP = ErrorsView.AddViewProperty( JobRel, JobEndedDateOCP ); JobNoVP.Order = 1; RequestedByVP.Order = 2; //CreatedDateVP.Order = 3; EndedDateVP.Order = 4; JobStateVP.Order = 5; JobLabelVP.Order = 6; ErrorVP.Order = 7; ErrorsView.AddViewPropertyFilter( JobStateVP, Value: CswNbtObjClassPrintJob.StateOption.Error, FilterMode: CswNbtPropFilterSql.PropertyFilterMode.Equals ); ErrorsView.AddViewPropertyFilter( EndedDateVP, Value: "today-7", FilterMode: CswNbtPropFilterSql.PropertyFilterMode.GreaterThanOrEquals ); ErrorsView.save(); } } //Update()
public override void update() { CswNbtMetaDataObjectClass MailReportGroupOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.MailReportGroupClass); CswNbtObjClassMailReportGroup DemoMailReports = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId(MailReportGroupOC.FirstNodeType.NodeTypeId, delegate(CswNbtNode NewNode) { CswNbtObjClassMailReportGroup DemoMailReportNode = NewNode; DemoMailReportNode.IsDemo = true; DemoMailReportNode.Name.Text = "Demo Mail Reports"; }); CswNbtMetaDataObjectClass MailReportOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.MailReportClass); foreach (CswNbtObjClassMailReport MailReportNode in MailReportOC.getNodes(false, false, false, true)) { if (MailReportNode.IsDemo) { MailReportNode.MailReportGroup.RelatedNodeId = DemoMailReports.NodeId; MailReportNode.postChanges(false); } } CswNbtMetaDataObjectClass MailReportGroupPermissionOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.MailReportGroupPermissionClass); CswNbtMetaDataObjectClass RoleOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.RoleClass); foreach (CswNbtObjClassRole RoleNode in RoleOC.getNodes(false, false, false, true)) { if (RoleNode.Administrator.Checked == CswEnumTristate.True) { CswNbtObjClassMailReportGroupPermission DemoMailReportGroupPerm = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId(MailReportGroupPermissionOC.FirstNodeType.NodeTypeId, delegate(CswNbtNode NewNode) { CswNbtObjClassMailReportGroupPermission DemoMailReportPermNode = NewNode; DemoMailReportPermNode.Role.RelatedNodeId = RoleNode.NodeId; DemoMailReportPermNode.ApplyToAllWorkUnits.Checked = CswEnumTristate.True; DemoMailReportPermNode.PermissionGroup.RelatedNodeId = DemoMailReports.NodeId; DemoMailReportPermNode.View.Checked = CswEnumTristate.True; DemoMailReportPermNode.Edit.Checked = CswEnumTristate.True; }); } } CswNbtObjClassMailReportGroup DefaultMailReportGroup = null; foreach (CswNbtObjClassMailReportGroup MailReportGroupNode in MailReportGroupOC.getNodes(false, false, false, true)) { if (MailReportGroupNode.Name.Text == "Default Mail Report Group") { DefaultMailReportGroup = MailReportGroupNode; } } CswNbtView MyExpiringContainersView = _CswNbtSchemaModTrnsctn.restoreView("My Expiring Containers"); if (null != MyExpiringContainersView && null != DefaultMailReportGroup) { CswNbtObjClassMailReport MyExpiringContainersReport = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId(MailReportOC.FirstNodeType.NodeTypeId, delegate(CswNbtNode NewNode) { CswNbtObjClassMailReport MyExpiringContainersReportNode = NewNode; MyExpiringContainersReportNode.Name.Text = "My Expiring Containers"; MyExpiringContainersReportNode.Type.Value = CswNbtObjClassMailReport.TypeOptionView; MyExpiringContainersReportNode.Event.Value = "Edit"; MyExpiringContainersReportNode.MailReportGroup.RelatedNodeId = DefaultMailReportGroup.NodeId; MyExpiringContainersReportNode.Message.Text = "The following containers will be expiring soon: "; MyExpiringContainersReportNode.Enabled.Checked = CswEnumTristate.False; CswNbtView MyExpContMRView = _CswNbtSchemaModTrnsctn.makeView(); MyExpContMRView.saveNew("My Expiring Containers", CswEnumNbtViewVisibility.Hidden, CopyViewId: MyExpiringContainersView.ViewId.get()); MyExpiringContainersReportNode.ReportView.ViewId = MyExpContMRView.ViewId; CswRateInterval DailyRate = _CswNbtSchemaModTrnsctn.makeRateInterval(); DailyRate.setHourly(24, DateTime.Today); MyExpiringContainersReportNode.DueDateInterval.RateInterval = DailyRate; }); } }