Exemple #1
0
        public List <TaskEntry> GetRange(int offset, int count)
        {
            // Read entire CSV
            string           contents = dbFile.DownloadTextAsync().Result;
            List <TaskEntry> tasks    = new List <TaskEntry>();
            int endOffset             = offset + count;

            IEnumerable <ICsvLine> lines = CsvReader.ReadFromText(contents, this.csvOptions);

            // Check we have enough entries
            if (lines.Count() < endOffset)
            {
                endOffset = lines.Count();
            }

            for (int i = offset; i < endOffset; i++)
            {
                ICsvLine line = lines.ElementAt(i);
                try
                {
                    tasks.Add(new TaskEntry(Int32.Parse(line["id"]), line["title"], System.Convert.ToBoolean(line["isComplete"])));
                } catch
                {
                    // Unable to parse entry or final blank line in CSV
                }
            }
            return(tasks);
        }
        static void Main(string[] args)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connection);

            CloudFileClient cloudFileClient = storageAccount.CreateCloudFileClient();

            // Get a reference to the file share we created previously.
            CloudFileShare fileShare = cloudFileClient.GetShareReference("doc2020");

            // Ensure that the share exists.
            if (fileShare.Exists())
            {
                // Get a reference to the root directory for the share.
                CloudFileDirectory fileDirectory = fileShare.GetRootDirectoryReference();

                // Get a reference to the directory we created previously.
                CloudFileDirectory customDirectory = fileDirectory.GetDirectoryReference("storage");

                // Ensure that the directory exists.
                if (customDirectory.Exists())
                {
                    // Get a reference to the file we created previously.
                    CloudFile fileInfo = customDirectory.GetFileReference("Log1.txt");

                    // Ensure that the file exists.
                    if (fileInfo.Exists())
                    {
                        // Write the contents of the file to the console window.
                        Console.WriteLine(fileInfo.DownloadTextAsync().Result);
                    }
                }

                NewFileCreate();
            }
        }
Exemple #3
0
        private static async Task refineLogs()
        {
            StorageConnection conn             = new StorageConnection();
            string            connectionString = "DefaultEndpointsProtocol=https;AccountName=storageaccountgepte86f5;AccountKey=tWMNBa2qlEgVEt6cOnmDbYdsJ0igQmnmJzcJx2d5lxuf0y1iYyMEbkM9n8KlUfPvlSF9Mtc3KE5CrhAWy/fpAg==;EndpointSuffix=core.windows.net";

            conn.config = new MyConfig()
            {
                StorageConnection = connectionString, Container = "techathoninput"
            };
            conn.Connect();
            CloudStorageAccount sAccount   = conn.storageAccount;
            CloudFileClient     fileClient = sAccount.CreateCloudFileClient();

            CloudFileShare share = fileClient.GetShareReference("scheduledfileconverter91d0");

            if (await share.ExistsAsync())
            {
                CloudFileDirectory rootDir = share.GetRootDirectoryReference();
                CloudFileDirectory dir     = rootDir.GetDirectoryReference(@"LogFiles/Application/Functions/Function/Function");
                CloudFile          logs    = rootDir.GetFileReference("Logs.txt");
                if (await dir.ExistsAsync())
                {
                    List <IListFileItem>  results = new List <IListFileItem>();
                    FileContinuationToken token   = null;
                    do
                    {
                        FileResultSegment resultSegment = await dir.ListFilesAndDirectoriesSegmentedAsync(token);

                        results.AddRange(resultSegment.Results);
                        token = resultSegment.ContinuationToken;
                    }while (token != null);
                    List <CloudFile> files = new List <CloudFile>();
                    foreach (IListFileItem item in results)
                    {
                        if (item.GetType() == typeof(Microsoft.WindowsAzure.Storage.File.CloudFile))
                        {
                            files.Add((CloudFile)item);
                        }
                    }
                    string name = "";
                    foreach (CloudFile file in files)
                    {
                        name = (string.Compare(name, Path.GetFileNameWithoutExtension(file.Name)) > 0) ? name : Path.GetFileNameWithoutExtension(file.Name);
                    }
                    name += ".log";
                    CloudFile recentFile = dir.GetFileReference(name);
                    string    data       = await recentFile.DownloadTextAsync();

                    string[] lines = data.Split("\n");
                    if (lines.Length < 50)
                    {
                        await logs.UploadTextAsync(data);
                    }
                    else
                    {
                        await logs.UploadTextAsync(string.Join("\n", lines.Skip(lines.Length - 50).ToArray()));
                    }
                }
            }
        }
 private static void PrintFileToConsole(CloudFile file)
 {
     if (file.Exists())
     {
         Console.WriteLine(file.DownloadTextAsync().Result);
     }
 }
 private void CreatePPDMModel(DataModelParameters dmParameters, ConnectParameters connector)
 {
     try
     {
         CloudStorageAccount account    = CloudStorageAccount.Parse(connectionString);
         CloudFileClient     fileClient = account.CreateCloudFileClient();
         CloudFileShare      share      = fileClient.GetShareReference(dmParameters.FileShare);
         if (share.Exists())
         {
             CloudFileDirectory rootDir = share.GetRootDirectoryReference();
             CloudFile          file    = rootDir.GetFileReference(dmParameters.FileName);
             if (file.Exists())
             {
                 string      sql    = file.DownloadTextAsync().Result;
                 DbUtilities dbConn = new DbUtilities();
                 dbConn.OpenConnection(connector);
                 dbConn.SQLExecute(sql);
                 dbConn.CloseConnection();
             }
         }
     }
     catch (Exception ex)
     {
         Exception error = new Exception("Create PPDM Model Error: ", ex);
         throw error;
     }
 }
