コード例 #1
0
        private void ScannFileList(string[] files, string path, string extension)
        {
            if (path == "")
            {
                return;
            }

            #region processing files
            List <string> fileList = new List <string>();

            foreach (string file in files)
            {
                fileList.Add(file);
            }

            var filedetailsList = new FileDetailsList(fileList, path, extension);
            _fileDetails = filedetailsList.LoadFiles();

            labelFolders.Content = filedetailsList.DirCount.ToString();
            labelFiles.Content   = filedetailsList.FileCount.ToString();

            if (_fileDetails.Count > 0)
            {
                buttonImport.IsEnabled = true;
            }

            checkboxSampler.IsChecked    = CheckIfSampler(_fileDetails);
            datagridFilelist.ItemsSource = _fileDetails;

            #endregion

            #region processing parser tokens

            List <ParserToken> tokens     = new List <ParserToken>();
            ParserTokenList    parserlist = new ParserTokenList(path);
            tokens = parserlist.Get();

            UpdateCombos(tokens);

            #endregion
        }
コード例 #2
0
        /// <summary>
        /// Get file details list from SharePoint filtered by folder name and document type
        /// </summary>
        /// <param name="listTitle"></param>
        /// <param name="folderName"></param>
        /// <param name="documentType"></param>
        /// <returns></returns>
        public async Task <List <FileDetailsList> > GetFileDetailsListInFolder(string listTitle, string folderName, string documentType)
        {
            // return early if SharePoint is disabled.
            if (!IsValid())
            {
                return(null);
            }

            folderName = FixFoldername(folderName);

            string serverRelativeUrl = "";

            // ensure the webname has a slash.
            if (!string.IsNullOrEmpty(WebName))
            {
                serverRelativeUrl += $"{WebName}/";
            }

            serverRelativeUrl += Uri.EscapeUriString(listTitle);
            if (!string.IsNullOrEmpty(folderName))
            {
                serverRelativeUrl += "/" + Uri.EscapeUriString(folderName);
            }

            string             _responseContent = null;
            HttpRequestMessage _httpRequest     = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(ApiEndpoint + "web/getFolderByServerRelativeUrl('" + EscapeApostrophe(serverRelativeUrl) + "')/files"),
                Headers    =
                {
                    { "Accept", "application/json" }
                }
            };

            // make the request.
            var _httpResponse = await _Client.SendAsync(_httpRequest);

            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            if ((int)_statusCode != 200)
            {
                var ex = new SharePointRestException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, null);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);

                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            else
            {
                _responseContent = await _httpResponse.Content.ReadAsStringAsync();
            }

            // parse the response
            JObject responseObject = null;

            try
            {
                responseObject = JObject.Parse(_responseContent);
            }
            catch (JsonReaderException jre)
            {
                throw jre;
            }
            // get JSON response objects into a list
            List <JToken> responseResults = responseObject["value"].Children().ToList();
            // create file details list to add from response
            List <FileDetailsList> fileDetailsList = new List <FileDetailsList>();

            // create .NET objects
            foreach (JToken responseResult in responseResults)
            {
                // JToken.ToObject is a helper method that uses JsonSerializer internally
                FileDetailsList searchResult = responseResult.ToObject <FileDetailsList>();
                //filter by parameter documentType
                int fileDoctypeEnd = searchResult.Name.IndexOf("__");
                if (fileDoctypeEnd > -1)
                {
                    string fileDoctype = searchResult.Name.Substring(0, fileDoctypeEnd);
                    if (fileDoctype == documentType)
                    {
                        searchResult.DocumentType = documentType;
                    }
                }
                fileDetailsList.Add(searchResult);
            }
            fileDetailsList = fileDetailsList.Where(f => string.IsNullOrEmpty(documentType) || f.DocumentType == documentType).ToList();
            return(fileDetailsList);
        }
