/// <summary> /// Gets the documents list using parameters specified in client request. /// </summary> /// <param name="xml">Parameters for the stored procedure.</param> /// <returns>Xml containing documents list.</returns> public XDocument GetDocuments(XDocument xml) { if (xml.Root.Attribute("type") == null) { throw new System.IO.InvalidDataException("Missing type element."); } BusinessObjectType type; try { type = (BusinessObjectType)Enum.Parse(typeof(BusinessObjectType), xml.Root.Attribute("type").Value, true); } catch (ArgumentException) { RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:123"); throw new ClientException(ClientExceptionId.UnknownBusinessObjectType, null, "objType:" + xml.Root.Attribute("type").Value); } if (this.SupportedBusinessObjectsTypes.Contains(type)) { DatabaseMappingCache dbCache = BusinessObject.ClassDatabaseMappingCache[this.SupportedBusinessObjectsTypes[type]][0]; if (dbCache.Attribute.List != StoredProcedure.Unknown) { return(this.ExecuteStoredProcedure(dbCache.Attribute.List, true, xml)); } } throw new ClientException(ClientExceptionId.UnsupportedBusinessObjectType, null, "objType:" + xml.Root.Attribute("type").Value); }
private static void CacheClass(Type t) { if (!BusinessObject.IsClassCached.ContainsKey(t)) { bool isObjectToCache = false; // get the class attributes object[] obj = t.GetCustomAttributes(typeof(XmlSerializableAttribute), true); if (obj != null && obj.Length == 1) { XmlSerializableAttribute attr = (XmlSerializableAttribute)obj[0]; BusinessObject.ClassXmlSerializationCache.Add(t, new XmlSerializationCache() { Attribute = attr }); isObjectToCache = true; } obj = t.GetCustomAttributes(typeof(DatabaseMappingAttribute), true); if (obj != null && obj.Length > 0) { DatabaseMappingCache[] cache = new DatabaseMappingCache[obj.Length]; for (int i = 0; i < obj.Length; i++) { DatabaseMappingAttribute attr = (DatabaseMappingAttribute)obj[i]; cache[i] = new DatabaseMappingCache() { Attribute = attr }; } BusinessObject.ClassDatabaseMappingCache.Add(t, cache); isObjectToCache = true; } if (isObjectToCache) { //get properties XmlSerializableAttribiute LinkedList <XmlSerializationCache> xmlSerializableCacheList = new LinkedList <XmlSerializationCache>(); foreach (PropertyInfo propertyInfo in t.GetProperties()) { obj = propertyInfo.GetCustomAttributes(typeof(XmlSerializableAttribute), true); if (obj != null && obj.Length == 1) { XmlSerializableAttribute attr = (XmlSerializableAttribute)obj[0]; XmlSerializationCache cache = new XmlSerializationCache() { Attribute = attr, Property = propertyInfo }; if (attr.ProcessLast) { xmlSerializableCacheList.AddLast(cache); } else { xmlSerializableCacheList.AddFirst(cache); } } } XmlSerializationCache[] xmlCache = new XmlSerializationCache[xmlSerializableCacheList.Count]; int u = 0; foreach (XmlSerializationCache c in xmlSerializableCacheList) { xmlCache[u++] = c; } BusinessObject.PropertiesXmlSerializationCache.Add(t, xmlCache); //get properties ComparableAttribiute List <ComparableCache> comparableCacheList = new List <ComparableCache>(); foreach (PropertyInfo propertyInfo in t.GetProperties()) { obj = propertyInfo.GetCustomAttributes(typeof(ComparableAttribute), true); if (obj != null && obj.Length == 1) { ComparableAttribute attr = (ComparableAttribute)obj[0]; ComparableCache cache = new ComparableCache() { Attribute = attr, Property = propertyInfo }; comparableCacheList.Add(cache); } } BusinessObject.PropertiesComparableCache.Add(t, comparableCacheList.ToArray()); //get properties DatabaseMappingCache List <DatabaseMappingCache> databaseMappingCacheList = new List <DatabaseMappingCache>(); foreach (PropertyInfo propertyInfo in t.GetProperties()) { obj = propertyInfo.GetCustomAttributes(typeof(DatabaseMappingAttribute), true); if (obj != null && obj.Length > 0) { foreach (object objAttr in obj) { DatabaseMappingAttribute attr = (DatabaseMappingAttribute)objAttr; DatabaseMappingCache cache = new DatabaseMappingCache() { Attribute = attr, Property = propertyInfo }; databaseMappingCacheList.Add(cache); } } } BusinessObject.PropertiesDatabaseMappingCache.Add(t, databaseMappingCacheList.ToArray()); BusinessObject.IsClassCached.Add(t, true); } } }
/// <summary> /// Saves changes of specified <see cref="IBusinessObjectRelation"/> to the operations list. /// </summary> /// <param name="businessObject"><see cref="IBusinessObjectRelation"/> to save.</param> /// <param name="document">Xml document containing operation list to execute.</param> public static void SaveRelationChanges(IBusinessObjectRelation businessObject, XDocument document) { IVersionedBusinessObject mainObject; IVersionedBusinessObject relatedObject; //if we are processing a relation from alternate object if (businessObject.Status == BusinessObjectStatus.Deleted) { mainObject = (IVersionedBusinessObject)businessObject.Parent.AlternateVersion; //related object doesn't have to be independently versioned relatedObject = businessObject.RelatedObject as IVersionedBusinessObject; //reference to the OLD version //if we delete an object in new version we dont have its old version via the new main object reference //so we have to grab it from the old main object } else { mainObject = (IVersionedBusinessObject)businessObject.Parent; //related object doesn't have to be independently versioned relatedObject = businessObject.RelatedObject as IVersionedBusinessObject; } //mainObject and relatedObject now reference the NEW version of the alternates if (mainObject.Status == BusinessObjectStatus.Unchanged && mainObject.ForceSave == false && mainObject.NewVersion == null) { businessObject.UpgradeMainObjectVersion = true; mainObject.NewVersion = Guid.NewGuid(); } if (relatedObject != null && relatedObject.Status == BusinessObjectStatus.Unchanged && relatedObject.ForceSave == false && relatedObject.NewVersion == null) { businessObject.UpgradeRelatedObjectVersion = true; relatedObject.NewVersion = Guid.NewGuid(); } Type t = businessObject.GetType(); DatabaseMappingCache[] classCaches = BusinessObject.ClassDatabaseMappingCache[t]; foreach (DatabaseMappingCache classCache in classCaches) //foreach tableName { DatabaseMappingAttribute objAttribute = classCache.Attribute; //find or create table element XElement table = document.Root.Element(objAttribute.TableName); if (table == null) { table = new XElement(objAttribute.TableName); document.Root.Add(table); } //create new entry element XElement entry = new XElement("entry"); table.Add(entry); if (businessObject.Status != BusinessObjectStatus.Deleted) { BusinessObjectHelper.SaveBusinessObjectColumns(businessObject, t, objAttribute, entry, null); Guid newVersion; IVersionedBusinessObject versionedObject = businessObject as IVersionedBusinessObject; if (versionedObject != null) { versionedObject.NewVersion = Guid.NewGuid(); newVersion = versionedObject.NewVersion.Value; } else { newVersion = Guid.NewGuid(); } if (businessObject.Status == BusinessObjectStatus.New) { entry.Add(new XAttribute("action", "insert")); entry.Add(new XElement("version", newVersion.ToUpperString())); } else //BusinessObjectStatus.Modified or child elements changed { entry.Add(new XAttribute("action", "update")); entry.Add(new XElement("_version", newVersion.ToUpperString())); } } else { entry.Add(new XElement("id", businessObject.Id.ToUpperString())); entry.Add(new XElement("version", businessObject.Version.ToUpperString())); entry.Add(new XAttribute("action", "delete")); DatabaseMappingCache[] cache = BusinessObject.PropertiesDatabaseMappingCache[t]; for (int i = 0; i < cache.Length; i++) { DatabaseMappingCache c = cache[i]; if (c.Attribute.ForceSaveOnDelete) { entry.Add(BusinessObjectHelper.SerializeSingleValue(c.Property.PropertyType, c.Attribute.ColumnName, c.Property.GetValue(businessObject, null), c.Attribute.OnlyId, false, false, false)); } } } if (businessObject.UpgradeMainObjectVersion) { entry.Add(new XElement("_object1from", mainObject.Version.ToUpperString())); entry.Add(new XElement("_object1to", mainObject.NewVersion.ToUpperString())); } if (businessObject.UpgradeRelatedObjectVersion) { entry.Add(new XElement("_object2from", relatedObject.Version.ToUpperString())); entry.Add(new XElement("_object2to", relatedObject.NewVersion.ToUpperString())); } } }