Exemplo n.º 1
0
        public static void ExecuteSyncActions(int packageId, FileSyncAction[] actions)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return;
            }

            OS.OperatingSystem os = GetOS(packageId);

            // update actions
            foreach (FileSyncAction action in actions)
            {
                if (!String.IsNullOrEmpty(action.SrcPath))
                {
                    action.SrcPath = GetFullPackagePath(packageId, action.SrcPath);
                }
                if (!String.IsNullOrEmpty(action.DestPath))
                {
                    action.DestPath = GetFullPackagePath(packageId, action.DestPath);
                }
            }

            // perform sync
            os.ExecuteSyncActions(actions);
        }
Exemplo n.º 2
0
        public static int SetFilePermissions(int packageId, string path, UserPermission[] users, bool resetChildPermissions)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "SET_PERMISSIONS", path, packageId);

            try
            {
                OS.OperatingSystem os       = GetOS(packageId);
                string             fullPath = GetFullPackagePath(packageId, path);

                // get users OU defined on web server
                string usersOU = WebServerController.GetWebUsersOU(packageId);

                os.GrantGroupNtfsPermissions(fullPath, users, usersOU, resetChildPermissions);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 3
0
        public static bool RemoteServerFolderWriteAccessible(int packageId, string path)
        {
            try
            {
                // copy to space folder
                int osServiceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.Os);
                if (osServiceId > 0)
                {
                    OS.OperatingSystem os = new OS.OperatingSystem();
                    ServiceProviderProxy.Init(os, osServiceId);

                    string remoteServerPathCheck = FilesController.GetFullPackagePath(packageId,
                                                                                      Path.Combine(path, "check.txt"));

                    //
                    os.CreateFile(remoteServerPathCheck);
                    os.AppendFileBinaryContent(remoteServerPathCheck, Encoding.UTF8.GetBytes(remoteServerPathCheck));
                    os.DeleteFile(remoteServerPathCheck);
                }
                //
                return(true);
            }
            catch
            {                           //
                return(false);
            }
        }
Exemplo n.º 4
0
        public static int AppendFileBinaryChunk(int packageId, string path, byte[] chunk)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            OS.OperatingSystem os       = GetOS(packageId);
            string             fullPath = GetFullPackagePath(packageId, path);

            os.AppendFileBinaryContent(fullPath, chunk);

            return(0);
        }
Exemplo n.º 5
0
        public static bool DirectoryExists(int packageId, string path)
        {
            OS.OperatingSystem os       = GetOS(packageId);
            string             fullPath = GetFullPackagePath(packageId, path);

            return(os.DirectoryExists(fullPath));
        }
Exemplo n.º 6
0
        public static byte[] GetFileBinaryChunk(int packageId, string path, int offset, int length)
        {
            OS.OperatingSystem os       = GetOS(packageId);
            string             fullPath = GetFullPackagePath(packageId, path);

            return(os.GetFileBinaryChunk(fullPath, offset, length));
        }
Exemplo n.º 7
0
        public static int ZipFiles(int packageId, string[] files, string archivePath)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "ZIP_FILES", archivePath, packageId);

            if (files != null)
            {
                foreach (string file in files)
                {
                    TaskManager.Write(file);
                }
            }

            try
            {
                OS.OperatingSystem os          = GetOS(packageId);
                string             zipFilePath = GetFullPackagePath(packageId, archivePath);

                List <string> archFiles  = new List <string>();
                string        rootFolder = "";
                foreach (string file in files)
                {
                    string archFile = GetFullPackagePath(packageId, file);
                    int    idx      = archFile.LastIndexOf("\\");
                    rootFolder = archFile.Substring(0, idx);
                    archFiles.Add(archFile.Substring(idx + 1));
                }

                os.ZipFiles(zipFilePath, rootFolder, archFiles.ToArray());

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 8
0
        // Synchronizing
        public static FolderGraph GetFolderGraph(int packageId, string path)
        {
            OS.OperatingSystem os       = GetOS(packageId);
            string             fullPath = GetFullPackagePath(packageId, path);

            // get graph
            return(os.GetFolderGraph(fullPath));
        }
Exemplo n.º 9
0
        public static string[] GetInstalledOdbcDrivers(int packageId)
        {
            // load service item
            int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.Os);

            OS.OperatingSystem os = GetOS(serviceId);
            return(os.GetInstalledOdbcDrivers());
        }