Exemple #6
0
        public String ReadTxt(String filename)
        {
            CloudFile file        = this.root.GetFileReference(filename);
            String    filecontent = file.DownloadTextAsync().Result;

            return(filecontent);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            CloudStorageAccount cuentaAlmacenamiento = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("FileConnectionString"));
            CloudFileClient     clienteArchivos      = cuentaAlmacenamiento.CreateCloudFileClient();
            CloudFileShare      archivoCompartido    = clienteArchivos.GetShareReference("platzifile");

            if (archivoCompartido.Exists())
            {
                CloudFileDirectory carpetaRaiz = archivoCompartido.GetRootDirectoryReference();
                CloudFileDirectory directorio  = carpetaRaiz.GetDirectoryReference(DIRECTORIO_NOMBRE);

                if (directorio.Exists())
                {
                    Console.WriteLine($"Archivo a leer: {ARCHIVO_NOMBRE}");
                    CloudFile archivo = directorio.GetFileReference(ARCHIVO_NOMBRE);
                    if (archivo.Exists())
                    {
                        Console.WriteLine(archivo.DownloadTextAsync().Result);
                    }
                    else
                    {
                        Console.WriteLine($"no se encontro el archivo: {ARCHIVO_NOMBRE}");
                    }
                }
                else
                {
                    Console.WriteLine($"no se encontro la carpeta: {DIRECTORIO_NOMBRE}");
                }
            }
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            CloudStorageAccount CuentaAlmacenamiento =
                CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("CadenaConexion"));

            CloudFileClient ClienteArchivos   = CuentaAlmacenamiento.CreateCloudFileClient();
            CloudFileShare  ArchivoCompartido = ClienteArchivos.GetShareReference("filepleon");

            if (ArchivoCompartido.Exists())
            {
                CloudFileDirectory CarpetaRaiz = ArchivoCompartido.GetRootDirectoryReference();
                CloudFileDirectory Directorio  = CarpetaRaiz.GetDirectoryReference("Archivos");

                if (Directorio.Exists())
                {
                    CloudFile Archivo = Directorio.GetFileReference("prueba.txt");

                    if (Archivo.Exists())
                    {
                        Console.WriteLine(Archivo.DownloadTextAsync().Result);
                        Console.ReadLine();
                    }
                }
            }
        }
