public void Create(ChatMessage message)
        {
            IContactRepository repo = new ContactRepository();
            var        id           = SPContext.Current.Web.CurrentUser.ID;
            SPList     list         = Config.GetList(SPContext.Current.Web);
            List <int> ids          = message.Receivers.Select(r => r.ID).ToList();

            ids.Add(id);
            SPListItem conversation = Config.GetConversationFolder(list, ids.ToArray());

            if (conversation == null)
            {
                conversation = Config.CreateConversationFolder(SPContext.Current.Web, Guid.NewGuid().ToString().Replace("-", ""), ids.Select(i => repo.CreateRoleAssignment(Language.SMUGroupName, i)).ToArray());
            }
            SPItem item = list.Items.Add(conversation.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, message.Title);

            item[ChatMessageFields.Title]   = message.Title;
            item[ChatMessageFields.Message] = message.Message;
            item[ChatMessageFields.IsRead]  = false;
            SPFieldLookupValueCollection receivers = new SPFieldLookupValueCollection();

            foreach (Contact c in message.Receivers)
            {
                receivers.Add(new SPFieldLookupValue(c.ID, null));
            }
            item[ChatMessageFields.Receivers] = receivers;
            item.Update();
        }
 /// <summary>
 /// When document finished upload try process the file, this happens when uploaded from Windows Explorer
 /// </summary>
 public override void ItemUpdated(SPItemEventProperties properties)
 {
     base.ItemUpdated(properties);
     GWUtility.WriteLog($"GW File Updated Event URL:{properties.ListItem.File.Url} Length:{properties.ListItem.File.Length}");
     try
     {
         properties.Web.AllowUnsafeUpdates = true;
         EventFiringEnabled = false;
         var fileItem = properties.ListItem.File;
         if (fileItem != null)
         {
             GWUtility.WriteLog("GW File URL processing ..." + fileItem.Url);
             System.Threading.Thread.Sleep(2000);
             byte[] fileContent = fileItem.OpenBinary();
             System.Threading.Thread.Sleep(2000); // not mandatory but if mp4 file of large size is uploaded it takes seconds to read
             string base64 = Convert.ToBase64String(fileContent);
             byte[] regeneratedFileBytes = new GlasswallRebuildClient().RebuildFile(base64);
             SPItem item = properties.ListItem;
             properties.ListItem["Title"] = "GW_" + fileItem.Name; // just updating the Title to make sure it is processed
             properties.ListItem.SystemUpdate();
             fileItem.SaveBinary(regeneratedFileBytes);
             GWUtility.WriteLog("GW file done :" + properties.ListItem.File.Length);
         }
     }
     catch (Exception ex)
     {
         GWUtility.WriteLog("GW Upload Exception: " + ex.Message + ex.StackTrace);
     }
     finally
     {
         properties.Web.AllowUnsafeUpdates = false;
         EventFiringEnabled = true;
     }
 }
Esempio n. 3
0
        private static string FormatBidderName(SPItem item)
        {
            var bidderColumn = (SPFieldUser)item.Fields.GetField("Bidder");
            var bidder       = (SPFieldUserValue)bidderColumn.GetFieldValue(item["Bidder"].ToString());

            return(bidder.User.Name);
        }
Esempio n. 4
0
 // Methods
 private static void ApplyRelatedItems(SPItem masterItem, IList <SPItem> expanded, IEnumerable <SPItem> related, IEnumerable <int> excludeExceptionIds, string beginFieldName, string endFieldName, SPTimeZone localTimeZone)
 {
     foreach (SPItem item in related)
     {
         int      integerFieldValue  = SafeFieldAccessor.GetIntegerFieldValue(masterItem, "ID");
         DateTime dateTimeFieldValue = SafeFieldAccessor.GetDateTimeFieldValue(item, "RecurrenceID");
         string   id    = GenerateRecurrenceItemId(integerFieldValue, dateTimeFieldValue, localTimeZone, false);
         SPItem   item2 = FindItemById(expanded, id);
         if (item2 != null)
         {
             expanded.Remove(item2);
         }
         int eventType = GetEventType(item);
         if ((eventType == 4) && ((excludeExceptionIds == null) || !excludeExceptionIds.Contains <int>(item.ID)))
         {
             DateTime start = SafeFieldAccessor.GetDateTimeFieldValue(item, beginFieldName);
             DateTime end   = SafeFieldAccessor.GetDateTimeFieldValue(item, endFieldName);
             item2 = FindItemByBeginEnd(expanded, beginFieldName, endFieldName, start, end);
             if (item2 != null)
             {
                 if (GetEventType(item2) == 4)
                 {
                     continue;
                 }
                 expanded.Remove(item2);
             }
             SPItem item3 = new ExpandedCalendarItem(item);
             string str2  = GenerateExceptionItemId(item.ID, integerFieldValue, eventType);
             item3["ID"] = str2;
             expanded.Add(item3);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 根据图片标题从图片库中查找图片
        /// </summary>
        /// <param name="imgTitle">图片标题</param>
        /// <param name="imgLib">图片库名</param>
        /// <param name="webUrl">图片库所在网站</param>
        /// <returns>查找到的图片地址</returns>
        string GetSignImgFromImgLibByTitle(string imgTitle, string imgLib, string webUrl)
        {
            string imgUrl = "";

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite spSite = new SPSite(SPContext.Current.Site.Url)) //找到网站集
                {
                    using (SPWeb spWeb = spSite.OpenWeb(webUrl))
                    {
                        SPList spList = spWeb.Lists.TryGetList(imgLib);
                        if (spList != null)
                        {
                            SPQuery spqry = new SPQuery();
                            spqry.Query   = @" <Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + imgTitle + "</Value></Eq></Where>";
                            SPListItemCollection spItems = spList.GetItems(spqry);
                            if (spItems.Count > 0)
                            {
                                SPItem item = spItems[0];
                                imgUrl      = item["FileRef"] == null ? "" : item["FileRef"].ToString();
                                if (imgUrl != "")
                                {
                                    imgUrl = "<img width='60px' height='40px' src='" + imgUrl + "'/>";
                                }
                            }
                        }
                    }
                }
            });
            return(imgUrl);
        }