コード例 #3
0
        /// <summary>
        /// Get file details list from SharePoint filtered by folder name and document type
        /// </summary>
        /// <param name="listTitle"></param>
        /// <param name="folderName"></param>
        /// <param name="documentType"></param>
        /// <returns></returns>
        public async Task <List <FileDetailsList> > GetFileDetailsListInFolder(string listTitle, string folderName, string documentType)
        {
            string             serverRelativeUrl = GetServerRelativeURL(listTitle, folderName);
            string             _responseContent  = null;
            HttpRequestMessage _httpRequest      =
                new HttpRequestMessage(HttpMethod.Post, ApiEndpoint + "web/getFolderByServerRelativeUrl('" + EscapeApostrophe(serverRelativeUrl) + "')/files");
            // make the request.
            var _httpResponse = await client.SendAsync(_httpRequest);

            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            if ((int)_statusCode != 200)
            {
                var ex = new SharePointRestException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, null);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);

                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            else
            {
                _responseContent = await _httpResponse.Content.ReadAsStringAsync();
            }

            // parse the response
            // parse the response
            JObject responseObject = null;

            try
            {
                responseObject = JObject.Parse(_responseContent);
            }
            catch (JsonReaderException jre)
            {
                throw jre;
            }
            // get JSON response objects into a list
            List <JToken> responseResults = responseObject["d"]["results"].Children().ToList();
            // create file details list to add from response
            List <FileDetailsList> fileDetailsList = new List <FileDetailsList>();

            // create .NET objects
            foreach (JToken responseResult in responseResults)
            {
                // JToken.ToObject is a helper method that uses JsonSerializer internally
                FileDetailsList searchResult = responseResult.ToObject <FileDetailsList>();
                //filter by parameter documentType
                int fileDoctypeEnd = searchResult.Name.IndexOf("__");
                if (fileDoctypeEnd > -1)
                {
                    string fileDoctype = searchResult.Name.Substring(0, fileDoctypeEnd);
                    if (fileDoctype == documentType)
                    {
                        searchResult.DocumentType = documentType;
                        fileDetailsList.Add(searchResult);
                    }
                }
            }

            return(fileDetailsList);
        }
コード例 #4
0
        private void ScannFolder(string startDirectory, string filePattern)
        {
            if (startDirectory == "")
            {
                return;
            }

            #region processing files

            var filedetails = new FileDetailsList(startDirectory, filePattern);
            _fileDetails = filedetails.Load();

            labelFolders.Content = filedetails.DirCount.ToString();
            labelFiles.Content   = filedetails.FileCount.ToString();

            var size = filedetails.FileSizeAll / 1024;
            labelSize.Content = size.ToString("#,#") + " Kb";

            if (filedetails.FileSizeAll > 0)
            {
                buttonImport.IsEnabled = true;
            }

            checkboxSampler.IsChecked    = CheckIfSampler(_fileDetails);
            datagridFilelist.ItemsSource = _fileDetails;

            #endregion

            #region processing parser tokens

            List <ParserToken> tokens     = new List <ParserToken>();
            ParserTokenList    parserlist = new ParserTokenList(startDirectory);
            tokens = parserlist.Get();

            UpdateCombos(tokens);

            #endregion

            #region Fill Albums condtionaly
            var folders = Convert.ToInt32(labelFolders.Content);

            if (comboboxArtist.SelectedItem.ToString() != "NA" && folders > 0)
            {
                DirectoryInfo di      = null;
                List <string> allDirs = Helpers.GetDirectories(startDirectory, false);
                _albums.Clear();

                foreach (string dir in allDirs)
                {
                    di = new DirectoryInfo(dir);

                    if (_ignores.Contains(dir.Split('\\').Last()) != true)
                    {
                        _albums.Add(di.Name);
                    }
                    else
                    {
                        _albums.Add(di.Parent.Name);
                    }
                }
                comboboxAlbum.SelectedIndex = 0;
            }

            #endregion
        }