Exemple #9
0
        private string LoadAzureStorageFileContents(string fileName)
        {
            var storageAccountCS = GetStorageAccountCS();

            if (!string.IsNullOrEmpty(storageAccountCS))
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageAccountCS);

                // Create a CloudFileClient object for credentialed access to Azure Files.
                CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
                CloudFileShare  share      = fileClient.GetShareReference("eshopmodified");

                //// Ensure that the share exists.
                if (share.Exists())
                {
                    // Get a reference to the root directory for the share.
                    CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                    //Get a reference to the file we created previously.
                    CloudFile file = rootDir.GetFileReference(fileName);

                    // Ensure that the file exists.
                    if (file.Exists())
                    {
                        //download file content
                        return(file.DownloadTextAsync().Result);
                    }
                }
            }

            return(string.Empty);
        }
Exemple #10
0
        /*
         * GetAppendBlobReference is removed from Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
         * So we cannot release the log function based on the append function from Microsoft.WindowsAzure.Storage.
         * stackoverflow: https://stackoverflow.com/questions/48411359/getappendblobreference-is-removed-from-microsoft-windowsazure-storage-blob-cloud
         */
        public static void MainMethod()
        {
            string accountName = "";
            string accountKey  = "";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(string.Format(@"DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", accountName, accountKey));
            // Create a CloudFileClient object for credentialed access to Azure Files.
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

            // Get a reference to the file share we created previously.
            CloudFileShare share = fileClient.GetShareReference("logs");

            // If the share does not exist, create it.
            if (!share.Exists())
            {
                share.Create();
            }
            // Get a reference to the root directory for the share.
            CloudFileDirectory rootDir = share.GetRootDirectoryReference();

            // Get a reference to the directory we created previously.
            CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("TestLogs");

            if (!sampleDir.Exists())
            {
                sampleDir.Create();
            }

            // Get a reference to the file we created previously.
            CloudFile file = sampleDir.GetFileReference("Log1.txt");

            // Ensure that the file exists.
            if (file.Exists())
            {
                // Write the contents of the file to the console window.
                Console.WriteLine(file.DownloadTextAsync().Result);
                file.UploadText("12345");
                Console.WriteLine(file.DownloadTextAsync().Result);
            }
            else
            {
                file.UploadText("1234");
            }

            Console.ReadKey();
        }
        public String LeerTXT(String nombrearchivo)
        {
            //BUSCAMOS EL NOMBRE DE NUESTRO ARCHIVO EN NUESTRO DIRECTORIO
            CloudFile archivo = this.directorio.GetFileReference(nombrearchivo);
            //DESCARGAMOS EL CONTENIDO DEL ARCHIVO COMO TEXTO
            String contenido = archivo.DownloadTextAsync().Result;

            return(contenido);
        }
Exemple #12
0
        public string GetFileFromFileStorage()
        {
            try
            {
                string returnString = "No data retreived.";
                string accountName  = "storagemartin";
                string accountKey   = ConfigurationManager.AppSettings["BlobPassword"];

                StorageCredentials  creds          = new StorageCredentials(accountName, accountKey);
                CloudStorageAccount storageAccount = new CloudStorageAccount(creds, useHttps: true);

                // Create a CloudFileClient object for credentialed access to Azure Files.
                CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

                // Get a reference to the file share we created previously.
                CloudFileShare share = fileClient.GetShareReference("tipslogs");

                // Ensure that the share exists.
                if (share.Exists())
                {
                    // Get a reference to the root directory for the share.
                    CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                    // Get a reference to the directory we created previously.
                    CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("thetipslogs");

                    // Ensure that the directory exists.
                    if (sampleDir.Exists())
                    {
                        // Get a reference to the file we created previously.
                        CloudFile file = sampleDir.GetFileReference("tipslogError.txt");

                        // Ensure that the file exists.
                        if (file.Exists())
                        {
                            // Write the contents of the file to the console window.
                            returnString = file.DownloadTextAsync().Result;

                            returnString = MakeHtmlFriendlyText(returnString);
                            return(returnString);
                        }
                    }
                }

                return(returnString);
            }
            catch (Exception e)
            {
                string inner = e.InnerException != null?e.InnerException.ToString() : "NULL";

                return(string.Format("Error in method GetFileFromFileStorage. Exception: {0}. Inner: {1}", e.Message.ToString(), inner));
            }
        }
