public ActionResult Create(Product p, HttpPostedFileBase file) { //upload image related to product on the bucket try { if (file != null) { #region Uploading file on Cloud Storage var storage = StorageClient.Create(); string link = ""; using (var f = file.InputStream) { var filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var storageObject = storage.UploadObject("pfcbrandonbucket", filename, null, f); link = "https://storage.cloud.google.com/pfcbrandonbucket/" + filename; if (null == storageObject.Acl) { storageObject.Acl = new List <ObjectAccessControl>(); } storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "pfcbrandonbucket", Entity = $"user-" + User.Identity.Name, //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "OWNER", }); storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "pfcbrandonbucket", Entity = $"user-" + p.Shareuser, //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "READER", //READER }); var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() { // Avoid race conditions. IfMetagenerationMatch = storageObject.Metageneration, }); } //store details in a relational db including the filename/link List <Product> results = new List <Product>(); p.File = link; // p.Name = System.IO.Path.GetExtension(model.Shareuser); //p.OwnerFK = User.Identity.Name; //p.Shareuser = Shareuser; // results.Add(p); #endregion } #region Storing details of product in db [INCOMPLETE] p.OwnerFK = User.Identity.Name; ProductsRepository pr = new ProductsRepository(); pr.AddProduct(p); #endregion #region Updating Cache with latest list of Products from db //enable: after you switch on db try { CacheRepository cr = new CacheRepository(); cr.UpdateCache(pr.GetProducts(User.Identity.Name)); } catch (Exception ex) { new LogsRepository().LogError(ex); } #endregion PubSubRepository psr = new PubSubRepository(); psr.AddToEmailQueue(p); //adding it to queue to be sent as an email later on. ViewBag.Message = "Product created successfully"; new LogsRepository().WriteLogEntry("Product created successfully for user: "******"Product failed to be created; " + ex.Message; } return(View()); ////upload image related to product on bucket //var storage = StorageClient.Create(); //string link = ""; //using (var f = file.InputStream) //{ // var filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); // var storageObject = storage.UploadObject("pfcbrandonbucket", filename, null, f); // link = storageObject.MediaLink; // if (null == storageObject.Acl) // { // storageObject.Acl = new List<ObjectAccessControl>(); // } // storageObject.Acl.Add(new ObjectAccessControl() // { // Bucket = "pfcbrandonbucket", // Entity = $"*****@*****.**", // Role = "READER", // }); // storageObject.Acl.Add(new ObjectAccessControl() // { // Bucket = "pfcbrandonbucket", // Entity = $"*****@*****.**", // Role = "OWNER", // }); // var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() // { // // Avoid race conditions. // IfMetagenerationMatch = storageObject.Metageneration, // }); //} ////create p in db ////p.Link = link; //return View(); }
public GoogleCloudStorageBlobStorage(string bucketName, GoogleCredential credential = null, EncryptionKey encryptionKey = null) : base() { _client = StorageClient.Create(credential, encryptionKey); _bucketName = bucketName; }
public VideoUploader(string bucketName, string projectId) { _bucketName = bucketName; _projectId = projectId; _storageClient = StorageClient.Create(); }
// [START vision_text_detection_pdf_gcs] private static object DetectDocument(string gcsSourceUri, string gcsDestinationBucketName, string gcsDestinationPrefixName) { var client = ImageAnnotatorClient.Create(); var asyncRequest = new AsyncAnnotateFileRequest { InputConfig = new InputConfig { GcsSource = new GcsSource { Uri = gcsSourceUri }, // Supported mime_types are: 'application/pdf' and 'image/tiff' MimeType = "application/pdf" }, OutputConfig = new OutputConfig { // How many pages should be grouped into each json output file. BatchSize = 2, GcsDestination = new GcsDestination { Uri = $"gs://{gcsDestinationBucketName}/{gcsDestinationPrefixName}" } } }; asyncRequest.Features.Add(new Feature { Type = Feature.Types.Type.DocumentTextDetection }); List <AsyncAnnotateFileRequest> requests = new List <AsyncAnnotateFileRequest>(); requests.Add(asyncRequest); var operation = client.AsyncBatchAnnotateFiles(requests); Console.WriteLine("Waiting for the operation to finish"); operation.PollUntilCompleted(); // Once the rquest has completed and the output has been // written to GCS, we can list all the output files. var storageClient = StorageClient.Create(); // List objects with the given prefix. var blobList = storageClient.ListObjects(gcsDestinationBucketName, gcsDestinationPrefixName); Console.WriteLine("Output files:"); foreach (var blob in blobList) { Console.WriteLine(blob.Name); } // Process the first output file from GCS. // Select the first JSON file from the objects in the list. var output = blobList.Where(x => x.Name.Contains(".json")).First(); var jsonString = ""; using (var stream = new MemoryStream()) { storageClient.DownloadObject(output, stream); jsonString = System.Text.Encoding.UTF8.GetString(stream.ToArray()); } var response = JsonParser.Default .Parse <AnnotateFileResponse>(jsonString); // The actual response for the first page of the input file. var firstPageResponses = response.Responses[0]; var annotation = firstPageResponses.FullTextAnnotation; // Here we print the full text from the first page. // The response contains more information: // annotation/pages/blocks/paragraphs/words/symbols // including confidence scores and bounding boxes Console.WriteLine($"Full text: \n {annotation.Text}"); return(0); }
public async static Task StreamToGCS() { //Task.Run(async () => { await test(); }).GetAwaiter().GetResult(); string connectionString = "Host=localhost;Port=5701;Database=hiring;Username=tri;Password=1hEWZ4GeN24c"; Connection = new NpgsqlConnection(connectionString); /** * Needs Cleanup * */ NpgsqlCommand cmd = new NpgsqlCommand(); cmd.CommandText = "SELECT * FROM public.language;"; cmd.Connection = Connection; cmd.Connection.Open(); MemoryStream ms = new MemoryStream(); /** * Needs Cleanup * */ NpgsqlDataReader reader = cmd.ExecuteReader(); new Thread(() => { var columns = reader.GetColumnSchema(); while (reader.Read()) { for (int i = 0; i < columns.Count; i++) { Type type = reader.GetFieldType(i); var method = reader.GetType().GetMethod("GetFieldValue", new Type[] { typeof(int) }); var genericMethod = method.MakeGenericMethod(type); var value = genericMethod.Invoke(reader, new object[] { i }); string valueHolder = "NULL"; if (value != null) { valueHolder = value.ToString(); } if (i == 0) { Console.Write(valueHolder); WriteStringToStream(ms, valueHolder); } else { Console.Write("\t{0}", valueHolder); WriteStringToStream(ms, string.Format("\t{0}", valueHolder)); } } Console.WriteLine(); WriteStringToStream(ms, "\n"); //Thread.Sleep(200); } }).Start(); var credentialsPath = "auth\\gd-hiring.json"; var credentialsJson = File.ReadAllText(credentialsPath); var googleCredential = GoogleCredential.FromJson(credentialsJson); var storageClient = StorageClient.Create(googleCredential); storageClient.Service.HttpClient.Timeout = new TimeSpan(1, 0, 0); var bucketName = "gd-hiring-tri"; await storageClient.UploadObjectAsync( bucketName, "public.language_2018-05-11.tsv", "text/html", ms ); Thread.Sleep(5000); using (var outputFile = File.OpenWrite("temp-output.tsv")) { storageClient.DownloadObject(bucketName, "public.language_2018-05-11.tsv", outputFile); } Console.WriteLine("Done??"); }
private StorageClient GetStorage() { var credential = GoogleCredential.FromJson(_json); return(StorageClient.Create(credential)); }
public ImageController(ILogger <ImageController> logger, TenantFileContext context) { _logger = logger; _storageClient = StorageClient.Create(); _context = context; }
public async static Task <List <ImageEntity> > GetBucket(string projectId) { var images = new List <ImageEntity>(); // Explicitly use service account credentials by specifying the private key // file. GoogleCredential credential = GetGoogleCredential(); var storage = StorageClient.Create(credential); // Make an authenticated API request. var itemsList = storage.ListObjectsAsync("sample_photos_2017"); //for (int i = 0; i < 1000; i++) //{ //int i = 0; //while (i <= await itemsList.Count()) //{ // var firstBatch = itemsList.Skip(i).Take(10); //DoAsync(async () => //{ int count = 0; var total = itemsList.Count().Result; var client = ImageAnnotatorClient.Create(); var skip = 0; var page = 10; var requestCount = 0; // use (ca) half of the kernels: int degreeOfParallelism = Environment.ProcessorCount > 1 ? Environment.ProcessorCount / 2 : 1; //var dateTimeStarted = DateTime.Now; while (skip < total) { //make the thread sleep when process 600 request because only 600 requests per minute are allowed. if (requestCount == 600) { requestCount = 0; System.Threading.Thread.Sleep(40000); } //we have to use localskip because of async threads var localskip = skip; skip = skip + page; requestCount = requestCount + page; await itemsList.Skip(localskip).Take(page).ForEachAsync(item => { var image = new ImageEntity() { ImageName = item.Name, ImagePath = item.SelfLink, ImageObj = item }; lock (lockObj1) { App.Current.Dispatcher.Invoke(() => { _collection.Add(image); //image.AnnotateRequest = CreateRequet(image.ImageObj); //images.Add(image); //image.AnnotateRequest = CreateRequet(image.ImageObj); //image.ImageText = GetInfo(client.Annotate(image.AnnotateRequest)); //_progressBar.Value = (skip / total) * 100; //Int64.Parse($"{count++ / total}"); }, DispatcherPriority.Background); } }); var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = degreeOfParallelism }; Parallel.ForEach(_collection.Skip(localskip).Take(page), parallelOptions, async(item) => //foreach (var item in _collection) { //Tuple<string, string> info = null; List <ImageInfo> list = null; try { item.AnnotateRequest = CreateRequet(item.ImageObj); var result = await client.AnnotateAsync(item.AnnotateRequest); list = GetInfo(result, item.CleanImageName); var builder = new StringBuilder(); //builder.AppendLine("Google Vision Labels:"); builder.AppendLine(string.Join(", ", list.Where(s => s.AnnotationCategory == AnnotationCategory.LabelAnnotations) .Select(s => s.ToString()))); App.Current.Dispatcher.Invoke(() => { item.ImageText = builder.ToString(); //info.Item1; }, DispatcherPriority.Background); } catch { //ignore it as we can't handle it. } if (list != null) { await LuceneService.Context.AddIndexesAsync(item.CleanImageName, list /*info.Item2*/, null); } }); LuceneService.Context.Flush(); App.Current.Dispatcher.Invoke(() => { _progressBar.Value = ((double)skip / (double)total) * 100; }, DispatcherPriority.Background); } //}); //images.All(s => { s.AnnotateRequest = CreateRequet(s.ImageObj); return true; }); //int i =0; //while (i < total) //{ // BatchAnnotateImagesRequest batch = new BatchAnnotateImagesRequest(); // batch.Requests.AddRange(images.Skip(i).Take(15).Select(s => s.AnnotateRequest)); // var client = ImageAnnotatorClient.Create(); // var result = client.BatchAnnotateImages(batch); // i = i + 15; //} // i += 10; //} //} return(images); }
public GoogleStorage(string projectId) { storageClient = StorageClient.Create(); this.projectId = projectId; }
public override void ConfigureServices(WebHostBuilderContext context, IServiceCollection services) => services .AddSingleton(ImageAnnotatorClient.Create()) .AddSingleton(StorageClient.Create());
public GoogleStorageReleaseRepository(GoogleCredential credential) { client = StorageClient.Create(credential); }
public ImageUploader(string bucketName) { _bucketName = bucketName; _storageClient = StorageClient.Create(); }
public GoogleCloudStorage() { googleCredential = GoogleCredential.FromFile(Environment.GetEnvironmentVariable("GOOGLE_CREDENTIAL_FILE")); storageClient = StorageClient.Create(googleCredential); bucketName = Environment.GetEnvironmentVariable("GOOGLE_CLOUD_STORAGE_BUCKET"); }
/// <summary> /// /// <para>BFileServiceGC: Parametered Constructor:</para> /// /// <para><paramref name="_ProjectID"/> GC Project ID</para> /// <para><paramref name="_ErrorMessageAction"/> Error messages will be pushed to this action</para> /// /// </summary> public BFileServiceGC( string _ProjectID, Action <string> _ErrorMessageAction = null) { try { string ApplicationCredentials = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"); string ApplicationCredentialsPlain = Environment.GetEnvironmentVariable("GOOGLE_PLAIN_CREDENTIALS"); if (ApplicationCredentials == null && ApplicationCredentialsPlain == null) { _ErrorMessageAction?.Invoke("BFileServiceGC->Constructor: GOOGLE_APPLICATION_CREDENTIALS (or GOOGLE_PLAIN_CREDENTIALS) environment variable is not defined."); bInitializationSucceed = false; } else { ProjectID = _ProjectID; if (ApplicationCredentials == null) { if (!BUtility.HexDecode(out ApplicationCredentialsPlain, ApplicationCredentialsPlain, _ErrorMessageAction)) { throw new Exception("Hex decode operation for application credentials plain has failed."); } Credential = GoogleCredential.FromJson(ApplicationCredentialsPlain); CredentialScoped = Credential.CreateScoped( new string[] { StorageService.Scope.DevstorageReadWrite }) .UnderlyingCredential as ServiceAccountCredential; } else { using (var Stream = new FileStream(ApplicationCredentials, FileMode.Open, FileAccess.Read)) { Credential = GoogleCredential.FromStream(Stream); CredentialScoped = Credential.CreateScoped( new string[] { StorageService.Scope.DevstorageReadWrite }) .UnderlyingCredential as ServiceAccountCredential; } } if (Credential != null) { GSClient = StorageClient.Create(Credential); bInitializationSucceed = GSClient != null; } else { bInitializationSucceed = false; } } } catch (Exception e) { _ErrorMessageAction?.Invoke("BFileServiceGC->Constructor: " + e.Message + ", Trace: " + e.StackTrace); bInitializationSucceed = false; } }
private GoogleCloudStorage() { string connection = ConfigurationManager.AppSettings["connection"]; _storageClient = StorageClient.Create(); }
public BackupCleaner(CrawlerOptions options, ILoggerFactory loggerFactory) { this.options = options; logger = loggerFactory.CreateLogger <BackupCleaner>(); storageClient = StorageClient.Create(); }
/// <summary> /// https://cloud.google.com/storage/docs/reference/libraries /// </summary> private StorageClient GetStorageClient() { var googleCredential = GoogleCredential.FromFile(_gcpSettings.Storage.JsonAuthPath); return(StorageClient.Create(googleCredential)); }
/// <summary> /// This Functions goes to Twilio, make a call, Twilio save a record of this call then goes to Google Speech to text API and transcribe the call saving a txt local file /// </summary> public static void Call() { Console.WriteLine("Init Twilio API..."); ///Twilio SID and Token const string accountSid = "ACa62c3db32794048447xxxxxxxxxxxx"; const string authToken = "f420e52ee6774e0898fdxxxxxxxxxxxx"; TwilioClient.Init(accountSid, authToken); Console.WriteLine("Let's make a call, please provide me your phone number (format: +AreaNumner)"); var phoneNumber = Console.ReadLine(); var call = CallResource.Create( record: true, url: new Uri("https://corn-collie-1715.twil.io/assets/Voice.xml"), //is a best practice to upload the assets in twilio account to: new Twilio.Types.PhoneNumber(phoneNumber), from: new Twilio.Types.PhoneNumber("+000000000") //Twilio number created in you account ); RecordingResource recordings; RecordingResource.StatusEnum recordingStatus; do { recordings = RecordingResource.Read().Where(x => x.CallSid == call.Sid).FirstOrDefault(); } while (recordings == null); do { Console.WriteLine("Processing Recording...."); recordingStatus = RecordingResource.Read().Where(x => x.CallSid == call.Sid).Select(x => x.Status).FirstOrDefault(); } while (recordingStatus == RecordingResource.StatusEnum.Processing); WebClient wc = new WebClient(); wc.DownloadFile(@"https://api.twilio.com/" + recordings.Uri.Replace("json", "wav"), recordings.Sid + ".wav"); Console.WriteLine("Now we have the recording,Lets sync with Google Services, please wait... "); string audioDirectory = Path.Combine(Environment.CurrentDirectory, recordings.Sid + ".wav"); var memoryStream = new MemoryStream(); using (var file = new FileStream(audioDirectory, FileMode.Open, FileAccess.Read)) file.CopyTo(memoryStream); var speechClient = SpeechClient.Create(); var storageClient = StorageClient.Create(); //We have to upload the file to google storage before transcribe var uploadedWavFile = storageClient.UploadObject(GoogleBucketName, recordings.Sid + ".wav", "audio/wav", memoryStream); //Get the file var storageObject = storageClient.GetObject(GoogleBucketName, recordings.Sid + ".wav"); var storageUri = $@"gs://{GoogleBucketName}/{storageObject.Name}"; storageObject.Acl = storageObject.Acl ?? new List <ObjectAccessControl>(); storageClient.UpdateObject(storageObject, new UpdateObjectOptions { PredefinedAcl = PredefinedObjectAcl.PublicRead }); Console.WriteLine("We will start to transcribe your recording, this operation will take few moments..."); //Speech to Text operation var longOperation = speechClient.LongRunningRecognize(new RecognitionConfig() { //the properties below are not the required for MP3 files and that's why the opertion returns null, we can make this more //generic knowing what kind of properties we need for each file type or standarize the result just for one type. //Encoding = RecognitionConfig.Types.AudioEncoding.Linear16, //SampleRateHertz = 44100, EnableWordTimeOffsets = true, LanguageCode = "en-US" }, RecognitionAudio.FromStorageUri(storageUri)); longOperation = longOperation.PollUntilCompleted(); //TODO: fix this implementation. Sometimes there is a null being returned from longOperation.Result var response = longOperation.Result; if (response != null && response.Results != null && response.Results.Count > 0) { Console.WriteLine("Is done!, now we will create a file with the complete transcription for you..."); //var resultArray = (JsonConvert.DeserializeObject<RootObject>(response.Results.ToString())); foreach (var res in response.Results) { string transcription = res.Alternatives.Select(x => x.Transcript).FirstOrDefault(); File.AppendAllText(Path.Combine(Environment.CurrentDirectory, recordings.Sid + ".txt"), transcription); } } Console.WriteLine("File Created!, Now we will clean our directories and give you the path of the mentioned file..."); storageClient.DeleteObject(GoogleBucketName, storageObject.Name); if (File.Exists(Path.Combine(Environment.CurrentDirectory, recordings.Sid + ".wav"))) { File.Delete(Path.Combine(Environment.CurrentDirectory, recordings.Sid + ".wav")); } Console.WriteLine("You can find your txt file here: " + Path.Combine(Environment.CurrentDirectory, recordings.Sid + ".txt")); Console.ReadLine(); }
private void GCS_SaveInNewThread() { String ProjectId = Settings.GetValueFromConfig("GCS_projectId"); String BucketName = Settings.GetValueFromConfig("GCS_bucketName"); String BaseFolderName = Settings.GetValueFromConfig("GCS_baseFolderName"); if (storageClient == null) { string CredPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + Settings.GetValueFromConfig("GCS_jsonKey"); var credential = GoogleCredential.FromFile(CredPath); storageClient = StorageClient.Create(credential); } System.IO.Stream fs = new System.IO.MemoryStream(0); String PathName = BaseFolderName += @"/"; var checkObj1 = storageClient.ListObjects(BucketName, PathName); if (checkObj1.Count() <= 0) { var result = storageClient.UploadObject(BucketName, PathName, null, fs); Console.WriteLine($"Image {result.Name} Uploaded to GCS"); } while (true) { if (RecordQueue.Count == 0) { Thread.Sleep(2000); continue; } ITweet tw = RecordQueue.Dequeue(); string TweetFolderName = tw.CreatedBy.ScreenName; var ffs = new System.IO.MemoryStream(0); String TweetPathName = PathName + TweetFolderName + @"/"; var checkObj2 = storageClient.ListObjects(BucketName, TweetPathName); if (checkObj2.Count() <= 0) { var result = storageClient.UploadObject(BucketName, TweetPathName, null, ffs); Console.WriteLine($"Image {result.Name} Uploaded to GCS"); } foreach (IMediaEntity m in tw.Media) { if (m.MediaURL.Contains(".jpg")) { String ImageName = m.IdStr + ".jpg"; String finalFilePathName = TweetPathName + ImageName; //var ImageFromTweet = new BitmapImage(new Uri(m.MediaURL)); System.Net.WebClient client = new System.Net.WebClient(); fs = new System.IO.MemoryStream(client.DownloadData(m.MediaURL)); //Console.WriteLine(PathNameUntili); var result = storageClient.UploadObject(BucketName, finalFilePathName, null, ffs); Console.WriteLine($"Image {result.Name} Uploaded to GCS"); } } } }
public int Executar(string nomeDoArquivo, MemoryStream arquivo) { var bucketName = BucketName.RandomName(); var outputPrefix = ""; var gcsSourceURI = $"gs://{bucketName}/{nomeDoArquivo}"; SortedDictionary <string, SortedSet <string> > _garbage = new SortedDictionary <string, SortedSet <string> >(); StorageClient _storage = StorageClient.Create(); _storage.CreateBucket(_projectId, bucketName); _storage.UploadObject(bucketName, nomeDoArquivo, "application/pdf", arquivo); SortedSet <string> objectNames; if (!_garbage.TryGetValue(bucketName, out objectNames)) { objectNames = _garbage[bucketName] = new SortedSet <string>(); } objectNames.Add(nomeDoArquivo); var client = ImageAnnotatorClient.Create(); var asyncRequest = new AsyncAnnotateFileRequest { InputConfig = new InputConfig { GcsSource = new GcsSource { Uri = gcsSourceURI }, MimeType = "application/pdf" }, OutputConfig = new OutputConfig { // How many pages should be grouped into each json output file. BatchSize = 100, GcsDestination = new GcsDestination { Uri = $"gs://{bucketName}/{outputPrefix}" } } }; asyncRequest.Features.Add(new Feature { Type = Feature.Types.Type.DocumentTextDetection }); List <AsyncAnnotateFileRequest> requests = new List <AsyncAnnotateFileRequest> { asyncRequest }; var operation = client.AsyncBatchAnnotateFiles(requests); operation.PollUntilCompleted(); var blobList = _storage.ListObjects(bucketName, outputPrefix); var output = blobList.Where(x => x.Name.Contains(".json")).First(); var jsonString = ""; using (var stream = new MemoryStream()) { _storage.DownloadObject(output, stream); jsonString = System.Text.Encoding.UTF8.GetString(stream.ToArray()); } var response = JsonParser.Default.Parse <AnnotateFileResponse>(jsonString); int total = 0; for (int i = 0; i < response.Responses.Count; i++) { var pageResponses = response.Responses[i]; if (pageResponses != null) { var annotation = pageResponses.FullTextAnnotation; var conteudo = annotation.Text.Replace("\n", " "); var remocaoDosEspacos = conteudo.Split(' '); foreach (var item in remocaoDosEspacos) { total += item.Length; } } } RemoverArquivos(bucketName); return(total); }
public void DeleteFileFromGcs(string bucket, string fileName) { StorageClient gcsClient = StorageClient.Create(); gcsClient.DeleteObject(bucket, fileName); }
static void Main(string[] args) { using (var connection = new NpgsqlConnection("Host=127.0.0.1;port=5701;Username=arun;Password=V0zxKQd6M0Qp;Database=hiring")) { connection.Open(); Console.WriteLine("\nEnter Table name ? "); var name = Console.ReadLine(); NpgsqlCommand command = new NpgsqlCommand("Select * from " + name + " ", connection); var value = connection.Query <string>("Select * from " + name + " ;"); NpgsqlDataReader dr = command.ExecuteReader(); FileStream ostrm; StreamWriter writer; try { ostrm = new FileStream("C:/" + name + ".tsv", FileMode.OpenOrCreate, FileAccess.ReadWrite); writer = new StreamWriter(ostrm); } catch (Exception e) { Console.WriteLine("Cannot open " + name + ".tsv for writing"); Console.WriteLine(e.Message); return; } Console.SetOut(writer); while (dr.Read()) { Console.WriteLine("{0}\t{1}\t{2} \n", dr[0], dr[1], dr[2]); } writer.Close(); ostrm.Close(); Console.Read(); } Console.Read(); var credentialsPath = "auth\\GCP.Client.Secret.Candidate.Task.json"; var credentialsJson = File.ReadAllText(credentialsPath); var googleCredential = GoogleCredential.FromJson(credentialsJson); var storageClient = StorageClient.Create(googleCredential); storageClient.Service.HttpClient.Timeout = new TimeSpan(1, 0, 0); var fileInfo = new FileInfo(credentialsPath); var fileStream = fileInfo.OpenRead(); var bucketName = "gd-hiring-tri"; storageClient.UploadObject( bucketName, "C:/film.tsv", "text/html", fileStream ); Console.ReadLine(); }
public BucketStore(IGcpBucketUtils _bucketUtils) { client = StorageClient.Create(); this.bucketUtils = _bucketUtils; }
public static async Task MainFirebaseAdminAuth() { using (var firebase = new FireBase.Notification.Firebase()) { await firebase.PushNotifyAsync(sender_Id, "Hello", "World"); FileStream serviceAccount = new FileStream(path_to_private_key, FileMode.Open); // get the content of the file var credential = GoogleCredential.FromStream(serviceAccount); // obtain the credential from the file serviceAccount.Close(); //close the file (release the file handle, and possibly the thread!) var storage = StorageClient.Create(credential); //storage details // Make an authenticated API request. //new FCMPushNotification().SendNotification("_title", "_message", "_topic", "deviceId"); //firebase.PushNotifyAsync(id, "Hello", "World").Wait(); var buckets = storage.ListBuckets(projectId);//Todo: check why the bucket was empty! //buckets foreach (var bucket in buckets) { Console.WriteLine($"{bucket.Name}::{bucket}"); } //FirebaseInstanceId.getInstance().getToken(); //try //{ // FirebaseApp.Create(new AppOptions() // { // Credential = GoogleCredential.GetApplicationDefault(), // }); //} //catch (Exception ex) //{ //} try { var firebaseApp = FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile(path_to_private_key), }, "My_Beautiful_App"); FirebaseMessaging.GetMessaging(firebaseApp); new FCMPushNotification().SendNotification("title", "message", "topic", deviceId); await new ProgramFirebaseAdminAuth().SendNotification(new List <string>() { deviceId, deviceId }, "title", "body: some sort of msg to be sent to a device!"); } catch (FirebaseException fex) { } catch (Exception ex) { } //try //{ // FirebaseApp.Create(); // // Initialize the default app // var defaultApp = FirebaseApp.Create("defaultOptions"); // // Initialize another app with a different config // var otherApp = FirebaseApp.Create("other"); // Console.WriteLine(defaultApp.Name); // "defaultOptions" // Console.WriteLine(otherApp.Name); // "other" // // Use the shorthand notation to retrieve the default app's services // var defaultAuth = FirebaseAuth.DefaultInstance; // // Use the otherApp variable to retrieve the other app's services // var otherAuth = FirebaseAuth.GetAuth(otherApp); //} //catch (Exception ex) //{ //} } }
public GoogleCloudStorage(IConfiguration configuration) { googleCredential = GoogleCredential.FromFile(configuration.GetValue <string>("GoogleCredentialFile")); storageClient = StorageClient.Create(googleCredential); bucketName = configuration.GetValue <string>("GoogleCloudStorageBucket"); }
public StorageBucketHelper(string bucketName) { this.storage = StorageClient.Create(); this.bucketName = bucketName; this.baseURI = "gs://receipt_imgs/"; }
public ImageCloudStorage() { var credential = GoogleCredential.FromFile("PopularityStatistics-cb0e0fe38381.json"); _storageClient = StorageClient.Create(credential); }
public CloudStorageStreamService(FileStreamService fileStreamService) { _storage = StorageClient.Create(); _fileStreamService = fileStreamService; }
private static void WriteToStorage(string bucket, string filename, Stream stream) { var storage = StorageClient.Create(); storage.UploadObject(bucket, filename, null, stream); }
public ActionResult FileUpload(FileUpload sf, HttpPostedFileBase file) { try { if (file != null) { var storage = StorageClient.Create(); string link = ""; using (var f = file.InputStream) { var filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var storageObject = storage.UploadObject("justinportellipfc", filename, null, f); link = "https://storage.cloud.google.com/justinportellipfc/" + filename; if (null == storageObject.Acl) { storageObject.Acl = new List <ObjectAccessControl>(); } storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "justinportellipfc", Entity = $"user-" + User.Identity.Name, //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "OWNER", //READER }); storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "justinportellinpfc", Entity = $"user-" + sf.receiverEmail, //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "READER", //READER }); var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() { // Avoid race conditions. IfMetagenerationMatch = storageObject.Metageneration, }); FileRepository fr = new FileRepository(); UsersRepository ur = new UsersRepository(); CacheRepository cr = new CacheRepository(); fr.AddFile(filename.ToString(), link, sf.receiverEmail, ur.GetUserID(User.Identity.Name)); cr.UpdateCache(GetFiles(ur.GetUserID(User.Identity.Name)), ur.GetUserID(User.Identity.Name)); PubSubRepository psr = new PubSubRepository(); psr.AddToEmailQueue(sf); } ViewBag.Message = "File uploaded"; LogsRepository logr = new LogsRepository(); logr.WriteLogEntry("File was Uploaded"); } } catch (Exception ex) { LogsRepository logr = new LogsRepository(); logr.LogError(ex); ViewBag.Message = "File was not uploaded"; } return(View()); }