Example #1
0
        public override void SetQuotaLimitOnFolder(string folderPath, string shareNameDrive, QuotaType quotaType, string quotaLimit, int mode, string wmiUserName, string wmiPassword)
        {
            Log.WriteStart("SetQuotaLimitOnFolder");
            Log.WriteInfo("FolderPath : {0}", folderPath);
            Log.WriteInfo("QuotaLimit : {0}", quotaLimit);

            string path = folderPath;

            if (shareNameDrive != null)
                path = Path.Combine(shareNameDrive + @":\", folderPath);

            Runspace runSpace = null;
            try
            {
                runSpace = OpenRunspace();

                if (path.IndexOfAny(Path.GetInvalidPathChars()) == -1)
                {
                    if (!FileUtils.DirectoryExists(path))
                        FileUtils.CreateDirectory(path);

                    if (quotaLimit.Contains("-"))
                    {
                        RemoveOldQuotaOnFolder(runSpace, path);
                    }
                    else
                    {
                        var quota = CalculateQuota(quotaLimit);

                        switch (mode)
                        {
                            //deleting old quota and creating new one
                            case 0:
                                {
                                    RemoveOldQuotaOnFolder(runSpace, path);
                                    ChangeQuotaOnFolder(runSpace, "New-FsrmQuota", path, quotaType, quota);
                                    break;
                                }
                            //modifying folder quota
                            case 1:
                                {
                                    ChangeQuotaOnFolder(runSpace, "Set-FsrmQuota", path, quotaType, quota);
                                    break;
                                }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteError("SetQuotaLimitOnFolder", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }

            Log.WriteEnd("SetQuotaLimitOnFolder");
        }
Example #2
0
        public void UpdateFolderQuota(string fullPath, long qouteSizeBytes, QuotaType quotaType)
        {
            var driveLetter            = Path.GetPathRoot(fullPath);
            var pathWithoutDriveLetter = fullPath.Replace(driveLetter, string.Empty);

            driveLetter = driveLetter.Replace(":\\", string.Empty);

            SetQuotaLimitOnFolder(pathWithoutDriveLetter, driveLetter, quotaType, (qouteSizeBytes / (1024 * 1024)).ToString() + "MB", 0, String.Empty, String.Empty);
        }
Example #3
0
        public UserQuota GetUserQuota(string uid, string tenant = null, QuotaType quotaType = QuotaType.User, TimeSpan?timeout = null)
        {
            var parameters = new Dictionary <string, string>
            {
                { "uid", UserWithTenant(uid, tenant) },
                { "quota-type", quotaType.ToString().ToLower() },
            };

            var rets = SendRequest("GET", "/user?quota", parameters, timeout);

            return(JsonConvert.DeserializeObject <UserQuota>(rets));
        }
        public HttpResponseMessage quata_typemanage()
        {
            try
            {
                string ManageAnimalSupplier = HttpContext.Current.Request.Form["manageanimalsupplieroid"].ToString();
                //      string animalSupplieOid = HttpContext.Current.Request.Form["animalSupplieOid"].ToString();
                string quotatypeoid = HttpContext.Current.Request.Form["quotatypeoid"].ToString();
                XpoTypesInfoHelper.GetXpoTypeInfoSource();
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageAnimalSupplier));
                XafTypesInfo.Instance.RegisterEntity(typeof(QuotaType));
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageSubAnimalSupplier));
                XafTypesInfo.Instance.RegisterEntity(typeof(AnimalSupplie));
                XPObjectSpaceProvider           directProvider = new XPObjectSpaceProvider(scc, null);
                IObjectSpace                    ObjectSpace    = directProvider.CreateObjectSpace();
                List <objManageAnimalSupplier>  listdetail     = new List <objManageAnimalSupplier>();
                ManageAnimalSupplier_Modelinfo2 item           = new ManageAnimalSupplier_Modelinfo2();
                QuotaType objQuotaType = ObjectSpace.FindObject <QuotaType>(CriteriaOperator.Parse(" GCRecord is null and  oid = ? ", quotatypeoid));
                IList <ManageSubAnimalSupplier> objmanageSubAnimalSupplier = ObjectSpace.GetObjects <ManageSubAnimalSupplier>(CriteriaOperator.Parse("ProvinceOid.OrganizationOid= '" + ManageAnimalSupplier + "' ", null));
                ManageSubAnimalSupplier         manageanimalsupplie        = ObjectSpace.FindObject <ManageSubAnimalSupplier>(CriteriaOperator.Parse(" GCRecord is null and  [ProvinceOid.OrganizationOid]= ? ", ManageAnimalSupplier));
                if (objQuotaType.QuotaName == "โควตาปศุสัตว์จังหวัด")
                {
                    QuotaType_Model itemquota = new QuotaType_Model();
                    item.QuotaName = objQuotaType.QuotaName;
                    //item.OrganizationOid = manageanimalsupplie.ManageAnimalSupplierOid.OrganizationOid.Oid.ToString();
                    //item.Organizationname = manageanimalsupplie.ManageAnimalSupplierOid.OrganizationOid.SubOrganizeName;

                    foreach (ManageSubAnimalSupplier row in objmanageSubAnimalSupplier)
                    {
                        objManageAnimalSupplier detail = new objManageAnimalSupplier();
                        detail.ProvinceOid  = row.ProvinceOid.Oid.ToString();
                        detail.Provincename = row.ProvinceOid.ProvinceNameTH;
                        listdetail.Add(detail);
                    }
                    item.detail = listdetail;
                }
                else
                {
                    item.QuotaName = objQuotaType.QuotaName;
                }

                return(Request.CreateResponse(HttpStatusCode.OK, item));
            }

            catch (Exception ex)
            {                   //Error case เกิดข้อผิดพลาด
                UserError err = new UserError();
                err.code = "6"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ

                err.message = ex.Message;
                //  Return resual
                return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
            }
        }
        public StorageSpaceFolder CreateFolder(string organizationId, int itemId, string type, long quotaInBytes, QuotaType qoutaType)
        {
            var folder = StorageSpacesController.CreateStorageSpaceFolder(ResourceGroups.HostedOrganizations, organizationId, type, quotaInBytes, qoutaType);

            if (!folder.IsSuccess)
            {
                throw new Exception(string.Join("---------------------------------------", folder.ErrorCodes));
            }

            DataProvider.AddOrganizationStoragSpacesFolder(itemId, type, folder.Value);

            return StorageSpacesController.GetStorageSpaceFolderById(folder.Value);
        }
Example #6
0
 public void SetQuotaLimitOnFolder(string folderPath, string shareNameDrive, QuotaType quotaType, string quotaLimit, int mode, string wmiUserName, string wmiPassword)
 {
     try
     {
         Log.WriteStart("'{0}' SetQuotaLimitOnFolder", ProviderSettings.ProviderName);
         OsProvider.SetQuotaLimitOnFolder(folderPath, shareNameDrive, quotaType, quotaLimit, mode, wmiUserName, wmiPassword);
         Log.WriteEnd("'{0}' SetQuotaLimitOnFolder", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' SetQuotaLimitOnFolder", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
 public void UpdateFolderQuota(string fullPath, long qouteSizeBytes, QuotaType type)
 {
     try
     {
         Log.WriteStart("'{0}' UpdateFolderQuota", ProviderSettings.ProviderName);
         StorageSpaceProvider.UpdateFolderQuota(fullPath, qouteSizeBytes, type);
         Log.WriteEnd("'{0}' UpdateFolderQuota", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' UpdateFolderQuota", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
 public void UpdateStorageSettings(string fullPath, long qouteSizeBytes, QuotaType type)
 {
     try
     {
         Log.WriteStart("'{0}' UpdateStorageSettings", ProviderSettings.ProviderName);
         StorageSpaceProvider.UpdateStorageSettings(fullPath, qouteSizeBytes, type);
         Log.WriteEnd("'{0}' UpdateStorageSettings", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' UpdateStorageSettings", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
        /// <summary>
        /// Инициализация таблицы "Типы квот для приёма абитуриентов"
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static async Task CreateQuotaTypes(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            using (var serviceScope = serviceProvider.GetRequiredService <Microsoft.Extensions.DependencyInjection.IServiceScopeFactory>().CreateScope())
            {
                AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>();

                #region Инициализация таблицы "Типы квот"
                if (!await context.QuotaTypes.AnyAsync())
                {
                    var row01 = new QuotaType
                    {
                        QuotaTypeId   = (int)QuotaTypesEnum.OsoboePravo,
                        QuotaTypeName = "Места в пределах квоты приёма лиц, имеющих особое право"
                    };

                    var row02 = new QuotaType
                    {
                        QuotaTypeId   = (int)QuotaTypesEnum.CelevoyPriem,
                        QuotaTypeName = "Места в пределах квоты целевого приёма"
                    };

                    var row03 = new QuotaType
                    {
                        QuotaTypeId   = (int)QuotaTypesEnum.KontrolnieCifri,
                        QuotaTypeName = "Основные места в рамках контрольных цифр"
                    };

                    var row04 = new QuotaType
                    {
                        QuotaTypeId   = (int)QuotaTypesEnum.DogovorObOkazaniiPlatnihObrazovatUslug,
                        QuotaTypeName = "Места по договорам об оказании платных образовательных услуг"
                    };

                    await context.QuotaTypes.AddRangeAsync(
                        row01,
                        row02,
                        row03,
                        row04
                        );

                    await context.SaveChangesAsync();
                }
                #endregion
            }
        }
Example #10
0
 public void SetEnterpriseFolderGeneralSettings(int itemId, SystemFile folder, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
 {
     EnterpriseStorageController.SetESGeneralSettings(itemId, folder, directoyBrowsingEnabled, quota, quotaType);
 }
Example #11
0
 public ResultObject CreateEnterpriseFolder(int itemId, string folderName, int quota, QuotaType quotaType, bool addDefaultGroup)
 {
     return(EnterpriseStorageController.CreateFolder(itemId, folderName, quota, quotaType, addDefaultGroup));
 }
Example #12
0
        public void UpdateStorageSettings(string fullPath, long qouteSizeBytes, QuotaType type)
        {
            UpdateFolderQuota(fullPath, qouteSizeBytes, type);

            AddPathToSearchIndex(fullPath);
        }
 /// <remarks/>
 public void UpdateFolderQuotaAsync(string fullPath, long qouteSizeBytes, QuotaType type, object userState) {
     if ((this.UpdateFolderQuotaOperationCompleted == null)) {
         this.UpdateFolderQuotaOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateFolderQuotaOperationCompleted);
     }
     this.InvokeAsync("UpdateFolderQuota", new object[] {
                 fullPath,
                 qouteSizeBytes,
                 type}, this.UpdateFolderQuotaOperationCompleted, userState);
 }
Example #14
0
        public static void AssertValidUsage(LicenseFeature feature, QuotaType quotaType, int count)
        {
            //去掉所有的License的限制https://servicestack.net/download
            //xupearl
            return;

            var licensedFeatures = ActivatedLicenseFeatures();

            if ((LicenseFeature.All & licensedFeatures) == LicenseFeature.All) //Standard Usage
            {
                return;
            }

            if (AccessTokenScope != null)
            {
                if ((feature & AccessTokenScope.tempFeatures) == feature)
                {
                    return;
                }
            }

            //Free Quotas
            switch (feature)
            {
            case LicenseFeature.Text:
                switch (quotaType)
                {
                case QuotaType.Types:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.TextTypes, count, ErrorMessages.ExceededTextTypes);
                    return;
                }
                break;

            case LicenseFeature.Redis:
                switch (quotaType)
                {
                case QuotaType.Types:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.RedisTypes, count, ErrorMessages.ExceededRedisTypes);
                    return;

                case QuotaType.RequestsPerHour:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.RedisRequestPerHour, count, ErrorMessages.ExceededRedisRequests);
                    return;
                }
                break;

            case LicenseFeature.OrmLite:
                switch (quotaType)
                {
                case QuotaType.Tables:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.OrmLiteTables, count, ErrorMessages.ExceededOrmLiteTables);
                    return;
                }
                break;

            case LicenseFeature.ServiceStack:
                switch (quotaType)
                {
                case QuotaType.Operations:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.ServiceStackOperations, count, ErrorMessages.ExceededServiceStackOperations);
                    return;
                }
                break;

            case LicenseFeature.Admin:
                switch (quotaType)
                {
                case QuotaType.PremiumFeature:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.PremiumFeature, count, ErrorMessages.ExceededAdminUi);
                    return;
                }
                break;

            case LicenseFeature.Premium:
                switch (quotaType)
                {
                case QuotaType.PremiumFeature:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.PremiumFeature, count, ErrorMessages.ExceededPremiumFeature);
                    return;
                }
                break;
            }

            throw new LicenseException("Unknown Quota Usage: {0}, {1}".Fmt(feature, quotaType));
        }
Example #15
0
 public static ResultObject SetStorageSpaceFolderQuota(int storageSpaceId, int storageSpaceFolderId, long quotaInBytes, QuotaType quotaType)
 {
     return(SetStorageSpaceFolderQuotaInternal(storageSpaceId, storageSpaceFolderId, quotaInBytes, quotaType));
 }
Example #16
0
 public static IntResult CreateStorageSpaceFolder(int storageSpaceId, string groupName, string organizationId, string folderName, long quotaInBytes, QuotaType quotaType)
 {
     return(CreateStorageSpaceFolderInternal(storageSpaceId, groupName, organizationId, folderName, quotaInBytes, quotaType));
 }
 public void SetQuotaLimitOnFolder(string folderPath, string shareNameDrive, QuotaType quotaType, string quotaLimit, int mode, string wmiUserName, string wmiPassword)
 {
     try
     {
         Log.WriteStart("'{0}' SetQuotaLimitOnFolder", ProviderSettings.ProviderName);
         OsProvider.SetQuotaLimitOnFolder(folderPath, shareNameDrive, quotaType, quotaLimit, mode, wmiUserName, wmiPassword);
         Log.WriteEnd("'{0}' SetQuotaLimitOnFolder", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' SetQuotaLimitOnFolder", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
Example #18
0
        public void UpdateFolderQuota(string fullPath, long qouteSizeBytes, QuotaType quotaType)
        {
            var driveLetter = Path.GetPathRoot(fullPath);
            var pathWithoutDriveLetter = fullPath.Replace(driveLetter, string.Empty);
            driveLetter = driveLetter.Replace(":\\", string.Empty);

            SetQuotaLimitOnFolder(pathWithoutDriveLetter, driveLetter, quotaType, (qouteSizeBytes / (1024 * 1024)).ToString() + "MB", 0, String.Empty, String.Empty);
        }
Example #19
0
        public void UpdateStorageSettings(string fullPath, long qouteSizeBytes, QuotaType type)
        {
            UpdateFolderQuota(fullPath, qouteSizeBytes, type);

            AddPathToSearchIndex(fullPath);
        }
Example #20
0
        [Route("ManageSubAnimalSupplierList_Quantity")]   ///เรียกโควต้า แห้ง   หมัก สด tmr
        public HttpResponseMessage ManageAnimalSupplierList_Quantity()
        {
            ManageQuantity item                  = new ManageQuantity();
            string         orgOid                = null;
            string         ProvinceOid           = null;
            string         managesuboid          = null;
            string         quotatypeoid          = null;
            string         animalsuppliertypeoid = null;
            string         seedtypeoid           = null;

            try
            {
                string scc = ConfigurationManager.ConnectionStrings["scc"].ConnectionString.ToString();
                if (HttpContext.Current.Request.Form["orgoid"] != null)
                {
                    orgOid = HttpContext.Current.Request.Form["orgoid"].ToString();
                }
                string ManageSubAnimalSupplierOid = null;
                if (HttpContext.Current.Request.Form["provinceOid"] != null)
                {
                    ProvinceOid = HttpContext.Current.Request.Form["provinceOid"].ToString();
                }
                if (HttpContext.Current.Request.Form["managesuboid"] != null)
                {
                    managesuboid = HttpContext.Current.Request.Form["managesuboid"].ToString();
                }
                if (HttpContext.Current.Request.Form["quotatypeoid"] != null)
                {
                    quotatypeoid = HttpContext.Current.Request.Form["quotatypeoid"].ToString();
                }


                string budgetsourceoid   = HttpContext.Current.Request.Form["budgetsourceoid"].ToString();
                string animalsupplieroid = HttpContext.Current.Request.Form["animalsupplieroid"].ToString();
                if (HttpContext.Current.Request.Form["animalsuppliertypeoid"] != null)
                {
                    animalsuppliertypeoid = HttpContext.Current.Request.Form["animalsuppliertypeoid"].ToString();
                }
                if (HttpContext.Current.Request.Form["seedtypeoid"] != null)
                {
                    seedtypeoid = HttpContext.Current.Request.Form["seedtypeoid"].ToString();
                }
                else
                {
                    seedtypeoid = null;
                }


                ///โควตา
                //ManageSubAnimalSupplierOid, string QuotaTypeOid, string BudgetSourceOid
                XpoTypesInfoHelper.GetXpoTypeInfoSource();
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageSubAnimalSupplier));
                XafTypesInfo.Instance.RegisterEntity(typeof(QuotaType));
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageAnimalSupplier));
                XafTypesInfo.Instance.RegisterEntity(typeof(SeedType));
                XafTypesInfo.Instance.RegisterEntity(typeof(AnimalSupplieType));
                XafTypesInfo.Instance.RegisterEntity(typeof(AnimalSupplie));
                List <ManageAnimalSupplier_Model2> list     = new List <ManageAnimalSupplier_Model2>();
                List <ManageQuantity>          listQuantity = new List <ManageQuantity>();
                List <objManageAnimalSupplier> listdetail   = new List <objManageAnimalSupplier>();
                ManageQuantity        listQuantity2         = new ManageQuantity();
                XPObjectSpaceProvider directProvider        = new XPObjectSpaceProvider(scc, null);
                IObjectSpace          ObjectSpace           = directProvider.CreateObjectSpace();
                double balanceQTY = 0.0;


                ManageAnimalSupplier objManageAnimalSupplierOid = ObjectSpace.FindObject <ManageAnimalSupplier>(CriteriaOperator.Parse("[OrganizationOid]=?", orgOid));
                AnimalSupplie        objAnimalSupplie           = ObjectSpace.FindObject <AnimalSupplie>(CriteriaOperator.Parse("[oid] =? ", animalsupplieroid));
                if (objAnimalSupplie.AnimalSupplieName == "แห้ง")
                {
                    QuotaType objQuotaType = ObjectSpace.FindObject <QuotaType>(CriteriaOperator.Parse("[Oid]=?", quotatypeoid));
                    if (objQuotaType != null)
                    {
                        if (objQuotaType.QuotaName != "โควตาปศุสัตว์จังหวัด")
                        {
                            ManageAnimalSupplier objManageAnimalSupplier = ObjectSpace.FindObject <ManageAnimalSupplier>(CriteriaOperator.Parse("[OrganizationOid] =? and Status = 1", orgOid));
                            if (objManageAnimalSupplier != null)
                            {
                                if (objQuotaType.QuotaName == "โควตาปศุสัตว์เขต")
                                {
                                    listQuantity2.QuotaName = objQuotaType.QuotaName;
                                    listQuantity2.QuotaQTY  = objManageAnimalSupplier.ZoneQTY;
                                }
                                else if (objQuotaType.QuotaName == "โควตาอื่นๆ")
                                {
                                    listQuantity2.QuotaName = objQuotaType.QuotaName;
                                    listQuantity2.QuotaQTY  = objManageAnimalSupplier.OtherQTY;
                                }
                                else if (objQuotaType.QuotaName == "โควตาศูนย์ฯ")
                                {
                                    listQuantity2.QuotaName = objQuotaType.QuotaName;
                                    listQuantity2.QuotaQTY  = objManageAnimalSupplier.CenterQTY;
                                }
                                else if (objQuotaType.QuotaName == "โควตาสำนัก")
                                {
                                    listQuantity2.QuotaName = objQuotaType.QuotaName;
                                    SeedType          objSeedType          = ObjectSpace.FindObject <SeedType>(CriteriaOperator.Parse("[Oid]=?", seedtypeoid));
                                    AnimalSupplieType objAnimalSupplieType = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[Oid]=?", animalsuppliertypeoid));
                                    if (objSeedType != null && objAnimalSupplieType != null)
                                    {
                                        if (objSeedType.SeedTypeName == "GAP" && objAnimalSupplieType.SupplietypeName == "หญ้าแห้ง")
                                        {
                                            listQuantity2.QuotaQTY = objManageAnimalSupplier.OfficeGAPQTY;
                                        }
                                        else if (objSeedType.SeedTypeName.ToLower() == "normal" && objAnimalSupplieType.SupplietypeName == "หญ้าแห้ง")
                                        {
                                            listQuantity2.QuotaQTY = objManageAnimalSupplier.OfficeQTY;
                                        }
                                        else if (objSeedType.SeedTypeName.ToLower() == "normal" && objAnimalSupplieType.SupplietypeName == "ถั่วแห้ง")
                                        {
                                            listQuantity2.QuotaQTY = objManageAnimalSupplier.OfficeBeanQTY;
                                        }
                                        else if (objSeedType.SeedTypeName.ToLower() == "oganic")
                                        {
                                            listQuantity2.QuotaQTY = 0;
                                        }
                                    }
                                }
                            }
                        }
                        else //โควตาจังหวัด
                        {
                            listQuantity2.QuotaName = objQuotaType.QuotaName;
                            ManageSubAnimalSupplier objManageSubAnimalSupplier = ObjectSpace.FindObject <ManageSubAnimalSupplier>(CriteriaOperator.Parse("[ManageAnimalSupplierOid] =? and [ProvinceOid]=?  ", objManageAnimalSupplierOid.Oid, ProvinceOid));
                            if (objManageSubAnimalSupplier != null)
                            {
                                listQuantity2.QuotaQTY     = objManageSubAnimalSupplier.ProvinceQTY;
                                ManageSubAnimalSupplierOid = objManageSubAnimalSupplier.Oid.ToString();
                                listQuantity2.Provincename = objManageSubAnimalSupplier.ProvinceOid.ProvinceNameTH;
                            }
                        }

                        //Get StockUsed
                        DataSet Ds = null;
                        if (managesuboid != null && managesuboid.ToString() != "")
                        {
                            Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "GetStockUsed_QuotaHay_Province"
                                                          , new SqlParameter("@OrganizationOid", orgOid)
                                                          , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                          , new SqlParameter("@QuotaTypeOid", quotatypeoid)
                                                          , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                          , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                          , new SqlParameter("@ManageSubAnimalSupplierOid", ManageSubAnimalSupplierOid)
                                                          , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        }
                        else
                        {
                            Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "GetStockUsed_QuotaHay"
                                                          , new SqlParameter("@OrganizationOid", orgOid.ToString())
                                                          , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid.ToString())
                                                          , new SqlParameter("@QuotaTypeOid", quotatypeoid.ToString())
                                                          , new SqlParameter("@BudgetSourceOid", budgetsourceoid.ToString())
                                                          , new SqlParameter("@AnimalSupplieOid", animalsupplieroid.ToString())
                                                          , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        }
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            //listQuantity2.ba = (double)Ds.Tables[0].Rows[0]["StockUsed"];
                            listQuantity2.balancQuotaQTY = listQuantity2.QuotaQTY - (double)Ds.Tables[0].Rows[0]["StockUsed"];
                            listQuantity2.StockUsed      = (double)Ds.Tables[0].Rows[0]["StockUsed"];
                        }
                        else
                        {
                            //listQuantity2.QuotaQTY = 0;
                            listQuantity2.balanceQTY     = 0;
                            listQuantity2.balancQuotaQTY = 0;
                        }

                        Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo"
                                                      , new SqlParameter("@OrganizationOid", orgOid)
                                                      , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                      , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                      , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                      , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            listQuantity2.balanceQTY = (double)Ds.Tables[0].Rows[0]["Total_StockAnimalInfo"];
                        }
                        else
                        {
                            listQuantity2.balanceQTY = 0;
                        }
                    }
                    else //QuotaType = null
                    {
                        listQuantity2.QuotaQTY       = 0; //ปริมาณตามแผนจัดสรร
                        listQuantity2.balanceQTY     = 0; //จำนวนคงเหลือตามจริง
                        listQuantity2.balancQuotaQTY = 0; //ปริมาณคงเหลือตามแผนจัดสรร
                    }

                    listQuantity.Add(listQuantity2);
                }
                else
                {
                    // string scc = ConfigurationManager.ConnectionStrings["scc"].ConnectionString.ToString();
                    orgOid = HttpContext.Current.Request.Form["orgoid"].ToString();
                    //   string quotatypeoid = HttpContext.Current.Request.Form["quotatypeoid"].ToString();
                    budgetsourceoid   = HttpContext.Current.Request.Form["budgetsourceoid"].ToString();
                    animalsupplieroid = HttpContext.Current.Request.Form["animalsupplieroid"].ToString();
                    if (HttpContext.Current.Request.Form["animalsuppliertypeoid"] != null)
                    {
                        animalsuppliertypeoid = HttpContext.Current.Request.Form["animalsuppliertypeoid"].ToString();
                    }

                    var stocklimit = 0.0;
                    if (seedtypeoid != null && seedtypeoid != "")
                    {
                        seedtypeoid = HttpContext.Current.Request.Form["seedtypeoid"].ToString();
                        DataSet Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo"
                                                              , new SqlParameter("@OrganizationOid", orgOid)
                                                              , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                              , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                              , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                              , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            balanceQTY = (double)Ds.Tables[0].Rows[0]["Total_StockAnimalInfo"];
                        }
                        else
                        {
                            balanceQTY = 0;
                        }

                        Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo_TMR"
                                                      , new SqlParameter("@OrganizationOid", orgOid)
                                                      , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                      , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                      , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                      , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            stocklimit = (double)Ds.Tables[0].Rows[0]["Total_Current"];
                        }
                        else
                        {
                            stocklimit = 0;
                        }
                    }
                    else
                    {
                        if (animalsuppliertypeoid != null)
                        {
                            animalsuppliertypeoid = HttpContext.Current.Request.Form["animalsuppliertypeoid"].ToString();
                        }
                        DataSet Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo"
                                                              , new SqlParameter("@OrganizationOid", orgOid)
                                                              , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                              , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                              , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                              , new SqlParameter("@SeedTypeOid", null));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            balanceQTY = (double)Ds.Tables[0].Rows[0]["Total_StockAnimalInfo"];
                        }
                        else
                        {
                            balanceQTY = 0;
                        }

                        Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo_TMR"
                                                      , new SqlParameter("@OrganizationOid", orgOid)
                                                      , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                      , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                      , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                      , new SqlParameter("@SeedTypeOid", null));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            stocklimit = (double)Ds.Tables[0].Rows[0]["Total_Current"];
                        }
                        else
                        {
                            stocklimit = 0;
                        }
                    }


                    listQuantity2.QuotaQTY       = 0;
                    listQuantity2.balanceQTY     = balanceQTY;
                    listQuantity2.balancQuotaQTY = 0;
                    listQuantity2.StockUsed      = stocklimit;
                    listQuantity.Add(listQuantity2);
                }

                UserError err = new UserError();
                err.code    = ""; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ
                err.message = "OK";
                return(Request.CreateResponse(HttpStatusCode.OK, listQuantity));
            }
            catch (Exception ex)
            {
                UserError err = new UserError();
                err.code    = "6"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ
                err.message = ex.Message;
                return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
            }
        }
        protected static ResultObject CreateFolderInternal(int itemId, string folderName, int quota, QuotaType quotaType, bool addDefaultGroup, bool rootFolder = false)
        {
            ResultObject result = TaskManager.StartResultTask<ResultObject>("ENTERPRISE_STORAGE", "CREATE_FOLDER");

            try
            {
                // load organization
                Organization org = OrganizationController.GetOrganization(itemId);
                if (org == null)
                {
                    result.IsSuccess = false;
                    result.AddError("", new NullReferenceException("Organization not found"));
                    return result;
                }

                long quotaInBytses = ((long)quota) * 1024 * 1024;

                EnterpriseStorage es = GetEnterpriseStorage(GetEnterpriseStorageServiceID(org.PackageId));

                var webDavSetting = ObjectUtils.FillObjectFromDataReader<WebDavSetting>(
                    DataProvider.GetEnterpriseFolder(itemId, folderName));

                if (webDavSetting == null)
                {
                    int esId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.EnterpriseStorage);

                    StringDictionary esSesstings = ServerController.GetServiceSettings(esId);
                    
                    webDavSetting = new WebDavSetting(esSesstings["LocationDrive"], esSesstings["UsersHome"], esSesstings["UsersDomain"]);

                    StorageSpaceFolder folder = null;

                    if (UsingStorageSpaces(esId) && !rootFolder)
                    {
                        var storageSpaceId = StorageSpacesController.FindBestStorageSpaceService(new EnterpriseStorageSpaceSelector(esId), 
                            ResourceGroups.EnterpriseStorage, quotaInBytses);

                        if (!storageSpaceId.IsSuccess)
                        {
                            throw new Exception(storageSpaceId.ErrorCodes.First());
                        }

                        var storageSpaceFolderResult =
                            StorageSpacesController.CreateStorageSpaceFolder(storageSpaceId.Value, ResourceGroups.EnterpriseStorage,
                                org.OrganizationId, folderName, quotaInBytses, quotaType);

                        if (!storageSpaceFolderResult.IsSuccess)
                        {
                            foreach (var errorCode in storageSpaceFolderResult.ErrorCodes)
                            {
                                result.ErrorCodes.Add(errorCode);
                            }

                            throw new Exception("Error creating cloud folder");
                        }

                        folder = StorageSpacesController.GetStorageSpaceFolderById(storageSpaceFolderResult.Value);

                        DataProvider.AddEntepriseFolder(itemId, folderName, quota, null, null, esSesstings["UsersDomain"], storageSpaceFolderResult.Value);

                        CreateEnterpriseStorageVirtualFolderInternal(org.PackageId, itemId, folderName, CheckIfSsAndEsOnSameServer(esId, folder.StorageSpaceId) ? folder.Path : folder.UncPath);

                        StorageSpacesController.SetStorageSpaceFolderAbeStatus(folder.Id, true);
                    }
                    else
                    {
                        es.CreateFolder(org.OrganizationId, folderName, webDavSetting);

                        DataProvider.AddEntepriseFolder(itemId, folderName, quota, webDavSetting.LocationDrive, webDavSetting.HomeFolder, webDavSetting.Domain, null);

                        SetFolderQuota(org.PackageId, org.OrganizationId, folderName, quota, quotaType, webDavSetting);

                        DataProvider.UpdateEnterpriseFolder(itemId, folderName, folderName, quota);
                    }

                    if (addDefaultGroup)
                    {
                        var groupName = string.Format("{0} Folder Users", folderName);

                        var account = ObjectUtils.CreateListFromDataReader<ExchangeAccount>(
                            DataProvider.GetOrganizationGroupsByDisplayName(itemId, groupName)).FirstOrDefault();

                        var accountId = account == null
                            ? OrganizationController.CreateSecurityGroup(itemId, groupName)
                            : account.AccountId;


                        var securityGroup = OrganizationController.GetSecurityGroupGeneralSettings(itemId, accountId);

                        var rules = new List<WebDavFolderRule>() {
                            new WebDavFolderRule
                            {
                                Roles = new List<string>() { securityGroup.AccountName },
                                Read = true,
                                Write = true,
                                Source = true,
                                Pathes = new List<string>() { "*" }
                           }
                        };

                        es.SetFolderWebDavRules(org.OrganizationId, folderName, null, rules.ToArray());

                        if (UsingStorageSpaces(esId) && folder != null)
                        {
                            StorageSpacesController.SetFolderNtfsPermissions(folder.StorageSpaceId, folder.Path, ConvertToUserPermissions(rules.ToArray()), true, false);
                        }
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.AddError("Cloud Folders", new Exception("Folder already exist"));
                    return result;
                }
            }
            catch (Exception ex)
            {
                result.AddError("ENTERPRISE_STORAGE_CREATE_FOLDER", ex);
            }
            finally
            {
                if (!result.IsSuccess)
                {
                    TaskManager.CompleteResultTask(result);
                }
                else
                {
                    TaskManager.CompleteResultTask();
                }
            }

            return result;
        }
        public StorageSpaceFolder CreateFolder(string organizationId, int itemId, string type, long quotaInBytes, QuotaType qoutaType)
        {
            var storageId = StorageSpacesController.FindBestStorageSpaceService(new DefaultStorageSpaceSelector(), ResourceGroups.HostedOrganizations, quotaInBytes);

            if (!storageId.IsSuccess)
            {
                throw new Exception(storageId.ErrorCodes.First());
            }

            var folder = StorageSpacesController.CreateStorageSpaceFolder(storageId.Value, ResourceGroups.HostedOrganizations, organizationId, type, quotaInBytes, qoutaType);

            if (!folder.IsSuccess)
            {
                throw new Exception(string.Join("---------------------------------------", folder.ErrorCodes));
            }

            DataProvider.AddOrganizationStoragSpacesFolder(itemId, type, folder.Value);

            return(StorageSpacesController.GetStorageSpaceFolderById(folder.Value));
        }
        protected static void StartESBackgroundTaskInternal(string taskName, int itemId, SystemFile folder, ESPermission[] permissions, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
        {
            // load organization
            var org = OrganizationController.GetOrganization(itemId);

            new Thread(() =>
            {
                try
                {
                    TaskManager.StartTask("ENTERPRISE_STORAGE", taskName, org.PackageId);

                    EnterpriseStorageController.SetFRSMQuotaOnFolder(itemId, folder.Name, quota, quotaType);
                    EnterpriseStorageController.SetFolderPermission(itemId, folder.Name, permissions);
                }
                catch (Exception ex)
                {
                    // log error
                    TaskManager.WriteError(ex, "Error executing Cloud Folders background task");
                }
                finally
                {
                    // complete task
                    try
                    {
                        TaskManager.CompleteTask();
                    }
                    catch (Exception)
                    {
                    }
                }

            }).Start();
        }
 public ResultObject CreateEnterpriseFolder(int itemId, string folderName, int quota, QuotaType quotaType, bool addDefaultGroup)
 {
     return EnterpriseStorageController.CreateFolder(itemId, folderName, quota, quotaType, addDefaultGroup);
 }
Example #25
0
 public static ResultObject UpdateStorageSpaceFolder(int storageSpaceId, int storageSpaceFolderId, string organizationId, string groupName, string folderName, string uncPath, long quotaInBytes, QuotaType quotaType)
 {
     return(UpdateStorageSpaceFolderInternal(storageSpaceId, storageSpaceFolderId, organizationId, groupName, folderName, uncPath, quotaInBytes, quotaType));
 }
 public void SetEnterpriseFolderSettings(int itemId, SystemFile folder, ESPermission[] permissions, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
 {
     EnterpriseStorageController.StartSetEnterpriseFolderSettingsBackgroundTask(itemId, folder, permissions, directoyBrowsingEnabled, quota, quotaType);
 }
Example #27
0
        public static void SetFolderQuota(int storageSpaceid, string fullPath, long quotaSizeBytes, QuotaType type)
        {
            var space = GetStorageSpaceById(storageSpaceid);

            var ss = GetStorageSpaceService(space.ServiceId);

            ss.UpdateFolderQuota(fullPath, quotaSizeBytes, type);
        }
 public void SetEnterpriseFolderGeneralSettings(int itemId, SystemFile folder, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
 {
     EnterpriseStorageController.SetESGeneralSettings(itemId, folder, directoyBrowsingEnabled, quota, quotaType);
 }
 /// <remarks/>
 public void UpdateFolderQuotaAsync(string fullPath, long qouteSizeBytes, QuotaType type) {
     this.UpdateFolderQuotaAsync(fullPath, qouteSizeBytes, type, null);
 }
Example #30
0
 public Quota()
 {
     _Size = -1;
     _QuotaType = QuotaType.Soft;
     _Usage = -1;
 }
 public LicenseUseCase(LicenseFeature licenseFeature, QuotaType quotaType, int allowedLimit)
 {
     Feature      = licenseFeature;
     QuotaType    = quotaType;
     AllowedLimit = allowedLimit;
 }
Example #32
0
 public Quota()
 {
     _Size      = -1;
     _QuotaType = QuotaType.Soft;
     _Usage     = -1;
 }
        public static void AssertValidUsage(LicenseFeature feature, QuotaType quotaType, int count)
        {
            var licensedFeatures = ActivatedLicenseFeatures();
            if ((LicenseFeature.All & licensedFeatures) == LicenseFeature.All) //Standard Usage
                return;

            if (AccessTokenScope != null)
            {
                if ((feature & AccessTokenScope.tempFeatures) == feature)
                    return;
            }

            //Free Quotas
            switch (feature)
            {
                case LicenseFeature.Text:
                    switch (quotaType)
                    {
                        case QuotaType.Types:
                            ApprovedUsage(licensedFeatures, feature, FreeQuotas.TextTypes, count, ErrorMessages.ExceededTextTypes);
                            return;
                    }
                    break;

                case LicenseFeature.Redis:
                    switch (quotaType)
                    {
                        case QuotaType.Types:
                            ApprovedUsage(licensedFeatures, feature, FreeQuotas.RedisTypes, count, ErrorMessages.ExceededRedisTypes);
                            return;
                        case QuotaType.RequestsPerHour:
                            ApprovedUsage(licensedFeatures, feature, FreeQuotas.RedisRequestPerHour, count, ErrorMessages.ExceededRedisRequests);
                            return;
                    }
                    break;

                case LicenseFeature.OrmLite:
                    switch (quotaType)
                    {
                        case QuotaType.Tables:
                            ApprovedUsage(licensedFeatures, feature, FreeQuotas.OrmLiteTables, count, ErrorMessages.ExceededOrmLiteTables);
                            return;
                    }
                    break;

                case LicenseFeature.ServiceStack:
                    switch (quotaType)
                    {
                        case QuotaType.Operations:
                            ApprovedUsage(licensedFeatures, feature, FreeQuotas.ServiceStackOperations, count, ErrorMessages.ExceededServiceStackOperations);
                            return;
                    }
                    break;

                case LicenseFeature.Admin:
                    switch (quotaType)
                    {
                        case QuotaType.PremiumFeature:
                            ApprovedUsage(licensedFeatures, feature, FreeQuotas.PremiumFeature, count, ErrorMessages.ExceededAdminUi);
                            return;
                    }
                    break;

                case LicenseFeature.Premium:
                    switch (quotaType)
                    {
                        case QuotaType.PremiumFeature:
                            ApprovedUsage(licensedFeatures, feature, FreeQuotas.PremiumFeature, count, ErrorMessages.ExceededPremiumFeature);
                            return;
                    }
                    break;
            }

            throw new LicenseException("Unknown Quota Usage: {0}, {1}".Fmt(feature, quotaType));
        }
        private static IntResult CreateStorageSpaceFolderInternal(string groupName, string organizationId, string folderName, long quotaInBytes, QuotaType quotaType)
        {
            var result = TaskManager.StartResultTask<IntResult>("STORAGE_SPACES", "CREATE_STORAGE_SPACE_FOLDER");

            try
            {
                var storageId = StorageSpacesController.FindBestStorageSpaceService(groupName, quotaInBytes);

                if (!storageId.IsSuccess)
                {
                    throw new Exception(storageId.ErrorCodes.First());
                }

                var storageSpace = StorageSpacesController.GetStorageSpaceById(storageId.Value);

                if (storageSpace == null)
                {
                    throw new Exception(string.Format("Storage space with id={0} not found", storageId.Value));
                }

                var ss = GetStorageSpaceService(storageSpace.ServiceId);

                var fullPath = CreateFilePath(storageSpace.Path, organizationId, groupName, folderName);

                ss.CreateFolder(fullPath);

                var shareName = GenerateShareName(organizationId, folderName);

                var share = ShareStorageSpaceFolderInternal(storageSpace.Id, fullPath, shareName);

                ss.UpdateFolderQuota(fullPath, quotaInBytes, quotaType);

                result.Value = DataProvider.CreateStorageSpaceFolder(folderName, storageSpace.Id, fullPath, share.UncPath, true, quotaType, quotaInBytes);
            }
            catch (Exception exception)
            {
                TaskManager.WriteError(exception);
                result.AddError("Error creating Storage Space folder", exception);

                if (result.Value > 0)
                {
                    DataProvider.RemoveStorageSpaceFolder(result.Value);
                }
            }
            finally
            {
                if (!result.IsSuccess)
                {
                    TaskManager.CompleteResultTask(result);
                }
                else
                {
                    TaskManager.CompleteResultTask();
                }
            }

            return result;
        }
Example #35
0
 public void SetEnterpriseFolderSettings(int itemId, SystemFile folder, ESPermission[] permissions, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
 {
     EnterpriseStorageController.StartSetEnterpriseFolderSettingsBackgroundTask(itemId, folder, permissions, directoyBrowsingEnabled, quota, quotaType);
 }
        private static ResultObject UpdateStorageSpaceFolderInternal(int storageSpaceId, int storageSpaceFolderId, string organizationId, string groupName, string folderName,string uncPath, long quotaInBytes, QuotaType quotaType)
        {
            var result = TaskManager.StartResultTask<ResultObject>("STORAGE_SPACES", "UPDATE_STORAGE_SPACE_FOLDER");

            try
            {
                var storageSpace = StorageSpacesController.GetStorageSpaceById(storageSpaceId);

                if (storageSpace == null)
                {
                    throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId));
                }

                var ss = StorageSpacesController.GetStorageSpaceService(storageSpace.ServiceId);

                var fullPath = CreateFilePath(storageSpace.Path, organizationId, groupName, folderName);

                if (quotaInBytes > 0)
                {
                    ss.UpdateFolderQuota(fullPath, quotaInBytes, quotaType);
                }

                DataProvider.UpdateStorageSpaceFolder(storageSpaceFolderId, folderName, storageSpace.Id, fullPath, uncPath, false, quotaType, quotaInBytes);
            }
            catch (Exception exception)
            {
                TaskManager.WriteError(exception);
                result.AddError("Error removing Storage Space", exception);
            }
            finally
            {
                if (!result.IsSuccess)
                {
                    TaskManager.CompleteResultTask(result);
                }
                else
                {
                    TaskManager.CompleteResultTask();
                }
            }

            return result;
        }
Example #37
0
 public virtual void SetQuotaLimitOnFolder(string folderPath, string shareNameDrive, QuotaType quotaType, string quotaLimit, int mode, string wmiUserName, string wmiPassword)
 {
     FileUtils.SetQuotaLimitOnFolder(folderPath, shareNameDrive, quotaLimit, mode, wmiUserName, wmiPassword);
 }
        private static ResultObject SetStorageSpaceFolderQuotaInternal(int storageSpaceId, int storageSpaceFolderId, long quotaInBytes, QuotaType quotaType)
        {
            var result = TaskManager.StartResultTask<IntResult>("STORAGE_SPACES", "SET_STORAGE_SPACE_FOLDER_QUOTA");

            try
            {
                if (storageSpaceId < 0)
                {
                    throw new ArgumentException("Storage Space iD must be greater than 0");
                }

                var storage = GetStorageSpaceById(storageSpaceId);

                if (storage == null)
                {
                    throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId));
                }

                var storageFolder = GetStorageSpaceFolderById(storageSpaceFolderId);

                if (storageFolder == null)
                {
                    throw new Exception(string.Format("Storage Space folder with id={0} not found", storageSpaceFolderId));
                }

                SetFolderQuota(storageSpaceId, storageFolder.Path, quotaInBytes, quotaType);

                DataProvider.UpdateStorageSpaceFolder(storageSpaceFolderId, storageFolder.Name, storageSpaceId, storageFolder.Path, storageFolder.UncPath, storageFolder.IsShared, quotaType, quotaInBytes);
            }
            catch (Exception exception)
            {
                TaskManager.WriteError(exception);
                result.AddError("Error removing Storage Space folder", exception);

                if (result.Value > 0)
                {
                    DataProvider.RemoveStorageSpaceFolder(result.Value);
                }
            }
            finally
            {
                if (!result.IsSuccess)
                {
                    TaskManager.CompleteResultTask(result);
                }
                else
                {
                    TaskManager.CompleteResultTask();
                }
            }

            return result;
        }
