Пример #1
0
        private static HashSet <CompiledFeature> LoadCompiledFeaturesByNamespace(
            FeatureScope featureScope,
            Assembly assembly,
            CompiledFeatureNamespace featureNamespace)
        {
            var loadedFeatures = new HashSet <CompiledFeature>();

            foreach (var featureMetadata in featureNamespace.CompiledFeatureMetadata)
            {
                try
                {
                    var compiledFeature = CompiledFeatureFactory.GetInstance(featureScope, assembly, featureNamespace.Namespace, featureMetadata);
                    loadedFeatures.Add(compiledFeature);
                }
                catch (ClassNotFoundException e)
                {
                    Logger.LogError(e, e.Message);
                }
                catch (InvalidFeatureException e)
                {
                    Logger.LogError(e, e.Message);
                }
            }

            return(loadedFeatures);
        }
Пример #2
0
        public void RetrieveFeaturesForOwnerId()
        {
            string          messageId = Guid.NewGuid().ToString();
            Guid            ownerId   = Guid.NewGuid();
            IList <Feature> features  = new List <Feature>
            {
                Feature.Create(1, ownerId, Guid.Empty, "Feature One"),
                Feature.Create(1, ownerId, Guid.NewGuid(), "Feature Two"),
                Feature.Create(1, ownerId, Guid.NewGuid(), "Feature Three")
            };

            IFeatureStore featureStore             = new StandardFeatureStore(m_StorageContainer);
            FeatureScope  featureScope             = FeatureScope.Create(ownerId, Guid.Empty);
            RetrieveDefinedFeaturesRequest request = RetrieveDefinedFeaturesRequest.Create(messageId, featureScope);

            using (m_MockRepository.Record())
            {
                Expect.Call(m_StorageContainer.Retrieve(featureScope)).Return(features);
                m_MockRepository.ReplayAll();

                RetrieveDefinedFeaturesResponse response = featureStore.RetrieveDefinedFeatures(request);

                Assert.AreEqual(request.Header.MessageId, response.Header.MessageId);
                foreach (Feature feature in response.Result)
                {
                    Assert.AreEqual(ownerId, feature.OwnerId);
                }

                m_MockRepository.VerifyAll();
            }
        }
Пример #3
0
 /// <summary>
 ///   Retrieves the specified feature space.
 /// </summary>
 /// <param name = "featureScope">The feature space.</param>
 /// <returns>An IEnumerable instance containing the results of the query.</returns>
 public IList <Feature> Retrieve(FeatureScope featureScope)
 {
     return(m_ActiveFeatureList.Values
            .Where(entry =>
                   (featureScope.OwnerId == Guid.Empty || featureScope.OwnerId == entry.OwnerId) &&
                   (featureScope.Space == Guid.Empty || featureScope.Space == entry.Space)).ToList());
 }
 /// <summary>
 ///   Builds the feature scope rich text.
 /// </summary>
 /// <param name = "featureScope">The feature scope.</param>
 /// <returns></returns>
 protected string BuildFeatureScopeRichText(FeatureScope featureScope)
 {
     return(string.Format(
                CultureInfo.CurrentUICulture,
                RtfResources.FEATURE_SCOPE_FORMAT,
                featureScope.OwnerId,
                featureScope.Space));
 }
Пример #5
0
        /// <summary>
        /// Factory method that dynamically instantiates a configured feature using condition group metadata
        /// </summary>
        /// <param name="featureScope">The scope in which to look for this feature</param>
        /// <param name="name">Name of the feature</param>
        /// <param name="conditionGroupMetadata">Metadata defining the feature condition group</param>
        /// <returns>Instance of the defined feature</returns>
        public static ConfiguredFeature GetInstance(FeatureScope featureScope, string name, ConditionGroupMetadata conditionGroupMetadata)
        {
            var conditionGroup = new ConditionGroup
            {
                JoinOperator = conditionGroupMetadata.JoinOperator,
                Conditions   = ConditionFactory.GetConditions(conditionGroupMetadata.Conditions)
            };

            return(new ConfiguredFeature(featureScope, name, conditionGroup));
        }
