c# - Minimizing code impact of migrating to Azure Blob storage -
i'm attempting migrate complex application windows azure. in both worker role , web role there many instances application saves files local file system.
here's example:
string thumbnailfilename = system.io.path.getdirectoryname(filename) + "\\" + "bthumb_" + system.io.path.getfilename(filename); thumbnail.save(thumbnailfilename);
and example:
using (system.io.streamwriter file = system.io.file.appendtext(getcurrentlogfilepath())) { string logentry = string.format("\r\n{0} - {1}: {2}", datetime.now.tostring("yyyy.mm.dd@hh.mm.ss"), type.tostring(), message); file.write(logentry); file.close(); }
in these examples saving images , log files file locations specified in app.config. here's example:
<add key="imagefiledirectory" value="c:\temp\foo\root\auth\inventorypictures"/>
i'd make few code changes possible support azure blob storage in case ever decide move more traditional hosting environment , more reduce potential creating unintended problems.
based on post i've decided azure drive not best way go.
can guide me in right direction (ideally example)? best solution in mind 1 requires change config file. i'm guessing not realistic.
indeed, want use azure blob storage save files.
as coding question, consider creating interface, call ifilestore:
public interface ifilestore { void save(string filepath, byte [] contents); byte [] read(string filepath); }
then create 2 provider classes, 1 file system, , 1 azure blob storage.
the file system provider can implement save function this:
public void save(string filepath, byte [] content) { file.writeallbytes(filepath, content); } public byte [] read(string filepath) { return file.readallbytes(filepath); }
as azure blob provider, have derive storage path based on filepath passed in you.
Comments
Post a Comment