Exemple #13
0
        private void btnread_Click(object sender, EventArgs e)
        {
            String keys = CloudConfigurationManager.GetSetting("Storage");
            CloudStorageAccount account = CloudStorageAccount.Parse(keys);
            CloudFileClient     client  = account.CreateCloudFileClient();
            CloudFileShare      shared  = client.GetShareReference("sharedtajamar");
            CloudFileDirectory  root    = shared.GetRootDirectoryReference();
            CloudFile           file    = root.GetFileReference("bbdd.sql");
            String content = file.DownloadTextAsync().Result;

            this.txt.Text = content;
        }
        public async Task <string> GetFhirBundleAndDelete(string fileName)
        {
            string    ret    = "";
            CloudFile source = PatientDirectory.GetFileReference(fileName);

            if (await source.ExistsAsync())
            {
                ret = await source.DownloadTextAsync();

                await source.DeleteAsync();
            }
            return(ret);
        }
        private async void btnleerfile_Click(object sender, EventArgs e)
        {
            //NECESITAMOS LA CLAVE DE ACCESO A STORAGE
            string key = CloudConfigurationManager.GetSetting("storagecnstring");
            //NECESITAMOS ACCEDER A TODA LA CUENTA CLOUD STORAGE PARA PODER ACCEDER A FILES
            CloudStorageAccount account   = CloudStorageAccount.Parse(key);
            CloudFileClient     client    = account.CreateCloudFileClient();
            CloudFileShare      fileshare = client.GetShareReference("ejemplo");
            CloudFileDirectory  raiz      = fileshare.GetRootDirectoryReference();
            CloudFile           file      = raiz.GetFileReference("clientessimples.json");
            string contenido = await file.DownloadTextAsync();

            this.txtcontenido.Text = contenido;
        }
Exemple #16
0
        private void WriteLogLine(WriteWay writeWay, string writeLogLine, params string[] logFilePath)
        {
            if (logFilePath.Length < 2)
            {
                Console.WriteLine(invalidExistLogFilePath);
                return;
            }

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                string.Format(@"DefaultEndpointsProtocol=https;AccountName={0};
                AccountKey={1};EndpointSuffix=core.windows.net",
                              Constant.LOGGER_ACCOUNT_NAME, Constant.Instance.StorageAccountKey));
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

            CloudFileShare share = fileClient.GetShareReference(logFilePath[0]);

            if (!share.Exists())
            {
                share.Create();
            }
            CloudFileDirectory sampleDir = share.GetRootDirectoryReference();

            for (int i = 1; i < logFilePath.Length - 1; i++)
            {
                CloudFileDirectory nextLevelDir = sampleDir.GetDirectoryReference("TestLogs");
                if (!sampleDir.Exists())
                {
                    sampleDir.Create();
                }
                sampleDir = nextLevelDir;
            }

            CloudFile file = sampleDir.GetFileReference(logFilePath[logFilePath.Length - 1]);

            string writenLineContent = "";

            if (file.Exists())
            {
                if (writeWay == WriteWay.Cover)
                {
                }
                else if (writeWay == WriteWay.Append)
                {
                    writenLineContent = file.DownloadTextAsync().Result;
                }
            }
            file.UploadText(writenLineContent + writeLogLine + "\n");
        }
Exemple #17
0
        static void Main(string[] args)
        {
            string accountname = "xxx";
            string accountkey  = "xxxxxxx";
            CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(accountname, accountkey), true);

            // Create a CloudFileClient object for credentialed access to Azure Files.
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

            // Get a reference to the file share.
            CloudFileShare share = fileClient.GetShareReference("s66");

            //if fileshare does not exist, create it.
            share.CreateIfNotExists();

            if (share.Exists())
            {
                // Get a reference to the root directory for the share.
                CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                // Get a reference to the directory.
                CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("CustomLogs");
                //if the directory does not exist, create it.
                sampleDir.CreateIfNotExists();

                if (sampleDir.Exists())
                {
                    // Get a reference to the file.
                    CloudFile file = sampleDir.GetFileReference("Log1.txt");

                    // if the file exists, read the content of the file.
                    if (file.Exists())
                    {
                        // Write the contents of the file to the console window.
                        Console.WriteLine(file.DownloadTextAsync().Result);
                    }
                    //if the file does not exist, create it with size == 500bytes
                    else
                    {
                        file.Create(500);
                    }
                }
            }

            Console.WriteLine("--file share test--");
            Console.ReadLine();
        }
    /// <summary>
    /// Get the Azure stored List and use the data retrieved to replicate a Shape creation pattern
    /// </summary>
    private async Task ReplicateListFromAzureAsync()
    {
        //Spawner.instance.shapeHistoryList = new List<int>();
        string azureTextFileContent = await shapeIndexCloudFile.DownloadTextAsync();

        string[] shapes = azureTextFileContent.Split(new char[] { ',' });
        foreach (string shape in shapes)
        {
            int i;
            Int32.TryParse(shape.ToString(), out i);
            ShapeFactory.instance.shapeHistoryList.Add(i);
            ShapeFactory.instance.CreateShape(i, true);
            await Task.Delay(500);
        }
        Gaze.instance.enableGaze = true;
        azureStatusText.text     = "Load Complete!";
    }