Exemplo n.º 10
0
        public static byte[] GetFileBinaryContentUsingEncoding(int packageId, string path, string encoding)
        {
            OS.OperatingSystem os       = GetOS(packageId);
            string             fullPath = GetFullPackagePath(packageId, path);

            // create file
            return(os.GetFileBinaryContentUsingEncoding(fullPath, encoding));
        }
Exemplo n.º 11
0
        public static string[] UnzipFiles(int packageId, string[] files)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(null);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(null);
            }

            // place log record
            TaskManager.StartTask("FILES", "UNZIP_FILES", packageId);

            if (files != null)
            {
                foreach (string file in files)
                {
                    TaskManager.Write(file);
                }
            }

            try
            {
                List <string> unzippedFiles = new List <string>();

                OS.OperatingSystem os = GetOS(packageId);

                for (int i = 0; i < files.Length; i++)
                {
                    string zipFilePath    = GetFullPackagePath(packageId, files[i]);
                    string destFolderPath = zipFilePath.Substring(0, zipFilePath.LastIndexOf("\\"));
                    unzippedFiles.AddRange(os.UnzipFiles(zipFilePath, destFolderPath));
                }

                return(unzippedFiles.ToArray());
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 12
0
        public static OS.OperatingSystem GetOS(int packageId)
        {
            int sid = PackageController.GetPackageServiceId(packageId, ResourceGroups.Os);

            if (sid <= 0)
            {
                return(null);
            }

            OS.OperatingSystem os = new OS.OperatingSystem();
            ServiceProviderProxy.Init(os, sid);

            return(os);
        }
Exemplo n.º 13
0
        public static int CreateFile(int packageId, string path)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "CREATE_FILE", path, packageId);

            try
            {
                OS.OperatingSystem os       = GetOS(packageId);
                string             fullPath = GetFullPackagePath(packageId, path);

                // cannot create a file with the same name as a directory
                if (os.DirectoryExists(fullPath))
                {
                    return(BusinessErrorCodes.ERROR_FILE_CREATE_FILE_WITH_DIR_NAME);
                }

                // create file
                os.CreateFile(fullPath);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 14
0
        public static int DeleteFiles(int packageId, string[] files)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "DELETE_FILES", packageId);

            if (files != null)
            {
                foreach (string file in files)
                {
                    TaskManager.Write(file);
                }
            }

            try
            {
                OS.OperatingSystem os = GetOS(packageId);
                for (int i = 0; i < files.Length; i++)
                {
                    files[i] = GetFullPackagePath(packageId, files[i]);
                }

                // delete files
                os.DeleteFiles(files);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 15
0
        public static int DeleteOdbcSource(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SystemDSN origItem = (SystemDSN)PackageController.GetPackageItem(itemId);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_OS_DSN_PACKAGE_ITEM_NOT_FOUND);
            }

            // place log record
            TaskManager.StartTask("ODBC_DSN", "DELETE", origItem.Name);
            TaskManager.ItemId = itemId;

            try
            {
                // get service
                OS.OperatingSystem os = GetOS(origItem.ServiceId);

                // delete service item
                os.DeleteDSN(origItem.Name);

                // delete meta item
                PackageController.DeletePackageItem(origItem.Id);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 16
0
        public static List <SystemFile> GetFiles(int packageId, string path, bool includeFiles)
        {
            OS.OperatingSystem os = GetOS(packageId);

            string            fullPath      = GetFullPackagePath(packageId, path);
            List <SystemFile> filteredFiles = new List <SystemFile>();

            SystemFile[] files = os.GetFiles(fullPath);

            foreach (SystemFile file in files)
            {
                if (file.IsDirectory || includeFiles)
                {
                    filteredFiles.Add(file);
                }
            }

            return(filteredFiles);
        }
        public static int CreateBackupZip(int packageId, string archivePath)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "ZIP_FILES", archivePath, packageId);


            try
            {
                OS.OperatingSystem os          = FilesController.GetOS(packageId);
                string             zipFilePath = FilesController.GetFullPackagePath(packageId, archivePath);
                string             rootFolder  = FilesController.GetFullPackagePath(packageId, "");
                os.CreateBackupZip(zipFilePath, rootFolder);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 18
0
        public static int CreateAccessDatabase(int packageId, string dbPath)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "CREATE_ACCESS_DATABASE", dbPath, packageId);

            try
            {
                OS.OperatingSystem os       = GetOS(packageId);
                string             fullPath = GetFullPackagePath(packageId, dbPath);

                os.CreateAccessDatabase(fullPath);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 19
0
        public static SystemDSN GetOdbcSource(int itemId)
        {
            // load meta item
            SystemDSN item = (SystemDSN)PackageController.GetPackageItem(itemId);

            // load service item
            OS.OperatingSystem os  = GetOS(item.ServiceId);
            SystemDSN          dsn = os.GetDSN(item.Name);

            // add common properties
            dsn.Id        = item.Id;
            dsn.PackageId = item.PackageId;
            dsn.ServiceId = item.ServiceId;

            if (dsn.Driver == "MsAccess" || dsn.Driver == "Excel" || dsn.Driver == "Text")
            {
                dsn.DatabaseName = FilesController.GetVirtualPackagePath(item.PackageId, dsn.DatabaseName);
            }

            return(dsn);
        }
Exemplo n.º 20
0
        public List <string> GetImportableItems(int packageId, int itemTypeId, Type itemType,
                                                ResourceGroupInfo group)
        {
            List <string> items = new List <string>();

            // get service id
            int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);

            if (serviceId == 0)
            {
                return(items);
            }

            OS.OperatingSystem os = GetOS(serviceId);
            if (itemType == typeof(SystemDSN))
            {
                items.AddRange(os.GetDSNNames());
            }

            return(items);
        }
