Ejemplo n.º 1
0
 public void TestGetBool()
 {
     Assert.AreEqual(true, ValueUtility.GetBool("true"));
     Assert.AreEqual(true, ValueUtility.GetBool("TRUE"));
     Assert.AreEqual(false, ValueUtility.GetBool("false"));
     Assert.AreEqual(false, ValueUtility.GetBool("FALSE"));
 }
Ejemplo n.º 2
0
        int GetLastItemID(ListInfo list)
        {
            var items = GetListXml(list).SelectNodes("//Item").OfType <XmlElement>();

            return(items.Any() ? items.Max(item =>
                                           ValueUtility.GetInt(item.GetAttribute("ID"))) : 0);
        }
Ejemplo n.º 3
0
        protected override DateTime GetItemLastModified(XmlElement source)
        {
            // Last modification time of a folder is computed as the most recent last modification
            // time of any of its children walked recursively. Starting value is read from its
            // attribute which can be set by a direct operation like renaming. Last modification
            // of a file or of a common item has to be stored as an attribute of the item element
            // otherwise the creation date is returned - the item has not been modified yet.
            var modified = source.GetAttribute("Modified");
            var date     = string.IsNullOrEmpty(modified) ? GetItemCreated(source) :
                           ValueUtility.GetDate(modified);

            if (GetItemType(source) == ItemType.Folder)
            {
                var children = source.ChildNodes.OfType <XmlElement>();
                if (children.Any())
                {
                    var maximum = children.Max(item => GetItemLastModified(item));
                    if (maximum > date)
                    {
                        date = maximum;
                    }
                }
            }
            return(date);
        }
Ejemplo n.º 4
0
        protected override int GetFolderChildCount(XmlElement source)
        {
            var value = source.GetAttribute("ows_ItemChildCount");

            return(string.IsNullOrEmpty(value) ? 0 :
                   ValueUtility.GetInt(ValueUtility.GetLookupValue(value)));
        }
Ejemplo n.º 5
0
        protected override DateTime GetListLastDeleted(XmlElement source)
        {
            // Last deletion time inside a list has to be stored as an attribute otherwise an
            // invalid value is returned.
            var date = source.GetAttribute("Deleted");

            return(string.IsNullOrEmpty(date) ? DateTime.MinValue : ValueUtility.GetDate(date));
        }
Ejemplo n.º 6
0
        public void TestTryGetInt()
        {
            int result;

            Assert.IsTrue(ValueUtility.TryGetInt("12", out result));
            Assert.AreEqual(12, result);
            Assert.IsFalse(ValueUtility.TryGetInt("", out result));
            Assert.IsFalse(ValueUtility.TryGetInt("1.2", out result));
            Assert.IsFalse(ValueUtility.TryGetInt("A", out result));
        }
Ejemplo n.º 7
0
        public void TestTryGetDate()
        {
            DateTime result;

            Assert.IsTrue(ValueUtility.TryGetDate("2012-11-30", out result));
            Assert.AreEqual(new DateTime(2012, 11, 30), result);
            Assert.IsTrue(ValueUtility.TryGetDate("2012-11-30 01:02:03", out result));
            Assert.AreEqual(new DateTime(2012, 11, 30, 01, 02, 03), result);
            Assert.IsFalse(ValueUtility.TryGetDate("", out result));
            Assert.IsFalse(ValueUtility.TryGetDate("1", out result));
        }
Ejemplo n.º 8
0
        protected override string GetItemName(XmlElement source)
        {
            // Looking for the FileLeafRef should be enough. Somehow I feel better having the
            // LinkFilename checked first...
            var name = source.GetAttribute("ows_LinkFilename");

            if (!string.IsNullOrEmpty(name))
            {
                return(name);
            }
            return(ValueUtility.GetLookupValue(source.GetAttribute("ows_FileLeafRef")));
        }
Ejemplo n.º 9
0
        protected override int GetFileSize(XmlElement source)
        {
            var value = source.GetAttribute("ows_FileSizeDisplay");
            int result;

            if (!string.IsNullOrEmpty(value) && ValueUtility.TryGetInt(value, out result))
            {
                return(result);
            }
            value = source.GetAttribute("ows_File_x0020_Size");
            return(string.IsNullOrEmpty(value) ? 0 :
                   ValueUtility.GetInt(ValueUtility.GetLookupValue(value)));
        }
Ejemplo n.º 10
0
        DateTime GetListDate(XmlElement source, string name)
        {
            // List Properties Created and Modified come in the format YYYYMMDD HH:MM:SS. Other
            // properties with a date value come in the format YYYY-MM-DD HH:MM:SS which is
            // acceptable for the DateTime.Parse() method. Let's ensure the latter format.
            var value = source.GetAttribute(name);

            if (!value.Contains('-'))
            {
                value = value.Insert(6, "-").Insert(4, "-");
            }
            return(ValueUtility.GetDate(value));
        }