Exemple #19
0
        /// <inheritdoc />
        public string GetFileContent(string fileName, string[] path = null)
        {
            #region validation

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            #endregion

            CloudFileDirectory cloudFileDirectory = CloudFileShare.GetDirectoryReference(path: path);

            CloudFile cloudFile = cloudFileDirectory.GetFileReference(fileName);

            return(TaskUtilities.ExecuteSync(cloudFile.DownloadTextAsync()));
        }
Exemple #20
0
        public void SetFileStreamTest(string fileName, string[] path)
        {
            // Act
            using (var streamContent = new MemoryStream(Encoding.Default.GetBytes(FILE_CONTENT)))
            {
                _fileContainer.SetFileStream(fileName, streamContent, path);
            }

            CloudFileDirectory cloudFileDirectory = _cloudFileShare.GetDirectoryReference(path: path);

            CloudFile fileReference = cloudFileDirectory.GetFileReference(fileName);

            string result = TaskUtilities.ExecuteSync(fileReference.DownloadTextAsync());

            // Assert
            Assert.AreEqual(FILE_CONTENT, result);
        }
Exemple #21
0
        private static async Task <bool> FileOperations(string shareName)
        {
            try
            {
                var storageAccount = CloudStorageAccount.Parse(GetConnectionString());
                var fileClient     = storageAccount.CreateCloudFileClient();
                var share          = fileClient.GetShareReference(shareName);
                await share.CreateIfNotExistsAsync();

                // Create a new shared access policy and define its constraints.
                SharedAccessFilePolicy sharedPolicy = new SharedAccessFilePolicy()
                {
                    SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
                    Permissions            = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.Write
                };
                var permissions = await share.GetPermissionsAsync();

                permissions.SharedAccessPolicies.Add("SA Policy", sharedPolicy);
                await share.SetPermissionsAsync(permissions);

                // Generate a SAS for a file in the share and associate this access policy with it.
                var root      = share.GetRootDirectoryReference();
                var directory = root.GetDirectoryReference("logs");
                await directory.CreateIfNotExistsAsync();

                var file       = directory.GetFileReference("Log1.txt");
                var sasToken   = file.GetSharedAccessSignature(null, "SA Policy");
                Uri fileSasUri = new Uri(file.StorageUri.PrimaryUri.ToString() + sasToken);

                // Create a new CloudFile object from the SAS, and write some text to the file.
                CloudFile fileSas = new CloudFile(fileSasUri);
                await fileSas.UploadTextAsync("This write operation is authorized via SAS.");

                Console.WriteLine(await fileSas.DownloadTextAsync());

                await share.DeleteIfExistsAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(false);
        }
Exemple #22
0
        public static void OutputLogContent(params string[] logFilePath)
        {
            if (logFilePath.Length < 2)
            {
                Console.WriteLine(invalidExistLogFilePath);
                return;
            }
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                string.Format(@"DefaultEndpointsProtocol=https;AccountName={0};
                AccountKey={1};EndpointSuffix=core.windows.net",
                              Constant.LOGGER_ACCOUNT_NAME, Constant.Instance.StorageAccountKey));

            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

            CloudFileShare share = fileClient.GetShareReference(logFilePath[0]);

            if (!share.Exists())
            {
                Console.WriteLine(invalidExistLogFilePath);
                return;
            }
            CloudFileDirectory sampleDir = share.GetRootDirectoryReference();

            for (int i = 1; i < logFilePath.Length - 1; i++)
            {
                CloudFileDirectory nextLevelDir = sampleDir.GetDirectoryReference(logFilePath[i]);
                if (!sampleDir.Exists())
                {
                    Console.WriteLine(invalidExistLogFilePath);
                    return;
                }
                sampleDir = nextLevelDir;
            }

            CloudFile file = sampleDir.GetFileReference(logFilePath[logFilePath.Length - 1]);

            if (file.Exists())
            {
                Console.WriteLine(file.DownloadTextAsync().Result);
            }
            else
            {
                Console.WriteLine();
            }
        }
