示例#1
0
        public void ShouldReturnCachedList()
        {
            var          siteMock       = new ShimSPSite();
            const string TestUrl        = "test/url";
            var          listMock       = new ShimSPList();
            var          listCollection = new ShimSPListCollection {
                ItemGetGuid = _ => listMock
            };

            var webMock = new ShimSPWeb {
                ServerRelativeUrlGet = () => TestUrl, ListsGet = () => listCollection
            };

            siteMock.OpenWebGuid = guid => webMock;

            using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                var properties = new ShimSPItemEventProperties {
                    RelativeWebUrlGet = () => TestUrl
                };
                var webById = cache.GetWeb(Guid.Empty.ToString());
                var list    = SaveDataJobExecuteCache.GetList(properties);

                webById.ShouldNotBeNull();
                list.ShouldBe(listMock);
            }
        }
示例#2
0
        public void ShouldReloadListItemOnRequest()
        {
            var       webId  = Guid.NewGuid();
            var       listId = Guid.NewGuid();
            const int ItemId = 1;

            var siteMock = new ShimSPSite();

            var listItemMock = new ShimSPListItem {
                IDGet = () => ItemId
            };
            var listItemMockNew = new ShimSPListItem {
                IDGet = () => ItemId
            };
            var listItemCollection = new ShimSPListItemCollection {
                GetEnumerator = () => Enumerable.Repeat <SPListItem>(listItemMock, 1).GetEnumerator()
            };
            var listMock = new ShimSPList
            {
                GetItemsSPQuery = _ => listItemCollection, IDGet = () => listId, GetItemByIdInt32 = _ => listItemMockNew
            };
            var listCollection = new ShimSPListCollection {
                ItemGetGuid = _ => listMock
            };

            const string TestUrl = "test/url";
            var          webMock = new ShimSPWeb {
                ServerRelativeUrlGet = () => TestUrl, ListsGet = () => listCollection
            };

            siteMock.OpenWebGuid = guid => webMock;

            using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                string preloadErrors;
                var    preloadHasErrors =
                    cache.PreloadListItems(new[]
                {
                    new SaveDataJobExecuteCache.ListItemInfo
                    {
                        WebId      = webId.ToString(),
                        ListId     = listId.ToString(),
                        ListItemId = ItemId.ToString()
                    }
                }, out preloadErrors);

                preloadHasErrors.ShouldBe(false);
                preloadErrors.ShouldBe(string.Empty);

                var listItem = SaveDataJobExecuteCache.Cache.GetListItem(TestUrl, listId, ItemId, refresh: true);
                listItem.ShouldBe(listItemMockNew);

                listItem = SaveDataJobExecuteCache.Cache.GetListItem(TestUrl, listId, ItemId);
                listItem.ShouldBe(listItemMockNew);
            }
        }
示例#3
0
        public void ShouldReturnListItemFromPropertiesIfListIsNotInCache()
        {
            var       webId   = Guid.NewGuid();
            var       listId  = Guid.NewGuid();
            var       list2Id = Guid.NewGuid();
            const int ItemId  = 1;

            var siteMock = new ShimSPSite();

            var listMock = new ShimSPList
            {
                GetItemsSPQuery = _ => new ShimSPListItemCollection {
                    GetEnumerator = () => Enumerable.Empty <SPListItem>().GetEnumerator()
                },
                IDGet = () => listId
            };
            var listCollection = new ShimSPListCollection {
                ItemGetGuid = _ => listMock
            };

            const string TestUrl = "test/url";
            var          webMock = new ShimSPWeb {
                ServerRelativeUrlGet = () => TestUrl, ListsGet = () => listCollection
            };

            siteMock.OpenWebGuid = guid => webMock;

            using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                string preloadErrors;
                var    preloadHasErrors = cache.PreloadListItems(new[]
                {
                    new SaveDataJobExecuteCache.ListItemInfo
                    {
                        WebId      = webId.ToString(),
                        ListId     = listId.ToString(),
                        ListItemId = ItemId.ToString()
                    }
                }, out preloadErrors);

                preloadHasErrors.ShouldBe(false);
                preloadErrors.ShouldBe(string.Empty);

                var listItemMock = new ShimSPListItem();
                var properties   = new ShimSPItemEventProperties
                {
                    RelativeWebUrlGet = () => TestUrl,
                    ListIdGet         = () => list2Id,
                    ListItemIdGet     = () => ItemId,
                    ListItemGet       = () => listItemMock
                };
                var listItem = SaveDataJobExecuteCache.GetListItem(properties);
                listItem.ShouldBe(listItemMock);
            }
        }