Exemplo n.º 21
0
        public static int UpdateFileBinaryContentUsingEncoding(int packageId, string path, byte[] content, string encoding)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "UPDATE_BINARY_CONTENT", path, packageId);

            try
            {
                OS.OperatingSystem os       = GetOS(packageId);
                string             fullPath = GetFullPackagePath(packageId, path);

                // create file
                os.UpdateFileBinaryContentUsingEncoding(fullPath, content, encoding);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 22
0
        public static int DeleteDirectoryRecursive(int packageId, string rootPath)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "DELETE_DIRECTORY_RECURSIVE", rootPath, packageId);

            try
            {
                OS.OperatingSystem os = GetOS(packageId);
                os.DeleteDirectoryRecursive(rootPath);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 23
0
        public static UserPermission[] GetFilePermissions(int packageId, string path)
        {
            try
            {
                // get all accounts
                UserPermission[] users = GetAvailableSecurityAccounts(packageId);

                OS.OperatingSystem os       = GetOS(packageId);
                string             fullPath = GetFullPackagePath(packageId, path);

                // get users OU defined on web server
                string usersOU = WebServerController.GetWebUsersOU(packageId);

                users = os.GetGroupNtfsPermissions(fullPath, users, usersOU);

                return(users);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
        }
Exemplo n.º 24
0
        public static int RenameFile(int packageId, string oldPath, string newPath)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "RENAME_FILE", oldPath, packageId);

            TaskManager.WriteParameter("New name", newPath);

            try
            {
                OS.OperatingSystem os           = GetOS(packageId);
                string             oldFullPath  = GetFullPackagePath(packageId, oldPath);
                string             destFullPath = GetFullPackagePath(packageId, newPath);

                os.MoveFile(oldFullPath, destFullPath);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 25
0
        public int RestoreItem(string tempFolder, System.Xml.XmlNode itemNode, int itemId, Type itemType, string itemName, int packageId, int serviceId, ResourceGroupInfo group)
        {
            if (itemType == typeof(HomeFolder))
            {
                OS.OperatingSystem os = GetOS(serviceId);

                // extract meta item
                XmlSerializer serializer = new XmlSerializer(typeof(HomeFolder));
                HomeFolder    homeFolder = (HomeFolder)serializer.Deserialize(
                    new XmlNodeReader(itemNode.SelectSingleNode("HomeFolder")));

                // create home folder if required
                if (!os.DirectoryExists(homeFolder.Name))
                {
                    os.CreatePackageFolder(homeFolder.Name);
                }

                // copy database backup to remote server
                XmlNode fileNode            = itemNode.SelectSingleNode("File[@name='SpaceFiles']");
                string  backupFileName      = fileNode.Attributes["path"].Value;
                long    backupFileLength    = Int64.Parse(fileNode.Attributes["size"].Value);
                string  localBackupFilePath = Path.Combine(tempFolder, backupFileName);

                if (new FileInfo(localBackupFilePath).Length != backupFileLength)
                {
                    return(-3);
                }

                FileStream stream = new FileStream(localBackupFilePath, FileMode.Open, FileAccess.Read);
                byte[]     buffer = new byte[FILE_BUFFER_LENGTH];

                int    readBytes        = 0;
                long   length           = 0;
                string remoteBackupPath = Path.Combine(homeFolder.Name, backupFileName);
                do
                {
                    // read package file
                    readBytes = stream.Read(buffer, 0, FILE_BUFFER_LENGTH);
                    length   += readBytes;

                    if (readBytes < FILE_BUFFER_LENGTH)
                    {
                        // resize buffer
                        Array.Resize <byte>(ref buffer, readBytes);
                    }

                    // write remote backup file
                    os.AppendFileBinaryContent(remoteBackupPath, buffer);
                }while (readBytes == FILE_BUFFER_LENGTH);
                stream.Close();

                // unzip files
                os.UnzipFiles(remoteBackupPath, homeFolder.Name);

                // delete archive
                if (os.FileExists(remoteBackupPath))
                {
                    os.DeleteFile(remoteBackupPath);
                }

                // add meta-item if required
                if (PackageController.GetPackageItemByName(packageId, itemName, typeof(HomeFolder)) == null)
                {
                    homeFolder.PackageId = packageId;
                    homeFolder.ServiceId = serviceId;
                    PackageController.AddPackageItem(homeFolder);
                }
            }
            else if (itemType == typeof(SystemDSN))
            {
                OS.OperatingSystem os = GetOS(serviceId);

                // extract meta item
                XmlSerializer serializer = new XmlSerializer(typeof(SystemDSN));
                SystemDSN     dsn        = (SystemDSN)serializer.Deserialize(
                    new XmlNodeReader(itemNode.SelectSingleNode("SystemDSN")));

                // create DSN if required
                if (os.GetDSN(itemName) == null)
                {
                    dsn.DatabasePassword = CryptoUtils.Decrypt(dsn.DatabasePassword);
                    os.CreateDSN(dsn);

                    // restore password
                    dsn.DatabasePassword = CryptoUtils.Encrypt(dsn.DatabasePassword);
                }

                // add meta-item if required
                if (PackageController.GetPackageItemByName(packageId, itemName, typeof(SystemDSN)) == null)
                {
                    dsn.PackageId = packageId;
                    dsn.ServiceId = serviceId;
                    PackageController.AddPackageItem(dsn);
                }
            }

            return(0);
        }
Exemplo n.º 26
0
        public int BackupItem(string tempFolder, System.Xml.XmlWriter writer, ServiceProviderItem item, ResourceGroupInfo group)
        {
            if (item is HomeFolder)
            {
                // backup home folder files
                string backupName = String.Format("SpaceFiles_{0}_{1}.zip",
                                                  item.Id, DateTime.Now.Ticks);

                // get the list of remote files
                List <SystemFile> files = FilesController.GetFiles(item.PackageId, "\\", true);

                string[] zipFiles = new string[files.Count];
                for (int i = 0; i < zipFiles.Length; i++)
                {
                    zipFiles[i] = files[i].Name;
                }

                // zip remote files
                FilesController.ZipFiles(item.PackageId, zipFiles, backupName);

                // download zipped file
                string localBackupPath = Path.Combine(tempFolder, backupName);

                byte[]     buffer = null;
                FileStream stream = new FileStream(localBackupPath, FileMode.Create, FileAccess.Write);

                int  offset = 0;
                long length = 0;
                do
                {
                    // read remote content
                    buffer = FilesController.GetFileBinaryChunk(item.PackageId, backupName, offset, FILE_BUFFER_LENGTH);

                    // write remote content
                    stream.Write(buffer, 0, buffer.Length);

                    length += buffer.Length;
                    offset += FILE_BUFFER_LENGTH;
                }while (buffer.Length == FILE_BUFFER_LENGTH);
                stream.Close();

                // delete zipped file
                if (FilesController.FileExists(item.PackageId, backupName))
                {
                    FilesController.DeleteFiles(item.PackageId, new string[] { backupName });
                }

                // add file pointer
                BackupController.WriteFileElement(writer, "SpaceFiles", backupName, length);

                // store meta item
                XmlSerializer serializer = new XmlSerializer(typeof(HomeFolder));
                serializer.Serialize(writer, item);
            }
            else if (item is SystemDSN)
            {
                // backup ODBC DSN
                OS.OperatingSystem os = GetOS(item.ServiceId);

                // read DSN info
                SystemDSN itemDsn = item as SystemDSN;
                SystemDSN dsn     = os.GetDSN(item.Name);
                dsn.DatabasePassword = itemDsn.DatabasePassword;

                XmlSerializer serializer = new XmlSerializer(typeof(SystemDSN));
                serializer.Serialize(writer, dsn);
            }

            return(0);
        }
Exemplo n.º 27
0
        private const int FILE_BUFFER_LENGTH = 5000000; // ~5MB

        private static OS.OperatingSystem GetOS(int serviceId)
        {
            OS.OperatingSystem os = new OS.OperatingSystem();
            ServiceProviderProxy.Init(os, serviceId);
            return(os);
        }
Exemplo n.º 28
0
 // Check If FSRM Role services were installed
 public static bool CheckFileServicesInstallation(int serviceId)
 {
     OS.OperatingSystem os = GetOS(serviceId);
     return(os.CheckFileServicesInstallation());
 }
Exemplo n.º 29
0
        public static int UpdateOdbcSource(SystemDSN item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SystemDSN origItem = (SystemDSN)PackageController.GetPackageItem(item.Id);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_OS_DSN_PACKAGE_ITEM_NOT_FOUND);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("ODBC_DSN", "UPDATE", origItem.Name);
            TaskManager.ItemId = item.Id;

            try
            {
                // get service
                OS.OperatingSystem os = GetOS(origItem.ServiceId);

                // password
                item.Driver = origItem.Driver;
                item.Name   = origItem.Name;

                if (item.DatabasePassword == "")
                {
                    item.DatabasePassword = CryptoUtils.Decrypt(origItem.DatabasePassword);
                }

                string[] dbNameParts = item.DatabaseName.Split('|');
                string   groupName   = null;
                if (dbNameParts.Length > 1)
                {
                    item.DatabaseName = dbNameParts[0];
                    groupName         = dbNameParts[1];
                }

                // get database server address
                item.DatabaseServer = GetDatabaseServerName(groupName, item.PackageId);

                if (item.Driver == "MsAccess" || item.Driver == "Excel" || item.Driver == "Text")
                {
                    item.DatabaseName = FilesController.GetFullPackagePath(origItem.PackageId, item.DatabaseName);
                }

                // update service item
                os.UpdateDSN(item);

                // update meta item
                if (item.DatabasePassword != "")
                {
                    item.DatabasePassword = CryptoUtils.Encrypt(item.DatabasePassword);
                    PackageController.UpdatePackageItem(item);
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 30
0
        public static int AddOdbcSource(SystemDSN item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // check quota
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.OS_ODBC);

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_OS_DSN_RESOURCE_QUOTA_LIMIT);
            }

            // check if mail resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Os);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_OS_RESOURCE_UNAVAILABLE);
            }

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SystemDSN)) != null)
            {
                return(BusinessErrorCodes.ERROR_OS_DSN_PACKAGE_ITEM_EXISTS);
            }

            // place log record
            TaskManager.StartTask("ODBC_DSN", "ADD", item.Name);

            try
            {
                // check service items
                OS.OperatingSystem os = GetOS(serviceId);
                if (os.GetDSN(item.Name) != null)
                {
                    return(BusinessErrorCodes.ERROR_OS_DSN_SERVICE_ITEM_EXISTS);
                }

                string[] dbNameParts = item.DatabaseName.Split('|');
                string   groupName   = null;
                if (dbNameParts.Length > 1)
                {
                    item.DatabaseName = dbNameParts[0];
                    groupName         = dbNameParts[1];
                }

                // get database server address
                item.DatabaseServer = GetDatabaseServerName(groupName, item.PackageId);

                if (item.Driver == "MsAccess" || item.Driver == "Excel" || item.Driver == "Text")
                {
                    item.DatabaseName = FilesController.GetFullPackagePath(item.PackageId, item.DatabaseName);
                }

                // add service item
                os.CreateDSN(item);

                // save item
                item.DatabasePassword = CryptoUtils.Encrypt(item.DatabasePassword);
                item.ServiceId        = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return(itemId);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }