Пример #1
0
        public static IItemNode GetListFileFolder(IItemNode node, bool folderonly = false, bool read_only = false)
        {
            bool     uri       = false;
            RootNode root      = node.GetRoot;
            string   Email     = root.RootType.Email;
            string   parent_ID = null;
            string   url       = null;
            Regex    rg;
            Match    match;

            if (string.IsNullOrEmpty(Email))
            {
                Email = AppSetting.settings.GetDefaultCloud(CloudType.GoogleDrive); uri = true;
            }

            #region Get parent_ID
            if (uri)//folder url
            {
                if (root.RootType.uri != null)
                {
                    url   = root.RootType.uri.ToString();
                    rg    = new Regex(Rg_url_idFolder);
                    match = rg.Match(url);
                    if (match.Success)
                    {
                        parent_ID = match.Value;
                    }
                    else
                    {
                        rg    = new Regex(Rg_url_idFolderOpen);
                        match = rg.Match(url);
                        if (match.Success)
                        {
                            parent_ID = match.Value;
                        }
                    }
                }
            }
            else//explorer node
            {
                parent_ID = "root";//root
                if (!string.IsNullOrEmpty(node.Info.ID))
                {
                    parent_ID = node.Info.ID;                             //id root or id node
                }
            }
            #endregion

            #region Get Child Node Data
            if (!string.IsNullOrEmpty(parent_ID))//if found id is folder
            {
                List <Drivev2_File> list_ = Search("'" + parent_ID + "' in parents and trashed=false", Email);
                if (parent_ID == "root")//save root id
                {
                    foreach (Drivev2_File item in list_)
                    {
                        foreach (Drivev2_Parent parent in item.parents)
                        {
                            if (parent.isRoot ?? false)
                            {
                                parent_ID = parent.id; break;
                            }
                        }
                        if (parent_ID != "root")
                        {
                            break;
                        }
                    }
                    node.Info.ID = parent_ID;
                    AppSetting.settings.SetRootID(Email, CloudType.GoogleDrive, parent_ID);
                }
                node.RenewChilds(list_.Convert(node));
                return(node);
            }
            else if (string.IsNullOrEmpty(url))//if id from url
            {
                rg    = new Regex(Rg_url_idFile);
                match = rg.Match(url);
                if (match.Success)
                {
                    RootNode n = new RootNode();
                    n.Info.ID        = match.Value;
                    n.RootType.Email = Email;
                    Drivev2_File item = GoogleDrive.GetMetadataItem(n);
                    n.Info.Size     = item.fileSize ?? -1;
                    n.Info.Name     = item.title;
                    n.Info.MimeType = item.mimeType;
                    AppSetting.UIMain.FileSaveDialog(PCPath.Mycomputer, item.title, PCPath.FilterAllFiles, n);
                    return(null);
                }
            }
            #endregion

            throw new Exception("Can't Analyze Data Input.");
        }