Example #1
0
        public bool DeleteImageFolders(string imageName)
        {
            //Check again
            if (string.IsNullOrEmpty(imageName))
            {
                return(false);
            }

            var primaryDp = new DistributionPointServices().GetPrimaryDistributionPoint();

            if (primaryDp.Location == "Local")
            {
                try
                {
                    Directory.Delete(primaryDp.PhysicalPath + "images" + Path.DirectorySeparatorChar + imageName,
                                     true);
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                    return(false);
                }
            }
            else if (primaryDp.Location == "Remote")
            {
                using (var unc = new UncServices())
                {
                    var basePath    = @"\\" + primaryDp.Server + @"\" + primaryDp.ShareName;
                    var smbPassword = new EncryptionServices().DecryptText(primaryDp.RwPassword);
                    if (
                        unc.NetUseWithCredentials(basePath, primaryDp.RwUsername, primaryDp.Domain,
                                                  smbPassword) || unc.LastError == 1219)
                    {
                        try
                        {
                            Directory.Delete(basePath + @"\images" + @"\" +
                                             imageName, true);
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex.Message);
                            return(false);
                        }
                    }
                    else
                    {
                        log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError);
                        return(false);
                    }
                }
            }
            else
            {
                log.Error("Could Not Determine Primary Distribution Point Location Type");
                return(false);
            }

            return(true);
        }
Example #2
0
        public string GetHdFileSize(string imageName, string hd)
        {
            var primaryDp = new DistributionPointServices().GetPrimaryDistributionPoint();

            if (primaryDp == null)
            {
                return("No Primary Dp");
            }
            if (primaryDp.Location == "Local")
            {
                try
                {
                    var imagePath = primaryDp.PhysicalPath + "images" + Path.DirectorySeparatorChar + imageName +
                                    Path.DirectorySeparatorChar + "hd" + hd;
                    var size = new FileOpsServices().GetDirectorySize(new DirectoryInfo(imagePath)) / 1024f / 1024f / 1024f;
                    return(Math.Abs(size) < 0.1f ? "< 100M" : size.ToString("#.##") + " GB");
                }
                catch
                {
                    return("N/A");
                }
            }
            if (primaryDp.Location == "Remote")
            {
                using (var unc = new UncServices())
                {
                    var basePath    = @"\\" + primaryDp.Server + @"\" + primaryDp.ShareName;
                    var smbPassword = new EncryptionServices().DecryptText(primaryDp.RwPassword);
                    if (
                        unc.NetUseWithCredentials(basePath, primaryDp.RwUsername, primaryDp.Domain,
                                                  smbPassword) || unc.LastError == 1219)
                    {
                        try
                        {
                            var imagePath = basePath + @"\images\" + imageName + @"\hd" + hd;
                            var size      = new FileOpsServices().GetDirectorySize(new DirectoryInfo(imagePath)) / 1024f / 1024f /
                                            1024f;
                            return(Math.Abs(size) < 0.1f ? "< 100M" : size.ToString("#.##") + " GB");
                        }
                        catch
                        {
                            return("N/A");
                        }
                    }
                    log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError);
                    return("N/A");
                }
            }
            log.Error("Could Not Determine Primary Distribution Point Location Type");
            return("N/A");
        }
Example #3
0
        public string DistributionPoint(string dpId, string task)
        {
            var smb = new SMB();

            var dp = new DistributionPointServices().GetDistributionPoint(Convert.ToInt32(dpId));

            smb.SharePath   = "//" + StringManipulationServices.PlaceHolderReplace(dp.Server) + "/" + dp.ShareName;
            smb.Domain      = dp.Domain;
            smb.DisplayName = dp.DisplayName;
            smb.IsPrimary   = dp.IsPrimary == 1 ? "true" : "false";
            if (task.Contains("upload"))
            {
                smb.Username = dp.RwUsername;
                smb.Password = new EncryptionServices().DecryptText(dp.RwPassword);
            }
            else
            {
                smb.Username = dp.RoUsername;
                smb.Password = new EncryptionServices().DecryptText(dp.RoPassword);
            }

            return(JsonConvert.SerializeObject(smb));
        }