Пример #6
0
        /// <summary>
        /// Factory method that dynamically instantiates a configured feature using a collection of condition group metadata
        /// </summary>
        /// <param name="featureScope">The scope in which to look for this feature</param>
        /// <param name="name">Name of the feature</param>
        /// <param name="conditionGroupsMetadata">Metadata defining the feature condition groups</param>
        /// <returns>Instance of the defined feature</returns>
        public static ConfiguredFeature GetInstance(FeatureScope featureScope, string name, IEnumerable <ConditionGroupMetadata> conditionGroupsMetadata)
        {
            var conditionGroups = conditionGroupsMetadata.Select(conditionGroupMetadata =>
                                                                 new ConditionGroup
            {
                JoinOperator = conditionGroupMetadata.JoinOperator,
                Conditions   = ConditionFactory.GetConditions(conditionGroupMetadata.Conditions)
            }
                                                                 );

            return(new ConfiguredFeature(featureScope, name, conditionGroups));
        }
Пример #7
0
        /// <summary>
        /// Factory method that dynamically instantiates a feature object by its type
        /// </summary>
        /// <param name="featureType">Type of feature to instantiate</param>
        /// <param name="name">Name of feature</param>
        /// <param name="featureScope">The scope in which to look for this feature</param>
        /// <returns>Feature instance</returns>
        public static CompiledFeature GetInstance(Type featureType, string name, FeatureScope featureScope)
        {
            if (!(Activator.CreateInstance(featureType) is CompiledFeature featureInstance))
            {
                throw new InvalidFeatureException(featureType);
            }

            featureInstance.Name         = name;
            featureInstance.FeatureScope = featureScope;

            return(featureInstance);
        }
Пример #8
0
        private static HashSet <CompiledFeature> LoadCompiledFeaturesFromAssembly(FeatureScope featureScope, CompiledFeatureAssembly compiledFeatureAssembly)
        {
            var loadedFeatures = new HashSet <CompiledFeature>();

            var loadedAssembly = Assembly.LoadFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), compiledFeatureAssembly.AssemblyPath));

            foreach (var featureNamespace in compiledFeatureAssembly.CompiledFeatureNamespaces)
            {
                var compiledFeatures = LoadCompiledFeaturesByNamespace(featureScope, loadedAssembly, featureNamespace);
                loadedFeatures.UnionWith(compiledFeatures);
            }

            return(loadedFeatures);
        }
Пример #9
0
        public void Execute(IServiceMethodUiBridge serviceMethodUiBridge)
        {
            FeatureScope featureScope = BuildFeatureScope(serviceMethodUiBridge);

            try
            {
                RetrieveDefinedFeaturesRequest request =
                    RetrieveDefinedFeaturesRequest.Create(MessageIdFactory.GenerateMessageId(), featureScope);
                IFeatureStoreServiceProxy       featureStoreServiceProxy = new FeatureStoreServiceProxy();
                RetrieveDefinedFeaturesResponse response = featureStoreServiceProxy.RetrieveDefinedFeatures(request);
                serviceMethodUiBridge.DisplayResults(BuildResultsRichText(request, response, GetType().Name));
            }
            catch (Exception e)
            {
                serviceMethodUiBridge.DisplayResults(BuildExceptionRichText(e));
            }
        }
