/// <summary> /// Print all the integers between a lowerBound and and upperBound (inclusive). /// Except, filter out certain integer values, if they are divisible by any of a List of integer Keys, /// replace those values with a Value associated with that particular Key. /// If more than one happens to match, then append each Value, in the order it appears in the List. /// Return the results, one number/string at a time, through a generic callBack method /// </summary> /// <param name="lowerBound">Start counting at this integer</param> /// <param name="upperBound">Stop counting at this integer</param> /// <param name="callBack">Invoke the CallBack method of this class to collect each integer/String</param> /// <param name="patternList">An ordered List of Name/Value pairs of integers/Strings to be replaced</param> public static void CountUp(int lowerBound, int upperBound, ICallBack callBack, List <KeyValuePair <int, String> > patternList) { for (int i = lowerBound; i <= upperBound; i++) { String result = ""; bool matched = false; foreach (KeyValuePair <int, String> pair in patternList) { // We'll never be evenly divisible by zero if (pair.Key == 0) { continue; } // Are we divisible by this Key? if (i % pair.Key == 0) { // Append the Value associated with this Key result += pair.Value; matched = true; } } // Did we match anything? If not, return the integer if (!matched) { result = String.Format("{0}", i); } // Send the result back to the caller callBack.CallBack(result); } }
public void Subscribe(DateTime a) { ICallBack handler = OperationContext.Current.GetCallbackChannel <ICallBack>(); while (true) { if (DateTime.Now.ToShortTimeString() == a.ToShortTimeString()) { handler.CallBack("LOX"); break; } } }