Esempio n. 1
0
        /// <summary>
        /// Execute the selection
        /// </summary>
        /// <param name="sQuery"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override IDList SelectIDs(string sQuery, CallContext context)
        {
            List <Guid> oResults;
            IDList      oSelectedIds;
            bool        bFound;

            Sitecore.Diagnostics.Log.Debug(string.Format("SelectIDs Start, Query:{0}", sQuery), this);

            oSelectedIds = new IDList();
            bFound       = false;

            using (var oContentService = new GenContentServiceProxy())
            {
                oResults = oContentService.SelectIDs(sQuery, context.DataManager.Database.Name);
            }

            if (oResults != null && oResults.Count > 0)
            {
                foreach (var oItemId in oResults)
                {
                    oSelectedIds.Add(ID.Parse(oItemId));
                }
                bFound = true;
            }

            if (bFound)
            {
                UpdateContext(oSelectedIds, context);
                context.Abort();
            }

            return(oSelectedIds);
        }
        protected void SetUserValues(User Usr, User DefUsr, ADUserInfo ADUsrInf, bool bUsrPro)
        {
            IDList GrpIDLst = null, DefGrpIDLst = null;
            int    nID = Global.IntegerNull;

            //--- Check user profile
            if (bUsrPro)
            {
                //--- Set the profile values
                Usr.SetChangeHistoryMask(DefUsr.GetChangeHistoryMask());
                Usr.SetDatePreference(DefUsr.GetDatePreference());
                Usr.SetTimePreference(DefUsr.GetTimePreference());
                Usr.SetOffsetFromGMT(DefUsr.GetOffsetFromGMT());
                Usr.SetTimeZone(DefUsr.GetTimeZone());
                Usr.SetLocale(DefUsr.GetLocale());
                Usr.SetDstSavings(DefUsr.GetDstSavings());
                Usr.SetBrowserMask(DefUsr.GetBrowserMask());
                Usr.SetFieldsMask(DefUsr.GetFieldsMask());
                Usr.SetNotesMask(DefUsr.GetNotesMask());
                Usr.SetMaxChangeHistory(DefUsr.GetMaxChangeHistory());
                Usr.SetMaxItemsPerPage(DefUsr.GetMaxItemsPerPage());
                Usr.SetMaxNotes(DefUsr.GetMaxNotes());
                Usr.SetNamespaceName(DefUsr.GetNamespaceName());
            }

            //--- Set the user ident values
            Usr.SetLoginID(ADUsrInf.LoginID.ToUpper());
            Usr.SetDisplayName(ADUsrInf.DisplayName);
            Usr.SetPhoneNumber(ADUsrInf.TelephoneNumber);
            Usr.SetEmail(ADUsrInf.Email);
            Usr.SetEmailCC(ADUsrInf.PersonnelNumber.ToString());

            GrpIDLst    = Usr.GetGroupIDs();
            DefGrpIDLst = DefUsr.GetGroupIDs();

            //--- Add the default group IDs to the group IDs
            for (int nGrpIdx = 0; nGrpIdx < DefGrpIDLst.Count; nGrpIdx++)
            {
                //--- Get the default group ID
                nID = DefGrpIDLst[nGrpIdx];

                //--- Add the default group ID to the group IDs if not exists
                if (!GrpIDLst.Contains(nID))
                {
                    GrpIDLst.Add(nID);
                }
            }

            //--- Set the group IDs
            Usr.SetGroupIDs(GrpIDLst);

            //--- Set the default access type if the default access type is more
            if (DefUsr.GetAccessType() > Usr.GetAccessType())
            {
                Usr.SetAccessType(DefUsr.GetAccessType());
            }

            //--- Clear the deleted flag
            Usr.SetDeleted(false);
        }
Esempio n. 3
0
 public RepricingLog()
 {
     AppliedRuleID        = -1;
     AppliedAirlineRuleID = -1;
     TargetSources        = new IDList <int>();
     PricingResults       = new SourceResultInfo();
 }
 void AddAllControllers(IDList list)
 {
     foreach (var controller in ControllerType.GetControllerIds(ParentId.ToGuid()))
     {
         list.Add(new ID(controller.Key));
     }
 }
Esempio n. 5
0
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            // TODO: Use prefecthing like the old one?
            var childIds = Provider.GetChildIds(itemDefinition.ID.ToGuid());

            return(IDList.Build(childIds.Select(guid => new ID(guid)).ToArray()));
        }
Esempio n. 6
0
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");

            if (itemDefinition == ItemDefinition.Empty)
            {
                return(null);
            }

            var children = SerializedDatabase.GetChildren(itemDefinition.ID);

            if (children == null)
            {
                return(null);
            }

            var ids = new IDList();

            foreach (var syncItem in children)
            {
                ids.Add(syncItem.GetSitecoreId());
            }

            return(ids);
        }
        protected virtual void AddChildIDsForContactFacetItem(IDList ids, ItemDefinition itemDefinition, CallContext context)
        {
            var facetName = IDTableHelper.GetFacetName(itemDefinition.ID);
            var contractType = ContactFacetHelper.GetContractTypeForFacet(facetName);
            
            foreach (string memberName in FacetReflectionUtil.NonFacetMemberNames(contractType))
            {
                var id = IDTableHelper.GenerateIdForFacetMember(memberName, itemDefinition.ID,
                            Sitecore.Strategy.Contacts.DataProviders.TemplateIDs.ContactFacetMemberTemplate);

                ids.Add(id);
            }

            foreach (string memberName in FacetReflectionUtil.FacetMemberNames(contractType))
            {
                foreach (
                    string subMemberName in
                        FacetReflectionUtil.NonFacetMemberNames(contractType.GetProperty(memberName).PropertyType))
                {
                    string key = $"{memberName}{NestedFacets.Delimeter}{subMemberName}";

                    var id = IDTableHelper.GenerateIdForFacetMember(key, itemDefinition.ID,
                        Sitecore.Strategy.Contacts.DataProviders.TemplateIDs.ContactFacetMemberTemplate);

                    ids.Add(id);
                }
            }
        }
