Esempio n. 1
0
        /// <summary>
        /// Get a list of files ordered by name (structure ResInfo._Embedded), a flat list of all files in the Drive in alphabetical order.
        /// </summary>
        /// <param name="limit">Maximum number of output resources, default 20</param>
        /// <param name="media_type">An array of file types to include in the list. Example 'new Media_type [] {Media_type.Unknown, Media_type.Text}'</param>
        /// <param name="sort">A field for sorting the nested resources. Example 'SortField.Size' sort by file size</param>
        /// <param name="fields">An array of return fields. Example 'new ResFields [] {ResFields.Name, ResFields.Type, ResFields.Size}'</param>
        /// <param name="offset">Offset from the beginning of the list of nested resources.</param>
        /// <param name="preview_crop">Allow trimming the preview.</param>
        /// <param name="preview_size">The size of the preview. Example "120x240"</param>
        /// <returns>The return value of the ResInfo._Embedded structure</returns>
        public ResInfo GetResourceByName(int?limit  = null, Media_type[] media_type = null, SortField?sort      = null, ResFields[] fields = null,
                                         int?offset = null, bool?preview_crop       = null, string preview_size = null)
        {
            string  content;
            ResInfo resInfo = new ResInfo();
            Param   param   = new Param();

            if (media_type != null)
            {
                foreach (Media_type i in media_type)
                {
                    param.Media_type += i + ",";
                }
                param.Media_type = param.Media_type.Remove(param.Media_type.Length - 1);
            }

            param.Limit = limit;

            if (sort != null)
            {
                param.Sort = Enum.GetName(typeof(SortField), sort);
            }

            if (fields != null)
            {
                foreach (ResFields i in fields)
                {
                    if (i != ResFields._Embedded)
                    {
                        param.Fields += "items." + i + ",";
                    }
                }
                param.Fields = param.Fields.Remove(param.Fields.Length - 1);
            }

            param.Offset       = offset;
            param.Preview_crop = preview_crop;
            param.Preview_size = preview_size;

            content = CommandDisk(Oauth, YandexDiskAsk.Get_list_files_order_by_name, param);

            if (content != null)
            {
                resInfo = ResInfo.GetResInfo(content, true);
            }

            return(resInfo);
        }
Esempio n. 2
0
        /// <summary>
        /// Get meta information about file or folder, dy default get meta information root disk
        /// </summary>
        /// <param name="limit">Maximum number of output resources, default 20</param>
        /// <param name="path">Path to resource. Required value in Url - format. Example 'old/new/good.txt'</param>
        /// <param name="sort">A field for sorting the nested resources. The example 'SortField.Created' is sorted by the date of creation of the resource</param>
        /// <param name="fields">An array of return fields. Example 'new ResFields [] {ResFields.Name, ResFields.Type, ResFields.Size}'</param>
        /// <param name="offset">Offset from the beginning of the list of nested resources.</param>
        /// <param name="preview_crop">Allow trimming the preview.</param>
        /// <param name="preview_size">The size of the preview. Example "120x240"</param>
        /// <returns>The return value of the ResInfo structure</returns>
        public ResInfo GetResInfo(int?limit  = null, string path       = null, SortField?sort      = null, ResFields[] fields = null,
                                  int?offset = null, bool?preview_crop = null, string preview_size = null)
        {
            string  content;
            ResInfo resInfo = new ResInfo();
            Param   param   = new Param();

            param.Path  = path;
            param.Limit = limit;

            if (sort != null)
            {
                param.Sort = Enum.GetName(typeof(SortField), sort);
            }

            if (fields != null)
            {
                foreach (ResFields i in fields)
                {
                    if (i != ResFields._Embedded)
                    {
                        param.Fields += i + "," + "_embedded.items." + i + ",";
                    }
                }
                param.Fields = param.Fields.Remove(param.Fields.Length - 1);
            }

            param.Offset       = offset;
            param.Preview_crop = preview_crop;
            param.Preview_size = preview_size;

            content = CommandDisk(Oauth, YandexDiskAsk.Get_meta_information_about_file_or_folder, param);

            if (content != null)
            {
                resInfo = ResInfo.GetResInfo(content);
            }

            return(resInfo);
        }
