@@ -53,8 +53,6 @@ private void BackgroundWorker_QueryProcessorObjectsReady(object sender, QueryPro
5353
5454 foreach ( IResultObject resultObject in e . ResultObjects )
5555 {
56- //string query = string.Format("SELECT * FROM SMS_CollectionSettings where CollectionID = '{0}'", resultObject["CollectionID"].StringValue);
57- //IResultObject collectionSettings = Utility.GetFirstWMIInstance(ConnectionManager, query);
5856 IResultObject collectionSettings = ConnectionManager . GetInstance ( "SMS_CollectionSettings.CollectionID='" + resultObject [ "CollectionID" ] . StringValue + "'" ) ;
5957 collectionSettings . Get ( ) ;
6058
@@ -114,16 +112,46 @@ private void BackgroundWorker_QueryProcessorObjectsReady(object sender, QueryPro
114112
115113 break ;
116114 case 4 :
115+ // monthly schedule with week selection, check when next windows occures
116+ currentTime = new DateTime ( currentTime . Year , currentTime . Month , 1 ) ;
117+ // add months
118+ if ( schedule [ "ForNumberOfMonths" ] . IntegerValue > 1 )
119+ {
120+ currentTime = currentTime . AddMonths ( schedule [ "ForNumberOfMonths" ] . IntegerValue ) ;
121+ }
122+ // find the day in month
123+ while ( ( int ) currentTime . DayOfWeek != ( schedule [ "Day" ] . IntegerValue - 1 ) )
124+ {
125+ currentTime = currentTime . AddDays ( 1 ) ;
126+ }
127+ // add weeks
128+ currentTime = currentTime . AddDays ( days [ ( schedule [ "WeekOrder" ] . IntegerValue - 1 ) ] ) ;
129+ currentTime = currentTime . Date . Add ( startTime . TimeOfDay ) ;
130+
131+ date = currentTime . ToLongDateString ( ) ;
117132
118- if ( schedule [ "WeekOrder" ] . IntegerValue >= 1 )
133+ break ;
134+ case 5 :
135+ // monthly schedule, check when next windows occures
136+ int monthDay = schedule [ "MonthDay" ] . IntegerValue ;
137+ // day of month
138+ if ( monthDay >= 1 )
139+ {
140+ currentTime = new DateTime ( currentTime . Year , currentTime . Month , monthDay ) ;
141+ }
142+ // last day of month
143+ else if ( monthDay == 0 )
119144 {
120- DateTime firstDayOfMonth = new DateTime ( currentTime . Year , currentTime . Month , 1 ) ;
145+ currentTime = new DateTime ( currentTime . Year , currentTime . Month , DateTime . DaysInMonth ( currentTime . Year , currentTime . Month ) ) ;
146+ }
121147
122- //while ((int)firstDayOfMonth.DayOfWeek != (schedule["Day"].IntegerValue - 1))
123- //{
124- // firstDayOfMonth = firstDayOfMonth.AddDays(1);
125- // }
148+ if ( schedule [ "ForNumberOfMonths" ] . IntegerValue > 1 )
149+ {
150+ currentTime = currentTime . AddMonths ( schedule [ "ForNumberOfMonths" ] . IntegerValue ) ;
126151 }
152+ currentTime = currentTime . Date . Add ( startTime . TimeOfDay ) ;
153+
154+ date = currentTime . ToLongDateString ( ) ;
127155
128156 break ;
129157 }
0 commit comments