Esempio n. 8
0
        public static IDList Read(ClrObject obj)
        {
            if (obj.IsNullObj)
            {
                return(null);
            }

            ClrObject idsRef = obj.GetRefFld("m_ids");

            if (idsRef.IsNullObj)
            {
                return(null);
            }

            List <ClrObject> ids = idsRef.Type?.Name?.Contains("ArrayList") == true?ClrCollectionHelper.EnumerateArrayList(idsRef) :
                                       ClrCollectionHelper.EnumerateListOfRefTypes(idsRef);

            var res = new IDList();

            foreach (ClrObject id in ids)
            {
                res.Add(IDReader.Read(id));
            }

            return(res);
        }
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            ControllerType controllerType;
            var            list = new IDList();

            if (itemDefinition.ID == ParentId)
            {
                if (GetSqlVersion(FolderId, context, GetSqlProvider(Database)) == null)
                {
                    list.Add(FolderId);
                }
            }
            else if (itemDefinition.ID == FolderId)
            {
                AddAllNamespaces(list, context);
            }
            else if (ControllerType.GetAllNamespaces().ContainsKey(itemDefinition.ID.ToGuid()))
            {
                AddControllers(list, itemDefinition.ID.ToGuid(), context);
            }
            else if ((controllerType = ControllerType.GetControllerType(itemDefinition.ID)) != null)
            {
                AddAllActions(list, controllerType, context);
            }
            else
            {
                return(null);
            }

            if (list.Count == 0)
            {
                return(null);
            }
            return(list);
        }
 void AddControllers(IDList list, Guid parentId, IDList existingList)
 {
     foreach (var controller in ControllerType.GetAllControllers().Values.Where(c => c.ParentId == parentId && !existingList.Contains(new ID(c.Id))))
     {
         list.Add(new ID(controller.Id));
     }
 }
        public override IDList SelectIDs(string query, CallContext context)
        {
            query = query.Replace("fast:", string.Empty);
            var items = Query.SelectItems(query, this.Database);

            return(items != null?IDList.Build(items.Select(i => i.ID).ToArray()) : new IDList());
        }
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            IEnumerable <FileInfo> children = null;

            if (itemDefinition.ID.ToString() == _repository.RootId)
            {
                children = _repository.GetChildren(_repository.RootId);
            }
            else
            {
                var entry = GetStoreEntry(itemDefinition.ID);
                if (entry == null)
                {
                    return(base.GetChildIDs(itemDefinition, context));
                }

                children = _repository.GetChildren(entry.Key);
            }

            var idlist = new IDList();

            foreach (var child in children.Select(x => x.ToModel()))
            {
                var scId = GetSitecoreId(child.ModelId);
                if (scId == (ID)null)
                {
                    scId = CreateSitecoreId(child.ModelId, itemDefinition);
                }

                idlist.Add(scId);
            }

            context.Abort();
            return(idlist);
        }
 void AddAllActions(IDList list, ControllerType controllerType)
 {
     foreach (var action in ControllerAction.GetAllActions(ParentId.ToGuid()).Where(a => a.ControllerType.Type == controllerType.Type))
     {
         list.Add(new ID(action.Id));
     }
 }
 /// <summary>
 /// 处理简单的删除聚合根的操作。
 /// </summary>
 /// <typeparam name="TAggregateRoot">需要删除的聚合根的类型。</typeparam>
 /// <param name="ids">需要删除的聚合根的ID值列表。</param>
 /// <param name="repository">应用于指定聚合根类型的仓储实例。</param>
 /// <param name="preDelete">在指定聚合根被删除前,对所需删除的聚合根的ID值进行处理的回调函数。</param>
 /// <param name="postDelete">在指定聚合根被删除后,对所需删除的聚合根的ID值进行处理的回调函数。</param>
 protected void PerformDeleteObjects <TAggregateRoot>(IDList ids, IRepository <TAggregateRoot> repository, Action <Guid> preDelete = null, Action <Guid> postDelete = null)
     where TAggregateRoot : class, IAggregateRoot
 {
     if (ids == null)
     {
         throw new ArgumentNullException("ids");
     }
     if (repository == null)
     {
         throw new ArgumentNullException("repository");
     }
     foreach (var id in ids)
     {
         var guid = new Guid(id);
         if (preDelete != null)
         {
             preDelete(guid);
         }
         var ar = repository.GetByKey(guid);
         repository.Remove(ar);
         if (postDelete != null)
         {
             postDelete(guid);
         }
     }
     repository.Context.Commit();
 }
Esempio n. 15
0
        public UserDTO AssignUserGroup(Guid userid, IDList groupids)
        {
            List <Guid> gids = new List <Guid>();

            groupids.ForEach(m =>
            {
                Guid id = new Guid();
                if (Guid.TryParse(m, out id))
                {
                    gids.Add(id);
                }
            });
            var user = userRepository.Find(Specification <User> .Eval(u => u.ID.Equals(userid)));

            using (ITransactionCoordinator coordinator = TransactionCoordinatorFactory.Create(Context, bus))
            {
                if (user == null)
                {
                    throw new NullReferenceException("无法找指定的用户");
                }

                var groups = groupRespository.GetAll((Specification <Group> .Eval(g => gids.Contains(g.ID)))).ToList();
                user.Groups = groups;
                userRepository.Update(user);
                user.UpdateGroup();
                coordinator.Commit();
            }
            return(Mapper.Map <User, UserDTO>(user));
        }
Esempio n. 16
0
        public IDList QueryFast([NotNull] Database database, [NotNull] Opcode opcode)
        {
            Assert.ArgumentNotNull(database, nameof(database));
            Assert.ArgumentNotNull(opcode, nameof(opcode));

            var parameters = new ParametersList();

            var sql = TranslateQuery(opcode, database, parameters);

            if (sql == null)
            {
                return(null);
            }

            using (var reader = _api.CreateReader(sql, parameters.ToArray()))
            {
                var list = new IDList();
                while (reader.Read())
                {
                    list.Add(_api.GetId(0, reader));
                }

                return(list);
            }
        }
Esempio n. 17
0
        private void Initialize()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            _sitecoreItems.Clear();

            _versions = null;

            var treeService = ObjectFactory.Instance.Resolve <ITreeContentService>(SitecoreConstants.SitecoreDataProviderTreeServiceId);

            // Add main catalog node: "stores".
            var storeNode        = treeService.GetChildren(Constants.DataProvider.NodeType.Root, "-1").First();
            var rootSiteCoreItem = _itemFactory.Create(storeNode, _sitecoreEntryPoint);

            _sitecoreItems[rootSiteCoreItem.Id] = rootSiteCoreItem;
            _firstLevelIds = new IDList {
                rootSiteCoreItem.Id
            };

            HydrateNodeStructure(rootSiteCoreItem);

            stopwatch.Stop();
            _log.Log <ContentNodeDataProvider>(string.Format("ContentNodeDataProvider.Initialize(). {0} ms", stopwatch.ElapsedMilliseconds));
        }
