コード例 #1
0
        /// <summary>
        /// Returns a dynamic representation of the provided content object.
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public static dynamic AsDynamic(this Content content)
        {
            Mandate.ParameterNotNull(content, "content");

            return(content.Bend());
        }
コード例 #2
0
        /// <summary>
        /// Gets the parent of the current Content entity relationships
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static File ParentAsFile(this EntityRelationCollection collection)
        {
            Mandate.ParameterNotNull(collection, "collection");

            return(collection.Parent <File>(FixedRelationTypes.FileRelationType));
        }
コード例 #3
0
        /// <summary>
        /// Gets the decendents or self of the current Content entity relationships
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static IEnumerable <File> DescendentsOrSelfAsFile(this EntityRelationCollection collection)
        {
            Mandate.ParameterNotNull(collection, "collection");

            return(collection.DescendentsOrSelf <File>(FixedRelationTypes.FileRelationType));
        }
コード例 #4
0
 /// <summary>
 /// Returns a logger for the object's type
 /// </summary>
 /// <param name="getTypeFromInstance"></param>
 /// <returns></returns>
 public static ILog LoggerFor(object getTypeFromInstance)
 {
     Mandate.ParameterNotNull(getTypeFromInstance, "getTypeFromInstance");
     return(LogManager.GetLogger(getTypeFromInstance.GetType()));
 }
