private void ParseFileElement(XElement fileElement, out File file, out UploadFileError error)
        {
            XAttribute errorAttribute = fileElement.Attribute(XName.Get("error"));

            file = ParseFileElement(fileElement);

            error = errorAttribute != null ? ParseUploadFileError(errorAttribute.Value) : UploadFileError.None;
        }
        private File ParseUnknownFileTypeElement(XElement fileElement)
        {
            File file = new File();

            XAttribute idAttribute = fileElement.Attribute(XName.Get("id"));
            XAttribute nameAttribute = fileElement.Attribute(XName.Get("file_name"));
            XAttribute descriptionAttribute = fileElement.Attribute(XName.Get("description"));
            XAttribute sizeAttribute = fileElement.Attribute(XName.Get("size"));
            XAttribute createdAttribute = fileElement.Attribute(XName.Get("created"));
            XAttribute updatedAttribute = fileElement.Attribute(XName.Get("updated"));
            XAttribute userIdAttribute = fileElement.Attribute(XName.Get("user_id"));
            XAttribute permissionsAttribute = fileElement.Attribute(XName.Get("permissions"));
            XAttribute sharedAttribute = fileElement.Attribute(XName.Get("shared"));
            XAttribute sha1Attribute = fileElement.Attribute(XName.Get("sha1"));
            XAttribute sharedLinkAttribute = fileElement.Attribute(XName.Get("shared_link"));
            XAttribute publicNameAttribute = fileElement.Attribute(XName.Get("public_name"));

            if (idAttribute != null)
            {
                file.ID = long.Parse(idAttribute.Value);
            }

            if (nameAttribute != null)
            {
                file.Name = nameAttribute.Value;
            }

            if (descriptionAttribute != null)
            {
                file.Description = descriptionAttribute.Value;
            }

            if (sharedAttribute != null)
            {
                file.IsShared = sharedAttribute.Value.Equals("1");
            }

            if (createdAttribute != null)
            {
                file.Created = UnixTimeConverter.Instance.FromUnixTime(double.Parse(createdAttribute.Value));
            }

            if (updatedAttribute != null)
            {
                file.Updated = UnixTimeConverter.Instance.FromUnixTime(double.Parse(updatedAttribute.Value));
            }

            if (sizeAttribute != null)
            {
                file.Size = long.Parse(sizeAttribute.Value);
            }

            if (userIdAttribute != null)
            {
                file.OwnerID = long.Parse(userIdAttribute.Value);
            }

            if (permissionsAttribute != null)
            {
                file.PermissionFlags = ParsePermissionString(permissionsAttribute.Value);
            }

            if (sha1Attribute != null)
            {
                file.SHA1Hash = sha1Attribute.Value;
            }

            if (sharedLinkAttribute != null)
            {
                file.SharedLink = sharedLinkAttribute.Value;
            }

            if (publicNameAttribute != null)
            {
                file.PublicName = publicNameAttribute.Value;
            }

            return file;
        }
Example #3
0
        /// <summary>
        /// Retrieves the details for a specified file by its ID
        /// </summary>
        /// <param name="fileID">File ID</param>
        /// <returns>Information about a file</returns>
        public GetFileInfoResponse GetFileInfo(long fileID)
        {
            SOAPFileInfo fileInfo;

            string status = _service.get_file_info(_apiKey, _token, fileID, out fileInfo);

            File file = new File
                            {
                                Created = UnixTimeConverter.Instance.FromUnixTime(fileInfo.created),
                                Description = fileInfo.description,
                                ID = fileInfo.file_id,
                                IsShared = fileInfo.shared == 1,
                                Name = fileInfo.file_name,
                                PublicName = fileInfo.public_name,
                                SHA1Hash = fileInfo.sha1,
                                Size = fileInfo.size,
                                Updated = UnixTimeConverter.Instance.FromUnixTime(fileInfo.updated)
                            };

            return new GetFileInfoResponse
                   	{
                        Status = StatusMessageParser.ParseGetFileInfoStatus(status),
                        File = file
                   	};
        }