private static void SetLinkingEntryValues(XPObject newObject, XPObject targetType, XPObject linking) { var session = newObject.Session; linking.SetMemberValue(newObject.ClassInfo.ClassType.Name, newObject); var defaultValue = session.GetObjectByKey(targetType.GetType(), targetType.Oid); linking.SetMemberValue(targetType.ClassInfo.ClassType.Name, defaultValue); }
private static void SetFieldValue(XPObject newObject, DataMap map, object value) { var fieldType = newObject.ClassInfo.GetPersistentMember(map.PropertyName).MemberType; if (value.GetType() != fieldType) { var result = Convert.ChangeType(value, fieldType); newObject.SetMemberValue(map.PropertyName, result); } else { newObject.SetMemberValue(map.PropertyName, value); } }
private void SetAllFieldValues(int i, XPObject newObject) { foreach (var map in MappingData) { try { if (map.IsAssociation) { //TODO: figure out how to handle creating Many-to-Many entries var test = newObject.GetMemberValue(map.PropertyName); var test2 = (XPCollection)test; if (newObject.GetMemberValue(map.PropertyName) is XPCollection collection) { collection.Add(map.DefaultValue); continue; } if (map.DefaultValue is XPObject targetType) { XPObject linking = FindLinkingTable(newObject, targetType); if (linking is null) { continue; } SetLinkingEntryValues(newObject, targetType, linking); continue; } } object value = GetValue(i, map); if (value is null) { continue; } SetFieldValue(newObject, map, value); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(ex.StackTrace); System.Diagnostics.Debug.WriteLine(ex.InnerException?.Message); System.Diagnostics.Debug.WriteLine(ex.InnerException?.StackTrace); continue; } } }
void LoadResources() { ResourceBaseCollection resources = schedulerStorage1.Resources.Items; if (resources.Count <= 0) { resources.Add(this.schedulerStorage1.CreateResource(0, "Andrew Fuller")); resources.Add(this.schedulerStorage1.CreateResource(1, "Nancy Davolio")); resources.Add(this.schedulerStorage1.CreateResource(2, "Janet Leverling")); resources.Add(this.schedulerStorage1.CreateResource(3, "Margaret Peacock")); } int count = xpResources.Count; for (int i = 0; i < count; i++) { XPObject o = (XPObject)xpResources[i]; o.Save(); } }
void InitData() { ResourceBaseCollection resources = schedulerStorage.Resources.Items; if (resources.Count <= 0) { resources.Add(this.schedulerStorage.CreateResource(0, "Andrew Fuller")); resources.Add(this.schedulerStorage.CreateResource(1, "Nancy Davolio")); resources.Add(this.schedulerStorage.CreateResource(2, "Janet Leverling")); resources.Add(this.schedulerStorage.CreateResource(3, "Margaret Peacock")); int count = xpCollectionResources.Count; for (int i = 0; i < count; i++) { XPObject o = (XPObject)xpCollectionResources[i]; o.Save(); } } if (schedulerStorage.Appointments.Count == 0) { schedulerStorage.BeginUpdate(); Appointment aptPattern = schedulerStorage.CreateAppointment(AppointmentType.Pattern); DateTime curHour = DateTime.Now.Date.AddHours(DateTime.Now.Hour); aptPattern.Start = curHour.AddDays(-2); aptPattern.End = aptPattern.Start.AddHours(2); aptPattern.RecurrenceInfo.Start = aptPattern.Start; aptPattern.Subject = "Test Appointment To Split"; aptPattern.Description = "Again and again..."; aptPattern.ResourceId = schedulerStorage.Resources[0].Id; aptPattern.StatusKey = (int)AppointmentStatusType.Busy; aptPattern.LabelKey = 1; aptPattern.RecurrenceInfo.Type = RecurrenceType.Daily; aptPattern.RecurrenceInfo.Periodicity = 2; aptPattern.RecurrenceInfo.Range = RecurrenceRange.OccurrenceCount; aptPattern.RecurrenceInfo.OccurrenceCount = 10; schedulerControl.Storage.Appointments.Add(aptPattern); schedulerStorage.EndUpdate(); } }
public static void Transfer <TypeReal>(XPCollection xpCollection, Collection <TypeReal> collectionReal) { if (TypeEx.IsSubclassOf(typeof(TypeReal), typeof(LinkXPObject))) { Collection <XPObject> collection = new Collection <XPObject>(); foreach (XPObject server in xpCollection) { collection.Add(server); } foreach (TypeReal serverReal in collectionReal) { LinkXPObject link = serverReal as LinkXPObject; XPObject server = link.FindXPOject(collection) as XPObject; if (server != null) { collection.Remove(server); } } } }
private static XPObject FindLinkingTable(XPObject newObject, XPObject targetType) { var types = ConnectionHelper.GetPersistentTypes(); var session = newObject.Session; XPObject linking = null; foreach (Type xpType in types) { var meta = session.GetClassInfo(xpType); bool hasRootType = false; bool hasTargetType = false; foreach (var item in meta.PersistentProperties) { if (item is ReflectionPropertyInfo info) { if (info.MemberType == newObject.ClassInfo.ClassType) { hasRootType = true; } if (info.MemberType == targetType.ClassInfo.ClassType) { hasTargetType = true; } if (hasRootType && hasTargetType) { // Create new object of that XP Table linking = Activator.CreateInstance(xpType, session) as XPObject; break; } } } if (hasRootType && hasTargetType) { break; } } return(linking); }
public RequiredPropertyValueMissing(XPObject theObject, string propertyName) : base(String.Format("The {0} property of the {1} object with id {2} must have a value", propertyName, theObject.GetType().Name, theObject.Oid)) { }
public LinkXPObject(XPObject xpObject) { XPObject = xpObject; Oid = xpObject.Oid; }
// Methods public string 生成编号(XPObject ins) { return null; }
// Methods public string 生成编号(XPObject ins) { return(null); }