Esempio n. 18
0
        public override Collections.IDList GetChildIDs(Data.ItemDefinition itemDefinition, CallContext context)
        {
            IDList currentChildIDs = context.CurrentResult as IDList;
            IDList idList = new IDList();
            XPathNavigator element = (XPathNavigator)courseCache[itemDefinition.ID];// CourseData.SelectSingleNode(string.Format("//course[@id='{0}']", itemDefinition.ID.ToString()));
            if (element != null)
            {
                context.Abort();
                XPathNodeIterator childCourses = element.Select("./courses/course");
                foreach (XPathNavigator childCourse in childCourses)
                {
                    ID id = ID.Parse(childCourse.GetAttribute("id", string.Empty));
                    idList.Add(id);
                }
            }
            else if (itemDefinition.ID.ToString() == ParentItemID)
            {
                context.Abort();
                XPathNodeIterator childCourses = CourseData.Select("/courses/course");
                foreach (XPathNavigator childCourse in childCourses)
                {
                    ID id = ID.Parse(childCourse.GetAttribute("id", string.Empty));
                    idList.Add(id);
                }
            }

            return idList;
        }
Esempio n. 19
0
        private IDList GetChildIDsTemplate(SitecoreClassConfig template, ItemDefinition itemDefinition)
        {
            IDList fields = new IDList();

            List <string> processed = new List <string>();
            var           sections  = template.Properties
                                      .Where(x => x.Property.DeclaringType == template.Type)
                                      .Select(x => x.Attribute).OfType <SitecoreFieldAttribute>()
                                      .Select(x => x.SectionName);

            foreach (var section in sections)
            {
                if (processed.Contains(section) || section.IsNullOrEmpty())
                {
                    continue;
                }

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section);

                if (record == null)
                {
                    record = new SectionInfo(section, new ID(Guid.NewGuid()), itemDefinition.ID);
                    SectionTable.Add(record);
                }
                processed.Add(section);
                fields.Add(record.SectionId);
            }
            return(fields);
        }
Esempio n. 20
0
        public object QueryFast([NotNull] Database database, [NotNull] Opcode opcode)
        {
            Assert.ArgumentNotNull(database, nameof(database));
            Assert.ArgumentNotNull(opcode, nameof(opcode));

            var parameters = new ParametersList();

            var sql = TranslateQuery(opcode, database, parameters);

            if (sql == null)
            {
                return(null);
            }


            using (var reader = _api.CreateReader(sql, parameters.ToArray()))
            {
                var idList = new IDList();

                while (reader.Read())
                {
                    idList.Add(_api.GetId(0, reader));
                }

                if (idList.Count == 1)
                {
                    return(new QueryContext(database.DataManager, idList[0]));
                }

                return(idList.Cast <ID>().Select(id => new QueryContext(database.DataManager, id)).ToArray());
            }
        }
        /// <summary>
        ///     Determines what items are children of the item and returns a list of their IDs.
        /// </summary>
        /// <param name="itemDefinition">Used to identify the particular item</param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            IEnumerable <KeyValuePair <ID, SyncItem> > childItems =
                ItemsByParentId.Where(item => item.Key == itemDefinition.ID);

            return(IDList.Build(childItems.Select(item => ParseId(item.Value.ID)).ToArray()));
        }
Esempio n. 22
0
        /// <summary>
        /// 加载窗体的事件
        /// </summary>
        public override void FormOnLoad()
        {
            base.FormOnLoad();
            if (!this.DesignMode)
            {
                if (!string.IsNullOrEmpty(ID))
                {
                    if (UseActionPrefix && !this.Text.Contains("编辑"))
                    {
                        this.Text = string.Format("{0} {1}", JsonLanguage.Default.GetString("编辑"), JsonLanguage.Default.GetString(this.Text));
                    }
                    this.btnAdd.Visible = false;//如果是编辑,则屏蔽添加按钮
                }
                else
                {
                    if (UseActionPrefix && !this.Text.Contains("新建"))
                    {
                        this.Text = string.Format("{0} {1}", JsonLanguage.Default.GetString("新建"), JsonLanguage.Default.GetString(this.Text));
                    }
                }

                this.dataNavigator1.IDList       = IDList;
                this.dataNavigator1.CurrentIndex = IDList.IndexOf(ID);
                if (IDList == null || IDList.Count == 0)
                {
                    this.dataNavigator1.Visible = false;
                    DisplayData();//CurrentIndex = -1的时候需要主动调用
                }

                //由于上面设置this.dataNavigator1.CurrentIndex,导致里面触发dataNavigator1_PositionChanged
                //从而调用了DisplayData,所以下面的代码不用重复调用,否则执行了两次。
                //DisplayData();
            }
        }
Esempio n. 23
0
    /// <summary>
    /// 添加id字典到列表
    /// </summary>
    /// <param name="DictKey"></param>
    /// <param name="table"></param>
    private void AddIdList(string DictKey, DataTable table)
    {
        List <int> idlistTemp = new List <int>();

        //获取id所在的列
        int numberForId = 0;

        for (int i = 0; i < table.Columns.Count; i++)
        {
            if (table.Rows[0][i].ToString().ToLower() == "id")
            {
                numberForId = i;
            }
        }

        //添加列表
        for (int i = 1; i < table.Rows.Count; i++)
        {
            int intNum;
            int.TryParse(table.Rows[i][numberForId].ToString(), out intNum);
            idlistTemp.Add(intNum);
        }


        IDList.Add(DictKey, idlistTemp);
    }
Esempio n. 24
0
        public UserDTO AssignUserRole(Guid userid, IDList roleids)
        {
            List <Guid> rids = new List <Guid>();

            roleids.ForEach(m =>
            {
                Guid id = new Guid();
                if (Guid.TryParse(m, out id))
                {
                    rids.Add(id);
                }
            });
            var user = userRepository.Find(Specification <User> .Eval(u => u.ID.Equals(userid)));

            using (ITransactionCoordinator coordinator = TransactionCoordinatorFactory.Create(Context, bus))
            {
                if (user == null)
                {
                    throw new NullReferenceException("无法找指定的用户");
                }
                var roles = roleRepository.GetAll((Specification <Role> .Eval(r => rids.Contains(r.ID)))).ToList();;
                user.Roles = roles;
                userRepository.Update(user);
                user.UpdateRole();
                coordinator.Commit();
            }
            return(Mapper.Map <User, UserDTO>(user).ToViewModel());
        }
        private void InitializeData()
        {
            _log.Log <SystemDataProvider>("Initializing the System Data Provider data");
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            _versions = null;
            _sitecoreItems.Clear();
            _idList = new IDList();

            var memberService = ObjectFactory.Instance.Resolve <IMemberService>();
            var domainService = ObjectFactory.Instance.Resolve <IDomainService>();

            if (memberService == null || domainService == null)
            {
                throw new InvalidOperationException("Could not get the dependencies!");
            }

            var systemNodesContentProvider = new SystemNodesContentProvider(domainService, memberService);

            foreach (var item in systemNodesContentProvider.GetSystemData())
            {
                AddSitecoreItem(item);
            }

            stopwatch.Stop();
            _log.Log <SystemDataProvider>(string.Format("SystemDataProvider.InitializeData(). {0} ms", stopwatch.ElapsedMilliseconds));
        }
        public IDList GetFirstLevelIds()
        {
            var ids = new IDList {
                _topUcommerceFolder.Id
            };

            return(ids);
        }