Example #39
0
        public static void AssertValidUsage(LicenseFeature feature, QuotaType quotaType, int count)
        {
            var licensedFeatures = ActivatedLicenseFeatures();

            if ((LicenseFeature.All & licensedFeatures) == LicenseFeature.All) //Standard Usage
            {
                return;
            }

            //Free Quotas
            switch (feature)
            {
            case LicenseFeature.Redis:
                switch (quotaType)
                {
                case QuotaType.Types:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.RedisTypes, count, ErrorMessages.ExceededRedisTypes);
                    return;

                case QuotaType.RequestsPerHour:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.RedisRequestPerHour, count, ErrorMessages.ExceededRedisRequests);
                    return;
                }
                break;

            case LicenseFeature.OrmLite:
                switch (quotaType)
                {
                case QuotaType.Tables:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.OrmLiteTables, count, ErrorMessages.ExceededOrmLiteTables);
                    return;
                }
                break;

            case LicenseFeature.Aws:
                switch (quotaType)
                {
                case QuotaType.Tables:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.AwsTables, count, ErrorMessages.ExceededAwsTables);
                    return;
                }
                break;

            case LicenseFeature.ServiceStack:
                switch (quotaType)
                {
                case QuotaType.Operations:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.ServiceStackOperations, count, ErrorMessages.ExceededServiceStackOperations);
                    return;
                }
                break;

            case LicenseFeature.Admin:
                switch (quotaType)
                {
                case QuotaType.PremiumFeature:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.PremiumFeature, count, ErrorMessages.ExceededAdminUi);
                    return;
                }
                break;

            case LicenseFeature.Premium:
                switch (quotaType)
                {
                case QuotaType.PremiumFeature:
                    ApprovedUsage(licensedFeatures, feature, FreeQuotas.PremiumFeature, count, ErrorMessages.ExceededPremiumFeature);
                    return;
                }
                break;
            }

            throw new LicenseException("Unknown Quota Usage: {0}, {1}".Fmt(feature, quotaType)).Trace();
        }
        protected static void SetESGeneralSettingsInternal(string taskName, int itemId, SystemFile folder, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
        {
            // load organization
            var org = OrganizationController.GetOrganization(itemId);

            try
            {
                TaskManager.StartTask("ENTERPRISE_STORAGE", taskName, org.PackageId);

                var esFolder = ObjectUtils.FillObjectFromDataReader<EsFolder>(DataProvider.GetEnterpriseFolder(itemId, folder.Name));

                if (esFolder.StorageSpaceFolderId == null)
                {
                    EnterpriseStorageController.SetFRSMQuotaOnFolder(itemId, folder.Name, quota, quotaType);
                }
                else
                {
                    StorageSpacesController.SetStorageSpaceFolderQuota(esFolder.StorageSpaceId, esFolder.StorageSpaceFolderId.Value, (long)quota * 1024 * 1024, quotaType);

                    DataProvider.UpdateEnterpriseFolder(itemId, folder.Name, folder.Name, quota);
                }
            }
            catch (Exception ex)
            {
                // log error
                TaskManager.WriteError(ex, "Error executing cloud folders background task");
            }
            finally
            {
                // complete task
                try
                {
                    TaskManager.CompleteTask();
                }
                catch (Exception)
                {
                }
            }
        }
 public static IntResult CreateStorageSpaceFolder(string groupName, string organizationId, string folderName, long quotaInBytes, QuotaType quotaType)
 {
     return CreateStorageSpaceFolderInternal(groupName, organizationId,folderName, quotaInBytes, quotaType);
 }
Example #42
0
        public static int CreateStorageSpaceFolder(string name, int storageSpaceId, string path, string uncPath, bool isShared, QuotaType quotaType, long fsrmQuotaSizeBytes)
        {
            SqlParameter id = new SqlParameter("@ID", SqlDbType.Int);
            id.Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(
                ConnectionString,
                CommandType.StoredProcedure,
                "CreateStorageSpaceFolder",
                id,
                new SqlParameter("@Name", name),
                new SqlParameter("@StorageSpaceId", storageSpaceId),
                new SqlParameter("@Path", path),
                new SqlParameter("@UncPath", uncPath),
                new SqlParameter("@IsShared", isShared),
                new SqlParameter("@FsrmQuotaType", quotaType),
                new SqlParameter("@FsrmQuotaSizeBytes", fsrmQuotaSizeBytes)
            );

            // read identity
            return Convert.ToInt32(id.Value);
        }
 public static ResultObject UpdateStorageSpaceFolder(int storageSpaceId, int storageSpaceFolderId, string organizationId, string groupName, string folderName, string uncPath, long quotaInBytes, QuotaType quotaType)
 {
     return UpdateStorageSpaceFolderInternal(storageSpaceId, storageSpaceFolderId, organizationId, groupName, folderName, uncPath, quotaInBytes, quotaType);
 }
Example #44
0
        public static int UpdateStorageSpaceFolder(int id, string folderName, int storageSpaceId, string path, string uncPath, bool isShared, QuotaType type, long fsrmQuotaSizeBytes)
        {
            SqlHelper.ExecuteNonQuery(
                ConnectionString,
                CommandType.StoredProcedure,
                "UpdateStorageSpaceFolder",
                new SqlParameter("@ID", id),
                new SqlParameter("@Name", folderName),
                new SqlParameter("@StorageSpaceId", storageSpaceId),
                new SqlParameter("@Path", path),
                new SqlParameter("@UncPath", uncPath),
                new SqlParameter("@IsShared", isShared),
                new SqlParameter("@FsrmQuotaType", type),
                new SqlParameter("@FsrmQuotaSizeBytes", fsrmQuotaSizeBytes)
            );

            return id;
        }
 public static ResultObject SetStorageSpaceFolderQuota(int storageSpaceId, int storageSpaceFolderId, long quotaInBytes, QuotaType quotaType)
 {
     return SetStorageSpaceFolderQuotaInternal(storageSpaceId, storageSpaceFolderId, quotaInBytes, quotaType);
 }
Example #46
0
        public void ChangeQuotaOnFolder(Runspace runSpace, string command, string path, QuotaType quotaType, UInt64 quota)
        {
            Command cmd = new Command(command);

            cmd.Parameters.Add("Path", path);
            cmd.Parameters.Add("Size", quota);

            if (quotaType == QuotaType.Soft)
            {
                cmd.Parameters.Add("SoftLimit", true);
            }

            ExecuteShellCommand(runSpace, cmd, false);
        }
        public static void SetFolderQuota(int storageSpaceid, string fullPath, long quotaSizeBytes, QuotaType type)
        {
            var space = GetStorageSpaceById(storageSpaceid);

            var ss = GetStorageSpaceService(space.ServiceId);

            ss.UpdateFolderQuota(fullPath, quotaSizeBytes,type);
        }
Example #48
0
        public override void SetQuotaLimitOnFolder(string folderPath, string shareNameDrive, QuotaType quotaType, string quotaLimit, int mode, string wmiUserName, string wmiPassword)
        {
            Log.WriteStart("SetQuotaLimitOnFolder");
            Log.WriteInfo("FolderPath : {0}", folderPath);
            Log.WriteInfo("QuotaLimit : {0}", quotaLimit);

            string path = folderPath;

            if (shareNameDrive != null)
            {
                path = Path.Combine(shareNameDrive + @":\", folderPath);
            }

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();

                if (path.IndexOfAny(Path.GetInvalidPathChars()) == -1)
                {
                    if (!FileUtils.DirectoryExists(path))
                    {
                        FileUtils.CreateDirectory(path);
                    }

                    if (quotaLimit.Contains("-"))
                    {
                        RemoveOldQuotaOnFolder(runSpace, path);
                    }
                    else
                    {
                        var quota = CalculateQuota(quotaLimit);

                        switch (mode)
                        {
                        //deleting old quota and creating new one
                        case 0:
                        {
                            RemoveOldQuotaOnFolder(runSpace, path);
                            ChangeQuotaOnFolder(runSpace, "New-FsrmQuota", path, quotaType, quota);
                            break;
                        }

                        //modifying folder quota
                        case 1:
                        {
                            ChangeQuotaOnFolder(runSpace, "Set-FsrmQuota", path, quotaType, quota);
                            break;
                        }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteError("SetQuotaLimitOnFolder", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }

            Log.WriteEnd("SetQuotaLimitOnFolder");
        }
Example #49
0
        private static IntResult CreateStorageSpaceFolderInternal(int storageSpaceId, string groupName, string organizationId, string folderName, long quotaInBytes, QuotaType quotaType)
        {
            var result = TaskManager.StartResultTask <IntResult>("STORAGE_SPACES", "CREATE_STORAGE_SPACE_FOLDER");

            try
            {
                var storageSpace = StorageSpacesController.GetStorageSpaceById(storageSpaceId);

                if (storageSpace == null)
                {
                    throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId));
                }

                var ss = GetStorageSpaceService(storageSpace.ServiceId);

                var fullPath = CreateFilePath(storageSpace.Path, organizationId, groupName, folderName);

                ss.CreateFolder(fullPath);

                var shareName = GenerateShareName(organizationId, folderName);

                var share = ShareStorageSpaceFolderInternal(storageSpace.Id, fullPath, shareName);

                ss.UpdateFolderQuota(fullPath, quotaInBytes, quotaType);

                result.Value = DataProvider.CreateStorageSpaceFolder(folderName, storageSpace.Id, fullPath, share.UncPath, true, quotaType, quotaInBytes);
            }
            catch (Exception exception)
            {
                TaskManager.WriteError(exception);
                result.AddError("Error creating Storage Space folder", exception);

                if (result.Value > 0)
                {
                    DataProvider.RemoveStorageSpaceFolder(result.Value);
                }
            }
            finally
            {
                if (!result.IsSuccess)
                {
                    TaskManager.CompleteResultTask(result);
                }
                else
                {
                    TaskManager.CompleteResultTask();
                }
            }

            return(result);
        }
 public void UpdateStorageSettings(string fullPath, long qouteSizeBytes, QuotaType type) {
     this.Invoke("UpdateStorageSettings", new object[] {
                 fullPath,
                 qouteSizeBytes,
                 type});
 }
Example #51
0
        private static ResultObject UpdateStorageSpaceFolderInternal(int storageSpaceId, int storageSpaceFolderId, string organizationId, string groupName, string folderName, string uncPath, long quotaInBytes, QuotaType quotaType)
        {
            var result = TaskManager.StartResultTask <ResultObject>("STORAGE_SPACES", "UPDATE_STORAGE_SPACE_FOLDER");

            try
            {
                var storageSpace = StorageSpacesController.GetStorageSpaceById(storageSpaceId);

                if (storageSpace == null)
                {
                    throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId));
                }

                var ss = StorageSpacesController.GetStorageSpaceService(storageSpace.ServiceId);

                var fullPath = CreateFilePath(storageSpace.Path, organizationId, groupName, folderName);

                if (quotaInBytes > 0)
                {
                    ss.UpdateFolderQuota(fullPath, quotaInBytes, quotaType);
                }

                DataProvider.UpdateStorageSpaceFolder(storageSpaceFolderId, folderName, storageSpace.Id, fullPath, uncPath, false, quotaType, quotaInBytes);
            }
            catch (Exception exception)
            {
                TaskManager.WriteError(exception);
                result.AddError("Error removing Storage Space", exception);
            }
            finally
            {
                if (!result.IsSuccess)
                {
                    TaskManager.CompleteResultTask(result);
                }
                else
                {
                    TaskManager.CompleteResultTask();
                }
            }

            return(result);
        }
 /// <remarks/>
 public void UpdateStorageSettingsAsync(string fullPath, long qouteSizeBytes, QuotaType type) {
     this.UpdateStorageSettingsAsync(fullPath, qouteSizeBytes, type, null);
 }
Example #53
0
        private static ResultObject SetStorageSpaceFolderQuotaInternal(int storageSpaceId, int storageSpaceFolderId, long quotaInBytes, QuotaType quotaType)
        {
            var result = TaskManager.StartResultTask <IntResult>("STORAGE_SPACES", "SET_STORAGE_SPACE_FOLDER_QUOTA");

            try
            {
                if (storageSpaceId < 0)
                {
                    throw new ArgumentException("Storage Space iD must be greater than 0");
                }

                var storage = GetStorageSpaceById(storageSpaceId);

                if (storage == null)
                {
                    throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId));
                }

                var storageFolder = GetStorageSpaceFolderById(storageSpaceFolderId);

                if (storageFolder == null)
                {
                    throw new Exception(string.Format("Storage Space folder with id={0} not found", storageSpaceFolderId));
                }

                SetFolderQuota(storageSpaceId, storageFolder.Path, quotaInBytes, quotaType);

                DataProvider.UpdateStorageSpaceFolder(storageSpaceFolderId, storageFolder.Name, storageSpaceId, storageFolder.Path, storageFolder.UncPath, storageFolder.IsShared, quotaType, quotaInBytes);
            }
            catch (Exception exception)
            {
                TaskManager.WriteError(exception);
                result.AddError("Error removing Storage Space folder", exception);

                if (result.Value > 0)
                {
                    DataProvider.RemoveStorageSpaceFolder(result.Value);
                }
            }
            finally
            {
                if (!result.IsSuccess)
                {
                    TaskManager.CompleteResultTask(result);
                }
                else
                {
                    TaskManager.CompleteResultTask();
                }
            }

            return(result);
        }
 public void UpdateFolderQuota(string fullPath, long qouteSizeBytes, QuotaType type) {
     this.Invoke("UpdateFolderQuota", new object[] {
                 fullPath,
                 qouteSizeBytes,
                 type});
 }
 public LicenseUseCase(LicenseFeature licenseFeature, QuotaType quotaType, int allowedLimit)
 {
     Feature = licenseFeature;
     QuotaType = quotaType;
     AllowedLimit = allowedLimit;
 }
 /// <remarks/>
 public System.IAsyncResult BeginUpdateFolderQuota(string fullPath, long qouteSizeBytes, QuotaType type, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("UpdateFolderQuota", new object[] {
                 fullPath,
                 qouteSizeBytes,
                 type}, callback, asyncState);
 }