Esempio n. 6
0
        private void SetStatus_Weryfikacja_ExecuteCode(object sender, EventArgs e)
        {
            SPItem item = workflowProperties.Item;

            item["Batch Status"] = "Weryfikacja";
            item.Update();
        }
        // Update Item value(s)
        protected void TextBox_OnTextChanged(object sender, EventArgs e)
        {
            // Text BOX where i changed/write smth.
            TextBox txtBox = ((TextBox)(sender));
            // Find the origine of repeater
            RepeaterItem repeater = (RepeaterItem)(txtBox.NamingContainer);

            // What is written now inside Text Box;
            string valueTxtBox = txtBox.Text.Trim();

            // What TxtBox is ? txtMovie_Name => remove first 3chars => Movie_Name
            string idTxtBox = txtBox.ID.ToString().Trim();

            // get the name of the Field => txtMovie_Name - 3chars => Movie_Name
            idTxtBox = idTxtBox.Remove(0, 3);

            // Get Id of the row in the list
            Label txtID = (Label)repeater.FindControl("lbl_Id");


            SPList movies = SPContext.Current.Web.Lists.TryGetList("Movies");
            SPItem item   = movies.GetItemById(int.Parse(txtID.Text));

            item[idTxtBox] = valueTxtBox;

            item.Update();


            //  this.BindRepeater();
        }
        /// <summary>
        /// Gets and ensure the field data.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <returns>The field content</returns>
        private string GetFieldData(SPItem item, string fieldName)
        {
            string fieldData = string.Empty;

            if (item[fieldName] != null)
            {
                fieldData = SPEncode.HtmlDecode(item[fieldName].ToString());

                // Dates in ISO8601
                if (_bDateTimeISO8601 &&
                    item.Fields.GetField(fieldName).Type == SPFieldType.DateTime)
                {
                    fieldData = SPUtility.CreateISO8601DateTimeFromSystemDateTime(
                        DateTime.Parse(fieldData, CultureInfo.InvariantCulture).ToUniversalTime().ToLocalTime());
                }
                else
                {
                    // fix: lookup fields
                    if (_bFixLookUp)
                    {
                        if (fieldData.IndexOf(LOOKUP_FIELD_SEPARATOR) > 0)
                        {
                            fieldData = fieldData.Substring(fieldData.IndexOf(LOOKUP_FIELD_SEPARATOR) + 2);
                        }
                    }
                }
            }
            return(fieldData);
        }
Esempio n. 9
0
        private void NotifyBidder(SPWeb web, SPItem item, SPUser bidder)
        {
            var mailFormatMessage = web.Lists[Constants.ConfigListName].Items[0]["AuctionItemLeadingBidder"].ToString();

            SPUtility.SendEmail(web, true, false,
                                bidder.Email, "You are the leading bidder",
                                string.Format(mailFormatMessage, _bidAmount, item["Title"], string.Format("{0}?uicontrol=ItemDetails&ItemId={1}", UrlHelper.GetUrl(Page.Request.Url), item.ID)));
        }