Esempio n. 27
0
 public DragDropObject(ListView lv, TreeNode node) : this()
 {
     SourceNode = node;
     foreach (ListViewItem lvi in lv.SelectedItems)
     {
         IDList.Add(Toolkit.ToInt32(lvi.Tag, -1));
     }
 }
        private IDList GetChildIDsSection(SectionInfo section, CallContext context)
        {
            var cls = Classes.First(x => x.Value.TemplateId == section.TemplateId.Guid).Value;

            var fields = cls.Properties.Where(x => x.Attribute is SitecoreFieldAttribute);

            IDList fieldIds = new IDList();

            var providers     = Database.GetDataProviders();
            var otherProvider = providers.FirstOrDefault(x => !(x is GlassDataProvider));

            foreach (var field in fields)
            {
                if (field.Property.DeclaringType != cls.Type)
                {
                    continue;
                }


                var attr = field.Attribute as SitecoreFieldAttribute;
                if (attr != null && attr.CodeFirst && attr.SectionName == section.Name)
                {
                    Guid guidId = Guid.Empty;
                    if (Utility.GuidTryParse(attr.FieldId, out guidId))
                    {
                        var record = FieldTable.FirstOrDefault(x => x.FieldId.Guid == guidId);
                        //test if the fields exists in the database: if so, we're using codefirst now, so remove it.
                        var existing = otherProvider.GetItemDefinition(new ID(guidId), context);
                        if (existing != null)
                        {
                            using (new SecurityDisabler())
                                otherProvider.DeleteItem(existing, context);
                        }
                        if (record == null)
                        {
                            string fieldName = attr.FieldName.IsNullOrEmpty() ? field.Property.Name : attr.FieldName;


                            record = new FieldInfo(new ID(guidId), section.SectionId, fieldName, attr.FieldType, attr.FieldSource, attr.FieldTitle, attr.IsShared, attr.IsUnversioned, attr.FieldSortOrder, attr.ValidationRegularExpression, attr.ValidationErrorText, attr.IsRequired);
                            var fieldfieldInfoAttributes =
                                field.Property.GetCustomAttributes(typeof(SitecoreFieldFieldValueAttribute), true);
                            if (fieldfieldInfoAttributes != null && fieldfieldInfoAttributes.Any())
                            {
                                foreach (var ffv in fieldfieldInfoAttributes.Cast <SitecoreFieldFieldValueAttribute>())
                                {
                                    record.FieldFieldValues.Add(ffv.FieldId, ffv.FieldValue);
                                }
                            }
                        }

                        fieldIds.Add(record.FieldId);
                        FieldTable.Add(record);
                    }
                }
            }

            return(fieldIds);
        }
        public void Add(string currency, int sourceID)
        {
            if (!this.ContainsKey(currency))
            {
                this[currency] = new IDList <int>();
            }

            this[currency].Add(sourceID);
        }
Esempio n. 30
0
        /// <summary>
        /// Gets the child I ds section.
        /// </summary>
        /// <param name="section">The section.</param>
        /// <param name="context">The context.</param>
        /// <returns>IDList.</returns>
        private IDList GetChildIDsSection(SectionInfo section, CallContext context)
        {
            var cls = _typeConfigurations.First(x => x.Value.TemplateId == section.TemplateId).Value;

            var fields = cls.Properties.OfType<SitecoreFieldConfiguration>();

            IDList fieldIds = new IDList();

            var providers = context.DataManager.Database.GetDataProviders();
            var otherProvider = providers.FirstOrDefault(x => !(x is GlassDataProvider));

            foreach (var field in fields)
            {
                if (field.PropertyInfo.DeclaringType != cls.Type)
                    continue;



                if (field.CodeFirst && field.SectionName == section.Name && !ID.IsNullOrEmpty(field.FieldId))
                {
                    var record = FieldTable.FirstOrDefault(x => x.FieldId == field.FieldId);
                    //test if the fields exists in the database: if so, we're using codefirst now, so remove it.
                    var existing = otherProvider.GetItemDefinition(field.FieldId, context);
                    if (existing != null)
                    {
                        using (new SecurityDisabler())
                            otherProvider.DeleteItem(existing, context);
                    }
                    if (record == null)
                    {
                        string fieldName = field.FieldName.IsNullOrEmpty() ? field.PropertyInfo.Name : field.FieldName;


                        record = new FieldInfo(field.FieldId, section.SectionId, fieldName, field.FieldType,
                                               field.FieldSource, field.FieldTitle, field.IsShared, field.IsUnversioned,
                                               field.FieldSortOrder, field.ValidationRegularExpression,
                                               field.ValidationErrorText, field.IsRequired);

                        if (field.FieldValueConfigs != null && field.FieldValueConfigs.Any())
                        {
                            foreach (var ffv in field.FieldValueConfigs)
                            {
                                record.FieldFieldValues.Add(ffv.FieldId, ffv.FieldValue);
                            }
                        }

                    }

                    fieldIds.Add(record.FieldId);
                    FieldTable.Add(record);


                }
            }

            return fieldIds;
        }
 protected virtual void AddChildIDsForContactFacetsRootItem(IDList ids, ItemDefinition itemDefinition, CallContext context)
 {
     var facetNames = ContactFacetHelper.GetFacetNames();
     foreach (var name in facetNames)
     {
         var id = IDTableHelper.GenerateIdForFacet(name, itemDefinition.ID, Sitecore.Strategy.Contacts.DataProviders.TemplateIDs.ContactFacetTemplate);
         ids.Add(id);
     }
 }
 public override IDList GetPublishQueue(DateTime from, DateTime to, [NotNull] CallContext context)
 {
     lock (this)
     {
         var result = new IDList();
         PublishQueue.Where(r => (r.Date >= from) && (r.Date <= to)).Apply(r => result.Add(r.ItemID));
         return(result);
     }
 }