Пример #10
0
        /// <summary>
        /// Add a feature to the Features List
        /// </summary>
        public void AddFeature(string featureToCheck, SPFeature activatedFeature, FeatureScope activatedFeatureScope, string parentUrl, bool customFeaturesOnly)
        {
            if (activatedFeature == null)
            {
                return;
            }
            if (activatedFeature.Definition == null)
            {
                return;
            }
            try
            {
                if (featureToCheck.Equals(activatedFeature.Definition.DisplayName, StringComparison.InvariantCultureIgnoreCase) ||
                    featureToCheck.Equals(activatedFeature.Definition.Name, StringComparison.InvariantCultureIgnoreCase) ||
                    featureToCheck.Equals(activatedFeature.Definition.Id.ToString(), StringComparison.InvariantCultureIgnoreCase) ||
                    featureToCheck == "<GUID / Feature Name>" ||
                    featureToCheck == string.Empty)
                {
                    FeatureType featureType = GetFeatureType(activatedFeature.Definition);
                    if (!fm_type_Custom.Checked && featureType == FeatureType.Custom)
                    {
                        return;
                    }
                    if (!fm_type_ThirdParty.Checked && (featureType == FeatureType.NextDocs || featureType == FeatureType.Nintex))
                    {
                        return;
                    }
                    if (!fm_type_SharePoint2007.Checked && featureType == FeatureType.SharePoint)
                    {
                        return;
                    }

                    FeatureToDisplay featureToDisplay = new FeatureToDisplay();
                    featureToDisplay.Type          = featureType;
                    featureToDisplay.Scope         = activatedFeatureScope;
                    featureToDisplay.ParentSiteUrl = parentUrl;
                    featureToDisplay.FolderName    = activatedFeature.Definition.DisplayName;
                    featureToDisplay.GUID          = activatedFeature.Definition.Id;
                    featuresToDisplay.Add(featureToDisplay);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #11
0
        /// <summary>
        ///   Retrieves the specified feature space.
        /// </summary>
        /// <param name = "featureScope">The feature space.</param>
        /// <returns>
        ///   An IEnumerable containing the results of the query.
        /// </returns>
        public IList <Feature> Retrieve(FeatureScope featureScope)
        {
            List <Feature> features = new List <Feature>();

            using (SqlConnection connection = CreateSqlConnection())
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandText = "[FeatureStore].[Retrieve]";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@OwnerUid",
                                                featureScope.OwnerId == Guid.Empty
                                                    ? (object)DBNull.Value
                                                    : featureScope.OwnerId);
                command.Parameters.AddWithValue("@SpaceUid",
                                                featureScope.Space == Guid.Empty
                                                    ? (object)DBNull.Value
                                                    : featureScope.Space);

                connection.Open();

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        long   id    = long.Parse(reader[0].ToString(), CultureInfo.CurrentCulture);
                        Guid   owner = new Guid(reader[1].ToString());
                        Guid   space = new Guid(reader[2].ToString());
                        string name  = reader.GetString(3);

                        Feature feature = Feature.Create(
                            id,
                            owner,
                            space,
                            name);

                        feature.Enabled = reader.GetBoolean(4);

                        features.Add(feature);
                    }
                }
            }

            return(features);
        }
Пример #12
0
        private static RetrieveDefinedFeaturesRequest BuildRetrieveDefinedFeaturesRequestWithSavedFeature(
            string messageId)
        {
            Guid ownerGuid = Guid.NewGuid();
            Guid space     = Guid.NewGuid();

            Feature[] features = new[]
            {
                Feature.Create(3, ownerGuid, space, "RetrieveDefinedFeaturesFeature3"),
                Feature.Create(4, ownerGuid, space, "RetrieveDefinedFeaturesFeature4"),
                Feature.Create(5, ownerGuid, space, "RetrieveDefinedFeaturesFeature5")
            };
            foreach (Feature feature in features)
            {
                AddFeatureToStorage(feature.Name, feature);
            }

            return(RetrieveDefinedFeaturesRequest.Create(messageId, FeatureScope.Create(ownerGuid, space)));
        }
Пример #13
0
        public static bool CheckFeatureActivation(ClientContext context, Guid featureId, FeatureScope scope)
        {
            FeatureCollection features = null;
            switch (scope)
            {
                case FeatureScope.Web:
                    features = context.Web.Features;
                    break;
                case FeatureScope.Site:
                    features = context.Site.Features;
                    break;
                default:
                    throw new NotImplementedException();

            }
            var featureCollection = context.LoadQuery(features.Include(f => f.DefinitionId));
            context.ExecuteQuery();

            return featureCollection.Any(f => f.DefinitionId.Equals(featureId));
        }
        public void Execute(IServiceMethodUiBridge serviceMethodUiBridge)
        {
            m_ServiceMethodUiBridge = serviceMethodUiBridge;
            AsyncOperation asyncOperation = AsyncOperationManager.CreateOperation(m_AsyncKey);

            try
            {
                FeatureScope featureScope = BuildFeatureScope(serviceMethodUiBridge);

                RetrieveDefinedFeaturesRequest request =
                    RetrieveDefinedFeaturesRequest.Create(MessageIdFactory.GenerateMessageId(), featureScope);

                IFeatureStoreServiceProxy featureStoreServiceProxy = new FeatureStoreServiceProxy();


                featureStoreServiceProxy.BeginRetrieveDefinedFeatures(
                    request,
                    ar =>
                {
                    string rtfResults;
                    try
                    {
                        RetrieveDefinedFeaturesResponse response =
                            featureStoreServiceProxy.EndRetrieveDefinedFeatures(ar);

                        rtfResults = BuildResultsRichText(request, response, GetType().Name);
                    }
                    catch (Exception e)
                    {
                        rtfResults = BuildExceptionRichText(e);
                    }

                    asyncOperation.PostOperationCompleted(HandleEndAsync, rtfResults);
                },
                    null);
            }
            catch (Exception e)
            {
                serviceMethodUiBridge.DisplayResults(BuildExceptionRichText(e));
            }
        }