Exemple #23
0
        public async Task <ActionResult <string> > SaveData(FileParameters fileParams)
        {
            if (fileParams == null)
            {
                return(BadRequest());
            }
            try
            {
                ConnectParameters   connector  = Common.GetConnectParameters(connectionString, container, fileParams.DataConnector);
                CloudStorageAccount account    = CloudStorageAccount.Parse(connectionString);
                CloudFileClient     fileClient = account.CreateCloudFileClient();
                CloudFileShare      share      = fileClient.GetShareReference(fileParams.FileShare);
                if (share.Exists())
                {
                    CloudFileDirectory rootDir = share.GetRootDirectoryReference();
                    CloudFile          file    = rootDir.GetFileReference(fileParams.FileName);
                    if (file.Exists())
                    {
                        string    fileText = file.DownloadTextAsync().Result;
                        LASLoader ls       = new LASLoader(_env);
                        ls.LoadLASFile(connector, fileText);
                        //DbUtilities dbConn = new DbUtilities();
                        //dbConn.OpenConnection(connector);
                        //dbConn.SQLExecute(sql);
                        //dbConn.CloseConnection();
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }

            return(Ok($"OK"));
        }
Exemple #24
0
        private async void botonleerfile_Click(object sender, EventArgs e)
        {
            //NECESITAMOS LA CLAVE DE ACCESO A STORAGE
            String key = CloudConfigurationManager.GetSetting("storagecnnstring");
            //NECESITAMOS ACCEDER A TODA LA CUENTA CLOUR STORAGE
            //PARA PODER ACCEDER A FILE
            CloudStorageAccount account = CloudStorageAccount.Parse(key);
            //PARA ACCEDER A CUALQUIER RECURSO, SE REALIZA MEDIANTE
            //UN CLIENT ESPECIALIZADO
            CloudFileClient client = account.CreateCloudFileClient();
            //DEBEMOS ACCEDER AL RECURSO (SHARED) COMPARTIDO
            //QUE HEMOS CREADO EN STORAGE FILE
            CloudFileShare fileshare = client.GetShareReference("ejemplo");
            //LOS FICHEROS LOS TENEMOS DIRECTAMENTE EN LA RAIZ DEL SHARED
            CloudFileDirectory raiz      = fileshare.GetRootDirectoryReference();
            CloudFile          file      = raiz.GetFileReference("PENDIENTE.txt");
            String             contenido = await file.DownloadTextAsync();

            this.txtcontenido.Text = contenido;
        }
        public string Get(string shareName, string path, string fileName)
        {
            CloudStorageAccount storageAcc = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));

            CloudFileClient cloudFileClient = storageAcc.CreateCloudFileClient();
            CloudFileShare  share           = cloudFileClient.GetShareReference(shareName);

            try
            {
                if (share.Exists())
                {
                    CloudFileDirectory rootDir   = share.GetRootDirectoryReference();
                    CloudFileDirectory targetDir = rootDir.GetDirectoryReference(path);
                    if (targetDir.Exists())
                    {
                        CloudFile file = targetDir.GetFileReference(fileName);
                        if (file.Exists())
                        {
                            return(file.DownloadTextAsync().Result);
                        }
                        else
                        {
                            return("Invalid file name.");
                        }
                    }
                    else
                    {
                        return("Invalid directory");
                    }
                }
                else
                {
                    return("Invalid share.");
                }
            }
            catch (Exception ex) {
                return(ex.Message);
            }
        }
        public ActionResult <string> GetFileContent()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(@"DefaultEndpointsProtocol=https;AccountName=lab1diag679;AccountKey=TtymI1zwujPy40v9NvlAApX1o04SSA4Jnj2TAH4VvlnoOiPbCym4Rt9qLZwVRgeKgPIHskJBcRtcW0Rt9vxFZw==;EndpointSuffix=core.windows.net");
            CloudFileClient     fileClient     = storageAccount.CreateCloudFileClient();
            CloudFileShare      share          = fileClient.GetShareReference("lab1-fs");

            if (share.ExistsAsync().Result)
            {
                // Get a reference to the root directory for the share.
                CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                // Get a reference to the directory we created previously.
                CloudFile file = rootDir.GetFileReference("Test1.txt");

                if (file.ExistsAsync().Result)
                {
                    // Write the contents of the file to the console window.
                    return(file.DownloadTextAsync().Result);
                }
            }
            return("file not found");
        }
        public async Task <string> GetText()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_configuration.GetConnectionString("StorageAccount"));

            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

            CloudFileShare share = fileClient.GetShareReference(_configuration.GetSection("FileConfig:Folder").Value);

            if (await share.ExistsAsync())
            {
                CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                CloudFile file = rootDir.GetFileReference(_configuration.GetSection("FileConfig:Filename").Value);

                if (await file.ExistsAsync())
                {
                    var result = file.DownloadTextAsync().Result;
                }
            }

            return(string.Empty);
        }