Esempio n. 10
0
        private static void IncrementBidCount(SPItem item)
        {
            var bids = 1;

            if (item["NumberOfBids"] != null)
            {
                bids = Convert.ToInt32(item["NumberOfBids"].ToString());
                bids++;
            }
            item["NumberOfBids"] = bids.ToString(CultureInfo.InvariantCulture);
        }
 /// <summary>
 /// Items the contains field and data.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="fieldName">Name of the field.</param>
 /// <returns></returns>
 private bool ItemContainsFieldAndData(SPItem item, string fieldName)
 {
     if (item.Fields.ContainsField(fieldName))
     {
         if (item[fieldName] != null)
         {
             return(true);
         }
     }
     return(false);
 }
        public ChatMessage GetByID(int id)
        {
            SPList list = Config.GetList(SPContext.Current.Web);
            SPItem item = list.Items.GetItemById(id);

            return(new ChatMessage()
            {
                ID = item.ID,
                Title = item[ChatMessageFields.Title].ToString(),
                Message = item[ChatMessageFields.Message].ToString(),
            });
        }
Esempio n. 13
0
        private void AddBidder(SPWeb web, SPItem item, SPUser name)
        {
            var bidder = web.Lists[Constants.BidderListName].Items.Add();

            bidder["Title"]  = string.Format("{0} bid by {1} at {2}", item["Title"], name, DateTime.Now);
            bidder["Bidder"] = name;
            bidder["Item"]   = new SPFieldLookupValue(item.ID, item["Title"].ToString());
            bidder["Amount"] = _bidAmount;
            bidder.Update();
            item["Bidder"] = name;
            item.Update();
        }
Esempio n. 14
0
        public static string TryGetItemValue(this SPItem item, string staticName)
        {
            try
            {
                var data = item[staticName];
                return(data.ToString());
            }
            catch (Exception)
            {
            }

            return(null);
        }
Esempio n. 15
0
        private String retornaLinkItemLista(SPItem item)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<li class=\"exibicaoLI\">");
            sb.Append(@"   <a href=""#"" onClick=""javascript:openDialog2(' " + urlPrincipal + "/_layouts/dbs.circulares/exibecircular.aspx?id=" + item.ID + @"',1050,'Circular')"">");
            sb.Append("      " + item["LinkTitle"].ToString());
            sb.AppendLine("<br/>");
            sb.Append("      " + item["Descricao"].ToString());
            sb.AppendLine("   </a>");
            sb.AppendLine("</li>");


            return(sb.ToString());
        }
Esempio n. 16
0
        private static string FormatNumberOfBids(SPItem listItem)
        {
            var rc = "";

            if (listItem["NumberOfBids"] != null)
            {
                var items = Convert.ToInt32(listItem["NumberOfBids"]);
                rc = string.Format("{0} Bid{1}", items, items > 1 ? "s" : "");
            }
            else
            {
                rc = "0 Bids";
            }

            return rc;
        }
Esempio n. 17
0
        private void NotifyOldBidder(SPWeb web, SPItem item)
        {
            if (item["Bidder"] == null)
            {
                return;
            }
            var bidderColumn      = (SPFieldUser)item.Fields.GetField("Bidder");
            var bidder            = (SPFieldUserValue)bidderColumn.GetFieldValue(item["Bidder"].ToString());
            var mailFormatMessage = web.Lists[Constants.ConfigListName].Items[0]["AuctionOutbidItem"].ToString();
            var itemUrl           = string.Format("{0}?uicontrol=ItemDetails&ItemId={1}", UrlHelper.GetUrl(Page.Request.Url),
                                                  item.ID);

            SPUtility.SendEmail(web, true, false,
                                bidder.User.Email, "You have been outbid!",
                                string.Format(mailFormatMessage, item["Title"], item["Bid"], itemUrl, web.Url));
        }
Esempio n. 18
0
        private static string FormatNumberOfBids(SPItem listItem)
        {
            var rc = "";

            if (listItem["NumberOfBids"] != null)
            {
                var items = Convert.ToInt32(listItem["NumberOfBids"]);
                rc = string.Format("{0} Bid{1}", items, items > 1 ? "s" : "");
            }
            else
            {
                rc = "0 Bids";
            }

            return(rc);
        }