Пример #15
0
        /// <summary>
        /// Writes all the features that have been defined in the service to the Console.
        /// </summary>
        private static void DumpStoredFeatures()
        {
            IFeatureStoreServiceProxy       proxy    = new FeatureStoreServiceProxy();
            RetrieveDefinedFeaturesResponse response =
                proxy.RetrieveDefinedFeatures(
                    RetrieveDefinedFeaturesRequest.Create(
                        "DumpStoredFeatures", FeatureScope.Create(Guid.Empty, Guid.Empty)));

            foreach (Feature feature in response.Result)
            {
                Console.WriteLine(
                    string.Format(
                        CultureInfo.CurrentUICulture,
                        "Id [{0}], OwnerOd [{1}], Space [{2}], Name [{3}], Enabled [{4}]",
                        feature.Id,
                        feature.OwnerId,
                        feature.Space,
                        feature.Name,
                        feature.Enabled));
            }
        }
Пример #16
0
        /// <summary>
        /// Loads compiled features from an assembly specified in a metadata collection
        /// </summary>
        /// <param name="featureScope">The scope in which to look for the features</param>
        /// <param name="compiledFeatureAssemblies">Collection of feature assembly metadata</param>
        /// <returns>Collection of compiled feature instances</returns>
        public static HashSet <CompiledFeature> LoadCompiledFeaturesFromAssemblies(
            FeatureScope featureScope,
            CompiledFeatureAssembly[] compiledFeatureAssemblies)
        {
            var loadedFeatures = new HashSet <CompiledFeature>();

            foreach (var compiledFeatureAssembly in compiledFeatureAssemblies)
            {
                try
                {
                    var compiledFeatures = LoadCompiledFeaturesFromAssembly(featureScope, compiledFeatureAssembly);
                    loadedFeatures.UnionWith(compiledFeatures);
                }
                catch (FileNotFoundException ex)
                {
                    Logger.LogError(ex, $"Could not find assembly {compiledFeatureAssembly.AssemblyPath}");
                }
            }

            return(loadedFeatures);
        }
