private bool CreateAttrN(AttributeStruct el, string entityNoStr) { try { int AttributeRecNo = _preactor.CreateRecord(entityNoStr); //_preactor.WriteField(_entityName, "Number", AttributeRecNo, el.Id); _preactor.WriteField(entityNoStr, "Name", AttributeRecNo, el.Name); int idxConstr = 0; if (el.SecondaryConstraints != null) { _preactor.SetAutoListSize($"{entityNoStr}", "Secondary Constraints", AttributeRecNo, el.SecondaryConstraints.Count); foreach (string elSc in el.SecondaryConstraints) { idxConstr++; _preactor.WriteListField($"{entityNoStr}", "Secondary Constraints", AttributeRecNo, elSc, idxConstr); } } logger.Trace($"Создан экземпляр Attribute {el.Name}"); return(true); } catch (Exception ex) { logger.Trace($"Ошибка создания экземпляра {ex.Message}{entityNoStr} {el.Name}"); } return(false); }
public override void OnGUI(UnityEngine.Rect position, SerializedProperty property, UnityEngine.GUIContent label) { AttributeStruct attribute = (AttributeStruct)base.attribute; property.intValue = Mathf.Min(Mathf.Max(EditorGUI.IntField(position, label.text, property.intValue), attribute.min), attribute.max); //EditorGUI.Slider(position, property, attribute.min, attribute.max, label); EditorGUI.LabelField(position, "00000"); }
static void Main(string[] args) { SchemaMapVersionList map = new SchemaMapVersionList(); if (NativeMethods.CS_has_schema("Conv", "")) { unsafe { var ptr = NativeMethods.CS_get_schema("Conv", 14, ""); if (ptr.has_function == 1) { string function_body = Marshal.PtrToStringAnsi((IntPtr)ptr.function_body); } string[] attrKeys = new string[ptr.attributes_length]; AttributeStruct[] attrValues = new AttributeStruct[ptr.attributes_length]; for (int i = 0; i < ptr.attributes_length; i++) { attrKeys[i] = Marshal.PtrToStringAnsi((IntPtr)ptr.attributesKeys[i]); attrValues[i] = ptr.attributesValues[i]; var proto = AttributeProto.Parser.ParseFrom(Encoding.ASCII.GetBytes(Marshal.PtrToStringAnsi((IntPtr)attrValues[i].default_value))); } FormalParameterStruct[] inputs = new FormalParameterStruct[ptr.inputs_length]; for (int i = 0; i < ptr.inputs_length; i++) { inputs[i] = ptr.inputs[i]; } FormalParameterStruct[] outputs = new FormalParameterStruct[ptr.outputs_length]; for (int i = 0; i < ptr.outputs_length; i++) { outputs[i] = ptr.outputs[i]; } TypeConstraintParamStruct[] constraints = new TypeConstraintParamStruct[ptr.type_constraints_length]; for (int i = 0; i < ptr.type_constraints_length; i++) { constraints[i] = ptr.type_constraints[i]; } } } }
/// <summary> /// Создает аттрибуты в преакторе, с помощью заполненых соответствующих коллекций в AttributeDTO /// для заполнения Constrains нужно заполнить соответствующий список в AttributeDTO /// </summary> /// <param name="obj">Объект с коллекциями аттрибутов</param> /// <returns></returns> public bool Create(AttributeDTO obj) { string entityNoStr; //int attrNo = 1; try { for (int attrNo = 1; attrNo <= 5; attrNo++) { AttributeDTO foundAttr = GetByNo(attrNo.ToString()); PropertyInfo fieldAttr = typeof(AttributeDTO).GetProperty($"Attribute{attrNo.ToString()}"); object fieldValue = fieldAttr.GetValue(obj); entityNoStr = $"{_entityName} {attrNo}"; if (fieldValue == null) { continue; } foreach (AttributeStruct el in (List <AttributeStruct>)fieldValue) { List <AttributeStruct> fieldValueFound = (List <AttributeStruct>)fieldAttr.GetValue(foundAttr); AttributeStruct foundEl = fieldValueFound.FirstOrDefault(x => x.Name == el.Name); if (foundEl.Name != null) { logger.Trace($"Экземпляр Attribute уже существует {el.Name}"); } else { CreateAttrN(el, entityNoStr); } } } return(true); } catch (Exception ex) { logger.Trace($"Ошибка в создании экземпляра{ex.Message} {_entityName}"); } return(false); }
public void Update(AttributeDTO obj) { for (int i = 1; i <= 5; i++) { PropertyInfo fieldAttr = typeof(AttributeDTO).GetProperty($"Attribute{i.ToString()}"); object fieldValue = fieldAttr.GetValue(obj); if (fieldValue == null) { continue; } fieldAttr = typeof(AttributeDTO).GetProperty($"Attribute{i.ToString()}"); AttributeDTO foundAttr = GetByNo(i.ToString()); List <AttributeStruct> fieldValueFound = (List <AttributeStruct>)fieldAttr.GetValue(foundAttr); string entityNoStr = $"{_entityName} {i}"; foreach (AttributeStruct attr1 in (List <AttributeStruct>)fieldValue) { AttributeStruct foundEl = fieldValueFound.FirstOrDefault(x => x.Name == attr1.Name); int attrRecNo = attr1.Id; try { if (foundEl.Name != null) { Delete(foundEl.Id, i); logger.Trace($"Обновлен экземпляр Attribute {attr1.Name}"); } else { logger.Trace($"Создан экземпляр Attribute {attr1.Name}"); } CreateAttrN(attr1, entityNoStr); } catch (Exception ex) { logger.Trace($"Ошибка создания экземпляра Attribute {ex.Message} {attr1.Name}"); } } } return; }
private static extern void SetFloat(ref AttributeStruct pAttributeStruct, string lpName, float fValue);
private static extern void SetBoolean(ref AttributeStruct pAttributeStruct, string lpName, [MarshalAs(UnmanagedType.U1)]bool bValue);
private static extern uint GetUnsignedInteger(ref AttributeStruct pAttributeStruct);
private static extern string GetString(ref AttributeStruct pAttributeStruct);
private static extern int GetInteger(ref AttributeStruct pAttributeStruct);
/// <summary> /// Получает все значения аттрибута по его номеру в Preactor, например Аттрибут2 , номер "2" /// </summary> /// <param name="attrNo">Номер аттрибута в преакторе ("1","2","3","4","5")</param> /// <returns></returns> public AttributeDTO GetByNo(string attrNo) { string entityNoStr; entityNoStr = $"{_entityName} {attrNo}"; logger.Trace($"Получение аттрибута по номеру начато {entityNoStr}"); string requestStr = $"~{{$Number}}~>~0~"; int recordNo = _preactor.FindMatchingRecord(entityNoStr, 0, requestStr); int firstRecNo = recordNo; List <string> secondaryConstraintList = new List <string>(); if (recordNo < 0) { return(null); } List <AttributeStruct> attrList = new List <AttributeStruct>(); int orderIdx = 0; while (recordNo >= 0) { if (recordNo < 0) { break; } try { int constraintCount = _preactor.MatrixFieldSize(entityNoStr, "Secondary Constraints", recordNo).X; for (int i = 1; i <= constraintCount; i++) { try { string secConstr = _preactor.ReadFieldString(entityNoStr, "Secondary Constraints", recordNo, i); secondaryConstraintList.Add(secConstr); } catch (Exception ex) { logger.Error(ex.Message + " (Attribute secondary constraint) " + ex.TargetSite.Name + " Attribute name" + entityNoStr); } } int id = 0; string attrName = ""; double color = 0; orderIdx++; try { id = _preactor.ReadFieldInt(entityNoStr, "Number", recordNo); attrName = _preactor.ReadFieldString(entityNoStr, "Name", recordNo); color = _preactor.ReadFieldDouble(entityNoStr, "Color", recordNo); AttributeStruct attrNewElem = new AttributeStruct { Id = id, Name = attrName, Color = color, SecondaryConstraints = secondaryConstraintList, OrderNumber = orderIdx }; attrList.Add(attrNewElem); } catch (Exception ex) { logger.Error(ex.Message + " (header)" + ex.TargetSite.Name + " Attribute" + entityNoStr); } } catch (Exception ex) { logger.Error(ex.Message + " (header)" + ex.TargetSite.Name + " Attribute" + entityNoStr); } recordNo = _preactor.FindMatchingRecord(entityNoStr, recordNo, requestStr); } AttributeDTO result = new AttributeDTO() { Attribute1 = attrNo == "1" ? attrList : null, Attribute2 = attrNo == "2" ? attrList : null, Attribute3 = attrNo == "3" ? attrList : null, Attribute4 = attrNo == "4" ? attrList : null, Attribute5 = attrNo == "5" ? attrList : null }; logger.Trace($"Получение Attribute по имени завершено {entityNoStr}"); return(result); }
private static extern void SetUnsignedInteger(ref AttributeStruct pAttributeStruct, string lpName, uint uiValue, [MarshalAs(UnmanagedType.U1)]bool bHexadecimal);
internal Attribute(AttributeStruct attr) { _attr = attr; }
private static extern bool GetAttribute(PackageAttribute eAttribute, out AttributeStruct pAttributeStruct);
private static extern void SetInteger(ref AttributeStruct pAttributeStruct, string lpName, int iValue);
private static extern void SetString(ref AttributeStruct pAttributeStruct, string lpName, string lpValue);
private static extern bool GetBoolean(ref AttributeStruct pAttributeStruct);
internal static extern bool GetItemAttribute(IntPtr pItem, PackageAttribute eAttribute, out AttributeStruct pAttributeStruct);
private static extern float GetFloat(ref AttributeStruct pAttributeStruct);