Esempio n. 3
0
        /// <summary>
        /// Get the list of published resources (structure ResInfo._Embedded), a flat list of all the list of published resources in the User's disk.
        /// </summary>
        /// <param name="limit">Maximum number of output resources, default 20</param>
        /// <param name="type">The type of resource to include in the list. Example 'TypeRes.Dir', folders only</param>
        /// <param name="fields">An array of return fields. Example 'new ResFields [] {ResFields.Name, ResFields.Type, ResFields.Size}'</param>
        /// <param name="offset">Offset from the beginning of the list of nested resources.</param>
        /// <param name="preview_crop">Allow trimming the preview.</param>
        /// <param name="preview_size">The size of the preview. Example "120x240"</param>
        /// <returns>The return value of the ResInfo._Embedded structure</returns>
        public ResInfo GetResourcePublic(int?limit = null, TypeRes?type = null, ResFields[] fields = null, int?offset = null, bool?preview_crop = null, string preview_size = null)
        {
            string  content;
            ResInfo resInfo = new ResInfo();
            Param   param   = new Param();

            if (type != null)
            {
                param.Type = Enum.GetName(typeof(TypeRes), type);
            }

            param.Limit = limit;

            if (fields != null)
            {
                foreach (ResFields i in fields)
                {
                    if (i != ResFields._Embedded)
                    {
                        param.Fields += "items." + i + ",";
                    }
                }
                param.Fields = param.Fields.Remove(param.Fields.Length - 1);
            }

            param.Offset       = offset;
            param.Preview_crop = preview_crop;
            param.Preview_size = preview_size;

            content = CommandDisk(Oauth, YandexDiskAsk.Get_list_public_resources, param);

            if (content != null)
            {
                resInfo = ResInfo.GetResInfo(content, true);
            }

            return(resInfo);
        }
