public override int GetHashCode() { unchecked { return(((DataObjectType?.GetHashCode() ?? 0) * 397) ^ Date.GetHashCode()); } }
public PropertyAttribute(string idShort, DataObjectTypes propertyType) { Property = new Property(new DataType(DataObjectType.Parse(propertyType))) { IdShort = idShort }; }
public static SubmodelElement CreateSubmodelElement(DataObjectType modelType, DataType valueType = null) { if (modelType == ModelType.Property) { return(new Property(valueType)); } if (modelType == ModelType.Operation) { return(new Operation()); } if (modelType == ModelType.Event) { return(new Event()); } if (modelType == ModelType.BasicEvent) { return(new BasicEvent()); } else if (modelType == ModelType.Blob) { return(new Blob()); } else if (modelType == ModelType.File) { return(new File()); } else if (modelType == ModelType.MultiLanguageProperty) { return(new MultiLanguageProperty()); } else if (modelType == ModelType.ReferenceElement) { return(new ReferenceElement()); } else if (modelType == ModelType.RelationshipElement) { return(new RelationshipElement()); } else if (modelType == ModelType.SubmodelElementCollection) { return(new SubmodelElementCollection()); } else if (modelType == ModelType.AnnotatedRelationshipElement) { return(new AnnotatedRelationshipElement()); } else if (modelType == ModelType.Entity) { return(new Entity()); } if (modelType == ModelType.Range) { return(new Range()); } else { return(null); } }
public PropertyAttribute(string idShort, DataObjectTypes propertyType, string semanticId, KeyElements semanticKeyElement, KeyType semanticKeyType, bool semanticIdLocal) { Property = new Property(new DataType(DataObjectType.Parse(propertyType))) { IdShort = idShort, SemanticId = new Reference(new Key(semanticKeyElement, semanticKeyType, semanticId, semanticIdLocal)) }; }
/// <summary> /// 设置对象值 /// </summary> /// <param name="objectStr"></param> public void SetDataObject(string objectStr) { if (objectStr.Contains("|A3|")) { string[] tempArray = objectStr.Split(new string[] { "|A3|" }, StringSplitOptions.None); if (tempArray.Count() == 2) //如果含有表名加查询 { this.TableName = tempArray[0]; if (string.IsNullOrEmpty(tempArray[1])) { this.Type = DataObjectType.ATable; //查询为空,则为表 } else { this.QueryStr = tempArray[1]; if (tempArray[0].Contains(".findOne(")) //findOne查询为单条记录,可为源记录 { this.Type = DataObjectType.ARecord; } else if (tempArray[0].Contains(".distinct(")) //distinct查询为多条记录 { this.Type = DataObjectType.MultipleRecords; } } } if (tempArray.Count() == 3) { this.TableName = tempArray[0]; this.QueryStr = tempArray[1]; this.DataStr = tempArray[2]; this.Type = DataObjectType.AStorage; //一个存储对象 } } else { this.TableName = null; this.QueryStr = null; this.ValueStr = objectStr; this.Type = DataObjectType.AValue; //一个值对象 } }
public static List<Guid> GetNewMemberIds(string exchangeCode, bool deafultStatus, List<RoleDataPermission> permissions, DataObjectType GroupType) { List<Guid> memberIds = new List<Guid>(); DataTable groupPermission = new DataTable(); groupPermission.Columns.Add("GroupId", typeof(Guid)); groupPermission.Columns.Add("Status", typeof(bool)); foreach (RoleDataPermission item in permissions) { if (item.Level == 3) { DataRow row = groupPermission.NewRow(); row["GroupId"] = item.DataObjectId; row["Status"] = item.IsAllow; groupPermission.Rows.Add(row); } } using (SqlConnection con = DataAccess.GetInstance(exchangeCode).GetSqlConnection()) { using (SqlCommand command = con.CreateCommand()) { command.CommandText = "[dbo].[Manager_GetMemberIds]"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@GroupType", GroupType.ToString())); command.Parameters.Add(new SqlParameter("@deafultStatus", deafultStatus)); SqlParameter tableParameter = command.Parameters.AddWithValue("@dataPermissions", groupPermission); tableParameter.SqlDbType = SqlDbType.Structured; tableParameter.TypeName = "[dbo].[DataPermissions]"; using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Guid memberId = (Guid)reader["MemberID"]; memberIds.Add(memberId); } } } } return memberIds; }
public static List<Guid> GetMemberIds(string exchangeCode, List<DataPermission> permissions, DataObjectType GroupType) { DataTable groupPermission = new DataTable(); groupPermission.Columns.Add("GroupId", typeof(Guid)); groupPermission.Columns.Add("Status", typeof(bool)); foreach (DataPermission item in permissions) { if (item.DataObjectId != null && item.DataObjectType == GroupType) { DataRow row = groupPermission.NewRow(); row["GroupId"] = item.DataObjectId; row["Status"] = item.IsAllow; groupPermission.Rows.Add(row); } } bool deafultStatus = false; DataPermission typePermission = permissions.SingleOrDefault(d => d.ExchangeSystemCode == exchangeCode && d.DataObjectType == GroupType && d.DataObjectId == null); if (typePermission != null) { deafultStatus = typePermission.IsAllow; } else { DataPermission exchangePermission = permissions.SingleOrDefault(d => d.ExchangeSystemCode == exchangeCode && d.DataObjectType == DataObjectType.Exchange); if (exchangePermission != null) { deafultStatus = exchangePermission.IsAllow; } } List<Guid> memberIds = new List<Guid>(); using (SqlConnection con = DataAccess.GetInstance(exchangeCode).GetSqlConnection()) { using (SqlCommand command = con.CreateCommand()) { command.CommandText = "[dbo].[Manager_GetMemberIds]"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@GroupType", GroupType.ToString())); command.Parameters.Add(new SqlParameter("@deafultStatus", deafultStatus)); SqlParameter tableParameter = command.Parameters.AddWithValue("@dataPermissions", groupPermission); tableParameter.SqlDbType = SqlDbType.Structured; tableParameter.TypeName = "[dbo].[DataPermissions]"; using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Guid memberId = (Guid)reader["MemberID"]; memberIds.Add(memberId); } } } } return memberIds; }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { return(DataObjectType.GetHashCode()); }
public static DataObjectCategory GetObjectCategory(DataObjectType item) { return(new DataObjectCategory(Items[(int)item])); }
private object LoadDataObject(string p_strSpName, object p_oDataObject, DataObjectType p_dotType, params object[] p_oParameters) { object oRetunObject = null; SqlConnection g_SqlConnection = GetConnectionSql(); try { //command oluşturulup parametreleri dolduruluyor.////////////////////////////// g_SqlConnection.InfoMessage += OnInfoMessage; g_SqlConnection.Open(); SqlCommand scCommand = new SqlCommand(p_strSpName, g_SqlConnection); scCommand.CommandTimeout = 20 * 60 * 1000; if (p_oParameters.Length > 0)//spnin parametreleri var ise { scCommand.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(scCommand);//commandın parametreleri alınıyor. for (int i = 1; i < scCommand.Parameters.Count; i++) { object o = p_oParameters[i - 1]; if (o == null) { o = DBNull.Value; } if (o is DateTime && Convert.ToDateTime(o).Year > 2500)//webserviste null değer gönderilemiyor. bu nedenle tarihler null gönderilecekse 2500 den büyük bir tarih veriliyor. Biz de burda onu yeniden null değere çeviriyoruz. { o = DBNull.Value; } scCommand.Parameters[i].Value = o; } } else { scCommand.CommandType = CommandType.Text; } /***********************************************************************/ if (p_dotType == DataObjectType.DataSet)//dataset döndürecek ise { SqlDataAdapter sdaAdapter = new SqlDataAdapter(scCommand); sdaAdapter.Fill((DataSet)p_oDataObject); } else if (p_dotType == DataObjectType.DataTable)//datatable döndürecek ise { SqlDataAdapter sdaAdapter = new SqlDataAdapter(scCommand); sdaAdapter.Fill((DataTable)p_oDataObject); if (((DataTable)p_oDataObject).Rows.Count > 0) { g_strInfoMessage = ((DataTable)p_oDataObject).Rows.Count.ToString() + " rows affected."; } } else if (p_dotType == DataObjectType.None)//sadece çalışacak ise { int iRowCount = scCommand.ExecuteNonQuery(); g_strInfoMessage = iRowCount.ToString() + " rows affected."; } else if (p_dotType == DataObjectType.Object)//obje döndürecek ise { oRetunObject = scCommand.ExecuteScalar(); g_strInfoMessage = "0 rows affected."; } } catch (SqlException ex) { DisplaySqlErrors(ex); if (g_SqlConnection != null && g_SqlConnection.State != ConnectionState.Closed) { g_SqlConnection.Close(); } throw (new Exception("Hata : " + ex.Message + "...")); //oRetunObject = ex.Message; } finally { //connection kapatılıyor if (g_SqlConnection != null && g_SqlConnection.State != ConnectionState.Closed) { g_SqlConnection.Close(); } } return(oRetunObject); }
/// <summary> /// Create new Data object like Table,Column,Row,Relation etc /// </summary> /// <param name="objectName">Object Name</param> /// <param name="objectType">Object Type</param> public DataContainerObject(string objectName, DataObjectType objectType) { DataObjectType = objectType; Name = objectName; OjbectId = Guid.NewGuid().ToString(); }
public static ISubmodelElement ToSubmodelElement(this SubmodelElementType_V1_0 envSubmodelElement, List <IConceptDescription> conceptDescriptions) { if (envSubmodelElement == null) { logger.Warn("EnvironmentSubmodelElement is null"); return(null); } ModelType modelType = envSubmodelElement.ModelType; if (modelType == null) { logger.Warn("ModelType of Element " + envSubmodelElement.IdShort + " is null"); return(null); } SubmodelElement submodelElement = null; if (modelType == ModelType.Property && envSubmodelElement is Property_V1_0 castedProperty) { Property property; if (DataObjectType.TryParse(castedProperty.ValueType, out DataObjectType dataObjectType)) { property = new Property(new DataType(dataObjectType)); } else { logger.Warn("Unable to parse ValueType of Property " + castedProperty.IdShort + " - ValueType: " + castedProperty.ValueType); property = new Property(); } property.Value = castedProperty.Value; property.ValueId = castedProperty.ValueId?.ToReference_V1_0(); submodelElement = property; } else if (modelType == ModelType.File && envSubmodelElement is File_V1_0 castedFile) { File file = new File { MimeType = castedFile.MimeType, Value = castedFile.Value }; submodelElement = file; } else if (modelType == ModelType.Blob && envSubmodelElement is Blob_V1_0 castedBlob) { Blob blob = new Blob { MimeType = castedBlob.MimeType, Value = Convert.FromBase64String(castedBlob.Value) }; submodelElement = blob; } else if (modelType == ModelType.RelationshipElement && envSubmodelElement is RelationshipElement_V1_0 castedRelationshipElement) { RelationshipElement relationshipElement = new RelationshipElement { First = castedRelationshipElement.First?.ToReference_V1_0 <IReferable>(), Second = castedRelationshipElement.Second?.ToReference_V1_0 <IReferable>() }; submodelElement = relationshipElement; } else if (modelType == ModelType.ReferenceElement && envSubmodelElement is ReferenceElement_V1_0 castedReferenceElement) { ReferenceElement referenceElement = new ReferenceElement { Value = castedReferenceElement.Value?.ToReference_V1_0() }; submodelElement = referenceElement; } else if (modelType == ModelType.Event && envSubmodelElement is Event_V1_0 castedEvent) { Event eventable = new Event(); submodelElement = eventable; } else if (modelType == ModelType.Operation && envSubmodelElement is Operation_V1_0 castedOperation) { Operation operation = new Operation { InputVariables = new OperationVariableSet(), OutputVariables = new OperationVariableSet() }; var operationInElements = castedOperation.In?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationInElements?.Count > 0) { foreach (var element in operationInElements) { operation.InputVariables.Add(element); } } var operationOutElements = castedOperation.Out?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationOutElements?.Count > 0) { foreach (var element in operationOutElements) { operation.OutputVariables.Add(element); } } submodelElement = operation; } else if (modelType == ModelType.SubmodelElementCollection && envSubmodelElement is SubmodelElementCollection_V1_0 castedSubmodelElementCollection) { SubmodelElementCollection submodelElementCollection = new SubmodelElementCollection(); if (castedSubmodelElementCollection.Value?.Count > 0) { submodelElementCollection.Value = new ElementContainer <ISubmodelElement>(); List <ISubmodelElement> smElements = castedSubmodelElementCollection.Value?.ConvertAll(c => c.submodelElement?.ToSubmodelElement(conceptDescriptions)); foreach (var smElement in smElements) { submodelElementCollection.Value.Add(smElement); } } submodelElement = submodelElementCollection; } if (submodelElement == null) { logger.Warn("SubmodelElement " + envSubmodelElement.IdShort + " is still null"); return(null); } submodelElement.Category = envSubmodelElement.Category; submodelElement.Description = envSubmodelElement.Description; submodelElement.IdShort = envSubmodelElement.IdShort; submodelElement.Kind = envSubmodelElement.Kind; submodelElement.SemanticId = envSubmodelElement.SemanticId?.ToReference_V1_0(); submodelElement.Constraints = null; string semanticId = envSubmodelElement.SemanticId?.Keys?.FirstOrDefault()?.Value; if (!string.IsNullOrEmpty(semanticId)) { submodelElement.ConceptDescription = conceptDescriptions.Find(f => f.Identification.Id == semanticId); submodelElement.EmbeddedDataSpecifications = submodelElement.ConceptDescription?.EmbeddedDataSpecifications; } return(submodelElement); }
public IEnumerable <DataObject> GetUntypedEditableReader(ITransaction transaction, IEnumerable <string> readOnlyFields = null) { SchemaObject schemaObject = Schema.Schema.GetSchemaObject(DataObjectType); HashSet <string> fields = new HashSet <string>(); foreach (Schema.Field field in schemaObject.GetFields()) { fields.Add(field.FieldName); } fields.AddRange(readOnlyFields); ISelectQuery selectQuery = GetBaseQuery(schemaObject, fields, out Dictionary <string, string> tableAliasesByFieldPath); DataTable table = selectQuery.Execute(transaction); FieldInfo isEditableField = DataObjectType.GetField("isEditable", BindingFlags.NonPublic | BindingFlags.Instance); foreach (DataRow row in table.Rows) { DataObject dataObject = (DataObject)Activator.CreateInstance(DataObjectType); isEditableField.SetValue(dataObject, true); foreach (IGrouping <string, string> fieldByPath in fields.GroupBy(field => { if (field.Contains(".")) { return(field.Substring(0, field.LastIndexOf('.'))); } return(string.Empty); })) { DataObject objectToSetValueOn = dataObject; if (fieldByPath.Key.Contains(".")) { string[] parts = fieldByPath.Key.Split('.'); SchemaObject lastSchemaObject = schemaObject; for (int i = 0; i < parts.Length - 1; i++) { Relationship relationship = lastSchemaObject.GetRelationship(parts[i]); DataObject relatedDataObject = relationship.GetValue(objectToSetValueOn); if (relatedDataObject == null) { relatedDataObject = (DataObject)Activator.CreateInstance(relationship.RelatedObjectType); relationship.SetPrivateDataCallback(objectToSetValueOn, relatedDataObject); } objectToSetValueOn = relatedDataObject; lastSchemaObject = relationship.RelatedSchemaObject; } } string fieldAlias = tableAliasesByFieldPath[fieldByPath.Key]; foreach (string field in fieldByPath) { string fieldName = field; if (fieldName.Contains('.')) { fieldName = fieldName.Substring(fieldName.LastIndexOf('.') + 1); } string columnName = $"{fieldAlias}_{fieldName}"; object databaseValue = row[columnName]; Schema.Field schemaField = schemaObject.GetField(field); schemaField.SetPrivateDataCallback(objectToSetValueOn, databaseValue); } } yield return(dataObject); } }
public static ISubmodelElement ToSubmodelElement(this SubmodelElementType_V2_0 envSubmodelElement, List <IConceptDescription> conceptDescriptions) { if (envSubmodelElement == null) { return(null); } ModelType modelType = envSubmodelElement.ModelType; if (modelType == null) { return(null); } SubmodelElement submodelElement = null; if (modelType == ModelType.Property && envSubmodelElement is Property_V2_0 castedProperty) { DataObjectType dataObjectType; if (string.IsNullOrEmpty(castedProperty.ValueType)) { dataObjectType = DataObjectType.None; } else if (!DataObjectType.TryParse(castedProperty.ValueType, out dataObjectType)) { return(null); } Property property = new Property(new DataType(dataObjectType)) { Value = castedProperty.Value, ValueId = castedProperty.ValueId?.ToReference_V2_0() }; submodelElement = property; } else if (modelType == ModelType.MultiLanguageProperty && envSubmodelElement is MultiLanguageProperty_V2_0 castedMultiLanguageProperty) { MultiLanguageProperty multiLanguageProperty = new MultiLanguageProperty { Value = castedMultiLanguageProperty.Value, ValueId = castedMultiLanguageProperty.ValueId?.ToReference_V2_0() }; submodelElement = multiLanguageProperty; } else if (modelType == ModelType.Range && envSubmodelElement is Range_V2_0 castedRange) { if (!DataObjectType.TryParse(castedRange.ValueType, out DataObjectType dataObjectType)) { return(null); } Range range = new Range() { Min = new ElementValue(castedRange.Min, new DataType(dataObjectType)), Max = new ElementValue(castedRange.Max, new DataType(dataObjectType)), ValueType = new DataType(dataObjectType) }; submodelElement = range; } else if (modelType == ModelType.File && envSubmodelElement is File_V2_0 castedFile) { File file = new File { MimeType = castedFile.MimeType, Value = castedFile.Value }; submodelElement = file; } else if (modelType == ModelType.Blob && envSubmodelElement is Blob_V2_0 castedBlob) { Blob blob = new Blob { MimeType = castedBlob.MimeType, Value = Convert.FromBase64String(castedBlob.Value) }; submodelElement = blob; } else if (modelType == ModelType.RelationshipElement && envSubmodelElement is RelationshipElement_V2_0 castedRelationshipElement) { RelationshipElement relationshipElement = new RelationshipElement { First = castedRelationshipElement.First?.ToReference_V2_0 <IReferable>(), Second = castedRelationshipElement.Second?.ToReference_V2_0 <IReferable>() }; submodelElement = relationshipElement; } else if (modelType == ModelType.AnnotatedRelationshipElement && envSubmodelElement is AnnotatedRelationshipElement_V2_0 castedAnnotatedRelationshipElement) { AnnotatedRelationshipElement annotatedRelationshipElement = new AnnotatedRelationshipElement() { First = castedAnnotatedRelationshipElement.First?.ToReference_V2_0 <IReferable>(), Second = castedAnnotatedRelationshipElement.Second?.ToReference_V2_0 <IReferable>(), Annotation = castedAnnotatedRelationshipElement.Annotation?.ToReference_V2_0 <ISubmodelElement>() }; submodelElement = annotatedRelationshipElement; } else if (modelType == ModelType.ReferenceElement && envSubmodelElement is ReferenceElement_V2_0 castedReferenceElement) { ReferenceElement referenceElement = new ReferenceElement { Value = castedReferenceElement.Value?.ToReference_V2_0() }; submodelElement = referenceElement; } else if (modelType == ModelType.Event && envSubmodelElement is Event_V2_0 castedEvent) { Event eventable = new Event(); submodelElement = eventable; } else if (modelType == ModelType.BasicEvent && envSubmodelElement is BasicEvent_V2_0 castedBasicEvent) { BasicEvent basicEvent = new BasicEvent() { Observed = castedBasicEvent.Observed.ToReference_V2_0 <IReferable>() }; submodelElement = basicEvent; } else if (modelType == ModelType.Entity && envSubmodelElement is Entity_V2_0 castedEntity) { Entity entity = new Entity() { EntityType = (EntityType)Enum.Parse(typeof(EntityType), castedEntity.EntityType.ToString()), Asset = castedEntity.AssetReference.ToReference_V2_0 <IAsset>() }; var statements = castedEntity.Statements?.ConvertAll(c => c.submodelElement.ToSubmodelElement(conceptDescriptions)); if (statements?.Count > 0) { foreach (var element in statements) { entity.Statements.Add(element); } } submodelElement = entity; } else if (modelType == ModelType.Operation && envSubmodelElement is Operation_V2_0 castedOperation) { Operation operation = new Operation { InputVariables = new OperationVariableSet(), OutputVariables = new OperationVariableSet(), InOutputVariables = new OperationVariableSet() }; var operationInElements = castedOperation.InputVariables?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationInElements?.Count > 0) { foreach (var element in operationInElements) { operation.InputVariables.Add(element); } } var operationOutElements = castedOperation.OutputVariables?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationOutElements?.Count > 0) { foreach (var element in operationOutElements) { operation.OutputVariables.Add(element); } } var operationInOutElements = castedOperation.InOutputVariables?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationInOutElements?.Count > 0) { foreach (var element in operationInOutElements) { operation.InOutputVariables.Add(element); } } submodelElement = operation; } else if (modelType == ModelType.SubmodelElementCollection && envSubmodelElement is SubmodelElementCollection_V2_0 castedSubmodelElementCollection) { SubmodelElementCollection submodelElementCollection = new SubmodelElementCollection(); if (castedSubmodelElementCollection.Value?.Count > 0) { submodelElementCollection.Value = new ElementContainer <ISubmodelElement>(); List <ISubmodelElement> smElements = castedSubmodelElementCollection.Value?.ConvertAll(c => c.submodelElement?.ToSubmodelElement(conceptDescriptions)); foreach (var smElement in smElements) { submodelElementCollection.Value.Add(smElement); } } submodelElement = submodelElementCollection; } if (submodelElement == null) { return(null); } submodelElement.Category = envSubmodelElement.Category; submodelElement.Description = envSubmodelElement.Description; submodelElement.IdShort = envSubmodelElement.IdShort; submodelElement.Kind = envSubmodelElement.Kind; submodelElement.SemanticId = envSubmodelElement.SemanticId?.ToReference_V2_0(); submodelElement.Parent = string.IsNullOrEmpty(envSubmodelElement.Parent) ? null : new Reference( new Key(KeyElements.AssetAdministrationShell, KeyType.IRI, envSubmodelElement.Parent, true)); submodelElement.Constraints = null; string semanticId = envSubmodelElement.SemanticId?.Keys?.FirstOrDefault()?.Value; if (!string.IsNullOrEmpty(semanticId)) { submodelElement.ConceptDescription = conceptDescriptions.Find(f => f.Identification.Id == semanticId); submodelElement.EmbeddedDataSpecifications = submodelElement.ConceptDescription?.EmbeddedDataSpecifications; } return(submodelElement); }