示例#4
0
        public void ShouldInitializeCacheAndClearOnDispose()
        {
            var siteMock = new ShimSPSite();

            using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                cache.ShouldSatisfyAllConditions(
                    () => cache.ShouldNotBeNull(),
                    () => cache.ShouldBe(SaveDataJobExecuteCache.Cache),
                    () => cache.Site.ShouldBe(siteMock));
            }

            SaveDataJobExecuteCache.Cache.ShouldBeNull();
        }
示例#5
0
        public void ShouldNotDisposeCachedSite()
        {
            var siteMock = new ShimSPSite();
            var disposed = false;

            siteMock.Dispose = () => disposed = true;

            using (SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                SaveDataJobExecuteCache.DisposeSite(siteMock);
            }

            disposed.ShouldBe(false);
        }
示例#6
0
        public void ShouldCallCallbackIfSiteOfDifferentId()
        {
            using (SaveDataJobExecuteCache.InitializeCache(new ShimSPSite()))
            {
                var siteId   = Guid.NewGuid();
                var siteMock = new ShimSPSite {
                    IDGet = () => siteId
                };
                var site = SaveDataJobExecuteCache.GetSiteFromCache(siteId, false, () => siteMock);
                site.ShouldBe(siteMock);

                site = SaveDataJobExecuteCache.GetSiteFromCache(siteId, true, () => siteMock);
                site.ShouldBe(siteMock);
            }
        }
示例#7
0
        public void ShouldReturnOriginalSiteForNonElevated()
        {
            var siteMock = new ShimSPSite();

            using (SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                var site = SaveDataJobExecuteCache.GetSiteFromCache(Guid.Empty, false, () =>
                {
                    Assert.Fail();
                    return(null);
                });

                site.ShouldBe(siteMock);
            }
        }
示例#8
0
        public void ShouldReturnListFromPropertiesIfItIsNotFoundInCache()
        {
            var          siteMock = new ShimSPSite();
            const string TestUrl  = "test/url";
            var          listMock = new ShimSPList();

            using (SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                var properties = new ShimSPItemEventProperties {
                    RelativeWebUrlGet = () => TestUrl, ListGet = () => listMock
                };
                var list = SaveDataJobExecuteCache.GetList(properties);

                list.ShouldBe(listMock);
            }
        }
