public static bool IsParamsValid(this SqlServerRequestHandler Handler, HttpMethod Method, HttpContext Context) { bool IsValid = false; string[] RequiredParameters; if (Method.Equals(HttpMethod.Post)) { RequiredParameters = new string[] { "EntryKey", "StoreUsername", "EntryName", "EntryUse" } } ; else { RequiredParameters = new string[] { "EntryKey", "StoreUsername" } }; foreach (string Parameter in RequiredParameters) { if (Context.Request.Query.TryGetValue(Parameter, out var ParamValue)) { if (!ParamValue.ToString().Equals("")) { IsValid = true; } } } return(IsValid); }
ParamValue Node2ParamValue(XmlNode node, ParamType type) { ParamValue param = new ParamValue(type); param.SetValue(node.InnerText, stringToHashLabels); return(param); }
private static void AddValue(Update update, ApplicationDbContext _context, QuestionTreeHistory lastAskedQuestionOfScenario, Question question, Param param, ParamValue paramValue) { var paramValueId = Guid.NewGuid(); if (param.HasUnit) { if (paramValue != null && !string.IsNullOrEmpty(paramValue.Value)) { paramValue.Unit = update.Message.Text; } } if (paramValue == null) { var paramVlaue = new ParamValue() { Id = paramValueId, ParamId = param.Id, QuestionId = question.Id, Value = update.Message.Text, MedcinId = lastAskedQuestionOfScenario.MedcinId, DateTimeCreate = DateTimeOffset.Now }; _context.Add(paramVlaue); var medcinParam = new MedcinParam() { Id = Guid.NewGuid(), MedcinId = lastAskedQuestionOfScenario.MedcinId, ParamsValueId = paramValueId }; _context.Add(medcinParam); } }
private static ParamValue WriteComplexType(List <ControlView> property, Guid g) { ParamValue paramValue = new ParamValue { Guid = g.ToString(), Param = new Dictionary <string, string>() }; foreach (ControlView cv in property) { if (cv.IsDictionary) { paramValue.Order = cv.DControlView.Order; GetDictinaryItemIm(cv, paramValue); } else if (cv.IsList) { paramValue.Order = cv.LControlView.Order; GetArrayItemIm(cv, paramValue); } else if (cv.IsPrimitive) { paramValue.Order = cv.PControlView.Order; paramValue.Param.Add(cv.PControlView.FieldName, cv.PControlView.FieldValue); } else { GetComplexItemIm(paramValue, cv); } } return(paramValue); }
/// <summary> /// Get the parameter object /// </summary> /// <param name="controlViewBindingObject">controls list to populate</param> /// <param name="mParameter">parameter info</param> /// <param name="parameterOrder">parameter order in method</param> /// <param name="paramValue">param value from xml</param> private static void GetParameter(ObservableCollection <ControlView> controlViewBindingObject, ParameterInfo mParameter, int parameterOrder, string guid, ParamValue paramValue = null) { //for dictionary if (mParameter.ParameterType.Name.ToLower() == "dictionary`2" && mParameter.ParameterType.IsGenericType && mParameter.ParameterType.GenericTypeArguments != null && mParameter.ParameterType.GenericTypeArguments.Length == 2) { var arrayObject = GetDictionaryObject(mParameter, parameterOrder, guid, paramValue); controlViewBindingObject.Add(arrayObject); } //for list else if (mParameter.ParameterType.IsArray) { var arrayObject = GetArrayObject(mParameter, parameterOrder, guid, paramValue); controlViewBindingObject.Add(arrayObject); } else if (!mParameter.ParameterType.IsPrimitive && !PrimitiveTypes.Test(mParameter.ParameterType)) { var complexObject = GetComplexObject(mParameter, parameterOrder, guid, paramValue); controlViewBindingObject.Add(complexObject); } else { var primitiveObject = GetPrimitiveObject(mParameter, parameterOrder, guid, paramValue); controlViewBindingObject.Add(primitiveObject); } }
public static ParamValueDTO createParamValueDTO(ParamValue source) { if (null == source) { return(null); } ParamValueDTO result = new ParamValueDTO(); // lookup static metadata about result parameter ParameterMetadata metadataLookup = new ParameterMetadata(); ParameterMetadataEntry data = metadataLookup.fetchMetadata(source.param_id); if (null != data) { result.DisplayName = data.DisplayName; result.Description = data.Description; result.Units = data.Units; result.Upper = data.Upper; result.Lower = data.Lower; } result.param_type = source.param_type.ToString(); result.param_value = source.param_value; result.param_index = source.param_index; result.param_id = source.param_id; result.param_count = source.param_count; return(result); }
private static void GetComplexItemIm(ParamValue paramValue, ControlView property) { Guid g = Guid.NewGuid(); paramValue.Param.Add(property.CControlView.FieldName, g.ToString()); paramValue.GuidValues.Add(WriteComplexType(property.CControlView.Properties.ToList(), g)); }
private static bool PropertyImageSet <T>(T entity, ParamValue property, PropertyInfo propertyInfo) { if (property.ImageValue != null && property.ImageValue.ContentLength > 0) { if (propertyInfo.GetCustomAttributes(typeof(ImageTypeAttribute), true).Length > 0) { var imgName = Guid.NewGuid() + "_" + property.ImageValue.FileName; var fileName = Path.GetFileName(imgName); var folder = Path.Combine(HttpContext.Current.Server.MapPath("~//upload/site-img")); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); UploadImagePath(entity, property, propertyInfo, imgName, fileName); } else { UploadImagePath(entity, property, propertyInfo, imgName, fileName); } return(true); } } return(false); }
private static void PropertyValueSet <T>(T entity, ParamValue property, PropertyInfo propertyInfo) { try { if (propertyInfo.PropertyType == typeof(System.Guid)) { propertyInfo.SetValue(entity, new Guid(property.Value.ToString()), null); return; } if (propertyInfo.PropertyType == typeof(System.Boolean)) { if (property.Value.Equals("true,false")) { propertyInfo.SetValue(entity, true, null); return; } propertyInfo.SetValue(entity, Convert.ToBoolean(property.Value), null); return; } if (property.Value != null && !string.IsNullOrEmpty(property.Value.ToString())) { propertyInfo.SetValue(entity, Convert.ChangeType(property.Value, propertyInfo.PropertyType), null); } } catch { } }
public void SetParameterValue(string ParamName, string ParamValue, bool localize = true) { bool flag = false; int i = 0; for (int count = _Params.Count; i < count; i++) { if (_Params[i].Name == ParamName) { ParamValue value = _Params[i]; value.Value = ParamValue; _Params[i] = value; flag = true; break; } } if (!flag) { _Params.Add(new ParamValue { Name = ParamName, Value = ParamValue }); } if (localize) { OnLocalize(); } }
public void CheckParameterValueObject() { MAVLink.mavlink_param_value_t data = new MAVLink.mavlink_param_value_t(); data.param_count = 1; data.param_id = Encoding.ASCII.GetBytes("foo"); data.param_index = 3; data.param_type = 4; data.param_value = 5; MavLinkMessage message = createSampleMessage(MAVLink.MAVLINK_MSG_ID.PARAM_VALUE, data); ParamValue obj = new ParamValue(message); Assert.AreEqual(obj.param_count, data.param_count); Assert.AreEqual(Encoding.ASCII.GetBytes(obj.param_id)[0], data.param_id[0]); Assert.AreEqual(obj.param_index, data.param_index); Assert.AreEqual((int)obj.param_type, data.param_type); Assert.AreEqual(obj.param_value, data.param_value); ParamValueDTO dto = DTOFactory.createParamValueDTO(obj); Assert.AreEqual(dto.param_count, obj.param_count); Assert.AreEqual(dto.param_id, obj.param_id); Assert.AreEqual(dto.param_index, obj.param_index); Assert.AreEqual(dto.param_type, obj.param_type.ToString()); Assert.AreEqual(dto.param_value, obj.param_value); }
void processMessage(MavLinkMessage message) { try { if (null == message) { logger.Error("Failed to parse MavLinkMessage from JSON in events callback"); return; } // store message in currentState Dictionary this.currentState[(MAVLink.MAVLINK_MSG_ID)message.messid] = message; // commands wait for their ack events and fetch them from these queues if (message.messid.Equals(MAVLink.MAVLINK_MSG_ID.COMMAND_ACK)) { CommandAck cmdack = new CommandAck(message); if (!this.commandAckStacks.ContainsKey(cmdack.command)) { this.commandAckStacks[cmdack.command] = new Stack <CommandAck>(); } lock (commandAckStacks[cmdack.command]) { this.commandAckStacks[cmdack.command].Push(cmdack); } } if (message.messid.Equals(MAVLink.MAVLINK_MSG_ID.HEARTBEAT)) { logger.Trace("Heartbeat received on port {0} {1}", connection.portName(), JsonConvert.SerializeObject(message)); } if (null == parameters) { parameters = new Dictionary <String, ParamValue>(); this.connection.sendParamsListRequest(); } if ((message.messid.Equals(MAVLink.MAVLINK_MSG_ID.PARAM_VALUE)) && (null != parameters)) { lock (parameters) { // set this value in the global parameter set ParamValue param = new ParamValue(message); parameterReceived(param); // set this object in case there is a thread waiting on a param_value 'ack' message on a param set request if (!parameterSetAckObj.ContainsKey(param.param_id)) { parameterSetAckObj.Add(param.param_id, param); } } } } catch (Exception e) { logger.Error("Failure in parsing message, exception with message {0}", e.Message); } }
XmlNode ParamValue2Node(ParamValue value) { XmlNode xmlNode = xml.CreateElement(value.TypeKey.ToString()); XmlText text = xml.CreateTextNode(value.ToString(hashToStringLabels)); xmlNode.AppendChild(text); return(xmlNode); }
private void WritePrc(Hash40Pairs <IParam> nodes, object inputObj, ulong hexKey, PropertyInfo inputObjPropertyInfo) { if (IsTypeAList(inputObjPropertyInfo.PropertyType)) { var newList = new ParamList(); nodes.Add(new HashValuePair <IParam>(hexKey, newList)); var inputObjList = (IEnumerable)inputObjPropertyInfo.GetValue(inputObj, null); var inputObjListProperties = GetListObjectType(inputObjList.GetType()).GetProperties(); foreach (var inputObjEntry in inputObjList) { var newStructList = new ParamStruct(); newList.Nodes.Add(newStructList); WritePrc(newStructList, inputObjEntry, inputObjListProperties); } } else if (IsTypeADictionary(inputObjPropertyInfo.PropertyType)) { var newList = new ParamList(); nodes.Add(new HashValuePair <IParam>(hexKey, newList)); var inputObjList = (IDictionary)inputObjPropertyInfo.GetValue(inputObj, null); var inputObjListProperties = GetDictionaryObjectType(inputObjList.GetType()).Item2.GetProperties(); foreach (var inputObjEntry in inputObjList.Values) { var newStructList = new ParamStruct(); newList.Nodes.Add(newStructList); WritePrc(newStructList, inputObjEntry, inputObjListProperties); } } else { var paramType = GetParamTypeFromProperty(inputObjPropertyInfo); var propertyValue = inputObjPropertyInfo.GetValue(inputObj); ParamValue newValue; if (paramType == ParamType.hash40) { if (!(propertyValue is PrcHash40 hash40Value)) { hash40Value = PrcHash40.EmptyValue; } newValue = new ParamValue(paramType, hash40Value.HexValue); } else if (propertyValue == null && paramType == ParamType.@string) { newValue = new ParamValue(paramType, string.Empty); } else { newValue = new ParamValue(paramType, propertyValue); } nodes.Add(new HashValuePair <IParam>(hexKey, newValue)); } }
public ParamValue(ParamValue p) { FullName = p.FullName; ShortName = p.ShortName; Icon = p.Icon; Max = p.Max; Min = p.Min; Step = p.Step; Level = p.Level; }
private static void UploadImagePath <T>(T entity, ParamValue property, PropertyInfo propertyInfo, string imgName, string fileName) { var path = Path.Combine(HttpContext.Current.Server.MapPath("~//upload/site-img")) + "/" + imgName; if (!Directory.Exists(path)) { property.ImageValue.SaveAs(path); propertyInfo.SetValue(entity, Convert.ChangeType(fileName, propertyInfo.PropertyType), null); } }
private static ParamValue CreateArrayItem(ControlView cv, Guid?gf = null) { ParamValue paramValue = new ParamValue { ArrayElements = new List <ParamValue>(), Param = new Dictionary <string, string>() }; if (gf != null) { paramValue.Guid = gf.Value.ToString(); } if (cv.IsDictionary) { paramValue.Order = cv.DControlView.Order; GetDictinaryItemIm(cv, paramValue); } else if (cv.IsList) { paramValue.Order = cv.LControlView.Order; GetArrayItemIm(cv, paramValue); } else if (cv.IsPrimitive) { paramValue.Order = cv.PControlView.Order; paramValue.Param.Add("value", cv.PControlView.FieldValue); } else { paramValue.Order = cv.CControlView.Order; foreach (var property in cv.CControlView.Properties) { if (property.IsDictionary) { GetDictinaryItemIm(property, paramValue); } else if (property.IsList) { GetArrayItemIm(property, paramValue); } else if (property.IsPrimitive) { paramValue.Param.Add(property.PControlView.FieldName, property.PControlView.FieldValue); } else { GetComplexItemIm(paramValue, property); } } } return(paramValue); }
/// <summary> /// Creates a new DBParam with a delegate method as the value provider (no parameters, returns object). /// NOTE: The parameter type cannot be determined if null or DBUnll is passed as the value /// </summary> /// <param name="valueprovider">The delegate method (cannot be null)</param> /// <returns></returns> /// <remarks> /// The method will be executed when any queries using this parameter are converted to their SQL statements /// </remarks> public static DBParam ParamWithDelegate(ParamValue valueprovider) { if (null == valueprovider) { throw new ArgumentNullException("valueProvider"); } DBDelegateParam del = new DBDelegateParam(valueprovider); return(del); }
public void GetParamValuebyIdTest() { List <ParamValue> values = new List <ParamValue>(); ParamBL paramBL = new ParamBL(); values = paramBL.GetParamValuesHistoryById(1); Assert.AreEqual(2, values.Count); ParamValue value = values.Find(x => x.IsActive == true); Assert.AreEqual(10, value.Value); }
public static string SqlAnd(ParamValue firstOrDefault, string sql) { if (firstOrDefault != null && firstOrDefault.Between.Any()) { var between = firstOrDefault.Between.EndsWith("AND") ? firstOrDefault.Between.Substring(0, firstOrDefault.Between.Length - 3) : firstOrDefault.Between; sql += " AND " + between; } return(sql); }
// function for processing new parameter message private void parameterReceived(ParamValue param) { if (this.parameters.ContainsKey(param.param_id)) { this.parameters[param.param_id] = param; } else { this.parameters.Add(param.param_id, param); } logger.Debug("Parameter {0} received with value {1}", param.param_id, param.param_value); }
/// <summary> /// Creates a new DBParam with a delegate method as the value provider (no parameters, returns object). /// </summary> /// <param name="type">The DbType of the parameter </param> /// <param name="valueProvider">The delegate method (cannot be null)</param> /// <returns></returns> /// <remarks> /// The valueProvider method will be executed when any queries using this parameter are converted to their SQL statements /// </remarks> public static DBParam ParamWithDelegate(System.Data.DbType type, ParamValue valueProvider) { if (null == valueProvider) { throw new ArgumentNullException("valueProvider"); } DBDelegateParam del = new DBDelegateParam(valueProvider); del.DbType = type; return(del); }
/// <summary> /// Creates a new DBParam with the specified name and a delegate method as the value provider (no parameters, returns object). /// NOTE: The parameter type cannot be determined if null or DBUnll is passed as the value /// </summary> /// <param name="genericName">The name of the parameter</param> /// <param name="valueprovider">The delegate method (cannot be null)</param> /// <returns></returns> /// <remarks> /// The method will be executed when any queries using this parameter are converted to their SQL statements /// </remarks> public static DBParam ParamWithDelegate(string genericName, ParamValue valueprovider) { if (null == valueprovider) { throw new ArgumentNullException("valueProvider"); } DBDelegateParam del = new DBDelegateParam(valueprovider); del.Name = genericName; return(del); }
public void GetAllParamNames() { ParamBL paramBL = new ParamBL(); string paramName = "testParamName"; int paramId = paramBL.StoreParamName(paramName); List <ParamValue> values = new List <ParamValue>(); values = paramBL.GetAllParamNames(); ParamValue value = values.Find(x => x.Id == paramId); Assert.AreEqual(paramName, value.Name); }
public static string SqlWhere(List <ParamValue> paramValues, string table, ParamValue whereSucces) { var sql = string.Format("{0} * {1} {2} {3} {4} ", SqlQueryEnum.SELECT, SqlQueryEnum.FROM, table, whereSucces != null ? SqlQueryEnum.WHERE.ToString() : string.Empty, whereSucces != null ? string.Join(SqlQueryEnum.AND.ToString(), paramValues.Select(p => p.Where) .SelectMany(whr => whr) .Select(p => string.Format(" {0}=@{1} ", p.Key, p.Key.Replace("<", " ").Replace(">", " ")))) : ""); return(sql); }
public void PublicProperties() { // Arrange var excpectedKey = ParamValue.Param.signature; var expectedValue = "test-signature"; // Act var actual = new ParamValue(excpectedKey, expectedValue); // Assert Assert.AreEqual(excpectedKey, actual.Key); Assert.AreEqual(expectedValue, actual.Value); }
public void FirstZeroChars() { // Arrange var excpectedKey = ParamValue.Param.token; var value = "test-token"; var paramValue = new ParamValue(excpectedKey, value); // Act var actual = paramValue.First(0); // Assert Assert.IsNull(actual); }
public void TrimLeftMoreCharsThanValue() { // Arrange var excpectedKey = ParamValue.Param.token; var value = "test-token"; var paramValue = new ParamValue(excpectedKey, value); // Act var actual = paramValue.TrimLeft(value.Length + 1); // Assert Assert.IsNull(actual); }
public void EqualsAgainstNull() { // Arrange var key = ParamValue.Param.bodyhash; var value = "test-hash"; var param = new ParamValue(key, value); // Act var actual = param.Equals(null); // Assert Assert.IsFalse(actual); }
private static void GetDictinaryItemIm(ControlView cv, ParamValue paramValue) { Guid g = Guid.NewGuid(); paramValue.Param.Add(cv.DControlView.FieldName, g.ToString()); ParamValue paramValueList = new ParamValue { Param = new Dictionary <string, string>() }; GetDictionaryObjectIm(cv, paramValueList, g); paramValue.GuidValues.Add(paramValueList); }
private static void GetObject(PropertyInfo pProperty, ParamValue propertyValue, object oo, string guid) { var coo = _assembly[guid].CreateInstance(pProperty.PropertyType.FullName, true); //.Unwrap(); var cooGuid = propertyValue.Param[pProperty.Name]; var cooPropertyValue = (from pv in propertyValue.GuidValues where pv.Guid == cooGuid select pv).First(); foreach (PropertyInfo cpProperty in pProperty.PropertyType.GetProperties()) { if (cpProperty.PropertyType.FullName == "System.Runtime.Serialization.ExtensionDataObject") continue; //object oo = null; if (cpProperty.PropertyType.Name.ToLower() == "dictionary`2" && cpProperty.PropertyType.IsGenericType && cpProperty.PropertyType.GenericTypeArguments != null && cpProperty.PropertyType.GenericTypeArguments.Length == 2) { var dictionaryObj = GetDictionaryObj(cpProperty.PropertyType, propertyValue, guid); cpProperty.SetValue(coo, dictionaryObj); } else if (cpProperty.PropertyType.IsArray) { int dimensions; Type arrayBaseType; var aOo = GetArrayObj(propertyValue, cpProperty.PropertyType, guid, out dimensions, out arrayBaseType); if (coo != null) { PropertyInfo propertyInfo = coo.GetType().GetProperty(cpProperty.Name); if (dimensions >= 2) { var d = ArrayHelper.GetJaggedArray(dimensions, arrayBaseType, aOo); propertyInfo.SetValue(coo, d); } else { propertyInfo.SetValue(coo, aOo); } } } //Primitive Type else if (cooPropertyValue.Param.ContainsKey(cpProperty.Name)) { if (PrimitiveTypes.Test(cpProperty.PropertyType)) { string val = cooPropertyValue.Param[cpProperty.Name]; val = TestHelper.CheckForSpecialValue(val); if (coo != null) { PropertyInfo propertyInfo = coo.GetType().GetProperty(cpProperty.Name); SetPrimitiveTypeValue(cpProperty, val, propertyInfo, coo); } } else { //Non-primitive type GetObject(cpProperty, cooPropertyValue, coo, guid); } } } pProperty.SetValue(oo, coo); }
private static Array GetArrayObj(ParamValue propertyValue, Type type, string guid, out int dimensions, out Type arrayBaseType) { dimensions = type.FullName.Split(new[] { "[]" }, StringSplitOptions.None).Length - 1; arrayBaseType = type.GetElementType(); for (int ii = 1; ii < dimensions; ii++) { arrayBaseType = arrayBaseType.GetElementType(); } var parameterObject = arrayBaseType.MakeArrayType(); for (int ii = 1; ii < dimensions; ii++) { parameterObject = parameterObject.MakeArrayType(); } List<int> arrayIndexes = propertyValue.ArrayIndexes.Select(o => o.Int).ToList(); Array aOo = Array.CreateInstance(arrayBaseType, arrayIndexes.ToArray()); int i = 0; #region traverse array elements foreach (var lElement in propertyValue.ArrayElements) { object arrayElementObj = GetArrayElementObject(arrayBaseType, guid, lElement); List<int> indexes = new List<int>(); for (int ir = 0; ir < arrayIndexes.Count; ir++) { #region old logic, check if incorrect delete //int tot = 0; //for (int ri = arrayIndexes.Count - 1; ri > ir; ri--) //{ // tot += arrayIndexes[ri]; //} //if (tot == 0) //{ // tot = arrayIndexes[arrayIndexes.Count - 1]; //} //if (ir == arrayIndexes.Count - 1) //{ // indexes.Add(i%tot); //} //else //{ // indexes.Add(i/tot); //} #endregion TestHelper.GetArrayIndexesFromLinearIndex(arrayIndexes, ir, indexes, i); } aOo.SetValue(arrayElementObj, indexes.ToArray()); i++; } #endregion return aOo; }
private static void PopulateDictionaryElement(ParamValue pv, XElement vp) { pv.IsDictionary = true; pv.DictionaryLength = Convert.ToInt32(vp.Attribute("dictionaryLength").Value); int i = 0; foreach (XElement xArrayElement in vp.Elements("param")) { PopulateDictElementValues(xArrayElement, pv, i <= pv.DictionaryLength / 2); i++; } }
private static ParamValue PopulateListTypeElement(XElement vp) { ParamValue pv = new ParamValue { Param = new Dictionary<string, string>() }; if (vp.Attributes("isDictionary").ToList().Count > 0) { PopulateDictionaryElement(pv, vp); } else if (vp.Attributes("isArray").ToList().Count > 0) { PopulateArrayElement(pv, vp); } else { PopulateComplexElement(vp, pv); } return pv; }
private static void PopulateArrayElement(ParamValue pv, XElement vp) { pv.IsArray = true; string indexesStr = vp.Attribute("arrayIndexes").Value; pv.ArrayIndexes = new List<IntWrappper>(); foreach (string istr in indexesStr.Split(',')) { pv.ArrayIndexes.Add(new IntWrappper { Int = Convert.ToInt32(istr) }); } foreach (XElement xArrayElement in vp.Elements("param")) { PopulateArrayElementValues(xArrayElement, pv); } }
private static void PopulateComplexElement(XElement vp, ParamValue pv) { foreach (XAttribute attr in vp.Attributes().ToList()) { GetElementValue(vp, pv, attr); } }
public ResultType_enum Learn(string docPath, out int productAddedCount, out int productRepeatCount, out int productMergeCount, out string message) { productAddedCount = 0; productRepeatCount = 0; productMergeCount = 0; try { isWork = true; message = ""; // Проверка пути документа if (!File.Exists(docPath)) { message = "Документа по пути <" + docPath + "> не существует"; return ResultType_enum.Error; } //Создаём новый Word.Application Word.Application application = new Microsoft.Office.Interop.Word.Application(); //Загружаем документ Microsoft.Office.Interop.Word.Document doc = null; object fileName = docPath; object falseValue = false; object trueValue = true; object missing = Type.Missing; doc = application.Documents.Open(ref fileName, ref missing, ref trueValue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); // Ищем таблицу с данными Microsoft.Office.Interop.Word.Table tbl = null; try { tbl = application.ActiveDocument.Tables[1]; } catch { message = "В документе не найдена таблица для обучения"; return ResultType_enum.Error; } if (tbl == null) { message = "В документе не найдена таблица для обучения"; return ResultType_enum.Error; } if (tbl.Columns.Count != 8) { message = "Количество столбцов таблицы не совпадает со спецификацией"; return ResultType_enum.Error; } // Заполняем продукты Product product = null; Property property = null; bool isNewProduct = false; string productName = ""; var r = mvm.dc.Rubrics.FirstOrDefault(m => m.Name.ToLower() == "--без рубрики--"); var t = mvm.dc.Templates.FirstOrDefault(m => m.Name.ToLower() == "форма 2"); for (int i = 4; i <= tbl.Rows.Count; i++) { // Название продукта try { /*tbl.Cell(i, 2).Select(); Word.Selection sel = application.Selection; bool sss = sel.IsEndOfRowMark; int ss = sel.Rows.Count;*/ //sel.MoveDown(); Word.Cell ddd = tbl.Cell(i, 2).Next; if ((Globals.CleanWordCell(tbl.Cell(i, 2).Range.Text.Trim()) == productName) || (Globals.CleanWordCell(tbl.Cell(i, 2).Range.Text.Trim()) == "")) { isNewProduct = false; } else { isNewProduct = true; productName = Globals.CleanWordCell(tbl.Cell(i, 2).Range.Text.Trim()); } } catch (Exception ex) { isNewProduct = false; } if (isNewProduct) { if (!isWork) break; product = new Product(); product.Name = productName; try { product.TradeMark = Globals.CleanWordCell(tbl.Cell(i, 3).Range.Text.Trim()); } catch { product.TradeMark = ""; } // Проверить на повтор Product repeatProduct = mvm.dc.Products.FirstOrDefault(m => (m.Name == product.Name && m.TradeMark == product.TradeMark)); if (repeatProduct != null) { if (repeatProduct.Templates.FirstOrDefault(m => m.Name.Trim().ToLower() == "форма 2") == null) { product = repeatProduct; } else { productRepeatCount++; continue; } } else { product.Rubric = r; mvm.dc.Products.Add(product); t.Products.Add(product); productAddedCount++; mvm.dc.SaveChanges(); try { Application.Current.Dispatcher.BeginInvoke(new Action(() => { mvm.ProductCollection.Add(product); })); } catch { } } product.Templates.Add(mvm.dc.Templates.FirstOrDefault(m => m.Name.ToLower() == "форма 2")); try { Application.Current.Dispatcher.BeginInvoke(new Action(() => { mvm.TemplateCollection.FirstOrDefault(m => m.Name.ToLower() == "форма 2").Products.Add(product); })); } catch { } //mvm.TemplateCollection = new ObservableCollection<Template>(mvm.dc.Templates); } // Добавляем свойство property = new Property(); product.Properties.Add(property); try { // Требуемый параметр ParamValue pv = new ParamValue(); property.ParamValues.Add(pv); pv.Param = mvm.dc.Params.FirstOrDefault(m => m.Name == "Требуемый параметр" && m.Template.Name.ToLower() == "форма 2"); pv.Property = property; pv.Value = Globals.ConvertTextExtent(Globals.CleanWordCell(tbl.Cell(i, 4).Range.Text.Trim())); // Требуемое значение pv = new ParamValue(); property.ParamValues.Add(pv); pv.Param = mvm.dc.Params.FirstOrDefault(m => m.Name == "Требуемое значение" && m.Template.Name.ToLower() == "форма 2"); pv.Property = property; pv.Value = Globals.ConvertTextExtent(Globals.CleanWordCell(tbl.Cell(i, 5).Range.Text.Trim())); // Значение, предлагаемое участником pv = new ParamValue(); property.ParamValues.Add(pv); pv.Param = mvm.dc.Params.FirstOrDefault(m => m.Name == "Значение, предлагаемое участником" && m.Template.Name.ToLower() == "форма 2"); pv.Property = property; try { pv.Value = Globals.ConvertTextExtent(Globals.CleanWordCell(tbl.Cell(i, 6).Range.Text.Trim())); } catch { pv.Value = ""; } // Единица измерения pv = new ParamValue(); property.ParamValues.Add(pv); pv.Param = mvm.dc.Params.FirstOrDefault(m => m.Name == "Единица измерения" && m.Template.Name.ToLower() == "форма 2"); pv.Property = property; pv.Value = Globals.ConvertTextExtent(Globals.CleanWordCell(tbl.Cell(i, 7).Range.Text.Trim())); // Сертификация pv = new ParamValue(); property.ParamValues.Add(pv); pv.Param = mvm.dc.Params.FirstOrDefault(m => m.Name == "Сертификация" && m.Template.Name.ToLower() == "форма 2"); pv.Property = property; try { pv.Value = Globals.ConvertTextExtent(Globals.CleanWordCell(tbl.Cell(i, 8).Range.Text.Trim())); } catch { pv.Value = ""; } } catch (Exception ex) { string sss = ""; } } // Закрываем приложение application.Quit(ref missing, ref missing, ref missing); application = null; return ResultType_enum.Done; // Заносим продукты в БД //return dbEngineDocs.SetProducts(DocTemplate.Template_2, products, out productAddedCount, out productRepeatCount, out message); } catch (Exception ex) { message = ex.Message + '\n' + ex.StackTrace; return ResultType_enum.Error; } finally { isWork = false; } }
private static ParamValue WriteComplexType(List<ControlView> property, Guid g) { ParamValue paramValue = new ParamValue { Guid = g.ToString(), Param = new Dictionary<string, string>() }; foreach (ControlView cv in property) { if (cv.IsDictionary) { paramValue.Order = cv.DControlView.Order; GetDictinaryItemIm(cv, paramValue); } else if (cv.IsList) { paramValue.Order = cv.LControlView.Order; GetArrayItemIm(cv, paramValue); } else if (cv.IsPrimitive) { paramValue.Order = cv.PControlView.Order; paramValue.Param.Add(cv.PControlView.FieldName, cv.PControlView.FieldValue); } else { GetComplexItemIm(paramValue, cv); } } return paramValue; }
private static void GetElementValue(XElement vp, ParamValue pv, XAttribute attr) { string localName = TestHelper.DecodeAttributeName(attr.Name.LocalName); pv.Param.Add(localName, attr.Value); PopulateGuidValues(vp, pv, attr); }
private static ParamValue GetNewParamValues(string name, ParamValue paramValue) { ParamValue newParamValues = null; if (paramValue != null) { string objectGuid = paramValue.Param.ContainsKey(name) ? paramValue.Param[name] : string.Empty; if (!string.IsNullOrEmpty(objectGuid)) { var newParamValuesList = (from pv in paramValue.GuidValues where pv.Guid == objectGuid select pv).ToList(); if (newParamValuesList.Count > 0) { newParamValues = newParamValuesList[0]; } } } return newParamValues; }
/// <summary> /// Creates Dictionary object /// </summary> /// <param name="mParameter">Parameter info</param> /// <param name="parameterOrder">parameter order</param> /// <param name="paramValue">param value object from project</param> /// <returns></returns> private static ControlView GetDictionaryObject(ParameterInfo mParameter, int parameterOrder, string guid, ParamValue paramValue = null) { ControlView arrayObject = new ControlView { IsDictionary = true, DControlView = new DictionartControlViewModel { FieldName = mParameter.Name, FieldType = mParameter.ParameterType.GenericTypeArguments[0], FieldValueType = mParameter.ParameterType.GenericTypeArguments[1], Order = parameterOrder, DictionaryItemsCount = paramValue != null ? paramValue.DictionaryLength : 0, BaseTypeProperties = GetTypeDetails(mParameter.ParameterType.GenericTypeArguments[0], guid), BaseValueTypeProperties = GetTypeDetails(mParameter.ParameterType.GenericTypeArguments[1], guid), AssemblyGuid = guid } }; for (int i = 0; i < arrayObject.DControlView.DictionaryItemsCount; i++) { arrayObject.DControlView.Properties.Add(GetTypeDetails(mParameter.ParameterType.GenericTypeArguments[0], guid, paramValue != null ? paramValue.DictKeyElements[i] : null)); arrayObject.DControlView.PropertiesValue.Add(GetTypeDetails(mParameter.ParameterType.GenericTypeArguments[1], guid, paramValue != null ? paramValue.DictValueElements[i] : null)); } return arrayObject; }
private static void GetDictinaryItemIm(ControlView cv, ParamValue paramValue) { Guid g = Guid.NewGuid(); paramValue.Param.Add(cv.DControlView.FieldName, g.ToString()); ParamValue paramValueList = new ParamValue { Param = new Dictionary<string, string>() }; GetDictionaryObjectIm(cv, paramValueList, g); paramValue.GuidValues.Add(paramValueList); }
private static void GetArrayObjectIm(ControlView cv, ParamValue paramValue, Guid? g = null) { paramValue.ArrayIndexes = cv.LControlView.ArrayIndexes.ToList(); paramValue.IsArray = true; if (g != null) { paramValue.Guid = g.Value.ToString(); } paramValue.ArrayElements = new List<ParamValue>(); foreach (ControlView eleCv in cv.LControlView.Properties) { paramValue.ArrayElements.Add(CreateArrayItem(eleCv)); } }
private static void GetParameterForServiceMethod(ParameterInfo mParameter, ParamValue propertyValue, List<object> parameters, string guid) { if (!PrimitiveTypes.Test(mParameter.ParameterType)) { if (mParameter.ParameterType.Name.ToLower() == "dictionary`2" && mParameter.ParameterType.IsGenericType && mParameter.ParameterType.GenericTypeArguments != null && mParameter.ParameterType.GenericTypeArguments.Length == 2) { var dictionaryObj = GetDictionaryObj(mParameter.ParameterType, propertyValue, guid); parameters.Add(dictionaryObj); } else if (mParameter.ParameterType.IsArray) { int dimensions; Type arrayBaseType; var aOo = GetArrayObj(propertyValue, mParameter.ParameterType, guid, out dimensions, out arrayBaseType); if (dimensions >= 2) { var d = ArrayHelper.GetJaggedArray(dimensions, arrayBaseType, aOo); parameters.Add(d); } else { parameters.Add(aOo); } } else { var oo = _assembly[guid].CreateInstance(mParameter.ParameterType.FullName, true); foreach (PropertyInfo pProperty in mParameter.ParameterType.GetProperties()) { //Primitive Type if (propertyValue.Param.ContainsKey(pProperty.Name)) { if (PrimitiveTypes.Test(pProperty.PropertyType)) { string val = propertyValue.Param[pProperty.Name]; val = TestHelper.CheckForSpecialValue(val); if (oo == null) continue; var propertyInfo = oo.GetType().GetProperty(pProperty.Name); SetPrimitiveTypeValue(pProperty, val, propertyInfo, oo); } else { //Non-primitive type GetObject(pProperty, propertyValue, oo, guid); } } } parameters.Add(oo); } } else { object safeValue = TestHelper.GetSafeValue(mParameter.ParameterType, propertyValue.Param["value"]); parameters.Add(safeValue); //parameters.Add(Convert.ChangeType(propertyValue.param["value"], mParameter.ParameterType)); } }
private static ControlView GetTypeDetailsDictionaryObject(Type propertyInfo, string fieldName, ParamValue newParamValues, string guid) { ControlView arrayObject = new ControlView { IsDictionary = true, DControlView = new DictionartControlViewModel { FieldName = fieldName, FieldType = propertyInfo.GenericTypeArguments[0], FieldValueType = propertyInfo.GenericTypeArguments[1], AssemblyGuid = guid } }; if (newParamValues != null) { arrayObject.DControlView.DictionaryItemsCount = newParamValues.DictionaryLength; for (int i = 0; i < arrayObject.DControlView.DictionaryItemsCount; i++) { arrayObject.DControlView.Properties.Add(GetTypeDetails(propertyInfo.GenericTypeArguments[0], guid, newParamValues.DictKeyElements[i])); arrayObject.DControlView.PropertiesValue.Add(GetTypeDetails(propertyInfo.GenericTypeArguments[1], guid, newParamValues.DictValueElements[i])); } } else { arrayObject.DControlView.BaseTypeProperties = GetTypeDetails(propertyInfo.GenericTypeArguments[0], guid); arrayObject.DControlView.BaseValueTypeProperties = GetTypeDetails(propertyInfo.GenericTypeArguments[1], guid); } return arrayObject; }
/// <summary> /// Load service element from xml /// </summary> /// <param name="test">test xml node</param> /// <param name="testCollection">perf test or functional test</param> /// <param name="isFunctional">Is Functional</param> private static void LoadServiceElement(XElement test, List<Common.Infrastructure.Entities.Test> testCollection, bool isFunctional) { var xElement = test.Element("service"); if (xElement != null) { var t = new Common.Infrastructure.Entities.Test { Service = new Service { MethodName = xElement.Attribute("methodName").Value, IsAsync = Convert.ToBoolean(xElement.Attribute("isAsync").Value), Parameters = new Parameter() } }; if (xElement.HasElements) { var valuesElement = xElement.Element("values"); if (valuesElement != null) { t.Service.Values = new Values { ValueList = new List<Value>() }; List<XElement> valElements = valuesElement.Elements("value").ToList(); foreach (XElement val in valElements) { Value v = new Value { Param = new List<ParamValue>(), Guid = val.Attributes("__guid__").Any() ? val.Attribute("__guid__").Value : string.Empty }; if (isFunctional) { v.MethodOutput = val.Attribute("methodOutput").Value; } List<XElement> valParams = val.Elements("param").ToList(); foreach (XElement vp in valParams) { ParamValue pv = new ParamValue { Param = new Dictionary<string, string>(), Order = Convert.ToInt32(vp.Attribute("order").Value) }; if (vp.Attributes("isDictionary").ToList().Count > 0) { PopulateDictionaryElement(pv, vp); } else if (vp.Attributes("isArray").ToList().Count > 0) { PopulateArrayElement(pv, vp); } else { PopulateComplexElement(vp, pv); } v.Param.Add(pv); } t.Service.Values.ValueList.Add(v); } } } testCollection.Add(t); } }
private static ControlView GetTypeDetailsArrayObject(string fieldName, Type arrayBaseType, ParamValue newParamValues, int dimensions, string guid) { ControlView arrayObject = new ControlView { IsList = true, LControlView = new ListControlViewModel { FieldName = fieldName, FieldType = arrayBaseType, BaseTypeProperties = GetTypeDetails(arrayBaseType, guid), AssemblyGuid = guid } }; if (newParamValues != null) { arrayObject.LControlView.ArrayIndexes = new BindingList<IntWrappper>(newParamValues.ArrayIndexes); int totalElementsInList = arrayObject.LControlView.ArrayIndexes.Aggregate(1, (current, iw) => current * iw.Int); for (int i = 0; i < totalElementsInList; i++) { arrayObject.LControlView.Properties.Add(GetTypeDetails(arrayBaseType, guid, newParamValues.ArrayElements[i])); } } else { for (int ai = 0; ai < dimensions; ai++) { arrayObject.LControlView.ArrayIndexes.Add(new IntWrappper() { Int = 0 }); } } return arrayObject; }
private static void PopulateArrayElementValues(XElement vp, ParamValue parentvalue) { var pv = PopulateListTypeElement(vp); parentvalue.ArrayElements.Add(pv); }
private static ControlView GetTypeDetails(Type propertyInfo, string guid, ParamValue paramValue = null) { bool isNullableType = Nullable.GetUnderlyingType(propertyInfo) != null; if ( propertyInfo.Name.ToLower() == "dictionary`2" && propertyInfo.IsGenericType && propertyInfo.GenericTypeArguments != null && propertyInfo.GenericTypeArguments.Length == 2) { var newParamValues = GetNewParamValues(propertyInfo.Name, paramValue); var arrayObject = GetTypeDetailsDictionaryObject(propertyInfo, propertyInfo.Name, newParamValues, guid); return arrayObject; } //for list else if (propertyInfo.IsArray) { int dimensions = propertyInfo.FullName.Split(new[] { "[]" }, StringSplitOptions.None).Length - 1; Type arrayBaseType = propertyInfo.GetElementType(); for (int ii = 1; ii < dimensions; ii++) { arrayBaseType = arrayBaseType.GetElementType(); } var newParamValues = GetNewParamValues(propertyInfo.Name, paramValue); var arrayObject = GetTypeDetailsArrayObject(propertyInfo.Name, arrayBaseType, newParamValues, dimensions, guid); return arrayObject; } else if (propertyInfo.IsPrimitive // ReSharper disable once PossibleMistakenCallToGetType.2 || propertyInfo.GetType().IsPrimitive || propertyInfo.Name.ToLower() == "string" || (isNullableType && PrimitiveTypes.Test(Nullable.GetUnderlyingType(propertyInfo))) || PrimitiveTypes.Test(propertyInfo) ) { string value = string.Empty; if (paramValue != null) { value = paramValue.Param.ContainsKey(propertyInfo.Name) ? paramValue.Param[propertyInfo.Name] : string.Empty; if (string.IsNullOrEmpty(value)) { value = paramValue.Param.ContainsKey("value") ? paramValue.Param["value"] : string.Empty; } } var cv = GetTypeDetailPrimitiveObject(propertyInfo, propertyInfo.Name, isNullableType, value, guid); return cv; } else { ParamValue newParamValues = null; if (paramValue != null) { newParamValues = paramValue; } ControlView cv1 = GetTypeDetailComplexObject(propertyInfo, guid, newParamValues); return cv1; } }
private static void PopulateDictElementValues(XElement vp, ParamValue parentvalue, bool isKey) { var pv = PopulateListTypeElement(vp); if (isKey) { parentvalue.DictKeyElements.Add(pv); } else { parentvalue.DictValueElements.Add(pv); } }
private static ControlView GetTypeDetailComplexObject(Type propertyInfo, string guid, ParamValue newParamValues = null, string fieldName = null) { ObservableCollection<ControlView> parameterPropertiesNew = new ObservableCollection<ControlView>(); foreach (PropertyInfo pProperty in propertyInfo.GetProperties()) { if (pProperty.PropertyType.FullName == "System.Runtime.Serialization.ExtensionDataObject") continue; parameterPropertiesNew.Add(GetPropertyDetails(pProperty, guid, newParamValues)); } ControlView cv1 = new ControlView() { IsPrimitive = false, CControlView = new ComplexControlViewModel() { FieldName = !string.IsNullOrEmpty(fieldName) ? fieldName : propertyInfo.Name, Properties = parameterPropertiesNew } }; return cv1; }
private static void PopulateGuidValues(XElement vp, ParamValue pv, XAttribute attr) { string resultString = Regex.Replace(attr.Value, @"\b[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12}\b", "'$0'", RegexOptions.IgnoreCase); if (!string.IsNullOrEmpty(resultString)) { var vpplist = vp.Elements("param").Where(vp1 => vp1.Attribute("__guid__") != null && vp1.Attribute("__guid__").Value == attr.Value).ToList(); if (vpplist.Count > 0) { ParamValue vpp = new ParamValue { Guid = attr.Value, Param = new Dictionary<string, string>() }; if (vpplist[0].Attributes("isDictionary").ToList().Count > 0) { PopulateDictionaryElement(vpp, vpplist[0]); } else if (vpplist[0].Attributes("isArray").ToList().Count > 0) { PopulateArrayElement(vpp, vpplist[0]); } else { foreach (XAttribute attr1 in vpplist[0].Attributes().ToList()) { if (attr1.Name.LocalName == "__guid__") continue; GetElementValue(vpplist[0], vpp, attr1); } } pv.GuidValues.Add(vpp); } } }
/// <summary> /// Creates Primitive object /// </summary> /// <param name="mParameter">Parameter info</param> /// <param name="parameterOrder">parameter order</param> /// <param name="guid"></param> /// <param name="paramValue">param value object from project</param> /// <returns></returns> private static ControlView GetPrimitiveObject(ParameterInfo mParameter, int parameterOrder, string guid, ParamValue paramValue = null) { var primitiveObject = new ControlView() { IsPrimitive = true, PControlView = new PrimitiveControlViewModel() { FieldName = mParameter.Name, FieldValue = paramValue != null ? (paramValue.Param.ContainsKey("value") ? paramValue.Param["value"] : string.Empty) : string.Empty, Order = parameterOrder, FieldType = mParameter.ParameterType, AssemblyGuid = guid } }; return primitiveObject; }
private static object GetArrayElementObject(Type baseType, string guid, ParamValue propertyValue) { var coo = _assembly[guid].CreateInstance(baseType.FullName, true); //.Unwrap(); var cooPropertyValue = propertyValue; // (from pv in propertyValue.guidValues //where pv.guid == cooGuid //select pv).First(); if (PrimitiveTypes.Test(baseType)) { object safeValue = TestHelper.GetSafeValue(baseType, propertyValue.Param["value"]); coo = safeValue; return coo; } if (baseType.Name.ToLower() == "dictionary`2" && baseType.IsGenericType && baseType.GenericTypeArguments != null && baseType.GenericTypeArguments.Length == 2) { var coPropertyValue = propertyValue.GuidValues[0]; var dictionaryObj = GetDictionaryObj(baseType, coPropertyValue, guid); return dictionaryObj; } foreach (PropertyInfo mProperty in baseType.GetProperties()) { if (mProperty.PropertyType.FullName == "System.Runtime.Serialization.ExtensionDataObject") continue; if (mProperty.PropertyType.Name.ToLower() == "dictionary`2" && mProperty.PropertyType.IsGenericType && mProperty.PropertyType.GenericTypeArguments != null && mProperty.PropertyType.GenericTypeArguments.Length == 2) { var cooGuid1 = cooPropertyValue.Param[mProperty.Name]; var cooPropertyValue1 = (from pv in cooPropertyValue.GuidValues where pv.Guid == cooGuid1 select pv).First(); var dictionaryObj = GetDictionaryObj(mProperty.PropertyType, cooPropertyValue1, guid); mProperty.SetValue(coo, dictionaryObj); } else if (mProperty.PropertyType.IsArray) { var cooGuid1 = cooPropertyValue.Param[mProperty.Name]; var cooPropertyValue1 = (from pv in cooPropertyValue.GuidValues where pv.Guid == cooGuid1 select pv).First(); int dimensions; Type arrayBaseType; var aOo = GetArrayObj(cooPropertyValue1, mProperty.PropertyType, guid, out dimensions, out arrayBaseType); if (dimensions >= 2) { var d = ArrayHelper.GetJaggedArray(dimensions, arrayBaseType, aOo); mProperty.SetValue(coo, d); } else { mProperty.SetValue(coo, aOo); } } else { //Primitive Type if (cooPropertyValue.Param.ContainsKey(mProperty.Name)) { if (PrimitiveTypes.Test(mProperty.PropertyType)) { string val = cooPropertyValue.Param[mProperty.Name]; val = TestHelper.CheckForSpecialValue(val); if (coo != null) { PropertyInfo propertyInfo = coo.GetType().GetProperty(mProperty.Name); SetPrimitiveTypeValue(mProperty, val, propertyInfo, coo); } } else { //Non-primitive type GetObject(mProperty, cooPropertyValue, coo, guid); } } //mProperty.SetValue(coo, a_oo); } } return coo; }
/// <summary> /// Get the parameter object /// </summary> /// <param name="controlViewBindingObject">controls list to populate</param> /// <param name="mParameter">parameter info</param> /// <param name="parameterOrder">parameter order in method</param> /// <param name="paramValue">param value from xml</param> private static void GetParameter(ObservableCollection<ControlView> controlViewBindingObject, ParameterInfo mParameter, int parameterOrder, string guid, ParamValue paramValue = null) { //for dictionary if (mParameter.ParameterType.Name.ToLower() == "dictionary`2" && mParameter.ParameterType.IsGenericType && mParameter.ParameterType.GenericTypeArguments != null && mParameter.ParameterType.GenericTypeArguments.Length == 2) { var arrayObject = GetDictionaryObject(mParameter, parameterOrder, guid, paramValue); controlViewBindingObject.Add(arrayObject); } //for list else if (mParameter.ParameterType.IsArray) { var arrayObject = GetArrayObject(mParameter, parameterOrder, guid, paramValue); controlViewBindingObject.Add(arrayObject); } else if (!mParameter.ParameterType.IsPrimitive && !PrimitiveTypes.Test(mParameter.ParameterType)) { var complexObject = GetComplexObject(mParameter, parameterOrder, guid, paramValue); controlViewBindingObject.Add(complexObject); } else { var primitiveObject = GetPrimitiveObject(mParameter, parameterOrder, guid, paramValue); controlViewBindingObject.Add(primitiveObject); } }
private static IDictionary GetDictionaryObj(Type dictionaryType, ParamValue propertyValue, string guid) { var dictionaryObj = (IDictionary)Activator.CreateInstance(dictionaryType); int totalElements = propertyValue.DictionaryLength; for (int di = 0; di < totalElements; di++) { var dkey = GetListDictionaryObject(dictionaryType.GenericTypeArguments[0], propertyValue.DictKeyElements[di], guid); var dvalue = GetListDictionaryObject(dictionaryType.GenericTypeArguments[1], propertyValue.DictValueElements[di], guid); dictionaryObj.Add(dkey, dvalue); } return dictionaryObj; }
/// <summary> /// Creates Complex object /// </summary> /// <param name="mParameter">Parameter info</param> /// <param name="parameterOrder">parameter order</param> /// <param name="guid"></param> /// <param name="paramValue">param value object from project</param> /// <returns></returns> private static ControlView GetComplexObject(ParameterInfo mParameter, int parameterOrder, string guid, ParamValue paramValue = null) { ObservableCollection<ControlView> parameterPropertiesNew = new ObservableCollection<ControlView>(); foreach (PropertyInfo pProperty in mParameter.ParameterType.GetProperties()) { if (pProperty.PropertyType.FullName == "System.Runtime.Serialization.ExtensionDataObject") continue; parameterPropertiesNew.Add(GetPropertyDetails(pProperty, guid, paramValue)); } var complexObject = new ControlView() { IsPrimitive = false, CControlView = new ComplexControlViewModel() { FieldName = mParameter.Name, Properties = parameterPropertiesNew, Order = parameterOrder } }; return complexObject; }
private static object GetListDictionaryObject(Type baseType, ParamValue propertyValue, string guid) { if (baseType.IsArray) { var coPropertyValue = propertyValue.GuidValues[0]; int dimensions; Type arrayBaseType; var aOo = GetArrayObj(coPropertyValue, baseType, guid, out dimensions, out arrayBaseType); if (dimensions >= 2) { var d = ArrayHelper.GetJaggedArray(dimensions, arrayBaseType, aOo); return d; } return aOo; } if (baseType.Name.ToLower() == "dictionary`2" && baseType.IsGenericType && baseType.GenericTypeArguments != null && baseType.GenericTypeArguments.Length == 2) { var dictionaryObj = GetDictionaryObj(baseType, propertyValue, guid); return dictionaryObj; } if (PrimitiveTypes.Test(baseType)) { object safeValue = TestHelper.GetSafeValue(baseType, propertyValue.Param["value"]); return safeValue; } if (!PrimitiveTypes.Test(baseType)) { var oo = _assembly[guid].CreateInstance(baseType.FullName, true); //.Unwrap(); foreach (PropertyInfo pProperty in baseType.GetProperties()) { //Primitive Type if (propertyValue.Param.ContainsKey(pProperty.Name)) { if (PrimitiveTypes.Test(pProperty.PropertyType)) { string val = propertyValue.Param[pProperty.Name]; val = TestHelper.CheckForSpecialValue(val); if (oo != null) { PropertyInfo propertyInfo = oo.GetType().GetProperty(pProperty.Name); SetPrimitiveTypeValue(pProperty, val, propertyInfo, oo); } } else { //Non-primitive type GetObject(pProperty, propertyValue, oo, guid); } } } return oo; } return GetArrayElementObject(baseType, guid, propertyValue); }
private static void GetDictionaryObjectIm(ControlView cv, ParamValue paramValue, Guid? g = null) { paramValue.DictionaryLength = cv.DControlView.DictionaryItemsCount; paramValue.IsDictionary = true; if (g != null) { paramValue.Guid = g.Value.ToString(); } foreach (ControlView eleCv in cv.DControlView.Properties) { paramValue.DictKeyElements.Add(CreateArrayItem(eleCv)); } foreach (ControlView eleCv in cv.DControlView.PropertiesValue) { paramValue.DictValueElements.Add(CreateArrayItem(eleCv)); } }