Exemple #28
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Parse the connection string and return a reference to the storage account.
            // CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=personal5772156649;AccountKey=GPV82gR7e7+1woWq0MwIlVU6zrNg1OCE+9/+cY1vCWHE6gfXzzGvscGNxnTerRiiXToiu+Du0yGLcq0MF7kLRg==;EndpointSuffix=core.windows.net");

            // Create a CloudFileClient object for credentialed access to Azure Files.
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

            // Get a reference to the file share we created previously.
            CloudFileShare share = fileClient.GetShareReference("genrestxt");

            // Ensure that the share exists.
            if (share.Exists())
            {
                // Get a reference to the root directory for the share.
                CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                // Get a reference to the directory we created previously.
                CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("CustomLogs");

                // Ensure that the directory exists.
                if (sampleDir.Exists())
                {
                    // Get a reference to the file we created previously.
                    CloudFile file = sampleDir.GetFileReference("Log1.txt");

                    // Ensure that the file exists.
                    if (file.Exists())
                    {
                        // Write the contents of the file to the console window.
                        Console.WriteLine(file.DownloadTextAsync().Result);
                    }
                }
            }
        }
        public static void Main(string[] args)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
            CloudFileClient     fileClient     = storageAccount.CreateCloudFileClient();
            CloudFileShare      shareFile      = fileClient.GetShareReference("unit name or directory");

            if (shareFile.Exists())
            {
                CloudFileDirectory rootDirectory = shareFile.GetRootDirectoryReference();
                CloudFileDirectory directory     = rootDirectory.GetDirectoryReference("especific directory");

                if (directory.Exists())
                {
                    CloudFile file = directory.GetFileReference("file_name.extension");

                    if (file.Exists())
                    {
                        Console.WriteLine(file.DownloadTextAsync().Result);
                        Console.ReadLine();
                    }
                }
            }
        }
Exemple #30
0
        /// <summary>
        /// Async Method to get Data from Azure Cloud.
        /// </summary>
        /// <returns>String of the file.</returns>
        private async Task <string> GetData_Async()
        {
            string DataToShare = string.Empty;
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_ConnectionString);
            // Create a new file share, if it does not already exist.
            // Create a CloudFileClient object for credentialed access to File storage.
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
            CloudFileShare  share      = fileClient.GetShareReference(_DirectoryLocation);

            if (await share.ExistsAsync())
            {
                CloudFileDirectory rootDir = share.GetRootDirectoryReference();
                if (await rootDir.ExistsAsync())
                {
                    CloudFile FiletoUse = rootDir.GetFileReference(_FileName);
                    if (await FiletoUse.ExistsAsync())
                    {
                        DataToShare = await FiletoUse.DownloadTextAsync();
                    }
                }
            }
            return(DataToShare);
        }