Exemplo n.º 1
0
        void Refresh()
        {
            this.Name  = m_Item[TemplateCT.TemplateName] as string;
            this.State = EnumConverter.ToState(m_Item[TemplateCT.TemplateState] as string);

            SPFieldUserValueCollection v = new SPFieldUserValueCollection(m_Item.Web, m_Item.GetFieldValue <object>(TemplateCT.SendDraftTo, string.Empty).ToString());

            this.SendDraftToAdresses = v.Select(p => p.User.Email).ToList();

            this.UseFileForSubject = m_Item.GetFieldValue <bool>(TemplateCT.TemplateSubjectUseFile);
            this.UseFileForBody    = m_Item.GetFieldValue <bool>(TemplateCT.TemplateBodyUseFile);
            this.UseFileForFrom    = m_Item.GetFieldValue <bool>(TemplateCT.TemplateFromUseFile);
            this.UseFileForReply   = m_Item.GetFieldValue <bool>(TemplateCT.TemplateReplayUseFile);

            this.From    = m_Item.GetValueFromTextFieldOrFile(this.UseFileForFrom, TemplateCT.TemplateFrom, TemplateCT.TemplateFromFile, out FromAttached);
            this.Replay  = m_Item.GetValueFromTextFieldOrFile(this.UseFileForReply, TemplateCT.TemplateReplay, TemplateCT.TemplateReplayFile, out ReplyAttached);
            this.Body    = m_Item.GetValueFromTextFieldOrFile(this.UseFileForBody, TemplateCT.TemplateBody, TemplateCT.TemplateBodyFile, out this.BodyAttached);
            this.Subject = m_Item.GetValueFromTextFieldOrFile(this.UseFileForSubject, TemplateCT.TemplateSubject, TemplateCT.TemplateSubjectFile, out this.SubjectAttached);

            if (m_Item[TemplateCT.TemplateType] != null)
            {
                var val = new SPFieldMultiChoiceValue(m_Item[TemplateCT.TemplateType].ToString());
                this.EventTypes = EnumConverter.ToType(val);
            }
            else
            {
                this.EventTypes = (int)TemplateTypeEnum.Unknown;
            }

            this.Associations = AssociationCollection.ParseOrDefault(m_Item[TemplateCT.Associations] as string);
        }
	    public object FromSpValue(object value)
		{
			if (value == null)
				return null;

			if (!Field.AllowMultipleValues)
			{
				var fieldValue = new SPFieldUserValue(Field.ParentList.ParentWeb, value.ToString());

				return new UserInfo(fieldValue.User);
			}

			var fieldValues = new SPFieldUserValueCollection(Field.ParentList.ParentWeb, value.ToString());
		    var users = fieldValues.Select(fieldValue => fieldValue.User).Select(user => new UserInfo(user));

		    return PropertyType == typeof (UserInfo[]) ? (object) users.ToArray() : users.ToList();
		}
Exemplo n.º 3
0
        public IEnumerator <User> GetEnumerator()
        {
            if (_users == null)
            {
                return(new List <User>().GetEnumerator());
            }

            return(_users
                   .Select(u =>
            {
                if (u.User == null)
                {
                    return _proxyGenerator.CreateClassProxy <User>(new UserAccessInterceptor(u));
                }
                return _proxyGenerator.CreateClassProxy <Person>(new UserAccessInterceptor(u));
            })
                   .GetEnumerator());
        }
Exemplo n.º 4
0
        // Private Methods (4) 

        private static void GetAssignedToUsers(SPItemEventProperties properties, Dictionary <string, object> data)
        {
            var users = new List <int>();

            if (properties.List.Fields.ContainsFieldWithInternalName("AssignedTo"))
            {
                object assignedToUsers = properties.ListItem["AssignedTo"];
                if (assignedToUsers != null)
                {
                    var au = assignedToUsers as string;

                    SPFieldUserValueCollection collection = !string.IsNullOrEmpty(au)
                        ? new SPFieldUserValueCollection(properties.Web, au)
                        : (SPFieldUserValueCollection)assignedToUsers;

                    users.AddRange(collection.Select(userValue => userValue.LookupId));
                }
            }

            data.Add("AssignedTo", string.Join(",", users.AsParallel().Distinct().ToArray()));
        }
 public static IEnumerable<SPUser> GetSPUsers(SPListItem listItem, string key)
 {
     object obj = null;
     try
     {
         obj = listItem[key];
     }
     catch (Exception)
     {
         var index = -1;
         switch (key)
         {
             case "Author":
                 index = GetFieldIndex(listItem, key);
                 obj = listItem[index]; //Ошибка шарепоинта - иногда не ищет поле Author               
                 break;
             case "Editor":
                 index = GetFieldIndex(listItem, key);
                 obj = listItem[index]; //Ошибка шарепоинта - иногда не ищет поле Editor               
                 break;
         }
     }
     if (obj == null)
         return null;
     try
     {
         var value = new SPFieldUserValueCollection(listItem.Web, obj.ToString());
         return value.Select(item => item.User);
     }
     catch (Exception)
     {
         return null;
     }
 }
