Nagendra Panyam

Nagendra Panyam

  • NA
  • 190
  • 17.8k

hi am working with list, i had fallowing code.

Mar 29 2019 4:32 AM
i had fallowing code which i write 5 methods in 5 different classes but my senior said that please do it as single fuction and pass parameters from those 5 classes how 
fallowing 5 methods 
public bool BoxCloudFileexistCheck(string filePath, string cloudId)
{
bool results = false;
string srcname = Path.GetFileName(filePath);
CLOUDSTATUSCODE result;
result = GetAccessToken(cloudId);
var auth = new OAuthSession(BoxAuth.access_token, BoxAuth.refresh_token, 3600, "bearer");
var config = new BoxConfig(BoxClientId, BoxSecret, new Uri("http://boxsdk"));
var client = new BoxClient(config, auth);
string parentFolderId = fncheckFolderExists("ParaDoxBox");
var task3 = client.FoldersManager.GetFolderItemsAsync(parentFolderId, 500, 0);
task3.Wait();
var filelistResult = task3.Result;
var filesList = filelistResult.Entries;
foreach (var item in filesList)
{
if (item.Name == srcname)
{
results = true;
return results;
}
}
return results;
}
}
public bool oneDriveFilexist(string filePath, string cloudId)
{
bool results=false;
CLOUDSTATUSCODE status=RefreshAccessToken(cloudId);
CloudInfo cloudInfo = SystemDataLib.GetCloudInfo(cloudId);
ServiceClient = OneDriveUtility.GetClient(cloudInfo.SessionToken);
var fileName = Path.GetFileName(filePath);
var taskDriveItems = ServiceClient.Drive.Items[cloudInfo.ClientSecret].Children.Request().GetAsync();
OneDriveAuth.refresh_token = cloudInfo.SecondaryToken;
taskDriveItems.Wait();
var filesList = taskDriveItems.Result.ToList();
foreach(var item in filesList)
{
if(item.Name==fileName)
{
results = true;
return results;
}
}
return results;
}
public bool FileExistInDrive(string filePath, string cloudId)
{
bool result = false;
CloudInfo cloudInfo = SystemDataLib.GetCloudInfo(cloudId);
Service = OAuthRequest.GetDriveService(cloudInfo.SessionToken, cloudInfo.SecondaryToken, cloudInfo.ClientKey, scopes);
FilesResource.ListRequest request = Service.Files.List();
request.Q = "trashed= false";
var fileName = IO.Path.GetFileName(filePath);
List<File> filesList = GetFiles();
foreach (var item in filesList)
{
if (item.Name == fileName)
{
result = true;
return result;
}
}
return result;
}
public bool FolderExists(string filePath, string cloudId)
{
bool results = false;
string srcname = Path.GetFileName(filePath);
CloudInfo cloudInfo = SystemDataLib.GetCloudInfo(cloudId);
var token = cloudInfo.SessionToken;
DropboxClient dbClient = new DropboxClient(token);
var folders = dbClient.Files.ListFolderAsync(UploadfolderPath);
// List<string> fileNames = new List<string>();
var result = folders.Result;
var filesList = result.Entries;
// for (int i = 0; i < result.Entries.Count; i++)
// {
// fileNames.Add(result.Entries[i].Name.ToString());
// }
foreach(var item in filesList)
{
if (item.Name == srcname)
{
results = true;
return results;
}
}
//foreach (var item in fileNames)
//{
// if (item.Equals(srcname))
// {
// return true;
// }
//}
return results;
}
}
can any one please restructre above code thanq..... 

Answers (1)