internal static void AddCryptoClass(string classType, string encryptMethod, string decryptMethod) { Type cType = Type.GetType(classType); if (cType == null) { throw new GDAException("CryptoClass\r\nType {0} not found", classType); } MethodInfo[] methods = cType.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public); if (!string.IsNullOrEmpty(encryptMethod)) { MethodInfo encrypt = Array.Find(methods, delegate(MethodInfo mi) { return(mi.Name == encryptMethod); }); if (encrypt == null) { throw new GDAException("CryptoClass\r\nMethod {0} not found in {1}.", encryptMethod, cType.FullName); } GDASettings._encryptMethod = (Converter <string, string>)Delegate.CreateDelegate(typeof(Converter <string, string>), encrypt); } if (!string.IsNullOrEmpty(decryptMethod)) { MethodInfo decrypt = Array.Find(methods, delegate(MethodInfo mi) { return(mi.Name == decryptMethod); }); if (decrypt == null) { throw new GDAException("CryptoClass\r\nMethod {0} not found in {1}.", decryptMethod, cType.FullName); } GDASettings._decryptMethod = (Converter <string, string>)Delegate.CreateDelegate(typeof(Converter <string, string>), decrypt); } }
/// <summary> /// Returns a new list by converting each member using the converter /// </summary> /// <remarks> /// This must be a hard override as the native ForEach function might break on iOS after AOT compilation /// </remarks> /// <typeparam name="TOutput">of converter's result</typeparam> /// <param name="converter">to convert each member</param> /// <returns>a converted list</returns> public new List <TOutput> ConvertAll <TOutput>(System.Converter <T, TOutput> converter) { List <TOutput> converted = new List <TOutput>(Count); for (int i = 0, imax = Count; i < imax; i++) { converted.Add(converter(this[i])); } return(converted); }
internal static void EditorTest(TaskService ts, System.IO.TextWriter output, params string[] arg) { try { const string taskName = "Test"; // Create a new task definition and assign properties TaskDefinition td = ts.NewTask(); /*td.RegistrationInfo.Description = "Test for XP SP3"; * td.RegistrationInfo.Author = "incaunu";*/ td.Triggers.Add(new DailyTrigger() { StartBoundary = new DateTime(2014, 1, 15, 9, 0, 0), EndBoundary = DateTime.Today.AddMonths(1) }); /*EventTrigger eTrig = new EventTrigger("Security", "VSSAudit", 25); * eTrig.ValueQueries.Add("Name", "Value"); * td.Triggers.Add(eTrig);*/ //td.Actions.Add(new ExecAction("cmd.exe", "/c \"date /t > c:\\cmd.txt\"")); EmailAction ea = (EmailAction)td.Actions.Add(new EmailAction("Hi", "*****@*****.**", "[email protected]; [email protected]", "<p>How you been?</p>", "smtp.codeplex.com")); ea.HeaderFields.Add("reply-to", "*****@*****.**"); ea.Attachments = new object[] { (string)new TemporaryScopedFile(), (string)new TemporaryScopedFile() }; //WriteXml(td, taskName); Task t = ts.RootFolder.RegisterTaskDefinition(taskName, td); //, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount); System.Converter <DateTime, string> d = delegate(DateTime ints) { return(ints == DateTime.MinValue ? "Never" : ints.ToString()); }; output.Write("***********************\r\nName: {0}\r\nEnabled: {1}\r\nLastRunTime: {2}\r\nState: {3}\r\nIsActive: {4}\r\nNextRunTime: {5}\r\nShouldHaveRun: {6}\r\nTriggerStart: {7}\r\nTriggerEnd: {8}\r\n", t.Name, t.Enabled, d(t.LastRunTime), t.State, t.IsActive, t.NextRunTime, d(t.LastRunTime), t.Definition.Triggers[0].StartBoundary, t.Definition.Triggers[0].EndBoundary); WriteXml(t); // Register then show task again while (DisplayTask(ts.GetTask(taskName), true) != null) { Task t2 = editorForm.Task; output.Write("***********************\r\nName: {0}\r\nEnabled: {1}\r\nLastRunTime: {2}\r\nState: {3}\r\nIsActive: {4}\r\nNextRunTime: {5}\r\nShouldHaveRun: {6}\r\nTriggerStart: {7}\r\nTriggerEnd: {8}\r\n", t2.Name, t2.Enabled, t2.LastRunTime, t2.State, t2.IsActive, t2.NextRunTime, t2.LastRunTime, t2.Definition.Triggers[0].StartBoundary, t2.Definition.Triggers[0].EndBoundary); } // Remove the task we just created ts.RootFolder.DeleteTask(taskName); } catch (Exception ex) { output.WriteLine(ex.ToString()); } }
public Pair <int, T> GenerateID(System.Converter <int, T> genfun) { int new_id; do { new_id = _rand.Next(); if (_nonneg && new_id < 0) { new_id = ~new_id; } } while(new_id == 0 || _obj_map.ContainsKey(new_id)); //Awesome! this is a new ID: T obj = genfun(new_id); _obj_map.Add(new_id, obj); return(new Pair <int, T>(new_id, obj)); }
public T[] ConvertAll <T>(System.Converter <AtomicFragment, T> f) { return(Array.ConvertAll(_fragments, f)); }
public static String[] ArrayFromColum(DataColumn Column) { System.Converter <DataRow, String> convi = delegate(DataRow row) { return(Convert.ToString(row[Column.ColumnName])); }; String[] rowValuesForColumn = Array.ConvertAll <DataRow, String>(Column.Table.Select(), convi); return(rowValuesForColumn); }
public Seq <T> Distinct(System.Converter <T, T> mapFunc) { return(Map(mapFunc).Unique); }
// Constructors public DictionaryEnumerator(IEnumerator <KeyValuePair <TKey, TValue> > innerEnumerator, System.Converter <KeyValuePair <TKey, TValue>, object> converter) : base(innerEnumerator, converter) { }
public void TestKalman() { Image <Bgr, Byte> img = new Image <Bgr, byte>(400, 400); SyntheticData syntheticData = new SyntheticData(); // state is (phi, delta_phi) - angle and angle increment Matrix <float> state = new Matrix <float>(new float[] { 0.0f, 0.0f }); //initial guess #region initialize Kalman filter Kalman tracker = new Kalman(2, 1, 0); tracker.TransitionMatrix = syntheticData.TransitionMatrix; tracker.MeasurementMatrix = syntheticData.MeasurementMatrix; tracker.ProcessNoiseCovariance = syntheticData.ProcessNoise; tracker.MeasurementNoiseCovariance = syntheticData.MeasurementNoise; tracker.ErrorCovariancePost = syntheticData.ErrorCovariancePost; tracker.CorrectedState = state; #endregion System.Converter <double, PointF> angleToPoint = delegate(double radianAngle) { return(new PointF( (float)(img.Width / 2 + img.Width / 3 * Math.Cos(radianAngle)), (float)(img.Height / 2 - img.Width / 3 * Math.Sin(radianAngle)))); }; Action <PointF, Bgr> drawCross = delegate(PointF point, Bgr color) { img.Draw(new Cross2DF(point, 15, 15), color, 1); }; ImageViewer viewer = new ImageViewer(); System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer.Interval = 200; timer.Tick += new EventHandler(delegate(object sender, EventArgs e) { Matrix <float> measurement = syntheticData.GetMeasurement(); // adjust Kalman filter state tracker.Correct(measurement); tracker.Predict(); #region draw the state, prediction and the measurement PointF statePoint = angleToPoint(tracker.CorrectedState[0, 0]); PointF predictPoint = angleToPoint(tracker.PredictedState[0, 0]); PointF measurementPoint = angleToPoint(measurement[0, 0]); img.SetZero(); //clear the image drawCross(statePoint, new Bgr(Color.White)); //draw current state in White drawCross(measurementPoint, new Bgr(Color.Red)); //draw the measurement in Red drawCross(predictPoint, new Bgr(Color.Green)); //draw the prediction (the next state) in green img.Draw(new LineSegment2DF(statePoint, predictPoint), new Bgr(Color.Magenta), 1); //Draw a line between the current position and prediction of next position //Trace.WriteLine(String.Format("Velocity: {0}", tracker.CorrectedState[1, 0])); #endregion syntheticData.GoToNextState(); viewer.Image = img; }); timer.Start(); viewer.Disposed += delegate(Object sender, EventArgs e) { timer.Stop(); }; viewer.Text = "Actual State: White; Measurement: Red; Prediction: Green"; viewer.ShowDialog(); }
public T[] ConvertAll <T>(System.Converter <JapaneseLetterFragment, T> f) { return(Array.ConvertAll(_fragments, f)); }