Example #4
0
        public string CheckQueue(int taskId)
        {
            var queueStatus = new QueueStatus();
            var activeImagingTaskServices = new ActiveImagingTaskServices();
            var thisComputerTask          = activeImagingTaskServices.GetTask(taskId);

            //var computer = new ComputerServices().GetComputer(thisComputerTask.ComputerId);
            //Check if already part of the queue

            if (thisComputerTask.Status == "2")
            {
                //Delete Any tasks that have passed the timeout value
                activeImagingTaskServices.CancelTimedOutTasks();
                //Check if the queue is open yet
                var inUse         = activeImagingTaskServices.GetCurrentQueue(thisComputerTask);
                var totalCapacity = 0;
                var dp            = new DistributionPointServices().GetDistributionPoint(thisComputerTask.DpId);
                totalCapacity = dp.QueueSize;
                if (inUse < totalCapacity)
                {
                    //queue is open, is this computer next
                    var firstTaskInQueue = activeImagingTaskServices.GetNextComputerInQueue(thisComputerTask);
                    if (firstTaskInQueue.ComputerId == thisComputerTask.ComputerId)
                    {
                        ChangeStatusInProgress(taskId);
                        queueStatus.Result   = "true";
                        queueStatus.Position = "0";
                        return(JsonConvert.SerializeObject(queueStatus));
                    }
                    //not time for this computer yet
                    queueStatus.Result   = "false";
                    queueStatus.Position = activeImagingTaskServices.GetQueuePosition(thisComputerTask);
                    return(JsonConvert.SerializeObject(queueStatus));
                }
                //queue not open yet
                queueStatus.Result   = "false";
                queueStatus.Position = activeImagingTaskServices.GetQueuePosition(thisComputerTask);
                return(JsonConvert.SerializeObject(queueStatus));
            }
            else
            {
                //New computer checking queue for the first time

                var inUse         = activeImagingTaskServices.GetCurrentQueue(thisComputerTask);
                var totalCapacity = 0;
                var dp            = new DistributionPointServices().GetDistributionPoint(thisComputerTask.DpId);
                totalCapacity = dp.QueueSize;
                if (inUse < totalCapacity)
                {
                    ChangeStatusInProgress(taskId);

                    queueStatus.Result   = "true";
                    queueStatus.Position = "0";
                    return(JsonConvert.SerializeObject(queueStatus));
                }
                //place into queue
                var lastQueuedTask = activeImagingTaskServices.GetLastQueuedTask(thisComputerTask);
                if (lastQueuedTask == null)
                {
                    thisComputerTask.QueuePosition = 1;
                }
                else
                {
                    thisComputerTask.QueuePosition = lastQueuedTask.QueuePosition + 1;
                }
                thisComputerTask.Status = "2";
                activeImagingTaskServices.UpdateActiveImagingTask(thisComputerTask);

                queueStatus.Result   = "false";
                queueStatus.Position = activeImagingTaskServices.GetQueuePosition(thisComputerTask);
                return(JsonConvert.SerializeObject(queueStatus));
            }
        }
