Exemplo n.º 1
0
        public override Dictionary<string, Quota> GetQuotasForOrganization(string folderPath, string wmiUserName, string wmiPassword)
        {
            Log.WriteStart("GetQuotasLimitsForOrganization");

            // 05.09.2015 [email protected]
            // New: Add LogInfo
            Log.WriteInfo("FolderPath : {0}", folderPath);

            Runspace runSpace = null;
            Quota quota = null;
            var quotas = new Dictionary<string, Quota>();

            try
            {
                runSpace = OpenRunspace();

                Command cmd = new Command("Get-FsrmQuota");

                cmd.Parameters.Add("Path", folderPath + "\\*");
                var result = ExecuteShellCommand(runSpace, cmd, false);

                if (result.Count > 0)
                {
                    foreach (var element in result)
                    {
                        quota = new Quota();

                        quota.Size = ConvertBytesToMB(Convert.ToInt64(GetPSObjectProperty(element, "Size")));
                        quota.QuotaType = Convert.ToBoolean(GetPSObjectProperty(element, "SoftLimit")) ? QuotaType.Soft : QuotaType.Hard;
                        quota.Usage = ConvertBytesToMB(Convert.ToInt64(GetPSObjectProperty(element, "usage")));

                        quotas.Add(Convert.ToString(GetPSObjectProperty(element, "Path")), quota);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteError("GetQuotasLimitsForOrganization", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }

            Log.WriteEnd("GetQuotasLimitsForOrganization");

            return quotas;
        }
Exemplo n.º 2
0
        public override Quota GetQuotaOnFolder(string folderPath, string wmiUserName, string wmiPassword)
        {
            Log.WriteStart("GetQuotaLimitOnFolder");
            Log.WriteInfo("FolderPath : {0}", folderPath);

            Runspace runSpace = null;
            Quota quota = new Quota();

            try
            {
                runSpace = OpenRunspace();

                if (folderPath.IndexOfAny(Path.GetInvalidPathChars()) == -1)
                {
                    Command cmd = new Command("Get-FsrmQuota");
                    cmd.Parameters.Add("Path", folderPath);
                    var result = ExecuteShellCommand(runSpace, cmd, false);

                    if (result.Count > 0)
                    {
                        quota.Size = ConvertBytesToMB(Convert.ToInt64(GetPSObjectProperty(result[0], "Size")));
                        quota.QuotaType = Convert.ToBoolean(GetPSObjectProperty(result[0], "SoftLimit")) ? QuotaType.Soft : QuotaType.Hard;
                        quota.Usage = ConvertBytesToMB(Convert.ToInt64(GetPSObjectProperty(result[0], "usage")));
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteError("GetQuotaLimitOnFolder", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }

            Log.WriteEnd("GetQuotaLimitOnFolder");

            return quota;
        }