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);
                        }
                    }
                }
            }
        }
        private TResult GetObjectInternal <TStorage, TResult>(Guid tenantId, Guid objectId, bool includeDeletedObjects, Func <TStorage, TResult> convertFunc) where TStorage : UnifiedPolicyStorageBase, new() where TResult : PolicyConfigurationBase
        {
            TResult result = default(TResult);
            ITenantConfigurationSession tenantSession = UnifiedPolicySession.GetTenantSession(tenantId);
            QueryFilter filter   = UnifiedPolicySession.CreateGetObjectQueryFilter(tenantId, objectId, includeDeletedObjects);
            TStorage    tstorage = tenantSession.Find <TStorage>(filter, null, false, null).Cast <TStorage>().FirstOrDefault <TStorage>();

            if (tstorage != null)
            {
                result = convertFunc(tstorage);
            }
            return(result);
        }
        private PolicyChangeBatch GetChangesInternal <TStorage, TResult>(TenantCookieCollection tenantCookies, Func <TStorage, TResult> convertFunc, bool scopeToWorkload) where TStorage : UnifiedPolicyStorageBase, new() where TResult : PolicyConfigurationBase
        {
            PolicyChangeBatch newBatch = UnifiedPolicySession.GetNewBatch <TResult>(tenantCookies);
            List <TResult>    list     = new List <TResult>();

            foreach (TenantCookie tenantCookie in ((IEnumerable <TenantCookie>)tenantCookies))
            {
                PolicySyncCookie policySyncCookie = PolicySyncCookie.Deserialize(tenantCookie.Cookie);
                string           pagingWatermark  = UnifiedPolicySession.GetPagingWatermark <TResult>(policySyncCookie);
                QueryFilter      queryFilter      = UnifiedPolicySession.CreateGetChangesQueryFilter(tenantCookie, pagingWatermark, tenantCookies.Workload, scopeToWorkload);
                list.AddRange(from TStorage s in UnifiedPolicySession.GetTenantSession(tenantCookie.TenantId).FindPaged <TStorage>(queryFilter, null, false, null, 1000)
                              select convertFunc(s));
                bool flag;
                UnifiedPolicySession.SetPagingWatermark <TResult>(policySyncCookie, PagingHelper.GetProcessedCookie(queryFilter, out flag));
                TenantCookie tenantCookie2 = newBatch.NewCookies[tenantCookie.TenantId];
                tenantCookie2.Cookie   = policySyncCookie.Serialize();
                tenantCookie2.MoreData = !flag;
            }
            newBatch.Changes = list;
            return(newBatch);
        }