private static void Traverse( ICollection <TraceCall> calls, Dictionary <string, RankingItem> routines, ref uint totalCount, GetNameDelegate getName) { foreach (TraceCall call in calls) { if (routines.ContainsKey(getName(call))) { RankingItem item = routines[getName(call)]; item.CallCount++; } else { routines[getName(call)] = new RankingItem(getName(call), 1); } totalCount++; if (!call.IsSynthetic) { Traverse(call.Calls, routines, ref totalCount, getName); } } }
public static List<ListGroup<T>> GroupList<T>(IEnumerable<T> listToGroup, GetNameDelegate<T> getName, bool sort) { string numberKey = "0 – 9"; string displayNumberKey = "#"; List<ListGroup<T>> groupedList = new List<ListGroup<T>>(); CharacterGroupings slg = new CharacterGroupings(); foreach (CharacterGrouping key in slg) { if (string.IsNullOrWhiteSpace(key.Label) == false){ string displayKey = key.Label; if (displayKey.Equals(numberKey)) { displayKey = displayNumberKey; } groupedList.Add(new ListGroup<T>(displayKey)); } } #if WINDOWS_APP //Duct tape for Windows 8 if (groupedList.Find(t => t.Key == "...") == null) { groupedList.Add(new ListGroup<T>("...")); } #endif //Duct tape ends foreach (T item in listToGroup) { string itemName = GetTrimmedName(getName(item)); string groupLabel = slg.Lookup(itemName); if (groupLabel.Equals(numberKey)) { groupLabel = displayNumberKey; } if (!string.IsNullOrEmpty(groupLabel)) { var groupToAddTo = groupedList.Find(t => t.Key == groupLabel); #if WINDOWS_APP //Duct tape for Windows 8 if (groupToAddTo == null) { groupToAddTo = groupedList.Find(t => t.Key == "..."); } #endif //Duct tape ends groupToAddTo.Add(item); } } if (sort) { foreach (ListGroup<T> group in groupedList) { group.Sort((c0, c1) => { return CultureInfo.InvariantCulture.CompareInfo.Compare(GetTrimmedName(getName(c0)), GetTrimmedName(getName(c1))); }); } } return groupedList; }
void SetupDelegates() { updateServerLogDelegate = new UpdateServerLogDelegate(UpdateServerLog); updateConnectionLabelsDelegate = new UpdateConnectionLabelsDelegate(UpdateConnectionLabels); closeFormDelegate = new CloseFormDelegate(CloseForm); getNameDelegate = new GetNameDelegate(GetName); getColorDelegate = new GetColorDelegate(GetColor); }
static void Main(string[] args) { DateTime start = System.DateTime.Now; HttpChannel channel = new HttpChannel(); ChannelServices.RegisterChannel(channel); IMyRemoteObject obj = (IMyRemoteObject)Activator.GetObject( typeof(IMyRemoteObject), "http://localhost:1234/MyRemoteObject.soap"); Console.WriteLine("Client.Main(): Reference to rem.obj. acquired"); Console.WriteLine("Client.Main(): Will call setValue(42)"); SetValueDelegate svDelegate = new SetValueDelegate(obj.SetValue); IAsyncResult svAsyncres = svDelegate.BeginInvoke(42, null, null); Console.WriteLine("Client.Main(): Invocation done"); Console.WriteLine("Client.Main(): Will call getName()"); GetNameDelegate gnDelegate = new GetNameDelegate(obj.GetName); IAsyncResult gnAsyncres = gnDelegate.BeginInvoke(null, null); Console.WriteLine("Client.Main(): Invocation done"); Console.WriteLine("Client.Main(): EndInvoke for setValue()"); svDelegate.EndInvoke(svAsyncres); Console.WriteLine("Client.Main(): EndInvoke for getName()"); String name = gnDelegate.EndInvoke(gnAsyncres); Console.WriteLine("Client.Main(): received name {0}", name); Console.WriteLine("Client.Main(): Will now read value"); int tmp = obj.GetValue(); Console.WriteLine("Client.Main(): New server side value {0}", tmp); DateTime end = System.DateTime.Now; TimeSpan duration = end.Subtract(start); Console.WriteLine("Client.Main(): Execution took {0} seconds.", duration.Seconds); Console.ReadLine(); }
public static string getSyncChannelCode(GetNameDelegate getname, Template t, SyncRule r) { VarDecl vd; switch (r.Expr.Type) { case Expression.ExpType.Func: // might be array/range if (r.Expr.Func != Expression.Funcs.ArrayIndex) { throw new CodeGenException("Only array dereferencing allowed on channels!"); } if (r.Expr.First.Type != Expression.ExpType.Var) { throw new CodeGenException("Synchronization rule must be a channel!"); } int idx; if (t.Declarations.getExprValue(r.Expr.Second, out idx)) { vd = t.Declarations.getVar(r.Expr.First.Var); if (vd == null || vd.Type.Type != VarType.Channel) { throw new CodeGenException(String.Format("Could not find '{0}' in declarations for template '{1}' or GLOBALly!", r.Expr.First.Var, t.Name)); } return(String.Format("{0}_ARRAY[{1}]", getname(vd), idx - vd.ArrLow)); } else { // add support for this later throw new CodeGenException("Channel array index must be a constant, dynamic channel index not yet support (but will be)!"); } case Expression.ExpType.Var: vd = t.Declarations.getVar(r.Expr.Var); if (vd == null || vd.Type.Type != VarType.Channel) { throw new CodeGenException(String.Format("Could not find '{0}' in declarations for template '{1}' or GLOBALly!", r.Expr.Var, t.Name)); } return(String.Format("&{0}", getname(vd))); default: throw new CodeGenException("Synchronization rule must be a channel"); } }
private static void ShowMostCalled( TraceFile file, int count, GetNameDelegate getName) { Dictionary <string, RankingItem> routines = new Dictionary <string, RankingItem>(); uint totalCount = 0; // // Build histogram. // foreach (TraceClient client in file.Clients) { Traverse(client.Calls, routines, ref totalCount, getName); } // // Create ranking. // OrderedBag <RankingItem> ranking = new OrderedBag <RankingItem>(); foreach (RankingItem item in routines.Values) { ranking.Add(item); } int index = 0; foreach (RankingItem item in ranking.Reversed()) { if (index++ == count) { break; } Console.WriteLine("{0,60}\t{1}", item.FunctionName, item.CallCount); } Console.WriteLine(); Console.WriteLine("{0} events total", totalCount); }
static void Main(string[] args) { // event와 delegate // 개념에 대한 이해 그리고 차이점 // 실제 온라인 코딩을 통한 질문/ 답변 GetNameDelegate del = new GetNameDelegate(GetName); string name = del(); Test t = new Test(); t.NameDelegateField = () => { return("Robert"); }; string name2 = t.NameDelegateField(); Test p = new Test(); // event is not field p.NameEvent += () => { return("Kim"); }; p.NameEvent += () => { return("Lee"); }; p.NameEvent += () => { return("Choi"); }; // static event의 경우에는 event의 특성을 잃어버리는 듯? NameEvent = () => { return("Park"); }; string name3 = NameEvent(); // delegate vs event 다른 점 // 1. filed가 아니라는 걸 정확하게 인지하고 있으면 됨 // 2. 접근성의 차이 // 2-1. raise하는 주체가 누구냐??? event를 가지고 있는 class가 주인 // 2-2. class외부에서는 add, remove 외에는 할 수 있는게 없다. // 다음 시간 // 1. 김한별 // 학교 연구과제중 WPF, MVVM을 쓰면 좋지 않을까에 대한 리뷰 // 2. Kyung Wong Gil님의 // Synchronous, Asynchronous, thread and callback, APM(Asynchronous Programming Model) // 3. Iccen님의 opencv를 이용해서 어떤 특정 포인트 찾아내기 리뷰 (선 내용 공유) }
//Used to get the sqaure name from another thread public static String CopySquare(Square square) { String result; GetNameDelegate a; a = new GetNameDelegate(GetName); result = square.Dispatcher.Invoke(a, square) as String; return result; }
public static List <ListGroup <T> > GroupList <T>(IEnumerable <T> listToGroup, GetNameDelegate <T> getName, bool sort) { List <ListGroup <T> > groupedList = new List <ListGroup <T> >(); SortedLocaleGrouping slg = new SortedLocaleGrouping(CultureInfo.InvariantCulture); foreach (string key in slg.GroupDisplayNames) { groupedList.Add(new ListGroup <T>(key)); } foreach (T item in listToGroup) { string itemName = GetTrimmedName(getName(item)); int index = slg.GetGroupIndex(itemName); if (index >= 0 && index < groupedList.Count) { groupedList[index].Add(item); } } if (sort) { foreach (ListGroup <T> group in groupedList) { group.Sort((c0, c1) => { return(CultureInfo.InvariantCulture.CompareInfo.Compare(GetTrimmedName(getName(c0)), GetTrimmedName(getName(c1)))); }); } } return(groupedList); }
public ExpressionGenerator(GetNameDelegate namer, Declarations decls, string stateStructName) { _stateStructName = stateStructName; _decls = decls; _namer = namer; }
public static GetNameDelegate middle1(GetNameDelegate next) { GetNameDelegate thismid = returnname; return(thismid); }
public static GetNameDelegate middle(GetNameDelegate next) { GetNameDelegate thismid = returnnameEnglish; return(thismid); }
public ChannelAnalyzer(Model model, GetNameDelegate namer) { _model = model; _namer = namer; }