Esempio n. 33
0
        /// <summary>
        /// Gets the child I ds template.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="itemDefinition">The item definition.</param>
        /// <param name="context">The context.</param>
        /// <param name="sqlProvider">The SQL provider.</param>
        /// <returns>
        /// IDList.
        /// </returns>
        private IDList GetChildIDsTemplate(SitecoreTypeConfiguration template, ItemDefinition itemDefinition, CallContext context, DataProvider sqlProvider)
        {
            var fields    = new IDList();
            var processed = new List <string>();
            var sections  = template.Properties
                            .Where(x => x.PropertyInfo.DeclaringType == template.Type)
                            .OfType <SitecoreFieldConfiguration>()
                            .Select(x => new { x.SectionName, x.SectionSortOrder });

            //If sitecore contains a section with the same name in the database, use that one instead of creating a new one
            var existing = sqlProvider.GetChildIDs(itemDefinition, context).OfType <ID>().Select(id => sqlProvider.GetItemDefinition(id, context))
                           .Where(item => item.TemplateID == SectionTemplateId).ToList();

            foreach (var section in sections)
            {
                if (processed.Contains(section.SectionName) || section.SectionName.IsNullOrEmpty())
                {
                    continue;
                }

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section.SectionName);

                if (record == null)
                {
                    var       exists       = existing.FirstOrDefault(def => def.Name.Equals(section.SectionName, StringComparison.InvariantCultureIgnoreCase));
                    var       newId        = GetUniqueGuid(itemDefinition.ID + section.SectionName);
                    const int newSortOrder = 100;

                    record = exists != null ?
                             new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder)
                    {
                        Existing = true
                    } :
                    new SectionInfo(section.SectionName, new ID(newId), itemDefinition.ID, newSortOrder);

                    SectionTable.Add(record);
                }

                processed.Add(section.SectionName);

                if (!record.Existing)
                {
                    fields.Add(record.SectionId);
                }
            }

            //we need to add sections already in the db, 'cause we have to
            foreach (var sqlOne in existing.Where(ex => SectionTable.All(s => s.SectionId != ex.ID)))
            {
                SectionTable.Add(new SectionInfo(sqlOne.Name, sqlOne.ID, itemDefinition.ID, 0)
                {
                    Existing = true
                });
            }

            return(fields);
        }
		public void DeleteProducts(IDList productIDs)
		{
			try
			{
				 productServiceImpl.DeleteProducts(productIDs);
			}
			catch(Exception ex)
			{
				throw new FaultException<FaultData>(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
			}
		}
		public void DeleteCategories(IDList categoryIDs)
		{
			try
			{
				 _productServiceImpl.DeleteCategories(categoryIDs);
			}
			catch(Exception ex)
			{
				throw new FaultException<FaultData>(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
			}
		}
Esempio n. 36
0
 public void DeleteRoles(IDList roleIDs)
 {
     try
     {
          userServiceImpl.DeleteRoles(roleIDs);
     }
     catch(Exception ex)
     {
         throw new FaultException<FaultData>(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
     }
 }
 protected virtual void AddChildIDsForContactFacetMemberItem(IDList ids, ItemDefinition itemDefinition, CallContext context)
 {
     var itemId = itemDefinition.ID;
     var facetName = IDTableHelper.GetFacetMemberFacetName(itemId);
     var memberName = IDTableHelper.GetFacetMemberName(itemId);
     var args = new GetFacetMemberValuesArgs(facetName, memberName);
     CorePipeline.Run("getFacetMemberValues", args);
     if (!args.Values.Any())
     {
         return;
     }
     foreach (var pair in args.Values)
     {
         var id = IDTableHelper.GenerateIdForFacetMemberValue(pair.Key, pair.Value, itemId, Sitecore.Strategy.Contacts.DataProviders.TemplateIDs.ContactFacetMemberValueTemplate);
         ids.Add(id);
     }
 }
Esempio n. 38
0
		public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
		{
			Assert.ArgumentNotNull(itemDefinition, "itemDefinition");

			if (itemDefinition == ItemDefinition.Empty) return null;

			var children = SerializedDatabase.GetChildren(itemDefinition.ID);
			
			if (children == null) return null;

			var ids = new IDList();
			foreach (var syncItem in children)
			{
				ids.Add(syncItem.GetSitecoreId());
			}

			return ids;
		}
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            var database = GetDatabase(context);
            var children = database.GetChildren(itemDefinition.ID.ToString());
            var ids = new IDList();

            if (children == null)
            {
                return ids;
            }

            foreach (var syncItem in children)
            {
                ids.Add(ID.Parse(syncItem.ID));
            }

            return ids;
        }
 protected virtual void AddChildIDsForContactFacetItem(IDList ids, ItemDefinition itemDefinition, CallContext context)
 {
     var facetName = IDTableHelper.GetFacetName(itemDefinition.ID);
     var contractType = ContactFacetHelper.GetContractTypeForFacet(facetName);
     if (contractType == null)
     {
         return;
     }
     var members = contractType.GetMembers();
     foreach (var member in members)
     {
         if (member.MemberType == MemberTypes.Field || member.MemberType == MemberTypes.Property)
         {
             var id = IDTableHelper.GenerateIdForFacetMember(member, itemDefinition.ID, Sitecore.Strategy.Contacts.DataProviders.TemplateIDs.ContactFacetMemberTemplate);
             ids.Add(id);
         }
     }
 }
    public override IDList GetChildIDs([NotNull] ItemDefinition itemDefinition, [NotNull] CallContext context)
    {
      Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
      Assert.ArgumentNotNull(context, "context");

      var itemId = itemDefinition.ID;
      Assert.IsNotNull(itemId, "itemId");

      var childIDs = new IDList();

      // several segments can point to same root so let's collect items from all of them
      foreach (var segment in this.Segments)
      {
        Assert.IsNotNull(segment, "segment");

        var segmentChildIDs = segment.GetChildIDs(itemId);
        if (segmentChildIDs == null)
        {
          continue;
        }

        foreach (var childID in segmentChildIDs)
        {
          Assert.IsNotNull(childID, "childID");

          childIDs.Add(childID);
        }
      }

      // check if SQL has items too
      var sqlChildIDs = base.GetChildIDs(itemDefinition, context);
      if (sqlChildIDs == null)
      {
        return childIDs;
      }

      // merge segments' items with ones from SQL
      foreach (var id in sqlChildIDs.Cast<ID>())
      {
        childIDs.Add(id);
      }

      return childIDs;
    }
        // Here we check if the item implements our container template. If it does,
        // we create an association between what Sitecore will store the item as
        // and what our repository is storing the item as (SitecoreID<->EntityID).
        // This is the purpose of the IDTable.
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            if (this.canProcessParent(itemDefinition.ID))
            {
                Trace.WriteLine(String.Format("GetChildIDs({0}, {1})", itemDefinition, context), "ProductDataProvider");
                context.Abort();

                var idList = new IDList();
                var products = this.productRepository.GetAll();
                foreach (var product in products)
                {
                    var tableEntry = this.getSitecoreId(product.Id, itemDefinition.ID, true);
                    idList.Add(tableEntry);
                }
                context.DataManager.Database.Caches.DataCache.Clear();
                return idList;
            }
            return base.GetChildIDs(itemDefinition, context);
        }
		public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
		{
			Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
			Assert.ArgumentNotNull(context, "context");

			if (!ShouldExecuteProvider(itemDefinition.ID)) return null;

			context.Abort();
			var childIds = base.GetChildIDs(itemDefinition, context);

			var filteredChildren = new IDList();

			foreach (ID child in childIds)
			{
				if (ShouldExecuteProvider(child)) filteredChildren.Add(child);
			}

			// invoke the other data providers, if any, and *unique* the child IDs
			// this allows us to merge serialized items on top of an existing database item
			// (without this uniquing we'd get two identical children for items that were both
			// serialized AND in the other providers)
			var providers = Database.GetDataProviders();
			for (int i = context.Index + 1; i < context.ProviderCount; i++)
			{
				var otherChildIds = providers[i].GetChildIDs(itemDefinition, context);

				if (otherChildIds == null) continue;

				foreach (ID child in otherChildIds)
				{
					if (!filteredChildren.Contains(child)) filteredChildren.Add(child);
				}
			}

			return filteredChildren;
		}
 /// <summary>
 /// 删除商品信息。
 /// </summary>
 /// <param name="productIDs">需要删除的商品信息的ID值。</param>
 public void DeleteProducts(IDList productIDs)
 {
     PerformDeleteObjects<Product>(productIDs,
         productRepository,
         id =>
         {
             var categorization = categorizationRepository.Find(Specification<Categorization>.Eval(c => c.ProductID == id));
             if (categorization != null)
                 categorizationRepository.Remove(categorization);
         });
 }
 void AddAllNamespaces(IDList list, CallContext context)
 {
     var sqlProvider = GetSqlProvider(Database);
     foreach (var nspace in ControllerType.GetAllNamespaces().Where(s =>
     {
         return GetSqlVersion(new ID(s.Key), context, sqlProvider) == null;
     }))
     {
         list.Add(new ID(nspace.Key));
     }
 }
 void AddControllers(IDList list, Guid parentId, CallContext context)
 {
     var sqlProvider = GetSqlProvider(Database);
     foreach (var controller in ControllerType.GetAllControllers().Values.Where(c =>
     {
         if (c.ParentId != parentId)
             return false;
         return GetSqlVersion(new ID(c.Id), context, sqlProvider) == null;
     }))
     {
         list.Add(new ID(controller.Id));
     }
 }
		void AddAllControllers(IDList list)
		{
			foreach (var controller in ControllerType.GetControllerIds(ParentId.ToGuid()))
			{
				list.Add(new ID(controller.Key));
			}
		}
Esempio n. 48
0
        /// <summary>
        /// Gets the child I ds template.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="itemDefinition">The item definition.</param>
        /// <param name="context">The context.</param>
        /// <param name="sqlProvider">The SQL provider.</param>
        /// <returns>
        /// IDList.
        /// </returns>
        private IDList GetChildIDsTemplate(SitecoreTypeConfiguration template, ItemDefinition itemDefinition, CallContext context, DataProvider sqlProvider)
        {
            var fields = new IDList();
            var processed = new List<string>();
            var sections = template.Properties
                .Where(x => x.PropertyInfo.DeclaringType == template.Type)
                .OfType<SitecoreFieldConfiguration>()
                .Select(x => new { x.SectionName, x.SectionSortOrder });

            //If sitecore contains a section with the same name in the database, use that one instead of creating a new one
            var existing = sqlProvider.GetChildIDs(itemDefinition, context).OfType<ID>().Select(id => sqlProvider.GetItemDefinition(id, context))
                .Where(item => item.TemplateID == SectionTemplateId).ToList();

            foreach (var section in sections)
            {
                if (processed.Contains(section.SectionName) || section.SectionName.IsNullOrEmpty())
                    continue;

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section.SectionName);

                if (record == null)
                {
                    var exists = existing.FirstOrDefault(def => def.Name.Equals(section.SectionName, StringComparison.InvariantCultureIgnoreCase));
                    var newId = GetUniqueGuid(itemDefinition.ID + section.SectionName);
                    const int newSortOrder = 100;
                    
                    record = exists != null ?
                        new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder) { Existing = true } :
                        new SectionInfo(section.SectionName, new ID(newId), itemDefinition.ID, newSortOrder);

                    SectionTable.Add(record);
                }

                processed.Add(section.SectionName);

                if (!record.Existing)
                    fields.Add(record.SectionId);
            }

            //we need to add sections already in the db, 'cause we have to 
            foreach (var sqlOne in existing.Where(ex => SectionTable.All(s => s.SectionId != ex.ID)))
            {
                SectionTable.Add(new SectionInfo(sqlOne.Name, sqlOne.ID, itemDefinition.ID, 0) { Existing = true } );
            }

            return fields;
        }
 public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
 {
     if (itemDefinition != null && itemDefinition.ID == JoinParentId)
     {
         IDList childIDs = new IDList();
         foreach (ID id in Items.Keys)
         {
             childIDs.Add(id);
         }
         return childIDs;
     }
     return null;
 }
