Beispiel #1
0
        /// <summary>
        /// Uploads a file to Fortnox Inbox from provided data array.
        /// </summary>
        /// <returns>Created file.</returns>
        public File UploadFileData(byte[] data, string name, InboxFolder inboxFolder = InboxFolder.Root)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (!System.IO.Path.HasExtension(name))
            {
                throw new ArgumentException("File name with extention must be set.", nameof(name));
            }

            Resource = BaseResource;

            var uploadedFile = base.BaseUploadFile("", GetRealValueFromAttribute(inboxFolder), data, name);

            var provider = new FileExtensionContentTypeProvider();

            provider.TryGetContentType(name, out var contentType);
            uploadedFile.ContentType = contentType;

            uploadedFile.Data = new byte[data.Length];

            data.CopyTo(uploadedFile.Data, 0);

            return(uploadedFile);
        }
Beispiel #2
0
        /// <summary>
        /// Gets at list of Files and Folders
        /// </summary>
        /// <returns>A list of Files and Folders</returns>
        public Folder Find(InboxFolder inboxFolder = InboxFolder.Root)
        {
            this.Parameters = new Dictionary <string, string>();

            if (inboxFolder == InboxFolder.Root)
            {
                if (!string.IsNullOrWhiteSpace(Path))
                {
                    this.Parameters.Add("path", this.Path);
                }

                if (!string.IsNullOrWhiteSpace(FolderId))
                {
                    base.Resource = BaseResource + "/" + FolderId;
                }
                else if (!string.IsNullOrWhiteSpace(Id))
                {
                    base.Resource = BaseResource + "/" + Id;
                }
            }
            else
            {
                base.Resource = BaseResource + "/" + GetRealValueFromAttribute(inboxFolder);
            }

            return(base.BaseFind(this.Parameters));
        }
Beispiel #3
0
        /// <summary>
        /// Uploads a file stream to Fortnox Inbox from provided data stream.
        /// </summary>
        /// <returns>Created file.</returns>
        public File UploadFileData(System.IO.Stream stream, string name, InboxFolder inboxFolder = InboxFolder.Root)
        {
            stream.Position = 0;
            var arr = new byte[stream.Length];

            stream.Read(arr, 0, (int)stream.Length);
            return(this.UploadFileData(arr, name, inboxFolder));
        }
Beispiel #4
0
        private static string GetRealValueFromAttribute(InboxFolder f)
        {
            string resource = "";

            Type type = f.GetType();

            MemberInfo[] memInfo = type.GetMember(f.ToString());
            object[]     attrs   = memInfo[0].GetCustomAttributes(typeof(RealValueAttribute), false);
            if (attrs.Length > 0)
            {
                resource = ((RealValueAttribute)attrs[0]).RealValue;
            }
            return(resource);
        }
Beispiel #5
0
        ///<summary>
        /// Uploads a file from local storage to Fortnox Inbox
        ///</summary>
        ///<param name="localPath">The local path to the file to upload</param>
        ///<param name="inboxFolder">The folder in Fortnox inbox to save the file in</param>
        ///<returns>Information of the uploaded file</returns>
        public File UploadFile(string localPath, InboxFolder inboxFolder = InboxFolder.Root)
        {
            base.Resource = BaseResource;

            return(base.BaseUploadFile(localPath, GetRealValueFromAttribute(inboxFolder)));
        }