Ejemplo n.º 1
0
        private void RepairLinkRestrictions()
        {
            IResourceStore store            = MyPalStorage.Storage;
            IResourceList  restrictionsList = store.GetAllResources("LinkRestriction");
            HashSet        involvedResTypes = new HashSet();

            PropTypeCollection propTypes = (PropTypeCollection)MyPalStorage.Storage.PropTypes;

            foreach (IResource lr in restrictionsList)
            {
                int linkType = lr.GetIntProp("LinkType");
                if (!propTypes.IsValidType(linkType))
                {
                    lr.Delete();
                }
                else
                {
                    string fromResourceType = lr.GetStringProp("fromResourceType");
                    if (fromResourceType != null)
                    {
                        involvedResTypes.Add(fromResourceType);
                    }
                }
            }

            restrictionsList = store.GetAllResources("LinkRestriction");

            foreach (HashSet.Entry E in involvedResTypes)
            {
                string resType = (string)E.Key;
                ShowProgress("Checking link restrictions for resources of type '{0}'...", resType);

                IResourceList resources = store.GetAllResources(resType);
                foreach (IResource resource in resources)
                {
                    foreach (IResource lr in restrictionsList)
                    {
                        if (lr.GetStringProp("fromResourceType") == resource.Type)
                        {
                            RepairLinkRestriction(lr, resource);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void RepairUniqueRestrictions()
        {
            IResourceStore store            = MyPalStorage.Storage;
            IResourceList  restrictionsList = store.GetAllResources("UniqueRestriction");
            HashSet        involvedResTypes = new HashSet();

            PropTypeCollection propTypes = (PropTypeCollection)MyPalStorage.Storage.PropTypes;

            foreach (IResource lr in restrictionsList)
            {
                int uniquePropId = lr.GetIntProp("UniquePropId");
                if (!propTypes.IsValidType(uniquePropId))
                {
                    lr.Delete();
                }
                else
                {
                    string fromResourceType = lr.GetStringProp("fromResourceType");
                    if (fromResourceType != null)
                    {
                        involvedResTypes.Add(fromResourceType);
                    }
                }
            }

            restrictionsList = store.GetAllResources("UniqueRestriction");

            foreach (HashSet.Entry E in involvedResTypes)
            {
                string resType = (string)E.Key;
                ShowProgress("Checking unique restrictions for resources of type '{0}'...", resType);

                IResourceList resources  = store.GetAllResources(resType);
                HashMap       propValues = new HashMap();

                foreach (IResource resource in resources)
                {
                    IntHashSet propIds = new IntHashSet();
                    foreach (IResource ur in restrictionsList)
                    {
                        if (ur.GetStringProp("fromResourceType") == resType)
                        {
                            int propId = ur.GetIntProp("UniquePropId");
                            if (propIds.Contains(propId))      // do not process duplicate restrictions
                            {
                                continue;
                            }
                            propIds.Add(propId);
                            object propValue = resource.GetProp(propId);
                            if (propValue != null)
                            {
                                HashSet propValueSet = (HashSet)propValues [propId];
                                if (propValueSet == null)
                                {
                                    propValueSet        = new HashSet();
                                    propValues [propId] = propValueSet;
                                }
                                if (propValueSet.Contains(propValue))
                                {
                                    ReportError("Unique property value restriction violated: resource ID="
                                                + resource.Id + " property " + store.PropTypes [propId].Name + ", value " + propValue);
                                    if (_fixErrors && IsSafeToDeleteResource(resource))
                                    {
                                        resource.Delete();
                                        ++_fixCount;
                                    }
                                }
                                propValueSet.Add(propValue);
                            }
                        }
                    }
                }
            }
        }