Ejemplo n.º 11
0
 public void TestGetDate()
 {
     Assert.AreEqual(new DateTime(2012, 11, 30), ValueUtility.GetDate("2012-11-30"));
     Assert.AreEqual(new DateTime(2012, 11, 30, 01, 02, 03),
                     ValueUtility.GetDate("2012-11-30 01:02:03"));
     try {
         ValueUtility.GetDate("");
         Assert.Fail();
     } catch {}
     try {
         ValueUtility.GetDate("1");
         Assert.Fail();
     } catch {}
 }
Ejemplo n.º 12
0
        protected override DateTime GetListLastModified(XmlElement source)
        {
            // Last modification time of a list is computed as the most recent last modification
            // time of any of its child items. More recent of the times of creation and last
            // deletion are used as starting values.
            var date     = ValueUtility.Max(GetListCreated(source), GetListLastDeleted(source));
            var children = source.ChildNodes.OfType <XmlElement>();

            if (!children.Any())
            {
                return(date);
            }
            return(ValueUtility.Max(date, children.Max(item => GetItemLastModified(item))));
        }
Ejemplo n.º 13
0
        protected override IEnumerable <FieldInfo> GetListFields(XmlElement source)
        {
            // Extract the field list from /List/Fields. Avoiding XPath with namespaces.
            var fields = source.ChildNodes.OfType <XmlElement>().FirstOrDefault(
                entry => entry.LocalName == "Fields");

            return(fields == null ? null : fields.ChildNodes.OfType <XmlElement>().Select(
                       field => new FieldInfo {
                Name = field.GetAttribute("Name"),
                Title = field.GetAttribute("Title"),
                Hidden = ValueUtility.GetBool(field.GetAttribute("Hidden")),
                ReadOnly = ValueUtility.GetBool(field.GetAttribute("ReadOnly"))
            }));
        }
Ejemplo n.º 14
0
        DateTime GetItemDate(XmlElement source, string rawName, string displayName)
        {
            var date = source.GetAttribute(rawName);

            if (!string.IsNullOrEmpty(date))
            {
                return(ValueUtility.GetDate(date));
            }
            date = source.GetAttribute(displayName);
            if (!string.IsNullOrEmpty(date))
            {
                return(ValueUtility.GetDate(ValueUtility.GetLookupValue(date)));
            }
            return(DateTime.MinValue);
        }
Ejemplo n.º 15
0
        string GetNextVersionNumber(XmlElement target)
        {
            // File can contain only versions - Version elements - no need for XPath here.
            // If the last version is deleted its number is "recycled" later for a new version.
            // The XPath computed is max(Version/@Number).
            var last = target.ChildNodes.OfType <XmlElement>().LastOrDefault();

            if (last == null)
            {
                return("1");
            }
            var next = ValueUtility.GetInt(last.GetAttribute("Number")) + 1;

            return(next.ToStringI());
        }
Ejemplo n.º 16
0
 public void TestGetInt()
 {
     Assert.AreEqual(12, ValueUtility.GetInt("12"));
     try {
         ValueUtility.GetInt("");
         Assert.Fail();
     } catch {}
     try {
         ValueUtility.GetInt("1.2");
         Assert.Fail();
     } catch {}
     try {
         ValueUtility.GetInt("A");
         Assert.Fail();
     } catch {}
 }
Ejemplo n.º 17
0
 protected override Guid GetItemUniqueID(XmlElement source)
 {
     return(new Guid(ValueUtility.GetLookupValue(source.GetAttribute("ows_UniqueId"))));
 }
Ejemplo n.º 18
0
 public void TestGetLookupValue()
 {
     Assert.AreEqual("value", ValueUtility.GetLookupValue("1;#value"));
     Assert.AreEqual("", ValueUtility.GetLookupValue("1;#"));
     Assert.AreEqual("value", ValueUtility.GetLookupValue("value"));
 }
Ejemplo n.º 19
0
 protected override DateTime GetItemCreated(XmlElement source)
 {
     return(ValueUtility.GetDate(source.GetAttribute("Created")));
 }
Ejemplo n.º 20
0
 protected override int GetItemID(XmlElement source)
 {
     return(ValueUtility.GetInt(source.GetAttribute("ID")));
 }
Ejemplo n.º 21
0
        protected override int GetListItemCount(XmlElement source)
        {
            var value = source.GetAttribute("ItemCount");

            return(string.IsNullOrEmpty(value) ? 0 : ValueUtility.GetInt(value));
        }