Ejemplo n.º 1
0
        public void PublishStatus(IEnumerable <UnifiedPolicyStatus> statuses, bool deleteConfiguration = true)
        {
            Dictionary <Guid, List <UnifiedPolicyStatus> > dictionary = UnifiedPolicySession.PartitionByTenant <UnifiedPolicyStatus>(statuses, (UnifiedPolicyStatus status) => status.TenantId);

            foreach (Guid guid in dictionary.Keys)
            {
                ITenantConfigurationSession              tenantSession = UnifiedPolicySession.GetTenantSession(guid);
                ConfigurationSettingStatusBatch          configurationSettingStatusBatch = new ConfigurationSettingStatusBatch(guid);
                IEnumerable <UnifiedPolicySettingStatus> enumerable = (from s in dictionary[guid]
                                                                       select UnifiedPolicyStorageFactory.ToStatusStorage(s)).Cache <UnifiedPolicySettingStatus>();
                foreach (UnifiedPolicySettingStatus configurable in enumerable)
                {
                    configurationSettingStatusBatch.Add(new TenantSettingFacade <UnifiedPolicySettingStatus>(configurable));
                }
                tenantSession.Save(configurationSettingStatusBatch);
                if (deleteConfiguration)
                {
                    foreach (UnifiedPolicySettingStatus unifiedPolicySettingStatus in from s in enumerable
                             where s.ObjectStatus == StatusMode.Deleted
                             select s)
                    {
                        IEnumerable <UnifiedPolicySettingStatus> source = tenantSession.Find <UnifiedPolicySettingStatus>(QueryFilter.AndTogether(new QueryFilter[]
                        {
                            new ComparisonFilter(ComparisonOperator.Equal, UnifiedPolicySettingStatusSchema.SettingType, unifiedPolicySettingStatus.SettingType),
                            new ComparisonFilter(ComparisonOperator.Equal, UnifiedPolicySettingStatusSchema.ObjectId, unifiedPolicySettingStatus.Id.ObjectGuid)
                        }), null, false, null).Cast <UnifiedPolicySettingStatus>();
                        if (source.All((UnifiedPolicySettingStatus s) => s.ObjectStatus == StatusMode.Deleted))
                        {
                            UnifiedPolicySession.DeleteReferencedObject(tenantSession, unifiedPolicySettingStatus);
                        }
                    }
                }
            }
        }