Exemple #1
0
        /// <summary>Registers a creator function for the type that can create
        /// an instance of type based on a thread.
        /// </summary>
        /// <param name="type">
        /// The type to register.
        /// </param>
        /// <param name="creator">
        /// The creator function.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the type or the creator is null.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// If the type is generic, or has no converter, or a convertor that can not
        /// convert from string.
        /// </exception>
        /// <remarks>
        /// These creators are used to generate a value, if no one is
        /// assigned or configured.
        /// </remarks>
        public static void Register(Type type, Func <Thread, object> creator)
        {
            Qowaiv.Guard.NotNull(type, "type");
            Qowaiv.Guard.NotNull(creator, "creator");
            Guard(type, Creators.ContainsKey(type));

            Creators.TryAdd(type, creator);
        }
Exemple #2
0
        public void DeleteAll(ClientContext ctx)
        {
            if (Creators != null && Creators.Count > 0)
            {
                _ctx = ctx;
                //Install to rootweb if not a hostweb
                _targetWeb = _ctx.Web.AppInstanceId == default(Guid) ? _ctx.Site.RootWeb : _ctx.Web;

                _ctx.Load(_targetWeb.ContentTypes,
                          c => c.Include(contentType => contentType.Name));

                _ctx.ExecuteQueryRetry();

                var deletionList = new Dictionary <string, ContentType>();

                foreach (var item in _targetWeb.ContentTypes)
                {
                    if (Creators.ContainsKey(item.Name))
                    {
                        Creators[item.Name].ContentType = item;

                        var id = Creators[item.Name].Id;
                        if (!string.IsNullOrEmpty(id))
                        {
                            deletionList[id] = item;
                        }
                    }
                }

                var sortedList = deletionList.OrderByDescending(kvp => kvp.Key).ToDictionary(c => c.Key, c => c.Value);

                foreach (var sortedListKey in sortedList.Keys)
                {
                    deletionList[sortedListKey].DeleteObject();
                }

                _ctx.ExecuteQueryRetry();
            }
        }