Example #5
0
        public string GetLVMFileNameWithFullPath(string imageName, string schemaHdNumber, string vgName, string lvName,
                                                 string extension)
        {
            var primaryDp = new DistributionPointServices().GetPrimaryDistributionPoint();

            if (primaryDp == null)
            {
                return(string.Empty);
            }

            var filePath = "";

            if (primaryDp.Location == "Local")
            {
                var imagePath = primaryDp.PhysicalPath + "images" +
                                Path.DirectorySeparatorChar + imageName + Path.DirectorySeparatorChar + "hd" +
                                schemaHdNumber;
                try
                {
                    filePath =
                        Directory.GetFiles(
                            imagePath + Path.DirectorySeparatorChar,
                            vgName + "-" + lvName + "." + extension + ".*")
                        .FirstOrDefault();
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                }
            }
            else if (primaryDp.Location == "Remote")
            {
                using (var unc = new UncServices())
                {
                    var basePath    = @"\\" + primaryDp.Server + @"\" + primaryDp.ShareName;
                    var smbPassword = new EncryptionServices().DecryptText(primaryDp.RwPassword);
                    if (
                        unc.NetUseWithCredentials(basePath, primaryDp.RwUsername, primaryDp.Domain,
                                                  smbPassword) || unc.LastError == 1219)
                    {
                        var imagePath = basePath + @"\images\" + imageName + @"\hd" +
                                        schemaHdNumber;
                        try
                        {
                            filePath =
                                Directory.GetFiles(
                                    imagePath + @"\",
                                    vgName + "-" + lvName + "." + extension + ".*")
                                .FirstOrDefault();
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex.Message);
                        }
                    }
                    else
                    {
                        log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError);
                    }
                }
            }
            else
            {
                log.Error("Could Not Determine Primary Distribution Point Location Type");
            }

            return(filePath);
        }
Example #6
0
        public string ReadSchemaFile(string imageName)
        {
            var primaryDp = new DistributionPointServices().GetPrimaryDistributionPoint();

            if (primaryDp == null)
            {
                return(string.Empty);
            }
            var schemaText = "";

            if (primaryDp.Location == "Local")
            {
                try
                {
                    var path = primaryDp.PhysicalPath + "images" + Path.DirectorySeparatorChar +
                               imageName + Path.DirectorySeparatorChar + "schema";

                    using (var reader = new StreamReader(path))
                    {
                        schemaText = reader.ReadLine() ?? "";
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Could Not Read Schema File On The Primary Distribution Point");
                    log.Error(ex.Message);
                }
            }
            else if (primaryDp.Location == "Remote")
            {
                using (var unc = new UncServices())
                {
                    var basePath    = @"\\" + primaryDp.Server + @"\" + primaryDp.ShareName;
                    var smbPassword = new EncryptionServices().DecryptText(primaryDp.RwPassword);
                    if (
                        unc.NetUseWithCredentials(basePath, primaryDp.RwUsername, primaryDp.Domain,
                                                  smbPassword) || unc.LastError == 1219)
                    {
                        try
                        {
                            var path = basePath + @"\images\" + imageName + @"\schema";

                            using (var reader = new StreamReader(path))
                            {
                                schemaText = reader.ReadLine() ?? "";
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Could Not Read Schema File On The Primary Distribution Point");
                            log.Error(ex.Message);
                        }
                    }
                    else
                    {
                        log.Error("Could Not Read Schema File On The Primary Distribution Point");
                        log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError);
                    }
                }
            }
            else
            {
                log.Error("Could Not Determine Primary Distribution Point Location Type");
            }

            return(schemaText);
        }
Example #7
0
        public List <ImageFileInfo> GetPartitionFileSize(string imageName, string hd, string partition)
        {
            var primaryDp = new DistributionPointServices().GetPrimaryDistributionPoint();

            if (primaryDp == null)
            {
                return(null);
            }
            var imageFileInfo = new ImageFileInfo();

            if (primaryDp.Location == "Local")
            {
                try
                {
                    var imageFile =
                        Directory.GetFiles(
                            primaryDp.PhysicalPath + "images" + Path.DirectorySeparatorChar + imageName +
                            Path.DirectorySeparatorChar + "hd" + hd +
                            Path.DirectorySeparatorChar,
                            "part" + partition + ".*").FirstOrDefault();

                    var fi = new FileInfo(imageFile);
                    imageFileInfo = new ImageFileInfo
                    {
                        FileName = fi.Name,
                        FileSize = (fi.Length / 1024f / 1024f).ToString("#.##") + " MB"
                    };
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                    return(null);
                }
            }
            else if (primaryDp.Location == "Remote")
            {
                using (var unc = new UncServices())
                {
                    var basePath    = @"\\" + primaryDp.Server + @"\" + primaryDp.ShareName;
                    var smbPassword = new EncryptionServices().DecryptText(primaryDp.RwPassword);
                    if (
                        unc.NetUseWithCredentials(basePath, primaryDp.RwUsername, primaryDp.Domain,
                                                  smbPassword) || unc.LastError == 1219)
                    {
                        try
                        {
                            var imageFile =
                                Directory.GetFiles(basePath + @"\images\" + imageName +
                                                   @"\" + "hd" + hd + @"\", "part" + partition + ".*").FirstOrDefault();

                            var fi = new FileInfo(imageFile);
                            imageFileInfo = new ImageFileInfo
                            {
                                FileName = fi.Name,
                                FileSize = (fi.Length / 1024f / 1024f).ToString("#.##") + " MB"
                            };
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex.Message);
                            return(null);
                        }
                    }
                    else
                    {
                        log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError);
                        return(null);
                    }
                }
            }
            else
            {
                log.Error("Could Not Determine Primary Distribution Point Location Type");
                return(null);
            }

            return(new List <ImageFileInfo> {
                imageFileInfo
            });
        }
