public ObjectVersions GetAsObjectVersions()
        {
            TestObjectVersions ovs = new TestObjectVersions();

            foreach (TestObjectVersionAndProperties testOvap in results)
            {
                ovs.Add(-1, testOvap.VersionData);
            }
            return(ovs);
        }
Exemplo n.º 2
0
        public ObjectVersions GetRelationships(ObjVer objVer, MFRelationshipsMode mode)
        {
            vault.MetricGatherer.MethodCalled();

            // TODO: far from optimal, vault.ovaps may need restructuring
            //      MFRelationshipsModeToThisObject is really bad
            List <ObjectVersion> relationships = new List <ObjectVersion>();

            if (mode == MFRelationshipsMode.MFRelationshipsModeAll || mode == MFRelationshipsMode.MFRelationshipsModeFromThisObject)
            {
                ObjectVersionAndProperties ovap = vault.GetOvap(objVer);
                foreach (PropertyValue propertyValue in ovap.Properties)
                {
                    if (propertyValue.Value.IsNULL())
                    {
                        continue;
                    }
                    PropertyDef pdef = vault.propertyDefs.Single(pd => pd.PropertyDef.ID == propertyValue.PropertyDef).PropertyDef;
                    if (pdef.ID <= 101)
                    {
                        continue;
                    }
                    if (!pdef.BasedOnValueList)
                    {
                        continue;
                    }
                    ObjType ot = vault.objTypes.Single(ota => ota.ObjectType.ID == pdef.ValueList).ObjectType;
                    if (!ot.RealObjectType)
                    {
                        continue;
                    }
                    if (propertyValue.Value.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                    {
                        foreach (Lookup value in propertyValue.Value.GetValueAsLookups())
                        {
                            // TODO: find out what causes the following line to be necessary
                            value.ObjectType = pdef.ValueList;
                            if (value.Deleted)
                            {
                                continue;
                            }
                            if (relationships.SingleOrDefault(obj => obj.ObjVer.ID == value.Item && obj.ObjVer.Type == value.ObjectType) == null)
                            {
                                relationships.Add(value.GetAsObjectVersion(vault, true));
                            }
                        }
                    }
                    if (propertyValue.Value.DataType == MFDataType.MFDatatypeLookup)
                    {
                        Lookup value = propertyValue.Value.GetValueAsLookup();
                        if (relationships.SingleOrDefault(obj => obj.ObjVer.ID == value.Item && obj.ObjVer.Type == value.ObjectType) == null)
                        {
                            relationships.Add(value.GetAsObjectVersion(vault, true));
                        }
                    }
                }
            }
            if (mode == MFRelationshipsMode.MFRelationshipsModeAll || mode == MFRelationshipsMode.MFRelationshipsModeToThisObject)
            {
                List <PropertyDef> propertiesThatReferenceThisObjType = vault.propertyDefs
                                                                        .Select(pda => pda.PropertyDef)
                                                                        .Where(pd => pd.BasedOnValueList && pd.ValueList == objVer.Type)
                                                                        .ToList();
                foreach (ObjectVersionAndProperties ovap in vault.ovaps)
                {
                    if (vault.ObjectOperations.GetLatestObjVer(ovap.ObjVer.ObjID, true, true).Version != ovap.ObjVer.Version)
                    {
                        continue;                         // Only do latest version
                    }
                    if (ovap.VersionData.Deleted)
                    {
                        continue;
                    }
                    foreach (PropertyDef propertyDef in propertiesThatReferenceThisObjType)
                    {
                        if (ovap.Properties.IndexOf(propertyDef.ID) == -1)
                        {
                            continue;
                        }
                        if (ovap.Properties.SearchForProperty(propertyDef.ID).Value.IsNULL())
                        {
                            continue;
                        }
                        if (propertyDef.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                        {
                            foreach (Lookup valueAsLookup in ovap.Properties.SearchForProperty(propertyDef.ID).Value.GetValueAsLookups())
                            {
                                if (valueAsLookup.Item != objVer.ID)
                                {
                                    continue;
                                }
                                if (relationships.SingleOrDefault(obj => obj.ObjVer.ID == ovap.ObjVer.ID && obj.ObjVer.Type == ovap.ObjVer.Type) == null)
                                {
                                    relationships.Add(ovap.VersionData);
                                }
                            }
                        }
                        else if (propertyDef.DataType == MFDataType.MFDatatypeLookup)
                        {
                            if (ovap.Properties.SearchForProperty(propertyDef.ID).Value.GetLookupID() != objVer.ID)
                            {
                                continue;
                            }
                            if (relationships.SingleOrDefault(obj => obj.ObjVer.ID == ovap.ObjVer.ID && obj.ObjVer.Type == ovap.ObjVer.Type) == null)
                            {
                                relationships.Add(ovap.VersionData);
                            }
                        }
                    }
                }
            }

            TestObjectVersions objectVersions = new TestObjectVersions();

            foreach (ObjectVersion objectVersion in relationships)
            {
                objectVersions.Add(-1, objectVersion);
            }

            return(objectVersions);
        }