示例#9
0
        public void ShouldReturnElevatedOnRequest()
        {
            var        siteMock         = new ShimSPSite();
            ShimSPSite siteMockElevated = null;

            ShimSPSite.ConstructorGuid = (site, guid) => { siteMockElevated = new ShimSPSite(site); };
            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = cb => cb();
            using (SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                var site = SaveDataJobExecuteCache.GetSiteFromCache(Guid.Empty, true, () =>
                {
                    Assert.Fail();
                    return(null);
                });

                site.ShouldSatisfyAllConditions(
                    () => site.ShouldNotBeNull(),
                    () => site.ShouldBe(siteMockElevated),
                    () => site.ShouldNotBe(siteMock));
            }
        }
        public void execute(SPSite site, string data)
        {
            DataTable dtItems = null;
            int       userid  = 0;

            WebAppId = site.WebApplication.Id;
            using (SqlConnection cn = CreateConnection())
            {
                try
                {
                    cn.Open();
                    try
                    {
                        WorkList = site.RootWeb.Lists["My Work"];
                    }
                    catch { }

                    XmlDocument docTimesheet = new XmlDocument();
                    docTimesheet.LoadXml(data);

                    using (SqlCommand cmd = new SqlCommand("SELECT     dbo.TSUSER.USER_ID FROM         dbo.TSUSER INNER JOIN dbo.TSTIMESHEET ON dbo.TSUSER.TSUSERUID = dbo.TSTIMESHEET.TSUSER_UID WHERE TS_UID=@tsuid", cn))
                    {
                        cmd.Parameters.AddWithValue("@tsuid", base.TSUID);
                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            if (dr.Read())
                            {
                                userid = dr.GetInt32(0);
                            }
                        }
                    }

                    //bool SaveAndSubmit = false;
                    //try
                    //{
                    //    SaveAndSubmit = bool.Parse(docTimesheet.FirstChild.Attributes["SaveAndSubmit"].Value);
                    //}
                    //catch { }

                    bool liveHours = false;

                    bool.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(site.RootWeb, "EPMLiveTSLiveHours"), out liveHours);

                    if (userid != 0)
                    {
                        SPUser user = TimesheetAPI.GetUser(site.RootWeb, userid.ToString());

                        if (user.ID != userid)
                        {
                            bErrors = true;
                            sErrors = "You do not have access to edit that timesheet.";
                        }
                        else
                        {
                            using (SqlCommand cmd1 = new SqlCommand("update TSQUEUE set percentcomplete=1 where TSQUEUE_ID=@QueueUid", cn))
                            {
                                cmd1.Parameters.AddWithValue("@queueuid", QueueUid);
                                cmd1.ExecuteNonQuery();
                            }

                            TimesheetSettings settings = new TimesheetSettings(site.RootWeb);

                            DataSet dsItems = new DataSet();

                            SPUser editUser = site.RootWeb.AllUsers.GetByID(base.userid);

                            using (var cache = SaveDataJobExecuteCache.InitializeCache(site))
                            {
                                using (SqlCommand cmd2 = new SqlCommand("SELECT * FROM TSITEM WHERE TS_UID=@tsuid", cn))
                                {
                                    cmd2.Parameters.AddWithValue("@tsuid", base.TSUID);
                                    using (SqlDataAdapter da = new SqlDataAdapter(cmd2))
                                    {
                                        da.Fill(dsItems);
                                        dtItems = dsItems.Tables[0];

                                        XmlNodeList ndItems = docTimesheet.FirstChild.SelectNodes("Item");

                                        float percent = 0;
                                        float count   = 0;
                                        float total   = ndItems.Count;

                                        using (SqlCommand cmd3 = new SqlCommand("update TSQUEUE set percentcomplete=2 where TSQUEUE_ID=@QueueUid",
                                                                                cn))
                                        {
                                            cmd3.Parameters.AddWithValue("@queueuid", QueueUid);
                                            cmd3.ExecuteNonQuery();
                                        }

                                        string preloadErrors;
                                        var    preloadHasErrors =
                                            cache.PreloadListItems(ndItems.Cast <XmlNode>().Select(i => new SaveDataJobExecuteCache.ListItemInfo
                                        {
                                            WebId      = iGetAttribute(i, "WebID"),
                                            ListId     = iGetAttribute(i, "ListID"),
                                            ListItemId = iGetAttribute(i, "ItemID")
                                        }), out preloadErrors);
                                        if (preloadHasErrors)
                                        {
                                            bErrors  = true;
                                            sErrors += preloadErrors;
                                        }

                                        foreach (XmlNode ndItem in ndItems)
                                        {
                                            string worktype = "";

                                            try
                                            {
                                                worktype = ndItem.Attributes["WorkTypeField"].Value;
                                            }
                                            catch
                                            {
                                            }

                                            ProcessItemRow(ndItem, dtItems, cn, site, settings, liveHours, worktype == settings.NonWorkList);

                                            count++;
                                            float pct = count / total * 98;

                                            if (pct >= percent + 10)
                                            {
                                                using (SqlCommand cmd4 =
                                                           new SqlCommand("update TSQUEUE set percentcomplete=@pct where TSQUEUE_ID=@QueueUid", cn))
                                                {
                                                    cmd4.Parameters.AddWithValue("@queueuid", QueueUid);
                                                    cmd4.Parameters.AddWithValue("@pct", pct);
                                                    cmd4.ExecuteNonQuery();
                                                }

                                                percent = pct;
                                            }
                                        }
                                    }
                                }

                                if (liveHours)
                                {
                                    sErrors += processProjectWork(cn, TSUID.ToString(), site, true, false);
                                }
                            }
                        }
                    }
                    else
                    {
                        bErrors = true;
                        sErrors = "Timesheet does not exist";
                    }
                }
                catch (Exception ex)
                {
                    bErrors = true;
                    sErrors = "Error: " + ex.ToString();
                }
                finally
                {
                    if (dtItems != null)
                    {
                        dtItems.Dispose();
                    }
                    if (site != null)
                    {
                        site.Dispose();
                    }
                    data = null;
                }
            }
        }