0

In order to charge appropriately for resource usage, i.e. database storage, we need to know the size of our client's files. Is there a simple way to calculate the resource usage for client's Workspace?

Thane Plummer
  • 7,966
  • 3
  • 26
  • 30

1 Answers1

2

If you just want to know the size of the files in the workspace, you can use the funciton below, although total resource usage is likely much higher.

Calculate file size -- useful, but not close to total storage.

public static int DocumentFileSizeMB(string path)
{
    var size = 0;

    var results = ContentQuery.Query(SafeQueries.TypeInTree, null, "File", path);
    if (results != null && results.Count > 0)
    {
        var longsize = results.Nodes.Sum(n => n.GetFullSize());
        size = (int)(longsize / 1000000);
    }

    return size;
}

To get a better idea of storage space resources, call the SenseNet function GetTreeSize() on a node. However, this doesn't give the full resource usage due to other content that is related to the node size calcuation, but not stored beneath the node, such as Index tables, Log entries, etc.

A better method, but still not the full resource usage.

public static int NodeStorageSizeMB(string path)
{
    var size = 0;

    var node = Node.LoadNode(path);
    if (node != null)
    {
        size = (int)(node.GetTreeSize() / 1000000); // Use 10**6 as Mega, not 1024*1024, which is "mebibyte".
    }

    return size;
}
Thane Plummer
  • 7,966
  • 3
  • 26
  • 30