Esempio n. 50
0
        public IDList SelectIds(string query, Sitecore.Data.DataProviders.CallContext callContext)
        {
            IDList returnList = new IDList();

            //fast query

            if (query.StartsWith("fast:"))
            {
                query = query.Substring(5);
                if (!query.Contains("*"))
                {
                    var id = GetItemFromSimplePath(query);
                    if (id != Guid.Empty)
                        returnList.Add(new ID(id));
                }
                else if(query.Contains("["))
                {
                    List<Guid> guids = GetItemsMatchingPredicate(query);
                    guids.ForEach(g => returnList.Add(new ID(g)));
                }
                else if (query.EndsWith(@"//*"))
                {
                    List<Guid> guids = GetMatchingItemsForDescendantPath(query);
                    guids.ForEach(g => returnList.Add(new ID(g)));
                }
                else if (query.EndsWith(@"/*") && !query.Contains(@"//"))
                {
                    List<Guid> guids = GetMatchingItemsForWildcardPath(query);
                    guids.ForEach(g => returnList.Add(new ID(g)));
                }

                return returnList;
            }

            return null;
        }
        private IDList GetChildIDsSection(SectionInfo section, CallContext context)
        {
            var cls = Classes.First(x => x.Value.TemplateId == section.TemplateId.Guid).Value;

            var fields = cls.Properties.Where(x=>x.Attribute is SitecoreFieldAttribute);

            IDList fieldIds = new IDList();

            var providers = Database.GetDataProviders();
            var otherProvider = providers.FirstOrDefault(x => !(x is GlassDataProvider));

            foreach (var field in fields)
            {
                if (field.Property.DeclaringType != cls.Type)
                    continue;


                var attr = field.Attribute as SitecoreFieldAttribute;
                if (attr != null && attr.CodeFirst && attr.SectionName == section.Name)
                {

                    Guid guidId = Guid.Empty;
                    if (Utility.GuidTryParse(attr.FieldId, out guidId))
                    {
                        var record = FieldTable.FirstOrDefault(x => x.FieldId.Guid == guidId);
                        //test if the fields exists in the database: if so, we're using codefirst now, so remove it.
                        var existing = otherProvider.GetItemDefinition(new ID(guidId), context);
                        if (existing != null)
                        {
                            ID nullId = null; //hmm, there is a bug in sitecore ID's equality operator
                            //ONLY delete fields belonging directly to this template!!! if the parent is not in the database OR if it is a codefirst class/section, we can safely delete it to prevent duplicates
                            var existingParent = otherProvider.GetParentID(existing, context);
                            if (existingParent == nullId || existingParent == ID.Null ||
                                this.SectionTable.Any(s => s.SectionId == existing.ID) ||
                                this.Classes.Any(c => c.Value.TemplateId == existing.ID.ToGuid()))
                            {
                                using (new SecurityDisabler())
                                    otherProvider.DeleteItem(existing, context);
                            }
                        }
                        if (record == null)
                        {
                            string fieldName = attr.FieldName.IsNullOrEmpty() ? field.Property.Name : attr.FieldName;
                           

                            record = new FieldInfo(new ID(guidId), section.SectionId, fieldName, attr.FieldType, attr.FieldSource, attr.FieldTitle, attr.IsShared, attr.IsUnversioned, attr.FieldSortOrder, attr.ValidationRegularExpression, attr.ValidationErrorText, attr.IsRequired);
                            var fieldfieldInfoAttributes = field.Property.GetCustomAttributes(typeof (SitecoreFieldFieldValueAttribute), true);
                            if (fieldfieldInfoAttributes != null && fieldfieldInfoAttributes.Any())
                            {
                                foreach (var ffv in fieldfieldInfoAttributes.Cast<SitecoreFieldFieldValueAttribute>())
                                {
                                    record.FieldFieldValues.Add(ffv.FieldId, ffv.FieldValue);
                                }
                            }
                          
                        }

                        fieldIds.Add(record.FieldId);
                        FieldTable.Add(record);
                    }
                }


            }

            return fieldIds;
        }
        private IDList GetChildIDsTemplate(SitecoreClassConfig template, ItemDefinition itemDefinition, CallContext context)
        {
            IDList fields = new IDList();

            List<string> processed = new List<string>();
            var sections = template.Properties
                .Where(x=>x.Property.DeclaringType == template.Type)
                .Select(x=>x.Attribute).OfType<SitecoreFieldAttribute>()
                .Select(x => new { x.SectionName, x.SectionSortOrder });

            var providers = Database.GetDataProviders();
            var otherProvider = providers.FirstOrDefault(x => !(x is GlassDataProvider));
            //If sitecore contains a section with the same name in the database, use that one instead of creating a new one
            var otherChildIds = otherProvider.GetChildIDs(itemDefinition, context);
            var existing = (otherChildIds ?? new IDList()).OfType<ID>().Select(id => otherProvider.GetItemDefinition(id, context)).ToList();

            foreach (var section in sections)
            {
                if (processed.Contains(section.SectionName) || section.SectionName.IsNullOrEmpty())
                    continue;

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section.SectionName);

                if (record == null)
                {
                    var exists = existing.FirstOrDefault(def => def.Name.Equals(section));
                    if (exists != null)
                    {
                        record = new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder) { Existing = true };
                    }
                    else
                    {
                        record = new SectionInfo(section.SectionName, new ID(Guid.NewGuid()), itemDefinition.ID, section.SectionSortOrder);
                    }
                    SectionTable.Add(record);
                }
                processed.Add(section.SectionName);
                if (!record.Existing)
                    fields.Add(record.SectionId);
            }
            return fields;
        }
		void AddAllActions(IDList list, ControllerType controllerType)
		{
			foreach (var action in ControllerAction.GetAllActions(ParentId.ToGuid()).Where(a => a.ControllerType.Type == controllerType.Type))
			{
				list.Add(new ID(action.Id));
			}
		}
Esempio n. 54
0
        /// <summary>
        /// Basically call the standard data provider.
        /// Queries the fast.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="context">The context.</param>
        /// <returns>A list of IDs.</returns>
        protected override IDList QueryFast(string query, CallContext context)
        {
            var baseIdList = this.SelectIDs(query, context);
            if (baseIdList != null && baseIdList.Count > 0) return baseIdList;

            if (!this.IsTraceEnabled(query)) return base.QueryFast(query, context);

            var parameters = new ParametersList();
            var sql = this.Translator.TranslateQuery(query, context, parameters);

            Log.Debug(string.Format("FastQuery: {0}", query), this);
            Log.Debug(string.Format("SQL Query: {0}", this.FormatSqlQuery(sql, parameters)), this);

            if (sql == null) return null;

            var stopwatch = Stopwatch.StartNew();
            using (var reader = this.Api.CreateReader(sql, parameters.ToArray()))
            {
                var idList = new IDList();
                while (reader.Read())
                {
                    idList.Add(this.Api.GetId(0, reader));
                }

                context.CurrentResult = idList;
            }

            Log.Debug(string.Format("Query Time: {0}ms", stopwatch.ElapsedMilliseconds), this);
            return null;
        }
Esempio n. 55
0
        /// <summary>
        /// returns a string array of gene_ids associated with a strain (transgenes, gene genotypes, genomic segments)
        /// </summary>
        /// <param name="StrainID">ID Object</param>
        /// <returns>string array</returns>
        public virtual string[] GetGeneIDsFromStrain(ID StrainID)
        {
            if (StrainID.IsNull)
            {
                string[] no_genes = new string[1];
                no_genes[0] = "";
                return no_genes;
            }
            GenomeMgr gMgr = GenomeMgr.Instance;
            GeneGenotypeList genotypes;
            TransgeneList transgenes;
            GenomicSegmentList segments;
            genotypes = gMgr.GetGeneGenotypes(StrainID);
            transgenes = gMgr.GetTransgenes(StrainID);
            segments = gMgr.GetGenomicSegments(StrainID);

            IDList EntrezGeneIDs = new IDList();
            foreach (GeneGenotype g in genotypes)
            {
                if (g.Gene.EntrezGeneID.IsValid)
                    EntrezGeneIDs.Add(g.Gene.EntrezGeneID);
            }
            foreach (Transgene tg in transgenes)
            {
                if (tg.Gene.EntrezGeneID.IsValid)
                    EntrezGeneIDs.Add(tg.Gene.EntrezGeneID);

                if (tg.Enhancer.Gene.EntrezGeneID.IsValid)
                    EntrezGeneIDs.Add(tg.Enhancer.Gene.EntrezGeneID);

                if (tg.Promoter.Gene.EntrezGeneID.IsValid)
                    EntrezGeneIDs.Add(tg.Promoter.Gene.EntrezGeneID);
            }

            foreach (GenomicSegment gs in segments)
            {
                if (gs.DistalFlanking.EntrezGeneID.IsValid)
                    EntrezGeneIDs.Add(gs.DistalFlanking.EntrezGeneID);

                if (gs.DistalLocus.EntrezGeneID.IsValid)
                    EntrezGeneIDs.Add(gs.DistalLocus.EntrezGeneID);

                if (gs.ProximalFlanking.EntrezGeneID.IsValid)
                    EntrezGeneIDs.Add(gs.ProximalFlanking.EntrezGeneID);

                if (gs.ProximalLocus.EntrezGeneID.IsValid)
                    EntrezGeneIDs.Add(gs.ProximalLocus.EntrezGeneID);
            }

            int count = EntrezGeneIDs.Count;
            if (count > 0)
            {
                string[] gene_ids = new string[count];
                for (int i = 0; i < count; i++)
                    gene_ids[i] = EntrezGeneIDs[i].ToString();
                return gene_ids;
            }

            return null;
        }
        public override IDList GetPublishQueue(DateTime from, DateTime to, CallContext context)
        {
            var items = Provider.WritableProvider.GetPublishQueue(from, to);

            Hashtable hashtable = new Hashtable();
            IDList list = new IDList();

            foreach (var item in items)
            {
                if (hashtable.ContainsKey(item.Id))
                    continue;

                hashtable[item.Id] = string.Empty;

                list.Add(new ID(item.Id));
            }

            return list;
        }
 /// <summary>
 /// 删除商品分类。
 /// </summary>
 /// <param name="categoryIDs">需要删除的商品分类的ID值。</param>
 public void DeleteCategories(IDList categoryIDs)
 {
     PerformDeleteObjects<Category>(categoryIDs,
         categoryRepository,
         id =>
         {
             var categorization = categorizationRepository.Find(Specification<Categorization>.Eval(c => c.CategoryID == id));
             if (categorization != null)
                 categorizationRepository.Remove(categorization);
         });
 }
