4

私のアプリケーションはMicrosoftAzureクラウドBLOBストレージを使用しており、コンテナー内のフォルダー内の最後のアイテムを取得する別の方法を探しています。

これが今の状況です。

CloudBlobClient blobClient = new CloudBlobClient("http://ferryjongmans.blob.core.windows.net/", new StorageCredentialsSharedAccessSignature(signature.Text));
CloudBlobContainer container = blobClient.GetContainerReference(cameraList.Items[Convert.ToInt32(Label1.Text)].ToString());

//Maak mooie datum notatie zoals : 01-01-2013 (standaard methode geeft in dit geval: 1-1-2013)
string dag = DateTime.Now.Day.ToString();
if (dag.Length == 1)
{
    string temp = dag;
    dag = "0" + temp;
}
string maand = DateTime.Now.Month.ToString();
if (maand.Length == 1)
{
    string temp = maand;
    maand = "0" + temp;
}
//Complete datum (DD-MM-YYYY)
string datum = dag + "-" + maand + "-" + DateTime.Now.Year.ToString();

CloudBlobDirectory direct = container.GetDirectoryReference(cameraList.Items[Convert.ToInt32(Label1.Text)].ToString());
CloudBlobDirectory subdir = direct.GetSubdirectory(datum);

BlobRequestOptions options = new BlobRequestOptions();
options.UseFlatBlobListing = true;
options.BlobListingDetails = BlobListingDetails.Snapshots;
//maak string voor het tijdelijk oplaan van de uri
string uri="";
//Ken steeds een waarde aan 'uri' toe om vervolgens wanneer de for loop klaar is
//de laatste uri te krijgen.
foreach (var blobItem in subdir.ListBlobs(options))
{
    uri = blobItem.Uri.ToString();
}
string url = uri + signature.Text;
if (url != pictureBox2.ImageUrl)
{
    loadImage(url);
}

そのため、アイテムをループして、毎回同じ文字列を使用してblobのURIを割り当てています。ループが終了すると、私の文字列にはディレクトリの最後のアイテムのURIが含まれます。

私はこれをより効率的な方法で行うことができると思います。ディレクトリにはたくさんのblobがあります。(+-30000)

このコードは1秒に1回実行されるため、効率的な方法で実行されることが重要です。

4

3 に答える 3

0

リストをhashSetに変換するとどうなりますか?これについてforeachを変更し、何が起こったかを確認します

 var hashSet = new HashSet<IListBlobItem>(subdir.ListBlobs(options).ToList());

 string url = uri = hashSet.Last().Uri.ToString() + signature.Text;

hashSetは、検索と検索が高速です。

于 2013-02-19T21:35:26.453 に答える
0

アップロードアプリケーションで、最新の画像の完全なURIをテキストファイル(txt)に毎回書き込む関数を作成しました。

                CloudBlobClient blobClient = new CloudBlobClient(sUrl, new StorageCredentialsSharedAccessSignature(signature));
                CloudBlobContainer container = blobClient.GetContainerReference(container1);
                CloudBlobDirectory dir = container.GetDirectoryReference(cameranaam);
                CloudBlob cloudBlob = dir.GetBlobReference(cameranaam+".txt");
                cloudBlob.UploadText(blobSAS.Uri.ToString());

そして、これはサーバーの最後のイメージをロードしている他のプロジェクトのタイマーです。

            blobClient = new CloudBlobClient(blobstoreurl, new StorageCredentialsSharedAccessSignature(signature));
            container = blobClient.GetContainerReference(containerName);
            CloudBlobDirectory dir = container.GetDirectoryReference(comboBoxCameras.SelectedItem.ToString());
            CloudBlob cloudBlob = dir.GetBlobReference(comboBoxCameras.SelectedItem.ToString().Replace(" ","")+".txt");
            pictureBoxLiveViewer.ImageLocation = cloudBlob.DownloadText()+signature;
于 2013-02-20T14:27:29.217 に答える
0

受け入れられた答えは混乱し、説明が不十分だと思います。私の好みは次のとおりです。

一時ファイルを作成するには(つまり、名前によってコンテキストが与えられます)、Azure Blob Storage仮想ディレクトリを使用し、特にSecondssinceEpochを使用してblobに名前を付けます

例として、パスが「SomeContainer /SomeFolder/」のディレクトリがあるとします。このディレクトリには、上記の「エポック以降の秒数」を使用して名前が付けられた1つ以上のファイルが含まれています。「最後の」または最新のファイルをフェッチするには、次を使用します。

StorageCredentials cred = new StorageCredentials("{{YOUR ACCOUNT NAME}}", ""{{YOUR ACCOUNT KEY}}");
CloudStorageAccount storageAccount = new CloudStorageAccount(cred, true);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); //invoke the blob client
CloudBlobContainer container = blobClient.GetContainerReference("SomeContainer"); //get your container reference
CloudBlobDirectory directory = container.GetDirectoryReference("SomeFolder"); //resolve the directory
IListBlobItem latestBlobItem = directory.ListBlobs(true, BlobListingDetails.All).LastOrDefault(); //get the latest blobItem
CloudBlockBlob blockBlob = null;

if(latestBlobItem != null && !String.IsNullOrWhiteSpace(latestBlobItem.Uri.LocalPath))
{
    //get the blob's local path
    string fullLocalPath = latestBlobItem.Uri.LocalPath;
    //remove container and leading slash
    string localPath = fullLocalPath.Substring(fullLocalPath.IndexOf('/', 1) + 1);

    //get your blob reference 
    blockBlob = container.GetBlockBlobReference(localPath);
}

そこから、ブロックBLOBリファレンス(ダウンロードなど)を使用して、必要に応じて実行します。

ハッピーブロビング!

于 2016-02-17T17:10:03.503 に答える