private void BuildMethodBlocks(CoverageReport.MethodDescriptor md, MethodItem mdItem) { foreach (CoverageReport.InnerBlockData ibd in md.insBlocks) { CoveredVariantItem cvItem = new CoveredVariantItem(); cvItem.Blocks = ibd.blocks; mdItem.AddBlock(cvItem); } }
private static MethodItem[] BuildMethods(Type interfaceType) { var methodInfoArray = interfaceType.GetMethods(); var methods = new MethodItem[methodInfoArray.Length]; for (int i = 0; i < methodInfoArray.Length; i++) { methods[i] = new MethodItem { Info = methodInfoArray[i] }; var attribute = GetRuntimeDllImportAttribute(methodInfoArray[i]); if (attribute == null) { throw new Exception(string.Format("Method '{0}' of interface '{1}' should be marked with the RuntimeDllImport attribute", methodInfoArray[i].Name, interfaceType.Name)); } methods[i].DllImportAttribute = attribute; } return(methods); }
public static object Invoke(Type interfacetype, WrapBase wrapBase, MethodInfo methodInfo, List <Object> args) { // if (InternalConfig.EmitTestCode) // { // Console.WriteLine("InvokeProxy args:"); // args.ForEach(x=>{ // Console.WriteLine((x??new object()).ToString()); // }); // } try { if (false == Lark.InterfaceWrapCache.ContainsKey(interfacetype)) { throw new LarkException("RuntimeException:wrapcache is not exists!"); } InterfaceItem interfaceItem = Lark.InterfaceWrapCache[interfacetype]; if (false == interfaceItem.WrapContext.MethodCache.ContainsKey(methodInfo)) { throw new LarkException("RuntimeException:MethodCache is not exists!"); } MethodItem methodItem = interfaceItem.WrapContext.MethodCache[methodInfo]; //todo need a pool of RequestCreContext RequestCreContext requestCreContext = RequestCreContext.Create(interfaceItem.WrapContext, methodItem.WrapContext, wrapBase); requestCreContext.ParameterValues.Value = args; return(HttpCreater.Create(requestCreContext).DealResponse(methodInfo.ReturnType)); } catch (System.Exception ex) { System.Console.WriteLine(ex.ToString()); throw ex; } }
private static void DisplayTraceResult(List <TraceItem> result, int indent = 0) { foreach (TraceItem item in result) { for (int i = 0; i < indent; i++) { Console.Write(" "); } if (item is ThreadItem) { Console.WriteLine($"thread #{(item as ThreadItem).ThreadID} - {item.ElapsedMilliseconds} ms:"); } else if (item is MethodItem) { MethodItem mItem = item as MethodItem; Console.WriteLine($"{mItem.MethodClassName} - {mItem.MethodName} - {mItem.ElapsedMilliseconds} ms"); } if (item.SubMethods != null) { DisplayTraceResult(item.SubMethods, indent + 2); } } }
public SimpleAssemblyProvider(string testFileFullPath) { //uchováme cestu k "definujícímu" souboru _fullPath = testFileFullPath; //jméno assembly odvodíme od názvu souboru _name = Path.GetFileName(_fullPath); //připravíme kontejner kam vložíme definovanou metodu _methods = new HashedMethodContainer(); //vytvoření metody začneme přípravou typu, kde je definovaná _declaringType = TypeDescriptor.Create("MEFEditor.ProviderTest"); //určíme jméno metody var methodName = "GetDefiningAssemblyName"; //návratový typ metody var returnType = TypeDescriptor.Create <string>(); //z definovaných údajů můžeme vytvořit popis //metody, která nebude mít žádné parametry a bude statická var methodInfo = new TypeMethodInfo( _declaringType, methodName, returnType, ParameterTypeInfo.NoParams, isStatic: true, methodTypeArguments: TypeDescriptor.NoDescriptors); //k dokončení definice metody stačí vytvořit //generátor jejích analyzačních instrukcí var methodGenerator = new DirectedGenerator(emitDirector); //definovanou metodu vytvoříme var method = new MethodItem(methodGenerator, methodInfo); //aby byla metoda dohledatelná, musíme ji ještě zaregistrovat _methods.AddItem(method); }
public int CreateNewRecipe(RecipeVM recipe) { try { var entity = new Recipe(); entity.CategoryId = recipe.CategoryId; entity.Name = recipe.Name; entity.DescriptionPrimary = recipe.DescriptionPrimary; entity.DescriptionSecondary = recipe.DescriptionSecondary; entity.Ingredients = new List <Ingredient>(); for (int i = 0; i < recipe.Ingredients.Count; i++) { var currentIngredient = recipe.Ingredients[i]; if (!string.IsNullOrEmpty(currentIngredient.Name)) { var ingredient = new Ingredient(); _mapper.Map(currentIngredient, ingredient); ingredient.PositionNo = i + 1; entity.Ingredients.Add(ingredient); } } entity.MethodItems = new List <MethodItem>(); for (int i = 0; i < recipe.MethodItems.Count; i++) { var currentMethodItem = recipe.MethodItems[i]; if (!string.IsNullOrEmpty(currentMethodItem.Text)) { var methodItem = new MethodItem(); _mapper.Map(currentMethodItem, methodItem); methodItem.StepNo = i + 1; entity.MethodItems.Add(methodItem); } } // trim file to convert to base64 if (!string.IsNullOrEmpty(recipe.ImageFile)) { var base64 = recipe.ImageFile.Substring(recipe.ImageFile.LastIndexOf(',') + 1); byte[] imageBytes = Convert.FromBase64String(base64); using (var stream = new MemoryStream(imageBytes)) { IFormFile file = new FormFile(stream, 0, imageBytes.Length, "", ""); var fileNameTask = _azureBlobService.UploadSingleAsync(file, imageContainerName); entity.ImageUrl = fileNameTask.Result; } } //add image // will be receiving a base64 byte array from front end //var file = recipe.Image; //_azureBlobService.UploadSingleAsync() _db.Recipes.Add(entity); _db.SaveChanges(); return(entity.RecipeId); } catch (Exception e) { var xx = e; return(0); } }
public int EditRecipe(RecipeVM recipe) { var entity = _db.Recipes .Include(r => r.Category) .FirstOrDefault(rcp => rcp.RecipeId == recipe.RecipeId); // edit existing entity if (entity == null) { entity = new Recipe(); } //_db.Recipes.Update(entity); //REMOVE existing values from lists var recipeIngredients = _db.Ingredients.Where(i => i.RecipeId == entity.RecipeId).ToList(); _db.Ingredients.RemoveRange(recipeIngredients); var methodItems = _db.MethodItems.Where(i => i.RecipeId == entity.RecipeId).ToList(); _db.MethodItems.RemoveRange(methodItems); //foreach (var ingredient in entity.Ingredients.ToList()) //{ // _db.Ingredients.Remove(ingredient); //} //foreach (var methodItem in entity.MethodItems.ToList()) //{ // _db.MethodItems.Remove(methodItem); //} _db.SaveChanges(); _mapper.Map(recipe, entity); entity.Category = _db.Categories.FirstOrDefault(c => c.CategoryId == recipe.CategoryId); entity.CategoryId = recipe.CategoryId; entity.Ingredients = new List <Ingredient>(); entity.MethodItems = new List <MethodItem>(); for (int i = 0; i < recipe.Ingredients.ToList().Count; i++) { var currentIngredient = recipe.Ingredients[i]; if (!string.IsNullOrEmpty(currentIngredient.Name)) { var ingredient = new Ingredient(); ingredient.Name = currentIngredient.Name; ingredient.Measure = currentIngredient.Measure; ingredient.Quantity = currentIngredient.Quantity; ingredient.PositionNo = i + 1; ingredient.RecipeId = entity.RecipeId; ingredient.Seperator = currentIngredient.Seperator; _db.Ingredients.Add(ingredient); } } for (int i = 0; i < recipe.MethodItems.Count; i++) { var currentMethodItem = recipe.MethodItems[i]; if (!string.IsNullOrEmpty(currentMethodItem.Text)) { var methodItem = new MethodItem(); methodItem.Text = currentMethodItem.Text; methodItem.StepNo = i + 1; methodItem.RecipeId = entity.RecipeId; methodItem.Seperator = currentMethodItem.Seperator; _db.MethodItems.Add(methodItem); } } // remove the existing image file from Azure if (entity.ImageUrl != null) { _azureBlobService.DeleteByNameAsync(entity.ImageUrl, imageContainerName); } // trim file to convert to base64 if (!string.IsNullOrEmpty(recipe.ImageFile)) { var base64 = recipe.ImageFile.Substring(recipe.ImageFile.LastIndexOf(',') + 1); byte[] imageBytes = Convert.FromBase64String(base64); using (var stream = new MemoryStream(imageBytes)) { IFormFile file = new FormFile(stream, 0, imageBytes.Length, "", ""); var fileNameTask = _azureBlobService.UploadSingleAsync(file, imageContainerName); entity.ImageUrl = fileNameTask.Result; } } //_db.Recipes.Update(entity); _db.SaveChanges(); return(entity.RecipeId); }
public void SetMethodInformation(System.Reflection.MethodInfo[] methods, string selectedMethodName, ParameterCollection selectedParameters, DataObjectMethodType methodType, System.Type dataObjectType) { try { this._signatureTextBox.Text = string.Empty; switch (methodType) { case DataObjectMethodType.Select: this._helpLabel.Text = System.Design.SR.GetString("ObjectDataSourceMethodEditor_SelectHelpLabel"); break; case DataObjectMethodType.Update: this._helpLabel.Text = System.Design.SR.GetString("ObjectDataSourceMethodEditor_UpdateHelpLabel"); break; case DataObjectMethodType.Insert: this._helpLabel.Text = System.Design.SR.GetString("ObjectDataSourceMethodEditor_InsertHelpLabel"); break; case DataObjectMethodType.Delete: this._helpLabel.Text = System.Design.SR.GetString("ObjectDataSourceMethodEditor_DeleteHelpLabel"); break; } this._methodComboBox.BeginUpdate(); this._methodComboBox.Items.Clear(); MethodItem item = null; bool flag = false; foreach (System.Reflection.MethodInfo info in methods) { if (this.FilterMethod(info, methodType)) { bool flag2 = false; DataObjectMethodAttribute attribute = Attribute.GetCustomAttribute(info, typeof(DataObjectMethodAttribute), true) as DataObjectMethodAttribute; if ((attribute != null) && (attribute.MethodType == methodType)) { if (!flag) { this._methodComboBox.Items.Clear(); } flag = true; flag2 = true; } else if (!flag) { flag2 = true; } bool flag3 = ObjectDataSourceDesigner.IsMatchingMethod(info, selectedMethodName, selectedParameters, dataObjectType); if (flag2 || flag3) { MethodItem item2 = new MethodItem(info); this._methodComboBox.Items.Add(item2); if (flag3) { item = item2; } else if (((attribute != null) && (attribute.MethodType == methodType)) && (attribute.IsDefault && (selectedMethodName.Length == 0))) { item = item2; } } } } if (methodType != DataObjectMethodType.Select) { this._methodComboBox.Items.Insert(0, new MethodItem(null)); } this._methodComboBox.InvalidateDropDownWidth(); this._methodComboBox.SelectedItem = item; } finally { this._methodComboBox.EndUpdate(); } }
private static Dictionary <string, AMemberItem> Parse(XDocument document) { Dictionary <string, AMemberItem> items = new Dictionary <string, AMemberItem>(); AMemberItem HandleTypeItem(XElement typeElement) { string parentNamespace = typeElement.GetNamespace(); if (!items.TryGetValue($"{TypeItem.Id}{parentNamespace}", out AMemberItem parent) && !items.TryGetValue($"{NamespaceItem.Id}{parentNamespace}", out parent)) { parent = new NamespaceItem(parentNamespace); items.Add($"{NamespaceItem.Id}{parent.Name}", parent); } TypeItem typeItem = new TypeItem(parent, typeElement); items.Add(typeElement.GetFullName(), typeItem); return(typeItem); } foreach (XElement element in document.GetMembers().Where(e => e.GetFullName().StartsWith(TypeItem.Id))) { HandleTypeItem(element); } foreach (XElement element in document.GetMembers().Where(e => !e.GetFullName().StartsWith(TypeItem.Id))) { string parentFullName = element.GetNamespace(); if (!items.TryGetValue($"{TypeItem.Id}{parentFullName}", out AMemberItem parent)) { parent = HandleTypeItem(TypeItem.CreateEmptyXElement(parentFullName)); } AMemberItem newItem; string fullName = element.GetFullName(); if (fullName.StartsWith(FieldItem.Id)) { newItem = new FieldItem(parent, element); } else if (fullName.StartsWith(PropertyItem.Id)) { newItem = fullName.EndsWith(")") ? new IndexItem(new MethodItem(parent, element)) : new PropertyItem(parent, element) as AMemberItem; } else if (fullName.StartsWith(MethodItem.Id)) { newItem = new MethodItem(parent, element); newItem = newItem.Name.StartsWith("#") ? new ConstructorItem(newItem as MethodItem) : OperatorItem.HandleOperator(newItem as MethodItem); } else if (fullName.StartsWith(EventItem.Id)) { newItem = new EventItem(parent, element); } else { throw new Exception($"unhandled doc item {fullName}"); } items.Add(fullName, newItem); } return(items); }
private void BuildMethods(CoverageReport.MethodDescriptor[] mdList, ClassItem classItem) { foreach (CoverageReport.MethodDescriptor md in mdList) { MethodItem mdItem = new MethodItem(md, classItem); BuildMethodBlocks(md, mdItem); classItem.AddMethod(mdItem); } }
/// <summary> /// Makes a new item. /// </summary> /// <param name="exception">The exception.</param> /// <param name="method">The method.</param> /// <param name="group">The group.</param> /// <returns></returns> protected ItemInfo MakeItem(ThrownException exception, Method method = null, ListViewGroup group = null) { bool isMethod = (method != null); bool isProperty = isMethod && method.MethodBase.IsProperty(); bool isThrow = !isMethod && (exception != null); if (!isMethod) { method = exception.Method; } ListViewItem item; PropertyInfo pi = null; if (isProperty) { bool getter = method.MethodBase.Name.StartsWith("get_"); pi = method.MethodBase.GetMethodProperty(); item = new ListViewItem(string.Format(CultureInfo.InvariantCulture, "{0} ({1})", pi.Name, getter ? "get" : "set")); } else { item = new ListViewItem(method.ToString()); } if (isProperty) { item.ImageKey = NodeInfo.ImageKeyFromObject(pi); } else if (isMethod) { // use the method for the icon item.ImageKey = NodeInfo.ImageKeyFromObject(method.MethodBase); } else { // use the exception for the icon item.ImageKey = NodeInfo.ImageKeyFromObject(exception.Exception); } ItemInfo info; MethodItem me = new MethodItem(method, exception); if (exception == null) { info = new ItemInfo(item, me, NodeType.Method); item.SubItems.Add(""); } else { info = new ItemInfo(item, me, NodeType.Method); info.Expandable = !isThrow; item.SubItems.Add(exception.Exception.Name); } item.Tag = info; item.SubItems.Add(method.MethodBase.DeclaringType.Name); item.SubItems.Add(method.MethodBase.DeclaringType.Module.Name); item.IndentCount = 1; if (group != null) { item.Group = group; } return info; }
private string GetRootModel(int tab, MethodItem methodItem) { var sb = new StringBuilder(); tab++; var className = methodItem.RequestUri.Split('/').Skip(1).ToList(); AppendLine(sb, tab, "///<summary>"); if (!string.IsNullOrWhiteSpace(methodItem.AlertText)) { AppendLine(sb, tab, "/// " + methodItem.AlertText); } AppendLine(sb, tab, "/// " + methodItem.MethodName); AppendLine(sb, tab, "/// " + methodItem.DescriptionUrl); AppendLine(sb, tab, "///</summary>"); AppendLine(sb, tab, $@"[Method(Url=""{methodItem.RequestUri}/"")]"); AppendLine(sb, tab, $@"[DescriptionUrl(Url= ""{methodItem.DescriptionUrl}"")]"); if (methodItem.AlertText?.Trim() == "Внимание! Метод будет отключён.") { AppendLine(sb, tab, $@"[Obsolete]"); } AppendLine(sb, tab, "public class Request" + GetNormalizedName(className) + ":IRequest"); AppendLine(sb, tab, "{"); tab++; foreach (var requestField in methodItem.RequestFields) { if (requestField.FieldDescription.Contains("Внимание! Поле будет отключено.")) { continue; } var fieldName = GetNormalizedName(requestField.FieldName.Split(new[] { ',', '_' }, StringSplitOptions.RemoveEmptyEntries)); bool isRequered = false; sb.AppendLine(); AppendLine(sb, tab, "///<summary>"); if (fieldName.StartsWith("*")) { AppendLine(sb, tab, "///Обязательный параметер"); fieldName = fieldName.Substring(1); isRequered = true; } AppendLine(sb, tab, "///" + requestField.FieldDescription.Trim().Replace("\r\n", "\r\n///").Replace("\n", "\n///")); AppendLine(sb, tab, "///" + requestField.FieldType); AppendLine(sb, tab, "///</summary>"); var jsonFieldName = requestField.FieldName; if (jsonFieldName.StartsWith("*")) { jsonFieldName = jsonFieldName.Substring(1); } AppendLine(sb, tab, $@"[JsonProperty(""{jsonFieldName}"")]"); if (isRequered) { AppendLine(sb, tab, "[FieldIsMandatory]"); } Append(sb, tab, "public "); sb.Append("string"); sb.Append(" "); sb.Append(GetNormalizedName(new[] { fieldName })); sb.AppendLine(" {get; set;}"); } tab--; AppendLine(sb, tab, "}"); AppendLine(sb, tab, ""); AppendLine(sb, tab, "///<summary>"); AppendLine(sb, tab, "///" + methodItem.MethodName); AppendLine(sb, tab, "///</summary>"); AppendLine(sb, tab, "public class Response" + GetNormalizedName(className) + ":IResponse"); AppendLine(sb, tab, "{"); tab++; foreach (var responseField in methodItem.RootResponse.ResponseFieldItems) { if (responseField.FieldDescription.Contains("Внимание! Поле будет отключено.")) { continue; } var fieldName = GetNormalizedName(responseField.FieldName.Split(new[] { ',', '_' }, StringSplitOptions.RemoveEmptyEntries)); sb.AppendLine(); AppendLine(sb, tab, "///<summary>"); AppendLine(sb, tab, "///" + responseField.FieldDescription.Trim().Replace("\r\n", "\r\n///").Replace("\n", "\n///")); AppendLine(sb, tab, "///</summary>"); AppendLine(sb, tab, $@"[JsonProperty(""{responseField.FieldName}"")]"); Append(sb, tab, "public "); sb.Append(GetTypeString(responseField.FieldType)); sb.Append(" "); sb.Append(fieldName); sb.AppendLine(" {get; set;}"); } var subClass = new StringBuilder(); foreach (var chieldClass in methodItem.RootResponse.ResponseClasses.Values) { if (chieldClass.ClassDescription.Contains("Внимание! Поле будет отключено.")) { continue; } var createClassModel = GetClass(GetNormalizedName(className), chieldClass); var typeName = createClassModel.Item1; var classModel = createClassModel.Item2; subClass.Append(classModel); var fieldName = GetNormalizedName(chieldClass.ClassName.Split(new[] { ',', '_' }, StringSplitOptions.RemoveEmptyEntries)); sb.AppendLine(); AppendLine(sb, tab, "///<summary>"); AppendLine(sb, tab, "///" + chieldClass.ClassDescription.Trim().Replace("\r\n", "\r\n///").Replace("\n", "\n///")); AppendLine(sb, tab, "///</summary>"); AppendLine(sb, tab, $@"[JsonProperty(""{chieldClass.ClassName}"")]"); Append(sb, tab, "public "); sb.Append(typeName); sb.Append(" "); sb.Append(fieldName); sb.AppendLine(" {get; set;}"); } tab--; AppendLine(sb, tab, "}"); tab--; AppendLine(sb, tab, subClass.ToString()); return(sb.ToString()); }
private void RunTest(MethodItem item, Action callback) { // Invoke the test. Invoke(item); // Execute next test in sequence. var next = methods.NextItem(item, false); if (next != null) { DelayedRunTest(next, callback); } else { if (callback != null) callback(); } }
private void Invoke(MethodItem item) { // Setup initial conditions. if (!item.Method.Attribute.AllowAutoRun) return; try { // Reset the test-class. This will cause the Default initialize method to be invoked. item.TestClass.Reload(); // NB: The 'DefaultViewTest' is exeuted during the 'Reload()' operation. var method = item.Method; if (method != item.TestClass.DefaultViewTest) method.Execute(); // Log success. passed.Add(item.MethodInfo); } catch (Exception) { failed.Add(item.MethodInfo); } }
private void DelayedRunTest(MethodItem item, Action callback) { DelayedAction.Invoke(Interval, () => RunTest(item, callback)); }
public void SetMethodInformation(System.Reflection.MethodInfo[] methods, string selectedMethodName, ParameterCollection selectedParameters, DataObjectMethodType methodType, System.Type dataObjectType) { try { this._signatureTextBox.Text = string.Empty; switch (methodType) { case DataObjectMethodType.Select: this._helpLabel.Text = System.Design.SR.GetString("ObjectDataSourceMethodEditor_SelectHelpLabel"); break; case DataObjectMethodType.Update: this._helpLabel.Text = System.Design.SR.GetString("ObjectDataSourceMethodEditor_UpdateHelpLabel"); break; case DataObjectMethodType.Insert: this._helpLabel.Text = System.Design.SR.GetString("ObjectDataSourceMethodEditor_InsertHelpLabel"); break; case DataObjectMethodType.Delete: this._helpLabel.Text = System.Design.SR.GetString("ObjectDataSourceMethodEditor_DeleteHelpLabel"); break; } this._methodComboBox.BeginUpdate(); this._methodComboBox.Items.Clear(); MethodItem item = null; bool flag = false; foreach (System.Reflection.MethodInfo info in methods) { if (this.FilterMethod(info, methodType)) { bool flag2 = false; DataObjectMethodAttribute attribute = Attribute.GetCustomAttribute(info, typeof(DataObjectMethodAttribute), true) as DataObjectMethodAttribute; if ((attribute != null) && (attribute.MethodType == methodType)) { if (!flag) { this._methodComboBox.Items.Clear(); } flag = true; flag2 = true; } else if (!flag) { flag2 = true; } bool flag3 = ObjectDataSourceDesigner.IsMatchingMethod(info, selectedMethodName, selectedParameters, dataObjectType); if (flag2 || flag3) { MethodItem item2 = new MethodItem(info); this._methodComboBox.Items.Add(item2); if (flag3) { item = item2; } else if (((attribute != null) && (attribute.MethodType == methodType)) && (attribute.IsDefault && (selectedMethodName.Length == 0))) { item = item2; } } } } if (methodType != DataObjectMethodType.Select) { this._methodComboBox.Items.Insert(0, new MethodItem(null)); } this._methodComboBox.InvalidateDropDownWidth(); this._methodComboBox.SelectedItem = item; } finally { this._methodComboBox.EndUpdate(); } }
protected virtual void OnShowSource(MethodItem methodItem) { ShowSourceEventArgs e = new ShowSourceEventArgs (); e.methodItem = methodItem; OnShowSource (e); }
static public void TypeInstantiated(Type type) { var _isMethod = type.DeclaringType != null && type.DeclaringType.Name == "<Intermediate>"; Item _item; MethodBase _genericTypeDefinitionMethod = null; MethodBase _constructedGenericTypeMethod = null; // possible a generic method definition MethodBase _constructedgenericMethod = null; int _neptuneMethodIndex = NeptuneMethodIndexUninitialized; if (_isMethod) { _neptuneMethodIndex = (int)type.GetField("<NeptuneMethodIndex>").GetValue(null); var _intermediate = type.DeclaringType; var _neptune = _intermediate.DeclaringType; var _targetType = _neptune.DeclaringType; var _genericArguments = type.GetGenericArguments(); var _typeArgumentCount = 0; if (_targetType.IsGenericTypeDefinition) { _genericTypeDefinitionMethod = GetTypeDefinitionItem(_targetType).Methods[_neptuneMethodIndex]; _typeArgumentCount = _targetType.GetGenericArguments().Length; _targetType = _targetType.MakeGenericType(_genericArguments.Subarray(0, _typeArgumentCount)); } var _typeItem = GetTypeItem(_targetType); _constructedGenericTypeMethod = _typeItem.Methods[_neptuneMethodIndex]; _typeItem.InvokedMethods[_neptuneMethodIndex] = true; if (_constructedGenericTypeMethod.IsGenericMethodDefinition) { var _typeArguments = _targetType.IsGenericType ? _genericArguments.Subarray(_typeArgumentCount) : _genericArguments; _constructedgenericMethod = ((MethodInfo)_constructedGenericTypeMethod).MakeGenericMethod(_typeArguments); GetGenericMethodDefinitionItem(_constructedGenericTypeMethod).ConstructedMethods.Add(_constructedgenericMethod); _item = new GenericMethodItem(_constructedgenericMethod, _neptuneMethodIndex); } else { _item = new MethodItem(_constructedGenericTypeMethod, _neptuneMethodIndex); } } else { _item = GetTypeItem(type); if (!type.IsGenericType) { return; } } m_ReadWriteLock.EnterReadLock(); try { if (_genericTypeDefinitionMethod != null && Aspect.Directory.ContainsKey(_genericTypeDefinitionMethod)) { Aspect.Directory.Register(_constructedGenericTypeMethod, _neptuneMethodIndex); } if (_constructedgenericMethod != null && Aspect.Directory.ContainsKey(_constructedGenericTypeMethod)) { Aspect.Directory.Register(_constructedgenericMethod, _neptuneMethodIndex); } foreach (var _weaver in m_ClosedWeavers) { _item.Weave(_weaver); } lock (m_Lock) { Extend(ref m_ConstructedGenerics, _item); } } finally { m_ReadWriteLock.ExitReadLock(); } }
private void xamDataGrid_RecordUpdated(object sender, Infragistics.Windows.DataPresenter.Events.RecordUpdatedEventArgs e) { if (e.Record.Tag == null) { return; } if (((string)e.Record.Tag).Equals("AddRecord")) // is this the "AddRecord"? { if (e.Record.DataItem.GetType() == typeof(MethodItem)) { DataRecord methodRecord = (DataRecord)e.Record; MethodItem mi = ((MethodItem)(methodRecord.DataItem)); MethodContainer newMethod = new MethodContainer(); newMethod.Description = mi.Description; newMethod.OwnerID = mi.OwnerID; newMethod.BravoMethodFile = mi.BravoMethodFile; newMethod.IsPublic = mi.IsPublic; bool success = wgDB.InsertMethod(ref newMethod); if (success) { mi.MethodID = newMethod.MethodID; UnMarkAddNewRecord(methodRecord); MethodItem miNew = new MethodItem(); miNew.Description = ""; miNew.MethodID = mi.MethodID; miNew.OwnerID = mi.OwnerID; miNew.IsPublic = false; miNew.BravoMethodFile = ""; VM.Methods.Insert(0, miNew); // mark the new Method as the AddRecord RecordCollectionBase coll = e.Record.ParentCollection; DataRecord newMethodRecord = (DataRecord)coll.ElementAt(0); MarkAddNewRecord(newMethodRecord); // add the AddRecord Indicator for this new method ObservableCollection <FilterContainer> exFilts = VM.ExcitationFilters; ObservableCollection <FilterContainer> emFilts = VM.EmissionsFilters; ObservableCollection <SignalTypeContainer> stList = VM.SignalTypeList; IndicatorItem ii = new IndicatorItem(0, mi.MethodID, "", ref stList, ref exFilts, ref emFilts); mi.Indicators.Add(ii); // mark the new Indicator as the AddRecord ExpandableFieldRecord expRecord = (ExpandableFieldRecord)methodRecord.ChildRecords[0]; DataRecord indicatorRecord = (DataRecord)expRecord.ChildRecords[0]; if (indicatorRecord.DataItem.GetType() == typeof(IndicatorItem)) { MarkAddNewRecord(indicatorRecord); } // add the AddRecord CompoundPlate for this new method CompoundPlateItem cpi = new CompoundPlateItem(); cpi.CompoundPlateID = 0; cpi.MethodID = mi.MethodID; cpi.Description = ""; mi.CompoundPlates.Add(cpi); // mark the new CompoundPlate as the AddRecord ExpandableFieldRecord expRecord1 = (ExpandableFieldRecord)methodRecord.ChildRecords[1]; DataRecord compoundPlateRecord = (DataRecord)expRecord1.ChildRecords[0]; if (compoundPlateRecord.DataItem.GetType() == typeof(CompoundPlateItem)) { MarkAddNewRecord(compoundPlateRecord); } } } else if (e.Record.DataItem.GetType() == typeof(IndicatorItem)) { IndicatorItem ii = (IndicatorItem)(e.Record.DataItem); IndicatorContainer ic = new IndicatorContainer(); ic.Description = ii.Description; ic.MethodID = ii.MethodID; ic.IndicatorID = ii.IndicatorID; ic.ExcitationFilterPosition = ii.ExcitationFilterPosition; ic.EmissionsFilterPosition = ii.EmissionsFilterPosition; ic.SignalType = ii.SignalType; bool success = wgDB.InsertIndicator(ref ic); if (success) { ii.IndicatorID = ic.IndicatorID; UnMarkAddNewRecord(e.Record); ObservableCollection <FilterContainer> exFilts = VM.ExcitationFilters; ObservableCollection <FilterContainer> emFilts = VM.EmissionsFilters; ObservableCollection <SignalTypeContainer> stList = VM.SignalTypeList; IndicatorItem iiNew = new IndicatorItem(0, ic.MethodID, "", ref stList, ref exFilts, ref emFilts); MethodItem mi = (MethodItem)(((DataRecord)e.Record.ParentRecord.ParentRecord).DataItem); mi.Indicators.Insert(0, iiNew); DataRecord newIndicatorRecord = (DataRecord)e.Record.ParentCollection[0]; MarkAddNewRecord(newIndicatorRecord); } } else if (e.Record.DataItem.GetType() == typeof(CompoundPlateItem)) { CompoundPlateItem cpi = (CompoundPlateItem)(e.Record.DataItem); CompoundPlateContainer cpc = new CompoundPlateContainer(); cpc.CompoundPlateID = cpi.CompoundPlateID; cpc.Description = cpi.Description; cpc.MethodID = cpi.MethodID; bool success = wgDB.InsertCompoundPlate(ref cpc); if (success) { cpi.CompoundPlateID = cpc.CompoundPlateID; UnMarkAddNewRecord(e.Record); CompoundPlateItem cpiNew = new CompoundPlateItem(); cpiNew.Description = ""; cpiNew.CompoundPlateID = 0; cpiNew.MethodID = cpc.MethodID; MethodItem mi = (MethodItem)(((DataRecord)e.Record.ParentRecord.ParentRecord).DataItem); mi.CompoundPlates.Insert(0, cpiNew); DataRecord newCompoundPlateRecord = (DataRecord)e.Record.ParentCollection[0]; MarkAddNewRecord(newCompoundPlateRecord); } } } }
public async Task <MethodItem> ExtractMethodItem() { var methodItem = new MethodItem(); methodItem.DescriptionUrl = MyWebBrowser.Address; methodItem.MethodName = await GetFromJquerySelector("#name"); methodItem.DescriptionPath = await GetFromJquerySelector("body>div>div.b-content.clearfix>div.b-content-column>div.b-page-header.js-page-header>div>span"); methodItem.AlertText = await GetFromJquerySelector("body > div > div.b-content.clearfix > div.b-content-column > div.b-maincontent.clearfix.js-maincontent > div.b-alert > div"); var len = await GetFromJS <int>("$('body > div > div.b-content.clearfix > div.b-content-column > div.b-maincontent.clearfix.js-maincontent > table > tbody>tr').length"); for (var i = 1; i <= len; i++) { var key = await GetFromJquerySelector($"body>div>div.b-content.clearfix>div.b-content-column>div.b-maincontent.clearfix.js-maincontent>table>tbody>tr:nth-child({i})>td:nth-child(1)"); var value = await GetFromJquerySelector($"body>div>div.b-content.clearfix>div.b-content-column>div.b-maincontent.clearfix.js-maincontent>table>tbody>tr:nth-child({i})>td:nth-child(2)"); if (key == "URI") { methodItem.RequestUri = value; } if (key == "Протокол запроса") { methodItem.SupportedProtocol = value; } if (key == "Метод запроса") { methodItem.SupportedHttpMethod = value; } } var requestParamLen = await GetFromJS <int>("$('#parameters_block > table > tbody > tr').length"); for (var i = 1; i <= requestParamLen; i++) { var requestItem = new RequestFieldItem(); requestItem.FieldName = await GetFromJquerySelector($"#parameters_block > table > tbody > tr:nth-child({i}) > td:nth-child(1)"); requestItem.FieldType = await GetFromJquerySelector($"#parameters_block > table > tbody > tr:nth-child({i}) > td:nth-child(2)"); requestItem.FieldDescription = await GetFromJquerySelector($"#parameters_block > table > tbody > tr:nth-child({i}) > td:nth-child(3)"); methodItem.RequestFields.Add(requestItem); AllHashTypes.Add("req: " + requestItem.FieldType); } var responseParamLen = await GetFromJS <int>("$('#response_block > table > tbody > tr').length"); for (var i = 1; i <= responseParamLen; i++) { var fieldName = (await GetFromJquerySelector($"#response_block > table > tbody > tr:nth-child({i}) > td:nth-child(1)")).Trim(); var fieldType = (await GetFromJquerySelector($"#response_block > table > tbody > tr:nth-child({i}) > td:nth-child(2)")).Trim(); var fieldDescription = (await GetFromJquerySelector($"#response_block > table > tbody > tr:nth-child({i}) > td:nth-child(3)")).Trim(); if (string.IsNullOrWhiteSpace(fieldType) && string.IsNullOrWhiteSpace(fieldName) && string.IsNullOrWhiteSpace(fieldDescription)) { continue; } var getKeys = GetClassKeys(fieldName); var responseClass = methodItem.RootResponse; foreach (var key in getKeys) { responseClass = responseClass.ResponseClasses[key]; } if (!string.IsNullOrWhiteSpace(fieldName) && string.IsNullOrWhiteSpace(fieldDescription)) { var className = GetClassName(fieldName); responseClass.ResponseClasses[className] = new ResponseClass() { ClassName = className, ClassDescription = fieldType }; } else { var responseItem = new ResponseFieldItem() { FieldName = GetClassName(fieldName), FieldType = fieldType, FieldDescription = fieldDescription }; responseClass.ResponseFieldItems.Add(responseItem); AllHashTypes.Add("res: " + fieldType); } } return(methodItem); }
public void AddMethod(MethodItem item) { methods.Add(item); }
internal virtual string GetMethodInformation(MethodItem method) { return(method.Name); }
private void onMethodChanged(object sender, System.EventArgs e) { MethodItem mi = (MethodItem)m_methodCB.SelectedItem; m_combo.MatchingMethod = mi.Value; }
public MethodManager() { InitializeComponent(); wgDB = new WaveguideDB(); VM = new MethodManagerViewModel(); RefreshSignalTypeList(); RefreshFilterList(); //Initialize data in the XamDataGrid - NOTE: A blank record is added FIRST, this is key to this approach for the XamDataGrid MethodItem blank = new MethodItem(); blank.Description = ""; blank.BravoMethodFile = ""; blank.OwnerID = GlobalVars.UserID; blank.MethodID = 0; blank.IsPublic = false; VM.Methods.Add(blank); // load all methods for user bool success = wgDB.GetAllMethodsForUser(GlobalVars.UserID); if (success) { foreach (MethodContainer mc in wgDB.m_methodList) { MethodItem mi = new MethodItem(); mi.Description = mc.Description; mi.BravoMethodFile = mc.BravoMethodFile; mi.OwnerID = mc.OwnerID; mi.MethodID = mc.MethodID; mi.IsPublic = mc.IsPublic; VM.Methods.Add(mi); // load all indicators for the method // add blank Indicator container to hold the AddRecord ObservableCollection <FilterContainer> exFilts = VM.ExcitationFilters; ObservableCollection <FilterContainer> emFilts = VM.EmissionsFilters; ObservableCollection <SignalTypeContainer> stList = VM.SignalTypeList; IndicatorItem blankInd = new IndicatorItem(0, mi.MethodID, "", ref stList, ref exFilts, ref emFilts); mi.Indicators.Add(blankInd); success = wgDB.GetAllIndicatorsForMethod(mc.MethodID); if (success) { foreach (IndicatorContainer ic in wgDB.m_indicatorList) { IndicatorItem ii = new IndicatorItem(ic.IndicatorID, ic.MethodID, ic.Description, ic.ExcitationFilterPosition, ic.EmissionsFilterPosition, ic.SignalType, ref stList, ref exFilts, ref emFilts); mi.Indicators.Add(ii); } } // load all compound plates for the method // add blank Compound Plate container to hold the AddRecord CompoundPlateItem blankCP = new CompoundPlateItem(); blankCP.CompoundPlateID = 0; blankCP.MethodID = mi.MethodID; blankCP.Description = ""; mi.CompoundPlates.Add(blankCP); success = wgDB.GetAllCompoundPlatesForMethod(mc.MethodID); if (success) { foreach (CompoundPlateContainer cpc in wgDB.m_compoundPlateList) { CompoundPlateItem cpi = new CompoundPlateItem(); cpi.CompoundPlateID = cpc.CompoundPlateID; cpi.MethodID = cpc.MethodID; cpi.Description = cpc.Description; mi.CompoundPlates.Add(cpi); } } } } xamDataGrid.DataContext = VM; }
private void ReflectAssembly(AssemblyItem assemblyItem, Assembly asm, bool invert) { string ns; NamespaceItem nsItem; Dictionary<string, NamespaceItem> nsItems = new Dictionary<string, NamespaceItem>(); // Add the assembly item itself to the lookup. _projectBrowser.AddLookup(assemblyItem, assemblyItem.GetID(), invert); try { Type[] types = asm.GetTypes(); } catch (ReflectionTypeLoadException exc) { _logView.LogExcStr(exc, "Failed to call GetTypes on " + asm.FullName); return; } foreach (Type t in asm.GetTypes()) { ns = t.Namespace; if (string.IsNullOrEmpty(ns)) ns = "(none)"; if (!nsItems.ContainsKey(ns)) { nsItem = new NamespaceItem(ns, assemblyItem); nsItems.Add(ns, nsItem); assemblyItem.NameSpaces.Add(nsItem); _projectBrowser.AddLookup(nsItem, nsItem.GetID(), invert); } else { nsItem = nsItems[ns]; } // Flatten nested types. string name = t.Name; if (t.IsNested) { // Flat with .id'd name. Type parentType = t.DeclaringType; while (parentType != null) { name = parentType.Name + "." + name; parentType = parentType.DeclaringType; } } try { TypeItem typeItem = new TypeItem(name, t.FullName, t, nsItem); nsItem.Types.Add(typeItem); _projectBrowser.AddLookup(typeItem, typeItem.GetID(), invert); foreach (MethodInfo mi in GetMethods(typeItem)) { MethodItem methodItem = new MethodItem(mi.Name, mi, typeItem); typeItem.Methods.Add(methodItem); _projectBrowser.AddLookup(methodItem, methodItem.GetID(), invert); } // Get the list of implemented interfaces. typeItem.Implements = GetImplementedInterfaces(typeItem); if (typeItem.TypeRef.BaseType != null) { typeItem.InheritsFrom = typeItem.TypeRef.BaseType.ToString(); } else { typeItem.InheritsFrom = null; } } catch (Exception exc) { _logView.LogExcStr(exc, "Generic Types issue?"); } } }
private static Type ImplementMethodDelegate(string assemblyName, ModuleBuilder moduleBuilder, MethodItem method) { // Consts const MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual; // Initial var delegateName = GetDelegateName(assemblyName, method.Info); var delegateBuilder = moduleBuilder.DefineType(delegateName, TypeAttributes.Public | TypeAttributes.AutoClass | TypeAttributes.Sealed, typeof(MulticastDelegate)); // UnmanagedFunctionPointer var importAttribute = method.DllImportAttribute; var attributeCtor = typeof(UnmanagedFunctionPointerAttribute).GetConstructor(new[] { typeof(CallingConvention) }); if (attributeCtor == null) { throw new Exception("There is no the target constructor of the UnmanagedFunctionPointerAttribute"); } var attributeBuilder = new CustomAttributeBuilder(attributeCtor, new object[] { importAttribute.CallingConvention }, new[] { typeof(UnmanagedFunctionPointerAttribute).GetField("CharSet"), typeof(UnmanagedFunctionPointerAttribute).GetField("BestFitMapping"), typeof(UnmanagedFunctionPointerAttribute).GetField("ThrowOnUnmappableChar"), typeof(UnmanagedFunctionPointerAttribute).GetField("SetLastError") }, new object[] { importAttribute.CharSet, importAttribute.BestFitMapping, importAttribute.ThrowOnUnmappableChar, importAttribute.SetLastError }); delegateBuilder.SetCustomAttribute(attributeBuilder); // ctor var ctorBuilder = delegateBuilder.DefineConstructor(MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new[] { typeof(object), typeof(IntPtr) }); ctorBuilder.SetImplementationFlags(MethodImplAttributes.CodeTypeMask); ctorBuilder.DefineParameter(1, ParameterAttributes.HasDefault, "object"); ctorBuilder.DefineParameter(2, ParameterAttributes.HasDefault, "method"); // Invoke var parameters = GetParameterInfoArray(method.Info); var methodBuilder = DefineMethod(delegateBuilder, "Invoke", methodAttributes, method.ReturnType, parameters); methodBuilder.SetImplementationFlags(MethodImplAttributes.CodeTypeMask); // BeginInvoke parameters = GetParameterInfoArray(method.Info, InfoArrayMode.BeginInvoke); methodBuilder = DefineMethod(delegateBuilder, "BeginInvoke", methodAttributes, typeof(IAsyncResult), parameters); methodBuilder.SetImplementationFlags(MethodImplAttributes.CodeTypeMask); // EndInvoke parameters = GetParameterInfoArray(method.Info, InfoArrayMode.EndInvoke); methodBuilder = DefineMethod(delegateBuilder, "EndInvoke", methodAttributes, method.ReturnType, parameters); methodBuilder.SetImplementationFlags(MethodImplAttributes.CodeTypeMask); // Create type return(delegateBuilder.CreateType()); }
internal virtual string GetMethodInformation(MethodItem method) => method.Name;