Пример #17
0
        /// <summary>
        /// Thread routine that calls the various service methods thus generating the performance counter data.
        /// </summary>
        /// <param name="stopper">
        /// The stopper.
        /// </param>
        private void Runner(object stopper)
        {
            ManualResetEvent          stopEvent = (ManualResetEvent)stopper;
            IFeatureStoreServiceProxy proxy     = new FeatureStoreServiceProxy();

            Action <int>[] calls = new Action <int>[]
            {
                v => proxy.CreateFeature(CreateFeatureRequest.Create(
                                             "CreateFeature lambda",
                                             Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), Thread.CurrentThread.ManagedThreadId.ToString()))),
                v =>
                proxy.UpdateFeatureState(
                    UpdateFeatureStateRequest.Create(
                        "UpdateFeatureState lambda",
                        CreateFeatureKey(v),
                        !m_StandardFeatures[v].Enabled)),
                v =>
                proxy.CheckFeatureState(
                    CheckFeatureStateRequest.Create(
                        "CheckFeatureState lambda", CreateFeatureKey(v))), v =>
                proxy.RetrieveDefinedFeatures(
                    RetrieveDefinedFeaturesRequest.Create(
                        "RetrieveDefinedFeatures lambda",
                        FeatureScope.Create(m_StandardFeatures[v].OwnerId, m_StandardFeatures[v].Space)))
            };

            while (true)
            {
                int index = m_Random.Next(0, calls.Length);

                Console.WriteLine(@"Invoking lambda {0}", index);
                calls[index].Invoke(index);

                if (stopEvent.WaitOne(20))
                {
                    break;
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Factory method that dynamically instantiates feature classes using assembly and class metadata
        /// </summary>
        /// <param name="featureScope">The scope in which to look for this feature</param>
        /// <param name="assembly">Assembly containing the feature type</param>
        /// <param name="namespace">Namespace containing the feature type</param>
        /// <param name="featureMetadata">Metadata about the feature type</param>
        /// <returns>Instance of the specified feature</returns>
        public static CompiledFeature GetInstance(FeatureScope featureScope, Assembly assembly, string @namespace, CompiledFeatureMetadata featureMetadata)
        {
            var fullyQualifiedClassName = $"{@namespace}.{featureMetadata.ClassName}";
            var featureType             = assembly.GetType(fullyQualifiedClassName);

            if (featureType == null)
            {
                throw new ClassNotFoundException(assembly, fullyQualifiedClassName);
            }

            try
            {
                var name            = featureMetadata.Name;
                var scope           = featureScope;
                var featureInstance = GetInstance(featureType, name, scope);
                return(featureInstance);
            }
            catch (InvalidFeatureException)
            {
                throw new InvalidFeatureException(assembly, fullyQualifiedClassName);
            }
        }
Пример #19
0
        public void RetrieveDefinedFeaturesExceptionThrown()
        {
            string    messageId = Guid.NewGuid().ToString();
            Exception exception = m_MockRepository.StrictMock <Exception>();

            RetrieveDefinedFeaturesRequest request = RetrieveDefinedFeaturesRequest.Create(messageId,
                                                                                           FeatureScope.Create(
                                                                                               Guid.NewGuid(),
                                                                                               Guid.NewGuid()));

            IFeatureStore featureStore = new StandardFeatureStore(m_StorageContainer);

            using (m_MockRepository.Record())
            {
                Expect.Call(m_StorageContainer.Retrieve(request.FeatureScope)).Throw(exception);

                m_MockRepository.ReplayAll();

                try
                {
                    featureStore.RetrieveDefinedFeatures(request);
                    Assert.Fail("Expected FeatureCreationException");
                }
                catch (RetrieveDefinedFeaturesException)
                {
                }

                m_MockRepository.VerifyAll();
            }
        }
Пример #20
0
        /// <summary>
        /// Factory method that dynamically instantiates a configured feature using condition metadata
        /// </summary>
        /// <param name="featureScope">The scope in which to look for this feature</param>
        /// <param name="name">Name of the feature</param>
        /// <param name="conditionMetadata">Metadata defining the feature condition</param>
        /// <returns>Instance of the defined feature</returns>
        public static ConfiguredFeature GetInstance(FeatureScope featureScope, string name, ConditionMetadata conditionMetadata)
        {
            var condition = ConditionFactory.GetCondition(conditionMetadata);

            return(new ConfiguredFeature(featureScope, name, condition));
        }
 /// <summary>
 ///   Builds the feature scope.
 /// </summary>
 /// <param name = "serviceMethodUiBridge">The service method UI bridge.</param>
 /// <returns></returns>
 protected FeatureScope BuildFeatureScope(IServiceMethodUiBridge serviceMethodUiBridge)
 {
     return(FeatureScope.Create(
                serviceMethodUiBridge.FeatureStoreMethodArguments.OwnerId,
                serviceMethodUiBridge.FeatureStoreMethodArguments.Space));
 }
Пример #22
0
        public void ExerciseFullInterface()
        {
            Debug.WriteLine("BEGIN: ExerciseFullInterface");

            CacheSwappingStorageContainer cacheSwappingStorageContainer =
                new CacheSwappingStorageContainer(@".\ExerciseFullInterface_Storage.dat");
            StandardFeatureStore standardFeatureStore = new StandardFeatureStore(cacheSwappingStorageContainer);

            /* -- CreateFeature -- */

            CreateFeatureRequest createFeatureRequest1 = CreateFeatureRequest.Create(
                Guid.NewGuid().ToString(),
                Feature.Create(
                    1,
                    Guid.NewGuid(),
                    Guid.NewGuid(),
                    "Feature One"));

            CreateFeatureRequest createFeatureRequest2 = CreateFeatureRequest.Create(
                Guid.NewGuid().ToString(),
                Feature.Create(
                    2,
                    Guid.NewGuid(),
                    Guid.NewGuid(),
                    "Feature Two"));

            CreateFeatureRequest createFeatureRequest3 = CreateFeatureRequest.Create(
                Guid.NewGuid().ToString(),
                Feature.Create(
                    3,
                    Guid.NewGuid(),
                    Guid.NewGuid(),
                    "Feature Three"));

            CreateFeatureResponse createFeatureResponse = standardFeatureStore.CreateFeature(createFeatureRequest1);

            AssertCreateFeatureResponse(createFeatureRequest1, createFeatureResponse);

            createFeatureResponse = standardFeatureStore.CreateFeature(createFeatureRequest2);
            AssertCreateFeatureResponse(createFeatureRequest2, createFeatureResponse);

            createFeatureResponse = standardFeatureStore.CreateFeature(createFeatureRequest3);
            AssertCreateFeatureResponse(createFeatureRequest3, createFeatureResponse);

            AssertPerformanceCountersRecorded(PerformanceCounterReporterType.CreateFeature, false, 3);

            /* -- CheckFeatureState -- */

            CheckFeatureStateRequest checkFeatureStateRequest1 =
                CheckFeatureStateRequest.Create(
                    Guid.NewGuid().ToString(),
                    FeatureKey.Create(
                        createFeatureRequest1.Feature.Id,
                        createFeatureRequest1.Feature.OwnerId,
                        createFeatureRequest1.Feature.Space));
            CheckFeatureStateResponse checkFeatureStateResponse =
                standardFeatureStore.CheckFeatureState(checkFeatureStateRequest1);

            AssertCheckFeatureStateResponse(checkFeatureStateRequest1, checkFeatureStateResponse);

            CheckFeatureStateRequest checkFeatureStateRequest2 =
                CheckFeatureStateRequest.Create(
                    Guid.NewGuid().ToString(),
                    FeatureKey.Create(
                        createFeatureRequest2.Feature.Id,
                        createFeatureRequest2.Feature.OwnerId,
                        createFeatureRequest2.Feature.Space));

            checkFeatureStateResponse = standardFeatureStore.CheckFeatureState(checkFeatureStateRequest2);
            AssertCheckFeatureStateResponse(checkFeatureStateRequest2, checkFeatureStateResponse);

            CheckFeatureStateRequest checkFeatureStateRequest3 =
                CheckFeatureStateRequest.Create(
                    Guid.NewGuid().ToString(),
                    FeatureKey.Create(
                        createFeatureRequest3.Feature.Id,
                        createFeatureRequest3.Feature.OwnerId,
                        createFeatureRequest3.Feature.Space));

            checkFeatureStateResponse = standardFeatureStore.CheckFeatureState(checkFeatureStateRequest3);
            AssertCheckFeatureStateResponse(checkFeatureStateRequest3, checkFeatureStateResponse);

            AssertPerformanceCountersRecorded(PerformanceCounterReporterType.CheckFeatureState, false, 3);

            /* -- UpdateFeatureState -- */

            UpdateFeatureStateRequest updateFeatureStateRequest1 =
                UpdateFeatureStateRequest.Create(
                    Guid.NewGuid().ToString(),
                    FeatureKey.Create(
                        createFeatureRequest1.Feature.Id,
                        createFeatureRequest1.Feature.OwnerId,
                        createFeatureRequest1.Feature.Space),
                    true);
            UpdateFeatureStateResponse updateFeatureStateResponse =
                standardFeatureStore.UpdateFeatureState(updateFeatureStateRequest1);

            Assert.IsTrue(updateFeatureStateResponse.Result.Enabled);

            UpdateFeatureStateRequest updateFeatureStateRequest2 =
                UpdateFeatureStateRequest.Create(
                    Guid.NewGuid().ToString(),
                    FeatureKey.Create(
                        createFeatureRequest2.Feature.Id,
                        createFeatureRequest2.Feature.OwnerId,
                        createFeatureRequest2.Feature.Space),
                    true);

            updateFeatureStateResponse = standardFeatureStore.UpdateFeatureState(updateFeatureStateRequest2);
            Assert.IsTrue(updateFeatureStateResponse.Result.Enabled);

            UpdateFeatureStateRequest updateFeatureStateRequest3 =
                UpdateFeatureStateRequest.Create(
                    Guid.NewGuid().ToString(),
                    FeatureKey.Create(
                        createFeatureRequest3.Feature.Id,
                        createFeatureRequest3.Feature.OwnerId,
                        createFeatureRequest3.Feature.Space),
                    true);

            updateFeatureStateResponse = standardFeatureStore.UpdateFeatureState(updateFeatureStateRequest3);
            Assert.IsTrue(updateFeatureStateResponse.Result.Enabled);

            AssertPerformanceCountersRecorded(PerformanceCounterReporterType.UpdateFeatureState, false, 3);

            /* -- RetrieveDefinedFeatures -- */

            RetrieveDefinedFeaturesRequest retrieveDefinedFeaturesRequest = RetrieveDefinedFeaturesRequest.Create(
                Guid.NewGuid().ToString(),
                FeatureScope.Create(createFeatureRequest1.Feature.OwnerId, createFeatureRequest1.Feature.Space));

            RetrieveDefinedFeaturesResponse retrieveDefinedFeaturesResponse =
                standardFeatureStore.RetrieveDefinedFeatures(retrieveDefinedFeaturesRequest);

            Assert.IsNotNull(retrieveDefinedFeaturesResponse.Result);
            Assert.IsTrue(retrieveDefinedFeaturesResponse.Result.GetEnumerator().MoveNext());

            AssertPerformanceCountersRecorded(PerformanceCounterReporterType.RetrieveDefinedFeatures, true, 1);

            Debug.WriteLine("END: ExerciseFullInterface");
        }
Пример #23
0
 public ConfiguredFeature(FeatureScope featureScope, string name, IEnumerable <ConditionGroup> conditionGroups)
 {
     FeatureScope    = featureScope;
     Name            = name;
     ConditionGroups = conditionGroups;
 }
Пример #24
0
 public ConfiguredFeature(FeatureScope featureScope, string name, ConditionGroup conditionGroup)
 {
     FeatureScope   = featureScope;
     Name           = name;
     ConditionGroup = conditionGroup;
 }
Пример #25
0
 public ConfiguredFeature(FeatureScope featureScope, string name, Condition condition)
 {
     FeatureScope = featureScope;
     Name         = name;
     Condition    = condition;
 }
Пример #26
0
        public void StorageIsQueryableBySpaceAndOwnerId()
        {
            Guid ownerId1 = Guid.NewGuid();
            Guid ownerId2 = Guid.NewGuid();
            Guid ownerId3 = Guid.NewGuid();

            Guid space1 = Guid.NewGuid();
            Guid space2 = Guid.NewGuid();
            Guid space3 = Guid.NewGuid();

            List <Feature> defined = new List <Feature>
            {
                Feature.Create(1, ownerId1, space1, "space1 ownerId1"),
                Feature.Create(1, ownerId1, space2, "space2 ownerId1"),
                Feature.Create(1, ownerId1, space3, "space3 ownerId1"),
                Feature.Create(1, ownerId2, space1, "space1 ownerId2"),
                Feature.Create(2, ownerId2, space1, "space1 ownerId2"),
                Feature.Create(3, ownerId2, space1, "space1 ownerId2"),
                Feature.Create(1, ownerId2, space2, "space2 ownerId2"),
                Feature.Create(1, ownerId2, space3, "space3 ownerId2"),
                Feature.Create(1, ownerId3, space1, "space1 ownerId3"),
                Feature.Create(1, ownerId3, space2, "space2 ownerId3"),
                Feature.Create(1, ownerId3, space3, "space3 ownerId3")
            };

            // CacheSwappingStorageContainer container = new CacheSwappingStorageContainer(@"MultipleQuery.dat");

            foreach (Feature feature in defined)
            {
                Feature stored = m_StorageContainer.Store(feature);

                Assert.AreEqual(feature.Id, stored.Id);
                Assert.AreEqual(feature.Space, stored.Space);
                Assert.AreEqual(feature.OwnerId, stored.OwnerId);
                Assert.AreEqual(feature.Name, stored.Name);
                Assert.AreEqual(feature.Enabled, stored.Enabled);
            }

            /* -- Assert Owner1 All Features -- */
            List <Feature> owner1Features =
                new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId1, Guid.Empty)));

            Assert.AreEqual(3, owner1Features.Count);
            CollectionAssert.Contains(owner1Features, defined[0]);
            CollectionAssert.Contains(owner1Features, defined[1]);
            CollectionAssert.Contains(owner1Features, defined[2]);

            /* -- Assert Owner2 All Features -- */
            List <Feature> owner2Features =
                new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId2, Guid.Empty)));

            Assert.AreEqual(5, owner2Features.Count);
            CollectionAssert.Contains(owner2Features, defined[3]);
            CollectionAssert.Contains(owner2Features, defined[4]);
            CollectionAssert.Contains(owner2Features, defined[5]);
            CollectionAssert.Contains(owner2Features, defined[6]);
            CollectionAssert.Contains(owner2Features, defined[7]);

            /* -- Assert Owner2 Space1 Features -- */
            List <Feature> owner2Space1Features =
                new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId2, space1)));

            Assert.AreEqual(3, owner2Space1Features.Count);
            CollectionAssert.Contains(owner2Space1Features, defined[3]);
            CollectionAssert.Contains(owner2Space1Features, defined[4]);
            CollectionAssert.Contains(owner2Space1Features, defined[5]);

            /* -- Assert Owner2 Space2 Features -- */
            List <Feature> owner2Space2Features =
                new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId2, space2)));

            Assert.AreEqual(1, owner2Space2Features.Count);
            CollectionAssert.Contains(owner2Space2Features, defined[6]);

            /* -- Assert Owner2 Space3 Features -- */
            List <Feature> owner2Space3Features =
                new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId2, space3)));

            Assert.AreEqual(1, owner2Space3Features.Count);
            CollectionAssert.Contains(owner2Space3Features, defined[7]);

            /* -- Assert Owner3 All Features -- */
            List <Feature> owner3Features =
                new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId3, Guid.Empty)));

            Assert.AreEqual(3, owner3Features.Count);
            CollectionAssert.Contains(owner3Features, defined[8]);
            CollectionAssert.Contains(owner3Features, defined[9]);
            CollectionAssert.Contains(owner3Features, defined[10]);

            /* -- Assert Owner3 Space1 Features -- */
            List <Feature> owner3Space1Features =
                new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId3, space1)));

            Assert.AreEqual(1, owner3Space1Features.Count);
            CollectionAssert.Contains(owner3Space1Features, defined[8]);

            /* -- Assert Owner2 Space2 Features -- */
            List <Feature> owner3Space2Features =
                new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId3, space2)));

            Assert.AreEqual(1, owner3Space2Features.Count);
            CollectionAssert.Contains(owner3Space2Features, defined[9]);

            /* -- Assert Owner2 Space3 Features -- */
            List <Feature> owner3Space3Features =
                new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId3, space3)));

            Assert.AreEqual(1, owner3Space3Features.Count);
            CollectionAssert.Contains(owner3Space3Features, defined[10]);
        }
Пример #27
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                Guid featureDefinitionID = GetFeatureID();
                if (featureDefinitionID == Guid.Empty)
                {
                    throw new ApplicationException("Feature titled " + FeatureTitle + " not defined in scope " + FeatureScope.ToString());
                }

                using (SPSite targetSite = new SPSite(WebURL, __Context.Site.UserToken))
                {
                    if (GetTargetScope() == SPFeatureScope.Site)
                    {
                        targetSite.Features.Add(featureDefinitionID, true);
                    }
                    else if (GetTargetScope() == SPFeatureScope.Web)
                    {
                        using (SPWeb targetWeb = targetSite.OpenWeb())
                        {
                            targetWeb.Features.Add(featureDefinitionID, true);
                        }
                    }

                    string message = GetTargetScope().ToString() + " feature, " + FeatureTitle + "(" + featureDefinitionID.ToString() + "), activated at " + WebURL;
                    WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }