private object Execute(SPListItem i, SetRightsPluginConfig config) { if (i == null) throw new ArgumentNullException("i"); //polozku otevreme jako elevated a zni j*z pak vse bude elevated!!! i.RunElevated(delegate(SPListItem item) { log.LogInfo("Start ExecuteSetRights from item " + item.FormUrlDisplay()); foreach (KeyValuePair<string, RightsSettings> right in config.Rights) { string rightsTitle = right.Key; RightsSettings settings = right.Value; string itemIdentification = settings.RightsFor; //Prava primo pro polozku if (itemIdentification == "self") { SetRightsForItem(item, settings.Roles, settings.Clear, settings.ExpandUsers); } else if (item.ParentList.ContainsFieldIntName(itemIdentification)) //Prava na lookupovanou polozku { try { SPField field = item.ParentList.OpenField(itemIdentification, true); if (field.IsLookup()) { item.GetItemsFromLookup(field.InternalName).ProcessItems(item.Web.Site, delegate(SPListItem lookupItem) { SetRightsForItem(lookupItem, settings.Roles, settings.Clear, settings.ExpandUsers); return null; }); } else { log.LogError("Field '" + field.InternalName + "' is not lookup"); continue; } } catch (Exception exc) { log.LogError(exc); } } else if (itemIdentification.Contains('|')) ////Prava na lookupovanou polozku a lookup v ni { WebListItemDictionary wild = item.TraverseItemLookups(itemIdentification.Split('|').ToList()); wild.ProcessItems(item.Web.Site, delegate(SPListItem lookupItem) { Console.WriteLine(lookupItem.Title); SetRightsForItem(lookupItem, settings.Roles, settings.Clear, settings.ExpandUsers); return null; }); } else { log.LogError("Could not recognize rights for: '" + itemIdentification + "'"); } } return null; }); log.LogInfo(setRightsLog); return "OK"; }
private KeyValuePair<string, FileAndDate> LoadScriptFromItem(SPListItem tempitem) { return (KeyValuePair<string, FileAndDate>) tempitem.RunElevated(delegate(SPListItem item) { string relativePath = RemoveMatchingStringFromStart(item.DocumentUrl(), item.ParentList.AbsoluteUrl()).Replace("/", "\\"); KeyValuePair<string, FileAndDate> result = new KeyValuePair<string, FileAndDate> (item.IsFolder() ? ".\\" + relativePath + "\\" : ".\\" + relativePath, new FileAndDate(item.IsFolder() ? null : item.File.OpenBinaryStream().ReadAllBytes(), (DateTime) item["Modified"])); return result; }); }