Exemple #1
0
 public object this[PropertyDefinition propertyDefinition]
 {
     get
     {
         object obj = this.TryGetProperty(propertyDefinition);
         if (obj is PropertyError)
         {
             throw PropertyErrorException.GetExceptionFromError((PropertyError)obj);
         }
         return(obj);
     }
 }
        internal static object GetValueFromFileSystemInfo(DocumentLibraryPropertyDefinition propertyDefinition, FileSystemInfo fileSystemInfo)
        {
            FileInfo fileInfo = fileSystemInfo as FileInfo;

            switch (propertyDefinition.PropertyId)
            {
            case DocumentLibraryPropertyId.Uri:
                return(new Uri(fileSystemInfo.FullName));

            case DocumentLibraryPropertyId.CreationTime:
                return(fileSystemInfo.CreationTimeUtc);

            case DocumentLibraryPropertyId.LastModifiedTime:
                return(fileSystemInfo.LastWriteTimeUtc);

            case DocumentLibraryPropertyId.IsFolder:
                return((fileSystemInfo.Attributes & FileAttributes.Directory) != (FileAttributes)0);

            case DocumentLibraryPropertyId.IsHidden:
                return((fileSystemInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden);

            case DocumentLibraryPropertyId.Id:
                return(new UncObjectId(new Uri(fileSystemInfo.FullName), ((fileSystemInfo.Attributes & FileAttributes.Directory) != (FileAttributes)0) ? UriFlags.UncFolder : UriFlags.UncDocument));

            case DocumentLibraryPropertyId.Title:
                return(fileSystemInfo.Name);

            case DocumentLibraryPropertyId.FileSize:
                if (fileInfo != null)
                {
                    return(fileInfo.Length);
                }
                return(new PropertyError(propertyDefinition, PropertyErrorCode.NotFound));

            case DocumentLibraryPropertyId.FileType:
                if (fileInfo == null)
                {
                    return(new PropertyError(propertyDefinition, PropertyErrorCode.NotFound));
                }
                if (!string.IsNullOrEmpty(fileInfo.Extension))
                {
                    return(ExtensionToContentTypeMapper.Instance.GetContentTypeByExtension(fileInfo.Extension.Substring(1)));
                }
                return("application/octet-stream");

            case DocumentLibraryPropertyId.BaseName:
                return(fileSystemInfo.Name);
            }
            throw PropertyErrorException.GetExceptionFromError(new PropertyError(propertyDefinition, PropertyErrorCode.NotSupported));
        }
Exemple #3
0
 public object this[PropertyDefinition propDef]
 {
     get
     {
         object obj = this.TryGetProperty(propDef);
         if (obj is PropertyError)
         {
             throw PropertyErrorException.GetExceptionFromError((PropertyError)obj);
         }
         return(obj);
     }
     set
     {
         throw new NotSupportedException();
     }
 }