Esempio n. 4
0
        /// <summary>
        /// Create meta information about a file or directory
        /// </summary>
        /// <param name="content">Json string</param>
        /// <param name="onlyFiles">Request only for files</param>
        /// <returns></returns>
        public static ResInfo GetResInfo(string content, bool onlyFiles = false)
        {
            string         node;
            ResInfo        resInfo       = new ResInfo();
            ResInfoList    resInfoList   = new ResInfoList();
            List <ResInfo> items         = new List <ResInfo>();
            ErrorResponse  errorResponse = new ErrorResponse();
            JArray         nodes         = new JArray();

            JToken            root;
            Exif              exif;
            Custom_properties custom_properties;
            ShareInfo         shareInfo;
            CommentIds        commentIds;

            if (content != null)
            {
                JObject json = JObject.Parse(content);

                exif = new Exif();
                custom_properties = new Custom_properties();
                shareInfo         = new ShareInfo();
                commentIds        = new CommentIds();

                resInfo.Antivirus_status    = (string)json.SelectToken("antivirus_status");
                resInfo.Public_key          = (string)json.SelectToken("public_key");
                resInfo.Sha256              = (string)json.SelectToken("sha256");
                resInfo.Name                = (string)json.SelectToken("name");
                exif.Date_time              = (string)json.SelectToken("exif.date_time");
                resInfo.Exif                = exif;
                resInfo.Resource_id         = (string)json.SelectToken("resource_id");
                resInfo.Custom_properties   = custom_properties;
                resInfo.Public_url          = (string)json.SelectToken("public_url");
                shareInfo.Is_root           = (bool?)json.SelectToken("share.is_root");
                shareInfo.Is_owned          = (bool?)json.SelectToken("share.is_owned");
                shareInfo.Rights            = (string)json.SelectToken("share.rights");
                resInfo.ShareInfo           = shareInfo;
                resInfo.Modified            = (string)json.SelectToken("modified");
                resInfo.Created             = (string)json.SelectToken("created");
                commentIds.Private_resource = (string)json.SelectToken("comment_ids.private_resource");
                commentIds.Public_resource  = (string)json.SelectToken("comment_ids.public_resource");
                resInfo.CommentIds          = commentIds;
                resInfo.Md5        = (string)json.SelectToken("md5");
                resInfo.Size       = (long?)json.SelectToken("size");
                resInfo.Media_type = (string)json.SelectToken("media_type");
                resInfo.Path       = (string)json.SelectToken("path");
                resInfo.Preview    = (string)json.SelectToken("preview");
                node = (string)json.SelectToken("type");
                if (node != null)
                {
                    foreach (var s in Enum.GetNames(typeof(TypeRes)))
                    {
                        if (string.Equals(node, s, StringComparison.OrdinalIgnoreCase))
                        {
                            resInfo.Type = (TypeRes)Enum.Parse(typeof(TypeRes), s, true);
                            break;
                        }
                    }
                }
                resInfo.Mime_type = (string)json.SelectToken("mime_type");
                resInfo.Revision  = (long?)json.SelectToken("revision");

                if (onlyFiles)
                {
                    root = json.SelectToken("items");
                }
                else
                {
                    root = json.SelectToken("_embedded.items");
                }

                if (root != null)
                {
                    nodes = JArray.FromObject(root);
                }
                if (nodes.Count != 0)
                {
                    foreach (JToken token in nodes)
                    {
                        ResInfo item = new ResInfo();

                        exif = new Exif();
                        custom_properties = new Custom_properties();
                        shareInfo         = new ShareInfo();
                        commentIds        = new CommentIds();

                        item.Antivirus_status       = (string)token.SelectToken("antivirus_status");
                        item.Public_key             = (string)token.SelectToken("public_key");
                        item.Sha256                 = (string)token.SelectToken("sha256");
                        item.Name                   = (string)token.SelectToken("name");
                        exif.Date_time              = (string)token.SelectToken("exif.date_time");
                        item.Exif                   = exif;
                        item.Resource_id            = (string)token.SelectToken("resource_id");
                        item.Custom_properties      = custom_properties;
                        item.Public_url             = (string)token.SelectToken("public_url");
                        shareInfo.Is_root           = (bool?)token.SelectToken("share.is_root");
                        shareInfo.Is_owned          = (bool?)token.SelectToken("share.is_owned");
                        shareInfo.Rights            = (string)token.SelectToken("share.rights");
                        item.ShareInfo              = shareInfo;
                        item.Modified               = (string)token.SelectToken("modified");
                        item.Created                = (string)token.SelectToken("created");
                        commentIds.Private_resource = (string)token.SelectToken("comment_ids.private_resource");
                        commentIds.Public_resource  = (string)token.SelectToken("comment_ids.public_resource");
                        item.CommentIds             = commentIds;
                        item.Md5        = (string)token.SelectToken("md5");
                        item.Size       = (long?)token.SelectToken("size");
                        item.Media_type = (string)token.SelectToken("media_type");
                        item.Path       = (string)token.SelectToken("path");
                        item.Preview    = (string)token.SelectToken("preview");
                        node            = (string)token.SelectToken("type");
                        if (node != null)
                        {
                            foreach (var s in Enum.GetNames(typeof(TypeRes)))
                            {
                                if (string.Equals(node, s, StringComparison.OrdinalIgnoreCase))
                                {
                                    item.Type = (TypeRes)Enum.Parse(typeof(TypeRes), s, true);
                                    break;
                                }
                            }
                        }
                        item.Mime_type = (string)token.SelectToken("mime_type");
                        item.Revision  = (long?)token.SelectToken("revision");

                        items.Add(item);
                    }

                    resInfoList.Sort   = (string)json.SelectToken("_embedded.sort");
                    resInfoList.Limit  = (int?)json.SelectToken("_embedded.limit");
                    resInfoList.Offset = (int?)json.SelectToken("_embedded.offset");
                    resInfoList.Path   = (string)json.SelectToken("_embedded.path");
                    resInfoList.Total  = (int?)json.SelectToken("_embedded.total");
                }
                resInfoList.Items     = items;
                resInfo._Embedded     = resInfoList;
                resInfo.ErrorResponse = errorResponse.GetError(content);
            }
            return(resInfo);
        }