Esempio n. 58
0
        /// <summary>
        /// Gets the child I ds section.
        /// </summary>
        /// <param name="section">The section.</param>
        /// <param name="context">The context.</param>
        /// <param name="sqlProvider">The SQL provider.</param>
        /// <returns>
        /// IDList.
        /// </returns>
        private IDList GetChildIDsSection(SectionInfo section, CallContext context, DataProvider sqlProvider)
        {
            var config = TypeConfigurations.First(x => x.Value.TemplateId == section.TemplateId);
            var cls = config.Value;

            var fields = cls.Properties.OfType<SitecoreFieldConfiguration>();

            IDList fieldIds = new IDList();

            var interfaces = cls.Type.GetInterfaces();

            foreach (var field in fields)
            {
                //fix: added check on interfaces, if field resides on interface then skip here
                var propertyFromInterface = interfaces.FirstOrDefault(inter => inter.GetProperty(field.PropertyInfo.Name) != null 
                                                                            && inter.GetProperty(field.PropertyInfo.Name).GetCustomAttributes(typeof(SitecoreFieldAttribute), false).Any());
                if (field.PropertyInfo.DeclaringType != cls.Type || propertyFromInterface != null)
                    continue;

                if (field.CodeFirst && field.SectionName == section.Name && !ID.IsNullOrEmpty(field.FieldId))
                {
                    var record = FieldTable.FirstOrDefault(x => x.FieldId == field.FieldId);
                    //test if the fields exists in the database: if so, we're using codefirst now, so remove it.
                    var existing = sqlProvider.GetItemDefinition(field.FieldId, context);
                    if (existing != null)
                    {
                        using (new SecurityDisabler())
                        {
                            if (DisableItemHandlerWhenDeletingFields)
                            {
                                using (new DisableItemHandler())
                                    sqlProvider.DeleteItem(existing, context);
                            }
                            else
                            {
                                sqlProvider.DeleteItem(existing, context);
                            }
                        }
                    }

                    if (record == null)
                    {
                        string fieldName = field.FieldName.IsNullOrEmpty() ? field.PropertyInfo.Name : field.FieldName;

                        record = new FieldInfo(field.FieldId, section.SectionId, fieldName, field.FieldType, field.CustomFieldType,
                                               field.FieldSource, field.FieldTitle, field.IsShared, field.IsUnversioned,
                                               field.FieldSortOrder, field.ValidationRegularExpression,
                                               field.ValidationErrorText, field.IsRequired);

                        if (field.FieldValueConfigs != null && field.FieldValueConfigs.Any())
                        {
                            foreach (var ffv in field.FieldValueConfigs)
                            {
                                record.FieldFieldValues.Add(ffv.FieldId, ffv.FieldValue);
                            }
                        }
                    }

                    fieldIds.Add(record.FieldId);
                    FieldTable.Add(record);
                }
            }

            return fieldIds;
        }
Esempio n. 59
0
 /// <summary>
 /// 删除角色。
 /// </summary>
 /// <param name="roleIDs">需要删除的角色ID值列表。</param>
 public void DeleteRoles(IDList roleIDs)
 {
     PerformDeleteObjects<Role>(roleIDs,
         roleRepository,
         id =>
         {
             var userRole = userRoleRepository.Find(Specification<UserRole>.Eval(ur => ur.RoleID == id));
             if (userRole != null)
                 userRoleRepository.Remove(userRole);
         });
 }