Exemplo n.º 6
0
 public UserValueCollection(SPFieldUserValueCollection userFieldValueCollection) :
     this(new UserValueCollection(userFieldValueCollection.Select(userFieldValue => new UserValue(userFieldValue.User)).ToList()))
 {
 }
Exemplo n.º 7
0
        public void Save(SPWeb web, bool addTemplates = true)
        {
            SPListItem briefingItem = null;
            SPList     list         = web.Lists[ListId];
            string     folderName   = FileUtil.CleanForUrlAndFileNameUse(Title);

            if (Id.HasValue)
            {
                briefingItem = list.GetItemById(Id.Value);
                briefingItem["FileLeafRef"] = folderName;
                BriefingNumber = (string)briefingItem[BriefingFields.BriefingNumberId];
            }
            else
            {
                if (string.IsNullOrEmpty(Category))
                {
                    briefingItem = list.AddItem(list.RootFolder.Url, SPFileSystemObjectType.Folder, folderName);
                }
                else
                {
                    string folderUrl = SPUrlUtility.CombineUrl(list.RootFolder.Url, Category);
                    if (web.GetFolder(folderUrl).Exists)
                    {
                        briefingItem = list.AddItem(folderUrl, SPFileSystemObjectType.Folder, folderName);
                    }
                    else
                    {
                        briefingItem = list.AddItem(list.RootFolder.Url, SPFileSystemObjectType.Folder, folderName);
                    }
                }

                SPContentType ctype = list.ContentTypes[list.ContentTypes.BestMatch(ContentTypes.BriefingContentTypeId)];
                briefingItem[SPBuiltInFieldId.ContentTypeId] = ctype.Id;
                briefingItem[SPBuiltInFieldId.ContentType]   = ContentTypes.BriefingContentTypeName;
                if (string.IsNullOrEmpty(BriefingNumber))
                {
                    BriefingNumber = Config.System.CurrentSystem == SystemType.Poline ? BriefingNumbers.GetNextPolineNumber(StartEventDate.Value.Year) : BriefingNumbers.GetNextNumber(web, StartEventDate.Value);
                }
                briefingItem[BriefingFields.BriefingNumberId] = BriefingNumber;
            }

            briefingItem[BriefingFields.BriefingTitleId]  = Title;
            briefingItem[BriefingFields.StartEventDateId] = StartEventDate;
            briefingItem[BriefingFields.EndEventDateId]   = EndEventDate;
            if (briefingItem.Fields.ContainsField(BriefingFields.IsProtectedName))
            {
                briefingItem[BriefingFields.IsProtectedName] = IsProtected;
            }
            briefingItem[BriefingFields.LocationId]             = Location;
            briefingItem[BriefingFields.MainTopicsId]           = Topics;
            briefingItem[BriefingFields.RequestDateName]        = RequestDate;
            briefingItem[BriefingFields.DraftDeadlineId]        = DraftDeadline;
            briefingItem[BriefingFields.FinalDeadlineId]        = FinalDeadline;
            briefingItem[BriefingFields.ServicesDeadlineId]     = ServicesDeadline;
            briefingItem[BriefingFields.CabMemberResponsibleId] = CabMemberResponsibleValue;
            SPFieldUserValueCollection PrevSGResponsibleValue = briefingItem[BriefingFields.SGResponsibleId] as SPFieldUserValueCollection ?? new SPFieldUserValueCollection();

            if (SGResponsibleValue.Count != PrevSGResponsibleValue.Count ||
                SGResponsibleValue.Except(PrevSGResponsibleValue, new SPFieldUserValueComparer()).Any())
            {
                briefingItem.Properties[PREVIOUS_SGRESPONSIBLE_KEY] = string.Join(",", PrevSGResponsibleValue.Select(user => user.User.LoginName).ToArray());
            }
            briefingItem[BriefingFields.SGResponsibleId]    = SGResponsibleValue;
            briefingItem[BriefingFields.OtherResponsibleId] = OtherResponsibleValue;
            briefingItem[BriefingFields.UnitResponsibleId]  = UnitResponsibleValue;
            briefingItem[BriefingFields.LinkToReportId]     = LinkToReport;
            briefingItem[BriefingFields.UrgentRequestId]    = UrgentRequest;
            briefingItem[BriefingFields.BriefingUrgencyId]  = NumberOfDaysValue;
            briefingItem[BriefingFields.CancelledId]        = EventCancelled;
            briefingItem[BriefingFields.BeneficiaryId]      = Beneficiary;
            briefingItem[BriefingFields.CommentsId]         = Comments;
            briefingItem[BriefingFields.FinalizedName]      = Finalized;
            briefingItem[BriefingFields.NoteTakerId]        = NoteTakerValue;

            if (briefingItem.Fields.Contains(BriefingFields.Language))
            {
                briefingItem[BriefingFields.Language] = Language;
            }
            if (briefingItem.Fields.Contains(BriefingFields.AdditionalDocuments))
            {
                briefingItem[BriefingFields.AdditionalDocuments] = AdditionalDocumentsValue.ToString();
            }
            if (briefingItem.Fields.Contains(BriefingFields.PrintedCopies))
            {
                briefingItem[BriefingFields.PrintedCopies] = PrintedCopies;
            }
            if (briefingItem.Fields.Contains(BriefingFields.WhoHasRequestedMeeting))
            {
                briefingItem[BriefingFields.WhoHasRequestedMeeting] = WhoHasRequestedMeeting;
            }
            if (briefingItem.Fields.Contains(BriefingFields.ParticipantsCommission))
            {
                briefingItem[BriefingFields.ParticipantsCommission] = ParticipantsCommission;
            }
            if (briefingItem.Fields.Contains(BriefingFields.ParticipantsInterlocutors))
            {
                briefingItem[BriefingFields.ParticipantsInterlocutors] = ParticipantsInterlocutors;
            }
            if (briefingItem.Fields.Contains(BriefingFields.HaveTheyMetBefore))
            {
                briefingItem[BriefingFields.HaveTheyMetBefore] = HaveTheyMetBefore;
            }
            if (briefingItem.Fields.Contains(BriefingFields.MetInWhichCapacity))
            {
                briefingItem[BriefingFields.MetInWhichCapacity] = MetInWhichCapacity;
            }
            if (briefingItem.Fields.Contains(BriefingFields.MetWhen))
            {
                briefingItem[BriefingFields.MetWhen] = MetWhen;
            }
            if (briefingItem.Fields.Contains(BriefingFields.PreviousCommitmentsControversies))
            {
                briefingItem[BriefingFields.PreviousCommitmentsControversies] = PreviousCommitmentsControversies;
            }
            if (briefingItem.Fields.Contains(BriefingFields.WhatDoTheyWant))
            {
                briefingItem[BriefingFields.WhatDoTheyWant] = WhatDoTheyWant;
            }
            if (briefingItem.Fields.Contains(BriefingFields.WhatDoWeWant))
            {
                briefingItem[BriefingFields.WhatDoWeWant] = WhatDoWeWant;
            }
            if (briefingItem.Fields.Contains(BriefingFields.MeetingTopics))
            {
                briefingItem[BriefingFields.MeetingTopics] = MeetingTopics;
            }

            if (briefingItem.Fields.Contains(BriefingFields.HermesLinkId) && briefingItem.Fields.Contains(BriefingFields.HermesReferenceId))
            {
                ARESLink      = (string)briefingItem[BriefingFields.HermesLinkId];
                ARESReference = (string)briefingItem[BriefingFields.HermesReferenceId];
            }

            briefingItem.Update();

            ServerRelativeUrl = briefingItem.Folder.ServerRelativeUrl;

            SPUserToken userToken = SPContext.Current.Site.UserToken;
            Guid        siteId    = web.Site.ID;
            Guid        webId     = web.ID;
            int         itemId    = briefingItem.ID;

            if (Id.HasValue)
            {
                if (briefingItem.Folder.ParentFolder.Name != Category)
                {
                    SPFolder folder = briefingItem.Folder;
                    if (string.IsNullOrEmpty(Category))
                    {
                        ServerRelativeUrl = SPUrlUtility.CombineUrl(list.RootFolder.ServerRelativeUrl, folderName);
                    }
                    else
                    {
                        ServerRelativeUrl = SPUrlUtility.CombineUrl(SPUrlUtility.CombineUrl(list.RootFolder.ServerRelativeUrl, Category), folderName);
                    }
                    if (briefingItem.Folder.ServerRelativeUrl != ServerRelativeUrl)
                    {
                        folder.MoveTo(ServerRelativeUrl);
                        briefingItem = list.GetItemById(Id.Value);
                    }
                }
            }
            else
            {
                HostingEnvironment.QueueBackgroundWorkItem(token => copyTemplatesAsync(siteId, webId, ListId, itemId, userToken, addTemplates, IsProtected));
            }

            string bn = Id.HasValue ? BriefingNumber : web.CurrentUser.LoginName.Substring(web.CurrentUser.LoginName.LastIndexOf("|") + 1) + "-new-briefing";

            HostingEnvironment.QueueBackgroundWorkItem(token => saveAdditionalDocumentsAsync(siteId, webId, userToken, ListId, itemId, bn, AdditionalDocuments));

            Id              = briefingItem.ID;
            UniqueId        = briefingItem.Folder.UniqueId;
            Modified        = ((DateTime)briefingItem[SPBuiltInFieldId.Modified]).ToString();
            ModifiedBy      = new SPFieldUserValue(web, (string)briefingItem[SPBuiltInFieldId.Editor]).LookupValue;
            BasePermissions = briefingItem.EffectiveBasePermissions.ToString();

            HostingEnvironment.QueueBackgroundWorkItem(token => ensureBriefingProtectedAsync(siteId, webId, ListId, itemId, IsProtected));
        }