Equivalent method to fetchCompleteState in RTC java plain api - version-control

Is there any equivalent method for fetchCompleteState on versionableManager to fetch data of historic files? I'm having troubles with retrieving file name of file added in previous changelists. Here is example:
Changelist 1:
add file: src/newFile.java
Changelist 2:
modify file: src/newFile.java
Changelist 3:
rename file: src/newFile.java -> src/newFile_rename.java
And now when I'm trying to get file name or file path of file in changelist 1 using following code:
// change is IChange, versionableManager is IVersionableManager
// method getFilePath retrieve file path using ancestors
file = versionableManager.fetchCompleteState(change.afterState(), monitor);
if (file instanceof IFolder) {
IFolder folder = (IFolder) file;
relativePath = getFilePath(file, workspaceConnection.configuration(changeSet.getComponent()), monitor);
fileName = folder.getName();
} else {
relativePath = getFilePath(file, workspaceConnection.configuration(changeSet.getComponent()), monitor);
fileName = ((FileItem) file).getName();
}
I'm getting name and path of renamed file. How to get it's old name and path?

Ok found the solution:
IFileItemHandle fileItemHandle = (IFileItemHandle) IFileItem.ITEM_TYPE.createItemHandle(change.afterState().getItemId(), change.afterState().getStateId());
file = versionableManager.fetchCompleteState(fileItemHandle, monitor);
if (file instanceof IFolder) {
IFolder folder = (IFolder) file;
relativePath = getFilePath(file, workspaceConnection.configuration(changeSet.getComponent()), monitor);
fileName = folder.getName();
} else {
relativePath = getFilePath(file, workspaceConnection.configuration(changeSet.getComponent()), monitor);
fileName = ((FileItem) file).getName();
}
But still having isses with resolving file path. Anyways this is a big step.

Related

Flutter How to get all files from assets folder in one List

I have a bunch of xml files in assets folder, I add path to pubspec.yaml and path looks like this 'assets/data/somename.xml' I need to get data from them and this is the way how i got it now
List filePathList = ['assets/data/widow.xml','assets/data/door.xml'];
for(int i = 0;i<filePathList.length;i++){
var xmlFile = XmlDocument.parse(await rootBundle.loadString(filePathList[i]));
checkListtemplateXmlList.add(xmlFile);
}
How you can see i use realy bad way to take data from files,
there will be many more xml files in the future so i need some solution to this problem to not add path in filePathList for every file in assets folder.
Also i made a loadData function that load all files like i want, but my json files are in directory that i got with using getApplicationDocumentDirectory class. There is a code
static Future<void> loadData() async {
final dir = await getApplicationDocumentsDirectory();
List<FileSystemEntity> files = await dir.list().toList();
for (int i = 0; i < files.length; i++) {
String filepath = files[i].path;
File newFile = File(filepath);
String name = p.basenameWithoutExtension(newFile.path);
String myExtension = p.extension(filepath);
if(myExtension != '.json'){
} else{
checkLists.add(CheckList(name));
}
}
for(int i = 0;i< checkLists.length;i++){
await checkLists[i].readFile();
}
}
how i can do something like this in my getXmlData function
Inside the pubspec define only the folder:
assets:
- assets/data/
This will "load" all files inside the data folder.
And using this code:
// This will give a list of all files inside the `assets`.
var assets = await rootBundle.loadString('AssetManifest.json');
And use a filter to get all xml files.
Map json = json.decode(assets);
List get = json.keys.where((element) => element.endsWith(".xml")).toList();

How to set the path of the file writer to location of the jar using it?

