예제 #1
0
        public void CreateFolder(string organizationId, string folder, WebDavSetting setting)
        {
            var webDavSetting = GetWebDavSetting(setting);

            FileUtils.CreateDirectory(string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive,
                webDavSetting.HomeFolder, organizationId, folder));
        }
 public SystemFile[] GetFoldersWithoutFrsm(string organizationId, WebDavSetting[] settings)
 {
     try
     {
         Log.WriteStart("'{0}' GetFolders", ProviderSettings.ProviderName);
         SystemFile[] result = EnterpriseStorageProvider.GetFoldersWithoutFrsm(organizationId, settings);
         Log.WriteEnd("'{0}' GetFolders", ProviderSettings.ProviderName);
         return result;
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' GetFolders", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
        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 SystemFile GetFolder(string organizationId, string folder, WebDavSetting setting)
 {
     try
     {
         Log.WriteStart("'{0}' GetFolder", ProviderSettings.ProviderName);
         SystemFile result = EnterpriseStorageProvider.GetFolder(organizationId, folder, setting);
         Log.WriteEnd("'{0}' GetFolder", ProviderSettings.ProviderName);
         return result;
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' GetFolder", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
 public SystemFile RenameFolder(string organizationId, string originalFolder, string newFolder, WebDavSetting setting)
 {
     try
     {
         Log.WriteStart("'{0}' RenameFolder", ProviderSettings.ProviderName);
         SystemFile systemFile = EnterpriseStorageProvider.RenameFolder(organizationId, originalFolder, newFolder, setting);
         Log.WriteEnd("'{0}' RenameFolder", ProviderSettings.ProviderName);
         return systemFile;
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' RenameFolder", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
 public bool SetFolderWebDavRules(string organizationId, string folder, WebDavSetting setting, Providers.Web.WebDavFolderRule[] rules)
 {
     try
     {
         Log.WriteStart("'{0}' SetFolderWebDavRules", ProviderSettings.ProviderName);
         bool bResult =  EnterpriseStorageProvider.SetFolderWebDavRules(organizationId, folder, setting, rules);
         Log.WriteEnd("'{0}' SetFolderWebDavRules", ProviderSettings.ProviderName);
         return bResult;
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' SetFolderWebDavRules", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
 /// <remarks/>
 public void RenameFolderAsync(string organizationId, string originalFolder, string newFolder, WebDavSetting setting, object userState) {
     if ((this.RenameFolderOperationCompleted == null)) {
         this.RenameFolderOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRenameFolderOperationCompleted);
     }
     this.InvokeAsync("RenameFolder", new object[] {
                 organizationId,
                 originalFolder,
                 newFolder,
                 setting}, this.RenameFolderOperationCompleted, userState);
 }
 /// <remarks/>
 public System.IAsyncResult BeginRenameFolder(string organizationId, string originalFolder, string newFolder, WebDavSetting setting, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("RenameFolder", new object[] {
                 organizationId,
                 originalFolder,
                 newFolder,
                 setting}, callback, asyncState);
 }
 /// <remarks/>
 public void GetFolderWebDavRulesAsync(string organizationId, string folder, WebDavSetting setting, object userState) {
     if ((this.GetFolderWebDavRulesOperationCompleted == null)) {
         this.GetFolderWebDavRulesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetFolderWebDavRulesOperationCompleted);
     }
     this.InvokeAsync("GetFolderWebDavRules", new object[] {
                 organizationId,
                 folder,
                 setting}, this.GetFolderWebDavRulesOperationCompleted, userState);
 }
 /// <remarks/>
 public void GetFoldersWithoutFrsmAsync(string organizationId, WebDavSetting[] settings) {
     this.GetFoldersWithoutFrsmAsync(organizationId, settings, null);
 }
 /// <remarks/>
 public System.IAsyncResult BeginGetFoldersWithoutFrsm(string organizationId, WebDavSetting[] settings, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("GetFoldersWithoutFrsm", new object[] {
                 organizationId,
                 settings}, callback, asyncState);
 }
 public SystemFile[] GetFoldersWithoutFrsm(string organizationId, WebDavSetting[] settings) {
     object[] results = this.Invoke("GetFoldersWithoutFrsm", new object[] {
                 organizationId,
                 settings});
     return ((SystemFile[])(results[0]));
 }
예제 #13
0
 public WebDav(WebDavSetting setting)
 {
     _Setting = setting;
 }
예제 #14
0
        public void DeleteFolder(string organizationId, string folder, WebDavSetting setting)
        {
            var webDavSetting = GetWebDavSetting(setting);

            string rootPath = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder,
                organizationId, folder);

            DirectoryInfo treeRoot = new DirectoryInfo(rootPath);

            if (treeRoot.Exists)
            {
                DirectoryInfo[] dirs = treeRoot.GetDirectories();
                while (dirs.Length > 0)
                {
                    foreach (DirectoryInfo dir in dirs)
                        DeleteFolder(organizationId,
                            folder != string.Empty ? string.Format("{0}\\{1}", folder, dir.Name) : dir.Name,
                            webDavSetting);

                    dirs = treeRoot.GetDirectories();
                }

                // DELETE THE FILES UNDER THE CURRENT ROOT
                string[] files = Directory.GetFiles(treeRoot.FullName);
                foreach (string file in files)
                {
                    File.SetAttributes(file, FileAttributes.Normal);
                    File.Delete(file);
                }

                IWebDav webdav = new WebDav(webDavSetting);

                webdav.DeleteAllWebDavRules(organizationId, folder);

                Directory.Delete(treeRoot.FullName, true);
            }
        }
예제 #15
0
        protected WebDavSetting[] GetWebDavSettings(WebDavSetting[] settings)
        {
            // 06.09.2015 [email protected]
            // Define a List as an temporary Storage-Object. It´s easier to handle.
            // var webDavSettings = new ArrayList();
            var webDavSettings = new List<WebDavSetting>();

            foreach (var setting in settings)
            {
                if (!setting.IsEmpty())
                {
                    webDavSettings.Add(setting);
                }
            }

            if (webDavSettings.Count == 0)
                return new WebDavSetting[] { GetWebDavSetting(new WebDavSetting()) };
            else
                // 06.09.2015 [email protected]
                // Problem: Parts of settings are empty. But the Method returns the wrong Settings-Object
                // Fix: Return the Cleaned Settings-Object
                return webDavSettings.ToArray();

            // return settings;
        }
 /// <remarks/>
 public void GetFolderWebDavRulesAsync(string organizationId, string folder, WebDavSetting setting) {
     this.GetFolderWebDavRulesAsync(organizationId, folder, setting, null);
 }
 /// <remarks/>
 public void GetFoldersWithoutFrsmAsync(string organizationId, WebDavSetting[] settings, object userState) {
     if ((this.GetFoldersWithoutFrsmOperationCompleted == null)) {
         this.GetFoldersWithoutFrsmOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetFoldersWithoutFrsmOperationCompleted);
     }
     this.InvokeAsync("GetFoldersWithoutFrsm", new object[] {
                 organizationId,
                 settings}, this.GetFoldersWithoutFrsmOperationCompleted, userState);
 }
 public SystemFile RenameFolder(string organizationId, string originalFolder, string newFolder, WebDavSetting setting) {
     object[] results = this.Invoke("RenameFolder", new object[] {
                 organizationId,
                 originalFolder,
                 newFolder,
                 setting});
     return ((SystemFile)(results[0]));
 }
 public SystemFile GetFolder(string organizationId, string folder, WebDavSetting setting) {
     object[] results = this.Invoke("GetFolder", new object[] {
                 organizationId,
                 folder,
                 setting});
     return ((SystemFile)(results[0]));
 }
 /// <remarks/>
 public void RenameFolderAsync(string organizationId, string originalFolder, string newFolder, WebDavSetting setting) {
     this.RenameFolderAsync(organizationId, originalFolder, newFolder, setting, null);
 }
 public void DeleteFolder(string organizationId, string folder, WebDavSetting setting) {
     this.Invoke("DeleteFolder", new object[] {
                 organizationId,
                 folder,
                 setting});
 }
 public void DeleteFolder(string organizationId, string folder, WebDavSetting setting)
 {
     try
     {
         Log.WriteStart("'{0}' DeleteFolder", ProviderSettings.ProviderName);
         EnterpriseStorageProvider.DeleteFolder(organizationId, folder, setting);
         Log.WriteEnd("'{0}' DeleteFolder", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' DeleteFolder", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
 /// <remarks/>
 public void DeleteFolderAsync(string organizationId, string folder, WebDavSetting setting) {
     this.DeleteFolderAsync(organizationId, folder, setting, null);
 }
 public Providers.Web.WebDavFolderRule[] GetFolderWebDavRules(string organizationId, string folder, WebDavSetting setting)
 {
     try
     {
         Log.WriteStart("'{0}' GetFolderWebDavRules", ProviderSettings.ProviderName);
         Providers.Web.WebDavFolderRule[]  webDavFolderRule =  EnterpriseStorageProvider.GetFolderWebDavRules(organizationId, folder, setting);
         Log.WriteEnd("'{0}' GetFolderWebDavRules", ProviderSettings.ProviderName);
         return webDavFolderRule;
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' GetFolderWebDavRules", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
 public bool SetFolderWebDavRules(string organizationId, string folder, WebDavSetting setting, WebDavFolderRule[] rules) {
     object[] results = this.Invoke("SetFolderWebDavRules", new object[] {
                 organizationId,
                 folder,
                 setting,
                 rules});
     return ((bool)(results[0]));
 }
 /// <remarks/>
 public void SetFolderWebDavRulesAsync(string organizationId, string folder, WebDavSetting setting, WebDavFolderRule[] rules) {
     this.SetFolderWebDavRulesAsync(organizationId, folder, setting, rules, null);
 }
 public WebDavFolderRule[] GetFolderWebDavRules(string organizationId, string folder, WebDavSetting setting) {
     object[] results = this.Invoke("GetFolderWebDavRules", new object[] {
                 organizationId,
                 folder,
                 setting});
     return ((WebDavFolderRule[])(results[0]));
 }
        private static void SetFolderQuota(int packageId, string orgId, string folderName, int quotaSize, QuotaType quotaType, WebDavSetting setting)
        {
            if (quotaSize == 0)
                return;

            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0)
                return;

            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);
            if (packageCheck < 0)
                return;

            int esServiceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.EnterpriseStorage);

            if (esServiceId != 0)
            {
                var curSetting = setting;

                if (curSetting == null || curSetting.IsEmpty())
                {
                    StringDictionary esSesstings = ServerController.GetServiceSettings(esServiceId);

                    curSetting = new WebDavSetting(esSesstings["LocationDrive"], esSesstings["UsersHome"], esSesstings["UsersDomain"]);
                }

                var orgFolder = Path.Combine(curSetting.HomeFolder, orgId, folderName);

                var os = GetOS(packageId);

                if (os != null && os.CheckFileServicesInstallation())
                {
                    TaskManager.StartTask("FILES", "SET_QUOTA_ON_FOLDER", orgFolder, packageId);

                    try
                    {
                        QuotaValueInfo diskSpaceQuota = PackageController.GetPackageQuota(packageId, Quotas.ENTERPRISESTORAGE_DISKSTORAGESPACE);

                        #region figure Quota Unit

                        // Quota Unit
                        string unit = string.Empty;
                        if (diskSpaceQuota.QuotaDescription.ToLower().Contains("gb"))
                            unit = "GB";
                        else if (diskSpaceQuota.QuotaDescription.ToLower().Contains("mb"))
                            unit = "MB";
                        else
                            unit = "KB";

                        #endregion

                        os.SetQuotaLimitOnFolder(orgFolder, curSetting.LocationDrive, quotaType, quotaSize.ToString() + unit, 0, String.Empty, String.Empty);
                    }
                    catch (Exception ex)
                    {
                        TaskManager.WriteError(ex);
                    }
                    finally
                    {
                        TaskManager.CompleteTask();
                    }
                }
            }
        }
 /// <remarks/>
 public System.IAsyncResult BeginGetFolderWebDavRules(string organizationId, string folder, WebDavSetting setting, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("GetFolderWebDavRules", new object[] {
                 organizationId,
                 folder,
                 setting}, callback, asyncState);
 }
예제 #30
0
 public WebDav(WebDavSetting setting)
 {
     _Setting = setting;
 }
예제 #31
0
        protected WebDavSetting GetWebDavSetting(WebDavSetting setting)
        {
            if (setting == null || setting.IsEmpty())
            {
                return new WebDavSetting(LocationDrive, UsersHome, UsersDomain);
            }

            return setting;
        }