How to get filepath of a file in Azure Service Fabric - azure

I have a project which is in an Azure Service Fabric Solution. How can I get specific full filepath of a content file? The content file is in the same folder with my source code.
What I tried:
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location
But it turns out:
C:\SfDevCluster\Data_App_Node_4\ABCXYZType_App126\ABCXYZPkg.Code.1.0.0\ABCXYZ.dll
This is a file in bin/debug folder

To get the location of content files you can use:
var path = Path.Combine(
FabricRuntime.GetActivationContext().GetCodePackageObject("Code").Path,
"Readme.txt");
ServiceEventSource.Current.ServiceMessage(this.Context, File.ReadAllText(path));
provided that the file Readme.txt has the Build Action is set to "Content" and the Copy to Output Directory setting is set to something else than "do not copy".

Related

Delete files in the drop location

I am trying to delete the folder with name "repro" and its contents in my build drop location. I have configured my delete files steps as below
Source Folder: $(BuildDropLocation)\$(BuildNumber)\CTrest\lime
Contents:
**/repro/*
repro folder resides here
$(BuildDropLocation)\$(BuildNumber)\CTrest\lime\version\package\code**repro**..
Is there something that I am missing here?
Here is the doc for the command: Delete Files task. Examples of contents:
**/temp/* deletes all files in any sub-folder named temp.
**/temp* deletes any file or folder with a name that begins with temp.
I think, **/repro* will be more suitable in your case.

Referencing Lambda Source Files in Sibling Directory using Terraform

I am attempting to deploy a Lambda function using Terraform, where my source files are in a different directory adjacent to where I have my Terraform files. I want to have Terraform do the zipping of the source files for me and deploy them into the Lambda. Terraform doesn't seem to want to recognize that my files are there, though.
My directory structure:
project_root/
deployment/
terraform/
my-terraform.tf
function_source/
function.py
I want it to package everything in function_source directory (there is only one file there now, but may be more later) and drop it into the deployment directory.
My Terraform:
data "archive_file" "lambda_zip" {
type = "zip"
output_path = "../function.zip"
source_dir = "../../function_source/"
}
resource "aws_lambda_function" "my_lambda" {
filename = "${data.archive_file.lambda_zip.output_path}"
function_name = "my-function"
role = "${aws_iam_role.lambda_role.arn}"
handler = "function.handler"
runtime = "python3.7"
}
When I run this, though, I get the error message data.archive_file.lambda_zip: data.archive_file.lambda_zip: error archiving directory: could not archive missing directory: ../../function_source/
I have tried using absolute paths without success (which wouldn't be a good solution anyway). I have also tried creating the .zip file manually and hardcoding its directly in Lambda declaration, but it only works if I put the .zip file in my terraform directory. It seems Terraform can only see files in its own directory or below, but I'd rather not co-mingle my source files there. Is there a way to do this?
I am using Terraform v0.12.4

java.io.FileNotFoundException: Resource not found: /credentials.json on Java QuickStart for Classroom API

I have implemented the Java QuickStart for the Classroom API and am getting an error message "java.io.FileNotFoundException: Resource not found: /credentials.json" at run-time. I copied my credentials.json file to the Project res directory, but continue to get this error. Any suggestions?
I tried it in a different way than I found on other websites, and it worked for me.
replace below code:
InputStream in = GoogleSheetAPIHandler.class.getClass().getResourceAsStream(CREDENTIALS_FILE_PATH);
With this code:
InputStream in = new FileInputStream(CREDENTIALS_FILE_PATH);
You need to import credential.json file into the src/main/resources folder in eclipse. You may be included in the project folder. But you need to import it into eclipse.
locate your credentials.json file in the folder.
click and drag it
drop it in src/main/resource and click ok.
After importing into eclipse it should show like the below image.
There are two steps needed to find the resource in Eclipse:
To have the file in the resources folder
Create the resource folder (if it does not exist): src/main/resouces
Add the credential file to the resource folder: src/main/resouces/credential.json
To have the resources folder in the Source Java Build Path
Go to Eclipse Path Source: Project > Properties > Java Build Path > Source (tab)
Add resources folder: Add Folder ... (button) > resources (check box) > OK (button)
https://stackoverflow.com/a/46950488/10850340
The name of your file has to be credentials only, if you have credentials.json as the name of your file in your folder you will get this error.

Creating A Folder In the Temp Folder

I'm trying to create a folder within the temp folder that doesn't have a random name.
Here is how I was trying to create the folder within the temp folder.
if not DirExists(ExpandConstant('{%tmp}\Utilities\SDK')) then
CreateDir(ExpandConstant('{%tmp}\Utilities\SDK'));
Log('Temp\Utilities\SDK Folder Has Been Created.');
I had a look at this thread, but even with the %, unfortunately, it still doesn't create the folder.The script compiles and runs as expected, however the folder doesn't create even though it says it has in the log file, I understand that the log file will say that because its told too, however, if the folder was unable to be created, wouldnt it crash? or return a false if an if statement was present?
With CreateDir() You must create dirs one after the other and not a dir structure at once.
if not DirExists(ExpandConstant('{tmp}\Utilities')) then
CreateDir(ExpandConstant('{tmp}\Utilities'));
if not DirExists(ExpandConstant('{tmp}\Utilities\SDK')) then
CreateDir(ExpandConstant('{tmp}\Utilities\SDK'));
if DirExists(ExpandConstant('{tmp}\Utilities\SDK')) then
Log('Temp\Utilities\SDK Folder Has Been Created.') else
Log('Temp\Utilities\SDK Folder ERROR : NOT Created.');
Inno Setup has a function to create a dir structure at once
function ForceDirectories(Dir: string): Boolean;
Example:
if not DirExists(ExpandConstant('{tmp}\Utilities\SDK')) then
ForceDirectories(ExpandConstant('{tmp}\Utilities\SDK'));
Also keep in mind :
{tmp} all is related to the Inno Setup Temp folder is-XXXXX.tmp
C:\Users\...\AppData\Local\Temp\is-XXXXX.tmp
{%temp} is the users Temp folder
C:\Users\...\AppData\Local\Temp
I think you want the Windows Temp and not the tmp from InnoSetup
{tmp}:
Temporary directory used by Setup or Uninstall. This is not the value of the user's TEMP environment variable. It is a subdirectory of the user's temporary directory which is created by Setup or Uninstall at startup (with a name like "C:\WINDOWS\TEMP\IS-xxxxx.tmp"). All files and subdirectories in this directory are deleted when Setup or Uninstall exits. During Setup, this is primarily useful for extracting files that are to be executed in the [Run] section but aren't needed after the installation.
So I think you want to do somethink like this:
if not DirExists(ExpandConstant('{%temp}\Utilities\SDK')) then
CreateDir(ExpandConstant('{%temp}\Utilities\SDK'));
Log('Temp\Utilities\SDK Folder Has Been Created.');

deleting existing files from temp directory in Azure

We are using the following to write a file to the temp direcotry in Azure webapp for almost a year:
string tempName = Path.GetTempFileName();
using (var tempFile = new FileStream(tempName, FileMode.Create))
{
await tempMemory.CopyToAsync(tempFile);
}
We encounter a problem of IOException of file alreay exists in the temp file.
Is there any way deleting the files from that temp directory and not from code. we do not want to apply a new code version currently, but just to somehow delete the files from the temp directory.
we tried using the azure webapp console from the portal but it didn't delete them.
Restart the WebApp, it will clear the temp directory.

Resources