Exemplo n.º 1
0
 public AzureFileSystemNode(AzureFileSystemNode parent,
     string path, NodeType type)
 {
     if (parent == null) // root dir
         this.parent = this;
     else
         this.parent = parent;
     this.name = path; //absolute path
     this.type = type;
     /* no children inserted yet */
     if (type == NodeType.DIRECTORY)
     {
         this.children = new Dictionary<string, AzureFileSystemNode>();
         this.children["."] = this;
         this.children[".."] = this.parent;
     }
     else
         this.children = null;
 }
Exemplo n.º 2
0
 public AzureFileSystem()
 {
     _initialized = false;
     _rootPath = null;
     _rootNode = null;
 }
Exemplo n.º 3
0
        /* format device */
        public void initialize(string id)
        {
            /* file system already initialized, return ASAP */
            if (_initialized == true)
            {
                return;
            }

            /*
             * no need to synchronize,
             * since when intialize the file system, only one process/thread
             * is active
             */
            try
            {
                Microsoft.WindowsAzure.CloudStorageAccount.
                    SetConfigurationSettingPublisher(
                        (configName, configSetter) =>
                        {
                            configSetter(RoleEnvironment.
                                GetConfigurationSettingValue(configName));
                        }
                    );
                var storageAccount =
                    CloudStorageAccount.FromConfigurationSetting(
                    "DataConnectionString");
                var client = storageAccount.CreateCloudBlobClient();
                /* get root path, create if not exists */
                var user_container = client.GetContainerReference("user");
                var blob = user_container.GetBlobReference("user/container/"+id);
                _rootPath = client.GetContainerReference(blob.DownloadText());
                _rootPath.CreateIfNotExist();
                Stream root = new MemoryStream();
                var root_blob = _rootPath.GetBlockBlobReference("/");
                root_blob.Properties.ContentType = AFS_BINARY_MODE;
                root_blob.UploadFromStream(root);
                root.Close();

            //            CloudBlockBlob blob = _rootPath.GetBlockBlobReference("a/");
            //           blob.Properties.ContentType = "application/octet-stream";
            //            Stream a = new MemoryStream();
            //            blob.UploadFromStream(a);
            //            a.Close();

                /* create root node */
                _rootNode = new AzureFileSystemNode(null, AFS_ROOT,
                    NodeType.DIRECTORY);

            }
            catch (WebException e)
            {
                System.Diagnostics.Trace.TraceError(
                    "An error occurs while intializing Azure file system. {0}",
                    e.Message);
            }

            _initialized = true;
            System.Diagnostics.Trace.TraceInformation(
                "Azure file system format complete!");
        }