Esempio n. 19
0
        private void CompleteTask()
        {
            SPList list = SPContext.Current.Web.Lists[_listId];
            SPItem item = list.GetItemById(_itemId);

            try
            {
                item["PercentComplete"] = "100";
                item["Status"]          = "3";
                item.Update();
                UpdateLits(list);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Esempio n. 20
0
        internal static int GetMasterId(SPItem item)
        {
            int    num              = 0;
            int    eventType        = GetEventType(item);
            string stringFieldValue = SafeFieldAccessor.GetStringFieldValue(item, "ID");

            if ((eventType == 1) && !stringFieldValue.Contains <char>('.'))
            {
                return(SafeFieldAccessor.GetIntegerFieldValue(item, "ID"));
            }

            if ((eventType != 4) && (eventType != 3))
            {
                return(num);
            }

            return(SafeFieldAccessor.GetIntegerFieldValue(item, "MasterSeriesItemID"));
        }
        /// <summary>
        /// Adds the list data.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <param name="item">The item.</param>
        private void AddListData(SPList list, SPItem item)
        {
            //_rollUpData.SetRowValue("_ListTitle", list.Title);
            _rollUpData.SetRowValue("_ListTitle", list.Title);
            _rollUpData.SetRowValue("_ListUrl", list.DefaultViewUrl);
            _rollUpData.SetRowValue("_ListId", list.ID.ToString("B"));
            _rollUpData.SetRowValue("_SiteTitle", list.ParentWeb.Title);
            _rollUpData.SetRowValue("_SiteUrl", list.ParentWeb.Url);
            _rollUpData.SetRowValue("_ItemId", item.ID.ToString());

            //TODO - ver como poner las urls para el calendar

            string baseViewUrl;

            baseViewUrl = list.DefaultViewUrl.Substring(0, list.DefaultViewUrl.LastIndexOf('/'));

            _rollUpData.SetRowValue("_ItemUrl", string.Format("{0}/DispForm.aspx?ID={1}", baseViewUrl, item.ID));
            _rollUpData.SetRowValue("_ItemEdit", string.Format("{0}/EditForm.aspx?ID={1}", baseViewUrl, item.ID));
        }
Esempio n. 22
0
        // Creates document in given list (root folder).
        // Returns true if the file was created, false if it already exists
        // or throws exception for other failure
        protected bool CreateDocument(string sFilename, string sContentType, string sList)
        {
            try
            {
                SPSite site = SPContext.Current.Site;

                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists[sList];
                    // this always uses root folder
                    SPFolder         folder = web.Folders[sList];
                    SPFileCollection fcol   = folder.Files;

                    // find the template url and open
                    string sTemplate = list.ContentTypes[sContentType].DocumentTemplateUrl;
                    SPFile spf       = web.GetFile(sTemplate);
                    byte[] binFile   = spf.OpenBinary();
                    // Url for file to be created
                    string destFile = fcol.Folder.Url + "/" + sFilename;

                    // create the document and get SPFile/SPItem for
                    // new document
                    SPFile addedFile = fcol.Add(destFile, binFile, false);
                    SPItem newItem   = addedFile.Item;
                    newItem["ContentType"] = sContentType;
                    newItem.Update();
                    addedFile.Update();
                    return(true);
                }
            }
            catch (SPException spEx)
            {
                // file already exists?
                if (spEx.ErrorCode == -2130575257)
                {
                    return(false);
                }
                else
                {
                    throw spEx;
                }
            }
        }
        /// <summary>
        /// SPEduQuickStart Information Architecture Strategy
        /// </summary>
        /// <param name="oItem">List Item with each configuration for the new sub-site</param>
        /// <returns></returns>
        public static string CalculateFinalUrl(SPItem oItem)
        {
            //string url = SPContext.Current.Site.Url;  //Assert, should be root site
            string url = "/";  //Assert, should be root site

            if (!String.IsNullOrEmpty(Convert.ToString(oItem["Root"])))
                url = VirtualPathUtility.Combine(url, oItem["Root"] + "/");

            if (!String.IsNullOrEmpty(Convert.ToString(oItem["CurricularYear"])))
                url = VirtualPathUtility.Combine(url, oItem["CurricularYear"] + "/");

            if (!String.IsNullOrEmpty(Convert.ToString(oItem["Parent"])))
                url = VirtualPathUtility.Combine(url, oItem["Parent"] + "/");

            if (!String.IsNullOrEmpty(Convert.ToString(oItem["Code"])))
                url = VirtualPathUtility.Combine(url, oItem["Code"] + "/");

            return VirtualPathUtility.AppendTrailingSlash(url);
        }
        /// <summary>
        /// Gets and ensure the field data.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <returns>The field content</returns>
        private string GetFieldData(SPItem item, string fieldName)
        {
            string fieldData = string.Empty;

            if (ItemContainsFieldAndData(item, fieldName))
            {
                try
                {
                    fieldData = SPEncode.HtmlDecode(item[fieldName].ToString());
                    fieldData = ProcessFieldData(item, fieldName, fieldData);
                }
                catch (FormatException ex)
                {
                    Debug.WriteLine(fieldName);
                    Debug.WriteLine("GetFieldData " + ex);
                }
            }
            Debug.WriteLine("GetFieldData " + fieldName + "=" + fieldData);
            return(fieldData);
        }
 /// <summary>
 /// Adds the field data to the result table
 /// </summary>
 /// <param name="dataRow">The data row.</param>
 /// <param name="item">The item.</param>
 /// <param name="fieldName">Name of the field.</param>
 private void AddFieldData(DataRow dataRow, SPItem item, string fieldName)
 {
     try
     {
         if (item.Fields.ContainsField(fieldName))
         {
             dataRow[fieldName] = GetFieldData(item, fieldName);
         }
         else
         {
             dataRow[fieldName] = String.Empty;
         }
     }
     catch (ArgumentException ex)
     {
         SendError(new SPSErrorArgs(ex.TargetSite.Name,
                                    string.Format(GetResourceString("SPS_Err_FieldNotFound"), fieldName),
                                    ex));
     }
 }
        /// <summary>
        /// Adds the list data.
        /// </summary>
        /// <param name="dataRow">The data row.</param>
        /// <param name="web">The web.</param>
        /// <param name="list">The list.</param>
        /// <param name="item">The item.</param>
        private static void AddListData(DataRow dataRow, SPWeb web, SPList list, SPItem item)
        {
            dataRow["_ListTitle"] = list.Title;
            dataRow["_ListUrl"]   = list.DefaultViewUrl;
            dataRow["_ListId"]    = list.ID.ToString("B");
            dataRow["_SiteTitle"] = web.Title;
            dataRow["_SiteUrl"]   = web.Url;
            dataRow["_ItemId"]    = item.ID;

            //SPFormCollection forms = list.Forms;

            //dataRow["_ItemUrl"] = string.Format("{0}?ID={1}", forms[PAGETYPE.PAGE_DISPLAYFORM].Url, item.ID);
            //dataRow["_ItemEdit"] = string.Format("{0}?ID={1}", forms[PAGETYPE.PAGE_EDITFORM].Url, item.ID);

            //TODO - ver como poner las urls para el calendar

            string baseViewUrl;

            baseViewUrl          = list.DefaultViewUrl.Substring(0, list.DefaultViewUrl.LastIndexOf('/'));
            dataRow["_ItemUrl"]  = string.Format("{0}/DispForm.aspx?ID={1}", baseViewUrl, item.ID);
            dataRow["_ItemEdit"] = string.Format("{0}/EditForm.aspx?ID={1}", baseViewUrl, item.ID);
        }
Esempio n. 27
0
        public static void SendProcessEndConfirmationMail(string subject, string bodyHtml, SPWeb web, SPItem item)
        {
            string from = "*****@*****.**";
            string fromName = "STAFix24 Robot";
            string to = new SPFieldUserValue(web, item["Author"].ToString()).User.Email;
            string bodyText = string.Empty;

            WebClient client = new WebClient();
            NameValueCollection values = new NameValueCollection();
            values.Add("username", USERNAME);
            values.Add("api_key", API_KEY);
            values.Add("from", from);
            values.Add("from_name", fromName);
            values.Add("subject", subject);
            if (bodyHtml != null)
                values.Add("body_html", bodyHtml);
            if (bodyText != null)
                values.Add("body_text", bodyText);
            values.Add("to", to);

            byte[] response = client.UploadValues("https://api.elasticemail.com/mailer/send", values);

        }
Esempio n. 28
0
        /// <summary>
        /// Adds an item to the configuration store.
        /// </summary>
        /// <param name="title">Name of the config item to add</param>
        /// <param name="category">Category of the config item to add</param>
        /// <param name="value">Value of the config item to add</param>
        /// <param name="description">Description of the config item to add</param>
        /// <param name="overwrite">Overwrite the item if it's already present in the configuration store</param>
        public static void AddValue(string title, string category, string value, string description, bool overwrite)
        {
            SPList configStoreList = attemptGetLocalConfigStoreListFromContext() ??
                                     attemptGetGlobalConfigStoreListFromConfig();

            // Est-ce que l'item est déjà présent?
            SPQuery query = getSingleItemQuery(category, title);
            SPListItemCollection items = configStoreList.GetItems(query);

            if (items.Count > 0) // Ok y'en a plus qu'un, qu'est-ce qu'on fait?
            {
                if (overwrite)
                {
                    // Si y'en a plus qu'un, ça va mal en partant: on va tous les effacer
                    foreach (SPListItem spListItem in items)
                    {
                        configStoreList.Items.DeleteItemById(spListItem.ID);
                    }
                }
                else
                {
                    // Y'en a au moins déjà un mais on a comme instruction de rien faire.
                    return;
                }
            }

            // On ajoute l'item
            SPItem item = configStoreList.Items.Add();

            item["Title"]                 = title;
            item["ConfigCategory"]        = category;
            item["ConfigValue"]           = value;
            item["ConfigItemDescription"] = description;

            item.Update();
        }
        /// <summary>
        /// Processes the field data.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="fieldData">The field data.</param>
        /// <returns></returns>
        private string ProcessFieldData(SPItem item, string fieldName, string fieldData)
        {
            const string LOOKUP_FIELD_SEPARATOR = ";#";
            // Dates in ISO8601
            SPField field = item.Fields.GetField(fieldName);

            if (_options.UseDateISO && field.Type == SPFieldType.DateTime)
            {
                fieldData = SPUtility.CreateISO8601DateTimeFromSystemDateTime(
                    DateTime.Parse(fieldData, CultureInfo.InvariantCulture).ToUniversalTime().ToLocalTime());
            }
            else
            {
                // fix: lookup fields
                if (_options.FixLookups)
                {
                    if (fieldData.IndexOf(LOOKUP_FIELD_SEPARATOR) > 0)
                    {
                        fieldData = fieldData.Substring(fieldData.IndexOf(LOOKUP_FIELD_SEPARATOR) + 2);
                    }
                }
            }
            return(fieldData);
        }
Esempio n. 30
0
 private static SPTimeZone GetTimeZone(SPItem item, SPTimeZone localTZ)
 {
     return(localTZ);
 }
 /// <summary>
 /// Finds the parent web.
 /// </summary>
 /// <param name="oItem">The o item.</param>
 /// <returns></returns>
 public static string FindParentWeb(SPItem oItem)
 {
     return VirtualPathUtility.AppendTrailingSlash(
         VirtualPathUtility.Combine(CalculateFinalUrl(oItem), ".."));
 }
Esempio n. 32
0
 internal static int GetEventType(SPItem item)
 {
     return(SafeFieldAccessor.GetIntegerFieldValue(item, "EventType"));
 }
Esempio n. 33
0
        private static IList <SPItem> ExpandSeriesItem(SPItem masterItem, string beginFieldName, string endFieldName, DateTime localTimeRangeBegin, DateTime localTimeRangeEnd, SPTimeZone localTZ)
        {
            DateTime       time;
            DateTime       time2;
            RecurrenceRule rule                   = new RecurrenceRule(SafeFieldAccessor.GetStringFieldValue(masterItem, "RecurrenceData"));
            bool           boolFieldValue         = SafeFieldAccessor.GetBoolFieldValue(masterItem, "fAllDayEvent");
            SPTimeZone     timeZone               = GetTimeZone(masterItem, localTZ);
            DateTime       dateTimeFieldValue     = SafeFieldAccessor.GetDateTimeFieldValue(masterItem, beginFieldName);
            DateTime       rangeEnd               = SafeFieldAccessor.GetDateTimeFieldValue(masterItem, endFieldName);
            RecurrenceTimeZoneConverter converter = new RecurrenceTimeZoneConverter(timeZone, localTZ, dateTimeFieldValue, rangeEnd);

            if (boolFieldValue)
            {
                time  = dateTimeFieldValue;
                time2 = rangeEnd;
            }
            else
            {
                time  = converter.ToOriginal(dateTimeFieldValue);
                time2 = converter.ToOriginal(rangeEnd);
            }
            TimeSpan itemLength = CalculateItemLength(time, time2);
            DateTime rangeBegin = converter.ToOriginal(localTimeRangeBegin);
            DateTime time6      = converter.ToOriginal(localTimeRangeEnd);

            if (boolFieldValue)
            {
                rangeBegin = localTimeRangeBegin;
                time6      = localTimeRangeEnd;
            }
            DateTime time7 = new DateTime(dateTimeFieldValue.Ticks) + itemLength;

            if (time7.Day != dateTimeFieldValue.Day)
            {
                rangeBegin = rangeBegin.AddDays(-1.0);
            }
            rangeBegin = ComputeExpandBegin(rangeBegin, time, rule);
            time6      = ComputeExpandEnd(time6, time, time2, rule, timeZone);
            List <SPItem> list = new List <SPItem>();
            DateTime      date = rangeBegin.Date;

            while (true)
            {
                DateTime itemBegin = ComputeTargetBegin(date, time, rule);
                DateTime time10    = ComputeTargetEnd(itemBegin, itemLength);
                TimeSpan span2     = (TimeSpan)(time10 - itemBegin);
                bool     flag2     = span2.Ticks == 0L;
                if ((time6 < itemBegin) || ((time6 == itemBegin) && !flag2))
                {
                    return(list);
                }
                if (0x3e7 <= list.Count)
                {
                    return(list);
                }
                if (((rule.Type == RecurrenceRule.RecurrenceType.Daily) && rule.IsWeekday) && ((itemBegin.DayOfWeek == DayOfWeek.Saturday) || (itemBegin.DayOfWeek == DayOfWeek.Sunday)))
                {
                    date = IncrementDate(date, rule);
                }
                else if ((rule.Type == RecurrenceRule.RecurrenceType.Weekly) && !rule.DaysOfWeek.Contains(itemBegin.DayOfWeek))
                {
                    date = IncrementDate(date, rule);
                }
                else
                {
                    ExpandedCalendarItem item = null;
                    if ((rangeBegin < time10) || ((rangeBegin == time10) && (itemLength.Ticks == 0L)))
                    {
                        item = new ExpandedCalendarItem(masterItem);
                        if (boolFieldValue)
                        {
                            item[beginFieldName] = itemBegin;
                            item[endFieldName]   = time10;
                        }
                        else
                        {
                            item[beginFieldName] = converter.ToLocal(itemBegin);
                            item[endFieldName]   = converter.ToLocal(time10);
                        }
                        string str2 = GenerateRecurrenceItemId(SafeFieldAccessor.GetIntegerFieldValue(masterItem, "ID"), (DateTime)item[beginFieldName], localTZ, boolFieldValue);
                        item["ID"] = str2;
                        if (0x3e7 > list.Count)
                        {
                            list.Add(item);
                        }
                    }
                    date = IncrementDate(date, rule);
                }
            }
        }
 /// <summary>
 /// Sets the anonymous access to all authenticated.
 /// </summary>
 /// <param name="web">The web.</param>
 /// <param name="oItem">The o item.</param>
 /// <param name="user">The user.</param>
 /// <exception cref="System.Exception"></exception>
 public static void SetAnonymousAccessToAll(SPWeb web, SPItem oItem, string user)
 {
     if (web.Url == "/") return;
     switch (oItem["VisibleBy"].ToString())
     {
         //SharepointAdminsOnly
         case "AuthenticatedUsers":
             // check if it has unique permissions
             if (!web.HasUniqueRoleAssignments)
             {
                 //This method breaks the role assignment inheritance
                 //for the list item, and creates unique role assignments
                 //for the list item with the copyRoleAssignments parameter
                 //which specifies whether to copy role assignments from the
                 //parent object and with the clearSubscopes parameter which
                 //specifies whether to clear role assignments from child objects.
                 web.BreakRoleInheritance(true, false);
             }
             switch (DetectSiteLanguage(web))
             {
                 //pt-PT
                 case 2070:
                     web.Groups["Visualizadores"].Users.Add(user, null, null, null);
                     break;
                 //eng-USA
                 case 1033:
                     web.Groups["Viewers"].Users.Add(user, null, null, null);
                     break;
                 default:
                     throw new Exception("Not Supported Language!");
             }
             break;
     }
 }
        /// <summary>
        /// Sets the public access to lists.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param name="oItem">The o item.</param>
        /// <param name="lists">The lists.</param>
        public void SetPublicAccessToLists(SPWeb web, SPItem oItem, IEnumerable<string> lists)
        {
            switch (oItem["VisibleBy"].ToString())
            {
                case "Anonymous":
                    foreach (SPList list in lists.Select(item => web.Lists[item]))
                    {
                        try
                        {
                            // check if it has unique permissions
                            if (!list.HasUniqueRoleAssignments)
                            {
                                list.BreakRoleInheritance(true);
                            }

                            // make sure people can edit their own items
                            list.WriteSecurity = 2;

                            // grant permissions to anonymous users
                            list.AnonymousPermMask64 =
                                (SPBasePermissions.Open |
                                 SPBasePermissions.OpenItems |
                                 SPBasePermissions.ViewFormPages |
                                 SPBasePermissions.ViewListItems |
                                 SPBasePermissions.AddListItems);

                            list.Update();
                        }
                        catch
                        {
                            continue;
                        }

                    }
                    break;
            }
        }
        public override PickerEntity ValidateEntity(PickerEntity needsValidation)
        {
            if (needsValidation.IsResolved)
            {
                return(needsValidation);
            }

            LoadContract();

            if (!String.IsNullOrEmpty(SearchListGuid) && !String.IsNullOrEmpty(SearchColumnsGuid) &&
                !String.IsNullOrEmpty(SearchDisplayName) && !String.IsNullOrEmpty(SearchKeyName))
            {
                using (SPWeb web = SPContext.Current.Web)
                {
                    SPList             searchList    = web.TryGetList(SearchListGuid);
                    List <string>      searchColumns = new List <string>();
                    CustomPickerHelper helper        = new CustomPickerHelper();

                    if (searchList != null)
                    {
                        helper.SplitGuidColumns(SearchColumnsGuid).ForEach((i) =>
                        {
                            string column = searchList.TryGetFieldName(i);
                            if (!string.IsNullOrEmpty(column))
                            {
                                searchColumns.Add(column);
                            }
                        });

                        SPQuery query = new SPQuery();
                        query.Query      = helper.BuildWhereQuery(searchColumns, needsValidation.Key, "Eq", "Or");
                        query.ViewFields = helper.BuildViewQuery(searchColumns, SearchKeyName);
                        query.RowLimit   = 1;

                        var results = searchList.GetItems(query);

                        if (results != null && results.Count >= 1)
                        {
                            SPItem result = results[0];

                            string keyValue     = result.TryGetItemValue(SearchKeyName);
                            string displayValue = result.TryGetItemValue(SearchDisplayName);

                            if (/*!String.IsNullOrEmpty(keyValue) && */ !String.IsNullOrEmpty(displayValue))
                            {
                                needsValidation.IsResolved  = true;
                                needsValidation.Key         = needsValidation.Key;
                                needsValidation.DisplayText = displayValue;

                                needsValidation.EntityData.Clear();
                                needsValidation.EntityData.Add(needsValidation.Key, keyValue);
                            }
                        }
                    }
                    else
                    {
                        this.ErrorLabel.Text = "List " + SearchListGuid + " doesn't exists.";
                    }
                }
            }

            return(needsValidation);
        }
Esempio n. 37
0
 private static string FormatBid(SPItem listItem)
 {
     return string.Format("<div class=\"auction-item-grid-bid\">{0:c}</div>", listItem["Bid"] ?? listItem["StartingBid"]);
 }
Esempio n. 38
0
 private void NotifyOldBidder(SPWeb web, SPItem item)
 {
     if (item["Bidder"] == null) return;
     var bidderColumn = (SPFieldUser)item.Fields.GetField("Bidder");
     var bidder = (SPFieldUserValue)bidderColumn.GetFieldValue(item["Bidder"].ToString());
     var mailFormatMessage = web.Lists[Constants.ConfigListName].Items[0]["AuctionOutbidItem"].ToString();
     var itemUrl = string.Format("{0}?uicontrol=ItemDetails&ItemId={1}", UrlHelper.GetUrl(Page.Request.Url),
                                 item.ID);
     SPUtility.SendEmail(web, true, false,
                         bidder.User.Email, "You have been outbid!",
                         string.Format(mailFormatMessage, item["Title"], item["Bid"], itemUrl, web.Url));
 }
Esempio n. 39
0
 private void UpdateCurrentBidPrice(SPItem item)
 {
     item["Bid"] = _bidAmount;
 }
Esempio n. 40
0
 private static void IncrementBidCount(SPItem item)
 {
     var bids = 1;
     if (item["NumberOfBids"] != null)
     {
         bids = Convert.ToInt32(item["NumberOfBids"].ToString());
         bids++;
     }
     item["NumberOfBids"] = bids.ToString(CultureInfo.InvariantCulture);
 }
Esempio n. 41
0
 private void AddBidder(SPWeb web, SPItem item, SPUser name)
 {
     var bidder = web.Lists[Constants.BidderListName].Items.Add();
     bidder["Title"] = string.Format("{0} bid by {1} at {2}", item["Title"], name, DateTime.Now);
     bidder["Bidder"] = name;
     bidder["Item"] = new SPFieldLookupValue(item.ID, item["Title"].ToString());
     bidder["Amount"] = _bidAmount;
     bidder.Update();
     item["Bidder"] = name;
     item.Update();
 }
Esempio n. 42
0
 private void NotifyBidder(SPWeb web, SPItem item, SPUser bidder)
 {
     var mailFormatMessage = web.Lists[Constants.ConfigListName].Items[0]["AuctionItemLeadingBidder"].ToString();
     SPUtility.SendEmail(web, true, false,
                         bidder.Email, "You are the leading bidder",
                         string.Format(mailFormatMessage, _bidAmount, item["Title"], string.Format("{0}?uicontrol=ItemDetails&ItemId={1}", UrlHelper.GetUrl(Page.Request.Url), item.ID)));
 }
Esempio n. 43
0
 private static string FormatTitle(SPItem listItem)
 {
     return listItem["Subtitle"] != null ? string.Format("<div class=\"auction-item-grid-title\">{0}</div><div class=\"auction-item-grid-subtitle\">{1}</div>", listItem["Title"], listItem["Subtitle"]) : string.Format("<div class=\"auction-item-grid-title\">{0}</div>", listItem["Title"]);
 }
Esempio n. 44
0
 private static string FormatBidderName(SPItem item)
 {
     var bidderColumn = (SPFieldUser)item.Fields.GetField("Bidder");
     var bidder = (SPFieldUserValue)bidderColumn.GetFieldValue(item["Bidder"].ToString());
     return bidder.User.Name;
 }