コード例 #5
0
        protected OrderCreationAttemptChainTaskBase(IInvoice invoice)
        {
            Mandate.ParameterNotNull(invoice, "invoice");

            _invoice = invoice;
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OfferRedemptionResultBase{TAward}"/> class for fail.
 /// </summary>
 /// <param name="exception">
 /// The exception.
 /// </param>
 /// <param name="messages">
 /// The messages.
 /// </param>
 protected OfferRedemptionResultBase(Exception exception, IEnumerable <string> messages = null)
 {
     Mandate.ParameterNotNull(exception, "exception");
     Exception = exception;
     Success   = false;
 }
コード例 #7
0
        /// <summary>
        /// When editing or creating a document type, this binds the model, checks for errors, determines which
        /// actions to take based on the button pressed, adds appropriate notifications and persists the data.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        private ActionResult ProcessSubmit(TEditorModel model, EntitySchema entity, IGroupUnit <IContentStore> uow)
        {
            Mandate.ParameterNotNull(model, "model");

            EnsureSelectListData(model);

            //bind the model to the posted values
            model.BindModel(this);

            //process creating a new tab
            ProcessCreatingTab(model);
            //process deleting a tab
            var tabToDelete = ProcessDeletingTab(model);
            //process deleting property
            var propToDelete = ProcessDeletingProperty(model);

            //check if we are NOT adding a new property, if not then remove the invalid required validation
            if (!model.IsCreatingNewProperty)
            {
                foreach (var m in ModelState.Where(x => x.Key.StartsWith("NewProperty")))
                {
                    m.Value.Errors.Clear();
                }
            }

            if (!ModelState.IsValid)
            {
                AddValidationErrorsNotification();
                EnsureNoInBuiltProperties(model);
                return(View("Edit", model));
            }

            //convert to persistence entity
            if (entity == null)
            {
                //map to a new entity
                entity = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <TEditorModel, EntitySchema>(model);
            }
            else
            {
                //map to existing
                BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map(model, entity);
            }

            //if we're creating a new property, then add one
            if (model.IsCreatingNewProperty)
            {
                //need to set the ordinal to the max sort order for the properties on the tab its being saved to
                var defsOnGroup = entity.AttributeDefinitions.Where(x => x.AttributeGroup.Id == model.NewProperty.TabId).ToArray();
                var maxOrdinal  = defsOnGroup.Any() ? defsOnGroup.Max(x => x.Ordinal) : 0;


                model.NewProperty.SortOrder = entity.AttributeDefinitions.Any()
                                                  ? maxOrdinal + 1
                                                  : 0;
                var propertyEntity = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <DocumentTypeProperty, AttributeDefinition>(model.NewProperty);
                entity.AttributeDefinitions.Add(propertyEntity);
            }

            // Manage relations
            EnsureInheritanceRelations(model, entity, uow);

            //Save the entity
            uow.Repositories.Schemas.AddOrUpdate(entity);

            Notifications.Add(new NotificationMessage(
                                  "DocumentType.Save.Message".Localize(this),
                                  "DocumentType.Save.Title".Localize(this),
                                  NotificationType.Success));

            return(RedirectToAction("Edit", new { id = entity.Id }));
        }
コード例 #8
0
        /// <summary>
        /// Gets all the configuration settings matching <paramref name="sectionName"/> by first searching for all consumable configuration files contained in
        /// <paramref name="absolutePluginRoot"/>. For every configuration found which has a matching section name, yields back the output specified in the provided
        /// delegate <paramref name="deferred"/>.
        /// </summary>
        /// <example>
        /// If you have a custom <see cref="ConfigurationSection"/> called <see cref="FoundationConfigurationSection"/>, you can ask for a specific setting like so:
        /// <code>
        /// var myValue = DeepConfigManager.Default.GetFirstWebSetting&lt;FoundationConfigurationSection, string&gt;("rebel.foundation", x => x.FoundationSettings.ApplicationTierAlias, "~/App_Plugins");
        /// </code>
        /// This will first scan the ~/App_Plugins folder recursively to find configuraiton settings called 'rebel.foundation' that are readable as <see cref="FoundationConfigurationSection"/>,
        /// and for all those it finds (including the main app config) it will invoke the delegate provided in <paramref name="deferred"/>.
        /// </example>
        /// <typeparam name="TSection">The type of the section.</typeparam>
        /// <typeparam name="TOut">The type outputted by the expression in <paramref name="deferred"/>.</typeparam>
        /// <param name="sectionName">Name of the section in the configuration files.</param>
        /// <param name="deferred">The deffered expression.</param>
        /// <param name="applicationRoot">The application root path.</param>
        /// <param name="absolutePluginRoot">The absolute plugin root path.</param>
        /// <param name="pluginBasePath">The relative plugin root path.</param>
        /// <returns></returns>
        public IEnumerable <TOut> GetWebSettings <TSection, TOut>(string sectionName, Expression <Func <TSection, TOut> > deferred, string applicationRoot, string absolutePluginRoot, string pluginBasePath) where TSection : ConfigurationSection
        {
            Mandate.ParameterNotNullOrEmpty(sectionName, "sectionName");
            Mandate.ParameterNotNull(deferred, "deferred");
            Mandate.ParameterNotNullOrEmpty(applicationRoot, "applicationRoot");
            Mandate.ParameterNotNullOrEmpty(absolutePluginRoot, "absolutePluginRoot");
            Mandate.ParameterNotNullOrEmpty(pluginBasePath, "pluginBasePath");
            Mandate.ParameterCondition(!Path.IsPathRooted(pluginBasePath), "pluginBasePath");
            Mandate.ParameterCondition(Path.IsPathRooted(applicationRoot), "applicationRoot");
            Mandate.ParameterCondition(Path.IsPathRooted(absolutePluginRoot), "absolutePluginRoot");

            var accessorDelegate = deferred.Compile();

            var isHosted = System.Web.Hosting.HostingEnvironment.IsHosted;

            if (!isHosted)
            {
                LogHelper.Warn <DeepConfigManager>("DeepConfigManager is designed for web applications, outside of a web context all config elements must follow normal configuraiton rules");
            }

            foreach (var searchPath in GetSearchPaths(pluginBasePath, absolutePluginRoot))
            {
                TSection localSection = null;
                try
                {
                    if (isHosted)
                    {
                        localSection = WebConfigurationManager.GetSection(sectionName, searchPath) as TSection;
                    }
                    else
                    {
                        localSection = ConfigurationManager.GetSection(sectionName) as TSection;
                    }
                }
                catch (Exception e)
                {
                    LogHelper.Error <DeepConfigManager>("Error parsing config section in path " + searchPath + ". This config is being skipped.", e);
                    continue;
                }

                // By default ASP.NET inherits settings down the config chain.
                // Since this configuration is purely for overriding in the opposite direction, we specifically don't want to include settings that are
                // inherited, since in this loop through sub-config locations we may later move to a setting file which contains a specific, genuine overriding value.
                if (localSection != null
                    //this check is required! ... if there is say a 'task' section declared, this file will be found, but if there are not tasks then the 'source' will be null!!
                    //this fixes: U5-735
                    && localSection.ElementInformation.Source != null &&
                    !IsRootConfig(searchPath, localSection.ElementInformation.Source, applicationRoot))
                {
                    var val = GetConfigValue(deferred, accessorDelegate, localSection);
                    yield return(val);
                }
            }

            // Finally add the app default to the enumerable at the end
            var mainSection = WebConfigurationManager.GetSection(sectionName) as TSection;

            if (mainSection != null)
            {
                yield return(accessorDelegate.Invoke(mainSection));
            }
        }
コード例 #9
0
        public DeepConfigManager(Func <string, string> mapPathDelegate)
        {
            Mandate.ParameterNotNull(mapPathDelegate, "mapPathDelegate");

            _mapPathDelegate = mapPathDelegate;
        }
コード例 #10
0
        /// <summary>
        /// Serializes the provider config section and returns the XElement to which the operation was performed.
        /// </summary>
        /// <param name="config">The config.</param>
        /// <param name="section">The section.</param>
        /// <param name="sectionPath">The section path.</param>
        /// <param name="writeSectionDeclaration">if set to <c>true</c> [write section declaration].</param>
        /// <returns></returns>
        public static XElement SerializeProviderConfigSection(
            XDocument config,
            ConfigurationElement section,
            string sectionPath,
            bool writeSectionDeclaration)
        {
            Mandate.ParameterNotNull(config, "config");
            Mandate.ParameterNotNull(section, "section");
            Mandate.ParameterNotNull(sectionPath, "sectionPath");
            Mandate.ParameterCondition(config.Root != null, "config");
            Mandate.ParameterCondition(config.Root.Elements().Any(x => x.Name == "configSections"), "config");

            var sectionParts = sectionPath.Split('/').ToList();

            if (writeSectionDeclaration)
            {
                //ensure the section group declarations's exist
                var configSectionsDeclaration = config.Root.Elements("configSections").Single();
                var currGroupDeclaration      = configSectionsDeclaration;
                foreach (var part in sectionParts)
                {
                    //if this is the last part, we need to write a section, otherwise write a sectionGroup
                    if (part == sectionParts.Last())
                    {
                        var newSection = new XElement("section",
                                                      new XAttribute("name", part),
                                                      new XAttribute("type", section.GetType().AssemblyQualifiedName),
                                                      new XAttribute("requirePermission", false));
                        currGroupDeclaration.Add(newSection);
                    }
                    else
                    {
                        //if the section group doesn't exist, then create it
                        if (!currGroupDeclaration.Elements("sectionGroup").Where(x => (string)x.Attribute("name") == part).Any())
                        {
                            var newGroup = new XElement("sectionGroup",
                                                        new XAttribute("name", part));
                            currGroupDeclaration.Add(newGroup);
                            currGroupDeclaration = newGroup;
                        }
                        else
                        {
                            currGroupDeclaration = currGroupDeclaration.Elements("sectionGroup").Where(x => (string)x.Attribute("name") == part).First();
                        }
                    }
                }
            }

            //now create the real section
            var currParent = config.Root;

            foreach (var part in sectionParts)
            {
                if (!currParent.Elements(part).Any())
                {
                    var newSection = new XElement(part);
                    currParent.Add(newSection);
                    currParent = newSection;
                }
                else
                {
                    currParent = currParent.Element(part);
                }
            }

            AddPropertiesToElement(section, currParent);

            return(currParent);
        }
コード例 #11
0
        ///<summary>
        /// Constructor
        ///</summary>
        ///<param name="context"></param>
        private DeepConfigManager(HttpContextBase context)
        {
            Mandate.ParameterNotNull(context, "context");

            _mapPathDelegate = path => context.Server.MapPath(path);
        }
コード例 #12
0
        /// <summary>
        /// Creates a custom individual route for the specified controller plugin. Individual routes
        /// are required by controller plugins to map to a unique URL based on ID.
        /// </summary>
        /// <param name="controllerName"></param>
        /// <param name="controllerType"></param>
        /// <param name="routes">An existing route collection</param>
        /// <param name="controllerSuffixName">
        /// The suffix name that the controller name must end in before the "Controller" string for example:
        /// ContentTreeController has a controllerSuffixName of "Tree", this is used for route constraints.
        /// </param>
        /// <param name="defaultAction"></param>
        /// <param name="defaultId"></param>
        /// <param name="area"></param>
        /// <param name="umbracoTokenValue">The DataToken value to set for the 'umbraco' key, this defaults to 'backoffice' </param>
        /// <param name="routeTokens">By default this value is just {action}/{id} but can be modified for things like web api routes</param>
        /// <param name="isMvc">Default is true for MVC, otherwise false for WebAPI</param>
        /// <remarks>
        /// </remarks>
        internal static Route RouteControllerPlugin(this AreaRegistration area, string controllerName, Type controllerType, RouteCollection routes,
                                                    string controllerSuffixName, string defaultAction, object defaultId,
                                                    string umbracoTokenValue = "backoffice",
                                                    string routeTokens       = "{action}/{id}",
                                                    bool isMvc = true)
        {
            Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
            Mandate.ParameterNotNull(controllerSuffixName, "controllerSuffixName");

            Mandate.ParameterNotNull(controllerType, "controllerType");
            Mandate.ParameterNotNull(routes, "routes");
            Mandate.ParameterNotNull(defaultId, "defaultId");

            var umbracoArea = GlobalSettings.UmbracoMvcArea;

            //routes are explicitly name with controller names and IDs
            var url = umbracoArea + "/" + area.AreaName + "/" + controllerName + "/" + routeTokens;

            Route controllerPluginRoute;

            //var meta = PluginController.GetMetadata(controllerType);
            if (isMvc)
            {
                //create a new route with custom name, specified url, and the namespace of the controller plugin
                controllerPluginRoute = routes.MapRoute(
                    //name
                    string.Format("umbraco-{0}-{1}", area.AreaName, controllerName),
                    //url format
                    url,
                    //set the namespace of the controller to match
                    new[] { controllerType.Namespace });

                //set defaults
                controllerPluginRoute.Defaults = new RouteValueDictionary(
                    new Dictionary <string, object>
                {
                    { "controller", controllerName },
                    { "action", defaultAction },
                    { "id", defaultId }
                });
            }
            else
            {
                controllerPluginRoute = routes.MapHttpRoute(
                    //name
                    string.Format("umbraco-{0}-{1}-{2}", "api", area.AreaName, controllerName),
                    //url format
                    url,
                    new { controller = controllerName, id = defaultId });
                //web api routes don't set the data tokens object
                if (controllerPluginRoute.DataTokens == null)
                {
                    controllerPluginRoute.DataTokens = new RouteValueDictionary();
                }
                //look in this namespace to create the controller
                controllerPluginRoute.DataTokens.Add("Namespaces", new[] { controllerType.Namespace });
            }

            //Don't look anywhere else except this namespace!
            controllerPluginRoute.DataTokens.Add("UseNamespaceFallback", false);

            //constraints: only match controllers ending with 'controllerSuffixName' and only match this controller's ID for this route
            if (controllerSuffixName.IsNullOrWhiteSpace() == false)
            {
                controllerPluginRoute.Constraints = new RouteValueDictionary(
                    new Dictionary <string, object>
                {
                    { "controller", @"(\w+)" + controllerSuffixName }
                });
            }

            //match this area
            controllerPluginRoute.DataTokens.Add("area", area.AreaName);
            controllerPluginRoute.DataTokens.Add("umbraco", umbracoTokenValue); //ensure the umbraco token is set

            return(controllerPluginRoute);
        }
コード例 #13
0
 /// <summary>
 /// Compares the current object with another object of the same type.
 /// </summary>
 /// <returns>
 /// A value that indicates the relative order of the objects being compared. The return value has the following meanings: Value Meaning Less than zero This object is less than the <paramref name="other"/> parameter.Zero This object is equal to <paramref name="other"/>. Greater than zero This object is greater than <paramref name="other"/>.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public int CompareTo(TypedAttributeName other)
 {
     Mandate.ParameterNotNull(other, "other");
     return(string.Compare(other.Alias, Alias, StringComparison.InvariantCultureIgnoreCase));
 }
コード例 #14
0
 /// <summary>
 /// Constructor to setup an existing DocumentTypeProperty from a DataType
 /// </summary>
 /// <param name="dataType"></param>
 public DocumentTypeProperty(DataType dataType)
 {
     Mandate.ParameterNotNull(dataType, "dataType");
     DataType   = dataType;
     DataTypeId = DataType.Id;
 }
コード例 #15
0
        public override void Build(IContainerBuilder containerBuilder, IBuilderContext context)
        {
            Mandate.ParameterNotNull(containerBuilder, "containerBuilder");
            Mandate.ParameterNotNull(context, "context");

            var configMgr = DeepConfigManager.Default;

            var configMain = context.ConfigurationResolver
                             .GetConfigSection(HiveConfigurationSection.ConfigXmlKey) as HiveConfigurationSection;

            if (configMain == null)
            {
                throw new ConfigurationErrorsException(
                          string.Format("Configuration section '{0}' not found when building packaging provider '{1}'",
                                        HiveConfigurationSection.ConfigXmlKey, ProviderKey));
            }

            var readWriteConfig = configMain.AvailableProviders.ReadWriters[ProviderKey] ?? configMain.AvailableProviders.Readers[ProviderKey];

            if (readWriteConfig == null)
            {
                throw new ConfigurationErrorsException(
                          string.Format("No configuration found for persistence provider '{0}'", ProviderKey));
            }


            var localConfig = DeepConfigManager
                              .Default
                              .GetWebSettings <ProviderConfigurationSection, ProviderConfigurationSection>(readWriteConfig.ConfigSectionKey, x => x, "~/App_Plugins")
                              .First();

            if (localConfig == null)
            {
                throw new ConfigurationErrorsException(
                          "Unable to resolve the configuration for the FileSystem repository");
            }

            //TODO: Fix hard-coded plugin folder path --Aaron
            var supportedExtensions =
                configMgr.GetWebSetting <ProviderConfigurationSection, string>(readWriteConfig.ConfigSectionKey,
                                                                               x => x.SupportedExtensions, "~/App_Plugins");
            var rootPath = configMgr.GetWebSetting <ProviderConfigurationSection, string>(readWriteConfig.ConfigSectionKey,
                                                                                          x => x.RootPath, "~/App_Plugins");
            var excludeExtensions = configMgr.GetWebSetting <ProviderConfigurationSection, string>(readWriteConfig.ConfigSectionKey,
                                                                                                   x => x.ExcludeExetensions, "~/App_Plugins");

            if (!rootPath.EndsWith("/"))
            {
                rootPath = rootPath + "/";
            }

            containerBuilder
            .ForFactory(x => new ProviderBootstrapper(localConfig))
            .Named <AbstractProviderBootstrapper>(ProviderKey)
            .ScopedAs.Singleton();

            containerBuilder
            .ForFactory(c => new DataContextFactory(
                            supportedExtensions,
                            c.Resolve <HttpContextBase>().Server.MapPath(rootPath),
                            rootPath,
                            excludeExtensions)
                        )
            .Named <AbstractDataContextFactory>(ProviderKey)
            .ScopedAs.NewInstanceEachTime();

            containerBuilder
            .For <ReadWriteUnitOfWorkFactory>()
            .Named <IReadOnlyUnitOfWorkFactory>(ProviderKey)
            .ScopedAs.Singleton();

            containerBuilder
            .For <ReadWriteUnitOfWorkFactory>()
            .Named <IReadWriteUnitOfWorkFactory>(ProviderKey)
            .ScopedAs.Singleton();
        }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CheckoutPaymentMethodModelFactory{TPaymentMethodModel}"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public CheckoutPaymentMethodModelFactory(IMerchelloContext merchelloContext)
 {
     Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
     _gatewayContext = merchelloContext.Gateways;
 }
コード例 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OfferRedemptionResultBase{TAward}"/> class for success.
 /// </summary>
 /// <param name="award">
 /// The award.
 /// </param>
 /// <param name="messages">
 /// The messages.
 /// </param>
 protected OfferRedemptionResultBase(TAward award, IEnumerable <string> messages = null)
 {
     Mandate.ParameterNotNull(award, "award");
     Award   = award;
     Success = true;
 }
コード例 #18
0
        protected ActionResult ProcessSubmit(UserGroupEditorModel model, UserGroup entity)
        {
            Mandate.ParameterNotNull(model, "model");

            //bind it's data
            model.BindModel(this);

            //if there's model errors, return the view
            if (!ModelState.IsValid)
            {
                AddValidationErrorsNotification();
                return(View("Edit", model));
            }

            //persist the data
            using (var uow = Hive.Create <ISecurityStore>())
            {
                if (entity == null)
                {
                    //map to new entity
                    entity =
                        BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map
                        <UserGroupEditorModel, UserGroup>(model);
                }
                else
                {
                    //map to existing entity
                    BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map(model, entity);
                }

                uow.Repositories.AddOrUpdate(entity);

                // Save permissions
                var metaDataumList = new List <RelationMetaDatum>();
                foreach (var permissionModel in model.Permissions)
                {
                    var permission = BackOfficeRequestContext.RegisteredComponents.Permissions.SingleOrDefault(x => x.Metadata.Id == permissionModel.PermissionId);
                    if (permission == null)
                    {
                        throw new NullReferenceException("Could not find permission with id " + permissionModel.PermissionId);
                    }

                    metaDataumList.Add(BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <RelationMetaDatum>(permissionModel));
                }

                // Change permissions relation
                uow.Repositories.ChangeOrCreateRelationMetadata(entity.Id, FixedHiveIds.SystemRoot, FixedRelationTypes.PermissionRelationType, metaDataumList.ToArray());

                uow.Complete();

                Notifications.Add(new NotificationMessage(
                                      "UserGroup.Save.Message".Localize(this),
                                      "UserGroup.Save.Title".Localize(this),
                                      NotificationType.Success));

                //add path for entity for SupportsPathGeneration (tree syncing) to work
                GeneratePathsForCurrentEntity(uow.Repositories.GetEntityPaths <TypedEntity>(entity.Id, FixedRelationTypes.DefaultRelationType));

                return(RedirectToAction("Edit", new { id = entity.Id }));
            }
        }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceResolver"/> class.
        /// </summary>
        /// <param name="cache">
        /// The <see cref="CacheHelper"/>.
        /// </param>
        /// <remarks>
        /// Used for testing
        /// </remarks>
        internal ServiceResolver(CacheHelper cache)
        {
            Mandate.ParameterNotNull(cache, "cache");

            this._cache = cache;
        }
コード例 #20
0
 public void MapFrom <TMember>(Func <TSource, TMember> sourceMember)
 {
     Mandate.ParameterNotNull(sourceMember, "sourceMember");
     ResultOfMapFrom = sourceMember((TSource)_info.Source.Value);
 }
コード例 #21
0
 public PluginControllerFactory(IRebelApplicationContext applicationContext)
 {
     Mandate.ParameterNotNull(applicationContext, "applicationContext");
     ApplicationContext = applicationContext;
 }
コード例 #22
0
 public void MapUsing <TMember>(MemberMapper <TSource, TMember> memberMapper)
 {
     Mandate.ParameterNotNull(memberMapper, "memberMapper");
     ResultOfMapFrom = memberMapper.GetValue((TSource)_info.Source.Value);
 }
コード例 #23
0
 public DependencyHelper(ProviderMetadata providerMetadata, CacheHelper cacheHelper)
     : base(providerMetadata)
 {
     Mandate.ParameterNotNull(cacheHelper, "cacheHelper");
     CacheHelper = cacheHelper;
 }
コード例 #24
0
 /// <summary>
 /// Constructor accepting an IDatabaseFactory instance
 /// </summary>
 /// <param name="dbFactory"></param>
 internal PetaPocoUnitOfWorkProvider(IDatabaseFactory dbFactory)
 {
     Mandate.ParameterNotNull(dbFactory, "dbFactory");
     _dbFactory = dbFactory;
 }
コード例 #25
0
        /// <summary>
        /// Processes the submit.
        /// </summary>
        /// <param name="createModel">The create model.</param>
        /// <param name="editModel">The model.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        protected ActionResult ProcessSubmit(CreateUserModel createModel, TEditorModel editModel, TUserType entity)
        {
            Mandate.ParameterNotNull(editModel, "model");

            var isNew = entity == null;

            // Clear out any previous groups before mapping, as we just want whatever is selected now
            editModel.Groups = Enumerable.Empty <HiveId>();

            //bind it's data
            editModel.BindModel(this);

            //if there's model errors, return the view
            if (!ModelState.IsValid)
            {
                AddValidationErrorsNotification();

                EnsureViewBagData();

                return(isNew ? View("CreateNew", createModel) : View("Edit", editModel));
            }

            //persist the data
            if (isNew)
            {
                editModel.Id = HiveId.Empty;
                editModel.LastPasswordChangeDate = DateTime.UtcNow;
                editModel.LastActivityDate       = DateTime.UtcNow;
                editModel.LastLoginDate          = DateTime.UtcNow;

                entity = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <TEditorModel, TUserType>(editModel);

                MembershipCreateStatus status;
                entity = MembershipService.Create(entity, out status);

                if (status != MembershipCreateStatus.Success)
                {
                    ModelState.AddModelError("", status.Localize());

                    EnsureViewBagData();

                    return(View("CreateNew", createModel));
                }
            }
            else
            {
                BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map(editModel, entity);

                try
                {
                    MembershipService.Update(entity);
                }
                catch (ArgumentException ex)
                {
                    ModelState.AddModelError("", ex.Message);

                    AddValidationErrorsNotification();

                    EnsureViewBagData();

                    return(View("Edit", editModel));
                }
            }

            OnAfterSave(entity);

            //TODO: Need to display the right messages
            Notifications.Add(new NotificationMessage(
                                  "User.Save.Message".Localize(this),
                                  "User.Save.Title".Localize(this),
                                  NotificationType.Success));

            GeneratePathsForCurrentEntity(entity);

            return(RedirectToAction("Edit", new { id = entity.Id }));
        }
コード例 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public RenderControllerFactory(IUmbracoApplicationContext applicationContext)
 {
     Mandate.ParameterNotNull(applicationContext, "applicationContext");
     ApplicationContext = applicationContext;
 }
コード例 #27
0
        /// <summary>
        /// Gets the ancestors of the current Content entity relationships
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static IEnumerable <File> AncestorsAsFile(this EntityRelationCollection collection)
        {
            Mandate.ParameterNotNull(collection, "collection");

            return(collection.Ancestors <File>(FixedRelationTypes.FileRelationType));
        }
コード例 #28
0
ファイル: ProductRepository.cs プロジェクト: kedde/Merchello
 public ProductRepository(IDatabaseUnitOfWork work, IRuntimeCacheProvider cache, IProductVariantRepository productVariantRepository)
     : base(work, cache)
 {
     Mandate.ParameterNotNull(productVariantRepository, "productVariantRepository");
     _productVariantRepository = productVariantRepository;
 }
コード例 #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BraintreeApiRequestFactory"/> class.
        /// </summary>
        /// <param name="settings">
        /// The settings.
        /// </param>
        public BraintreeApiRequestFactory(BraintreeProviderSettings settings)
        {
            Mandate.ParameterNotNull(settings, "settings");

            this._settings = settings;
        }
コード例 #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductInventoryValidationVisitor"/> class.
        /// </summary>
        /// <param name="merchello">
        /// The merchello.
        /// </param>
        public ProductInventoryValidationVisitor(MerchelloHelper merchello)
        {
            Mandate.ParameterNotNull(merchello, "merchello");

            _merchello = merchello;
        }