So i recently switch from starting the jar file from a service rather than a script that first goes to the relevant directory. Is there a way to make sure that the path to the jar file is used instead of wherever the service started it? Inside the application i use the code below to get the correct path.
try {
Path p = Path.of(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
workPath = p.getParent().toString();
if( workPath.matches(".*[lib]")) { // Meaning used as a lib
workPath = Path.of(workPath).getParent().toString();
}
settingsFile = Path.of(workPath, "settings.xml");
} catch (URISyntaxException e) {
Logger.error(e);
}
Store your work path as system property:
try {
Path p = Path.of(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
workPath = p.getParent().toString();
if(workPath.matches(".*[lib]")) { // Meaning used as a lib
workPath = Path.of(workPath).getParent().toString();
}
System.setProperty("tinylog.directory", workPath); // Set work path as system property
settingsFile = Path.of(workPath, "settings.xml");
} catch (URISyntaxException e) {
Logger.error(e);
}
Use the system property in tinylog.properties:
writer = file
writer.file = #{tinylog.directory}/log.txt
writer.format = {date: HH:mm:ss.SSS} {level}: {message}

Take all text files in a folder and combine then into 1

I'm trying to merge all my text files into one file.
The problem I am having is that the file names are based on data previously captured in my app. I don't know how to define my path to where the text files are, maybe. I keep getting a error, but the path to the files are correct.
What am I missing?
string filesread = System.AppDomain.CurrentDomain.BaseDirectory + #"\data\Customers\" + CustComboB.SelectedItem + #"\";
Directory.GetFiles(filesread);
using (var output = File.Create("allfiles.txt"))
{
foreach (var file in new[] { filesread })
{
using (var input = File.OpenRead(file))
{
input.CopyTo(output);
}
}
}
System.Diagnostics.Process.Start("allfiles.txt");
my error:
System.IO.DirectoryNotFoundException
HResult=0x80070003
Message=Could not find a part of the path 'C:\Users\simeo\source\repos\UpMarker\UpMarker\bin\Debug\data\Customers\13Dec2018\'.
I cant post a pic, but let me try and give some more details on my form.
I select a combobox item, this item is a directory. then I have a listbox that displays the files in my directory. I then have a button that executes my desires of combining the files. thanks
I finally got it working.
string path = #"data\Customers\" + CustComboB.SelectedItem;
string topath = #"data\Customers\";
string files = "*.txt";
string[] txtFiles;
txtFiles = Directory.GetFiles(path, files);
using (StreamWriter writer = new StreamWriter(topath + #"\allfiles.txt"))
{
for (int i = 0; i < txtFiles.Length; i++)
{
using (StreamReader reader = File.OpenText(txtFiles[i]))
{
writer.Write(reader.ReadToEnd());
}
}
System.Diagnostics.Process.Start(topath + #"\allfiles.txt");
}

Google script: Download web image and save it in a specific drive folder

I need to download an image with GS and save it in a specific drive folder.
I'm able to save the image in the root folder but i cannot save it in a specific folder:
function downloadFile(fileURL,folder) {
var fileName = "";
var fileSize = 0;
var response = UrlFetchApp.fetch(fileURL, {muteHttpExceptions: true});
var rc = response.getResponseCode();
if (rc == 200) {
var fileBlob = response.getBlob()
var folder = DriveApp.getFoldersByName(folder);
if (folder != null) {
var file = DriveApp.createFile(fileBlob);
fileName = file.getName();
fileSize = file.getSize();
}
}
var fileInfo = { "rc":rc, "fileName":fileName, "fileSize":fileSize };
return fileInfo;
}
Question: what have I to add to use the variable "folder"?
I found a lot of examples with "DocList" Class that is not in use anymore
Many thanks
Well, I guess GAS has make a lot of progress on developing its API, the function
createFile(blob) of an object Folder will do the job:
https://developers.google.com/apps-script/reference/drive/folder#createfileblob
// Create an image file in Google Drive using the Maps service.
var blob = Maps.newStaticMap().setCenter('76 9th Avenue, New York NY').getBlob();
DriveApp.getRootFolder().createFile(blob);
It's quite late for the answer but just incase some one runs into the situation.
Are you familiar with this app? It does exactly what you're asking for.
However, if you want to re-create this for your own purposes, I would change your declaration of variable file to read as such:
var file = folder.next().createFile(fileBlob);
when you create your variable folder, the method you use creates a FolderIterator, not a single folder. You have to call the next() method to get a Folder object.
To be precise with your script and avoid saving to an incorrect-but-similarly-named folder, I would recommend passing the folder ID to your script rather than the folder Name. If you pass the folder ID, you could declare folder as:
var folder = DriveApp.getFolderById(folder);
and then continue the script as you have it written. I hope that helps.
Working on similar problem, I came up with the solution below to save a file to a folder. If the folder doesn't exist it creates it, otherwise it saves the file specified by "FOLDER_NAME"
var folderExists = checkFolderExists("FOLDER_NAME");
if (folderExists) {
saveFolder = DriveApp.getFolderById(folderExists);
} else {
saveFolder = DriveApp.createFolder("FOLDER_NAME");
}
// Make a copy of the file in the root drive.
var file = DriveApp.getFileById(sheetID);
// Take the copy of the file created above and move it into the folder:
var newFile = DriveApp.getFolderById(saveFolder.getId()).addFile(file);
// Remove the copy of the file in the root drive.
var docfile = file.getParents().next().removeFile(file);
Further to Eric's answer, I have also provided a utility function that checks if the folder exists. It's reusable in any project.
function checkFolderExists(fName) {
try {
var folderId;
var folders = DriveApp.getFolders();
while (folders.hasNext()) {
var folder = folders.next();
folderName = folder.getName();
if (folderName == fName) {
folderId = folder.getId();
}
}
} catch(e) {
log("Services::checkFolderExists()" + e.toString());
throw e;
}
return folderId;
}

Creating a NuGet package programmatically

I am trying to create a basic NuGet package programmatically using Nuget.core API.
Firstly I populate Metadata and Files field of NuSpec manifest file:
Manifest nuspec = new Manifest(); //creating a nuspec
ManifestMetadata metaDataLocal = new ManifestMetadata()
{
Authors = "mauvo",
Version = "1.0.0.0",
Id = "myPackageIdentifier",
Description = "A description",
};
nuspec.Metadata = metaDataLocal; //populating nuspec's metadata
ManifestFile mf = new ManifestFile();
mf.Source = "bin\\Debug\\DX11VideoRenderer.dll";
mf.Target = "lib";
List<ManifestFile> listManifestFile = new List<ManifestFile>();
listManifestFile.Add(mf);
nuspec.Files = listManifestFile; //populating nuspec's Files field
Then I use package builder class to create the package and save it to the debug folder of my project:
PackageBuilder builder = new PackageBuilder()
{
Id = "1",
Description = "Some test package"
};
builder.Populate(nuspec.Metadata);
foreach (ManifestFile value in nuspec.Files)
{
builder.PopulateFiles(value.Target, nuspec.Files);
builder.Files.Add(new PhysicalPackageFile()
{
SourcePath = value.Target,
TargetPath = #"lib\"
});
}
using (FileStream stream = File.Open("bin\\Debug", FileMode.OpenOrCreate))
{
builder.Save(stream);
}
I have hardcoded all the source paths, destination path, package info and metadata. But for some reason the package is not being created. Code runs without any errors.
I would guess it is probably being saved, but the file's name is Debug rather than x.nupkg.
using (FileStream stream = File.Open("bin\\Debug", FileMode.OpenOrCreate))
{ ^^^^^^^^^^^^
builder.Save(stream);
}