Exemplo n.º 1
0
        public ObjectVersionAndProperties SetProperties(ObjVer objVer, PropertyValues propertyValues)
        {
            vault.MetricGatherer.MethodCalled();

            // TODO: use arguments
            // TODO: error checking
            // TODO: use SetAllProperties?
            foreach (PropertyValue propertyValue in propertyValues)
            {
                if (vault.propertyDefs.SingleOrDefault(prop => prop.PropertyDef.ID == propertyValue.PropertyDef) == null)
                {
                    throw new Exception(string.Format("Property does not exist. ({0})", propertyValue.PropertyDef));
                }
            }

            List <TestObjectVersionAndProperties> thisObj =
                vault.ovaps.Where(obj => obj.ObjVer.ID == objVer.ID && obj.ObjVer.Type == objVer.Type).ToList();

            if (thisObj.Count == 0)
            {
                throw new Exception("Object not found");
            }
            int maxVersion = thisObj.Max(obj => obj.ObjVer.Version);

            if (objVer.Version != -1 && objVer.Version != maxVersion)
            {
                throw new Exception("Invalid version.");
            }

            TestObjectVersionAndProperties current = thisObj.Single(obj => obj.ObjVer.Version == maxVersion);

            if (!current.VersionData.ObjectCheckedOut)
            {
                current = ( TestObjectVersionAndProperties )current.Clone();
                current.ObjVer.Version += 1;
                vault.ovaps.Add(current);
            }

            foreach (PropertyValue propertyValue in propertyValues)
            {
                int index = current.properties.IndexOf(propertyValue.PropertyDef);
                if (index == -1)
                {
                    current.properties.Add(-1, propertyValue);
                }
                else
                {
                    current.properties[index] = propertyValue;
                }
            }

            return(current);
        }
Exemplo n.º 2
0
        public ObjectVersionAndProperties SetAllProperties(ObjVer objVer, bool allowModifyingCheckedInObject, PropertyValues propertyValues)
        {
            vault.MetricGatherer.MethodCalled();

            // TODO: error checking
            foreach (PropertyValue propertyValue in propertyValues)
            {
                if (vault.propertyDefs.SingleOrDefault(prop => prop.PropertyDef.ID == propertyValue.PropertyDef) == null)
                {
                    throw new Exception(string.Format("Property does not exist. ({0})", propertyValue.PropertyDef));
                }
            }

            List <TestObjectVersionAndProperties> thisObj =
                vault.ovaps.Where(obj => obj.ObjVer.ID == objVer.ID && obj.ObjVer.Type == objVer.Type).ToList();

            if (thisObj.Count == 0)
            {
                throw new Exception("Object not found");
            }
            int maxVersion = thisObj.Max(obj => obj.ObjVer.Version);

            if (objVer.Version != -1 && objVer.Version != maxVersion)
            {
                throw new Exception("Invalid version");
            }
            TestObjectVersionAndProperties current = thisObj.Single(obj => obj.ObjVer.Version == maxVersion);

            if (!current.VersionData.ObjectCheckedOut)
            {
                if (!allowModifyingCheckedInObject)
                {
                    throw new Exception("Modifying Checked In Object not allowed.");
                }
                current = ( TestObjectVersionAndProperties )current.Clone();
                current.ObjVer.Version += 1;
                vault.ovaps.Add(current);
            }
            current.Properties = propertyValues.Clone();

            return(current);
        }