Example #8
0
        public DpFreeSpaceDTO GetDpFreeSpace()
        {
            var dp = new DistributionPointServices().GetPrimaryDistributionPoint();

            if (dp == null)
            {
                return(new DpFreeSpaceDTO());
            }

            var dpFreeSpace = new DpFreeSpaceDTO();

            if (dp.Location == "Remote")
            {
                var basePath = @"\\" + dp.Server + @"\" + dp.ShareName;
                dpFreeSpace.dPPath = basePath;
                using (var unc = new UncServices())
                {
                    var smbPassword = new EncryptionServices().DecryptText(dp.RwPassword);
                    if (
                        unc.NetUseWithCredentials(basePath, dp.RwUsername, dp.Domain,
                                                  smbPassword) || unc.LastError == 1219)
                    {
                        ulong freespace = 0;
                        ulong total     = 0;
                        var   success   = DriveFreeBytes(basePath, out freespace, out total);

                        if (!success)
                        {
                            return(null);
                        }

                        var freePercent = 0;
                        var usedPercent = 0;

                        if (total > 0 && freespace > 0)
                        {
                            freePercent = (int)(0.5f + 100f * Convert.ToInt64(freespace) / Convert.ToInt64(total));
                            usedPercent =
                                (int)(0.5f + 100f * Convert.ToInt64(total - freespace) / Convert.ToInt64(total));
                        }
                        dpFreeSpace.freespace   = freespace;
                        dpFreeSpace.total       = total;
                        dpFreeSpace.freePercent = freePercent;
                        dpFreeSpace.usedPercent = usedPercent;
                    }
                    else
                    {
                        log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError);
                    }
                }
            }
            else
            {
                dpFreeSpace.dPPath = dp.PhysicalPath;

                if (Directory.Exists(dp.PhysicalPath))
                {
                    ulong freespace = 0;
                    ulong total     = 0;

                    var  isUnix = Environment.OSVersion.ToString().Contains("Unix");
                    bool success;
                    if (isUnix)
                    {
                        success = MonoDriveFreeBytes(dp.PhysicalPath, out freespace, out total);
                    }
                    else
                    {
                        success = DriveFreeBytes(dp.PhysicalPath, out freespace, out total);
                    }


                    if (!success)
                    {
                        return(null);
                    }

                    var freePercent = 0;
                    var usedPercent = 0;

                    if (total > 0 && freespace > 0)
                    {
                        freePercent = (int)(0.5f + 100f * Convert.ToInt64(freespace) / Convert.ToInt64(total));
                        usedPercent =
                            (int)(0.5f + 100f * Convert.ToInt64(total - freespace) / Convert.ToInt64(total));
                    }
                    dpFreeSpace.freespace   = freespace;
                    dpFreeSpace.total       = total;
                    dpFreeSpace.freePercent = freePercent;
                    dpFreeSpace.usedPercent = usedPercent;
                }
            }

            return(dpFreeSpace);
        }