Exemple #1
0
        private void BackupSpaceCheck(string backupPath)
        {
            try
            {
                string text = "";
                double freeSpace;
                double totalSize;
                double postotak;
                ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk WHERE DeviceID='C:'");

                foreach (ManagementObject moDisk in mosDisks.Get())
                {
                    freeSpace = Convert.ToDouble(moDisk["FreeSpace"]);
                    totalSize = Convert.ToDouble(moDisk["Size"]);
                    postotak  = Math.Round((freeSpace / totalSize), 3) * 100;

                    freeSpace = Math.Round(freeSpace / (1024 * 1024 * 1024), 1);
                    totalSize = Math.Round(totalSize / (1024 * 1024 * 1024), 1);

                    text += "FREE SPACE: " + freeSpace.ToString() + " GB;" + Environment.NewLine;
                    text += "TOTAL SIZE: " + totalSize.ToString() + " GB;" + Environment.NewLine;
                    text += "Postotak " + postotak.ToString() + "% ;" + Environment.NewLine;

                    AvailableFreeSpace = freeSpace.ToString() + "/" + totalSize.ToString() + " GB (" + postotak.ToString() + "%)";
                }
            }
            catch (Exception ex)
            {
                RestHelpers.PostDataSync(fullAddress + logsInsertEndpoint, JsonConvert.SerializeObject(new { Type = "Error - Provjera diska", Message = "Greska pri provjeri slobodnog prostora na Backup disku", DevicesID = deviceID, LogDate = DateTime.Now }));
            }
        }
Exemple #2
0
        private void SmartStatusCheck()
        {
            try
            {
                //Get all disk drives
                ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

                string text = "";
                // Loop through each object (disk) retrieved by WMI
                foreach (ManagementObject moDisk in mosDisks.Get())
                {
                    text += "S.M.A.R.T: " + moDisk["Status"].ToString() + Environment.NewLine;
                    text += "Type: " + moDisk["MediaType"].ToString() + Environment.NewLine;
                    text += "Model: " + moDisk["Model"].ToString() + Environment.NewLine;
                    text += "------------------------------------" + Environment.NewLine;

                    SMARTStatus = moDisk["Status"].ToString();
                    HDDType     = moDisk["MediaType"].ToString();
                    HDDModel    = moDisk["Model"].ToString();
                }
            }
            catch (Exception ex)
            {
                RestHelpers.PostDataSync(fullAddress + logsInsertEndpoint, JsonConvert.SerializeObject(new { Type = "Error - SMART Status", Message = "Greska pri provjeri SMART statusa diska (ili drugih svojstava diska)", DevicesID = deviceID, LogDate = DateTime.Now }));
            }
        }
Exemple #3
0
        private void ZipFileCheck(string backupPath)
        {
            if (Directory.Exists(backupPath))
            {
                try
                {
                    DirectoryInfo backupDir = new DirectoryInfo(backupPath);
                    FileInfo[]    zipFiles  = backupDir.GetFiles("*.zip");
                    zipFiles = zipFiles.OrderByDescending(file => file.CreationTime).ToArray();

                    if (zipFiles.Length > 0)
                    {
                        FileInfo latestZip = zipFiles[0];

                        if (ZipFile.IsZipFile(backupPath + "\\" + latestZip.Name))
                        {
                            BackupCheck     = "Latest - Valid";
                            BackupCheckDate = DateTime.Now;
                            RestHelpers.PostDataSync(fullAddress + logsInsertEndpoint, JsonConvert.SerializeObject(new { Type = "Zip status", Message = "ZIP File " + latestZip.Name + "- VALID", DevicesID = deviceID, LogDate = DateTime.Now }));
                        }
                        else
                        {
                            BackupCheck     = "Latest - Corrputed";
                            BackupCheckDate = DateTime.Now;
                            RestHelpers.PostDataSync(fullAddress + logsInsertEndpoint, JsonConvert.SerializeObject(new { Type = "Zip status", Message = "ZIP File " + latestZip.Name + "- CORRUPTED", DevicesID = deviceID, LogDate = DateTime.Now }));
                        }
                    }
                }
                catch (Exception ex)
                {
                    RestHelpers.PostDataSync(fullAddress + logsInsertEndpoint, JsonConvert.SerializeObject(new { Type = "Error - Zip status", Message = "Greska pri provjeri Backup Zip datoteka", DevicesID = deviceID, LogDate = DateTime.Now }));
                }
            }
        }
Exemple #4
0
        private bool CheckUser()
        {
            try
            {
                string userJson = RestHelpers.GetDataSync(fullAddress + partnerSelectEndpoint + OIB);
                if (String.IsNullOrEmpty(userJson))
                {
                    return(false);
                }

                dynamic isUser = JsonConvert.DeserializeObject(userJson);

                if (isUser["COUNT(*)"] == 0)
                {
                    string isPosted = RestHelpers.PostDataSync(fullAddress + partnerInsertEndpoint, JsonConvert.SerializeObject(new { OIB = OIB, PartnerName = partnerName }));

                    if (String.IsNullOrEmpty(isPosted))
                    {
                        return(false);
                    }
                }
                else if (isUser["COUNT(*)"] == 1)
                {
                    return(true);
                }

                //Provjeri jos sta ako imamo COUNT > 1;
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #5
0
        private void SetStatus()
        {
            var statusJsonObj = new {
                SMARTStatus        = SMARTStatus,
                AvailableFreeSpace = AvailableFreeSpace,
                HDDType            = HDDType,
                HDDModel           = HDDModel,
                DevicesID          = deviceID,
                StatusDate         = StatusDate,
                BackupCheck        = BackupCheck,
                BackupCheckDate    = BackupCheckDate,
                TempDelDate        = TempDelDate,
                BackupCleanupDate  = BackupCleanupDate
            };

            RestHelpers.PostDataSync(fullAddress + statusInsertEndpoint, JsonConvert.SerializeObject(statusJsonObj));
        }
Exemple #6
0
        private bool CheckLocation()
        {
            try
            {
                string locationJson = RestHelpers.GetDataSync(fullAddress + locationSelectEndpoint + OIB.ToString() + "," + location.ToString());

                if (String.IsNullOrEmpty(locationJson))
                {
                    return(false);
                }

                dynamic isLocation = JsonConvert.DeserializeObject(locationJson);

                if (isLocation["COUNT(*)"] == 0)
                {
                    string isLocId = RestHelpers.PostDataSync(fullAddress + locationInsertEndpoint, JsonConvert.SerializeObject(new { LocationName = location, PartnerOIB = OIB }));
                    if (String.IsNullOrEmpty(isLocId))
                    {
                        return(false);
                    }

                    dynamic isLocationId = JsonConvert.DeserializeObject(isLocId);
                    Int32.TryParse(isLocationId, out locationID);
                }
                else if (isLocation["COUNT(*)"] == 1)
                {
                    string isLocId = RestHelpers.GetDataSync(fullAddress + locationIDEndpoint + OIB.ToString() + "," + location.ToString());
                    if (String.IsNullOrEmpty(isLocId))
                    {
                        return(false);
                    }

                    dynamic isLocationId = JsonConvert.DeserializeObject(isLocId);
                    locationID = isLocationId["ID"];
                }

                //Provjeri jos sta ako imamo COUNT > 1;
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #7
0
        private bool CheckDevice()
        {
            try
            {
                string deviceJson = RestHelpers.GetDataSync(fullAddress + deviceSelectEndpoint + locationID.ToString() + "," + device.ToString());
                if (String.IsNullOrEmpty(deviceJson))
                {
                    return(false);
                }

                dynamic isDevice = JsonConvert.DeserializeObject(deviceJson);

                if (isDevice["COUNT(*)"] == 0)
                {
                    string isDevId = RestHelpers.PostDataSync(fullAddress + deviceInsertEndpoint, JsonConvert.SerializeObject(new { DeviceName = device, LocationID = locationID }));
                    if (String.IsNullOrEmpty(isDevId))
                    {
                        return(false);
                    }

                    dynamic isDeviceId = JsonConvert.DeserializeObject(isDevId);
                    Int32.TryParse(isDeviceId, out deviceID);
                }
                else if (isDevice["COUNT(*)"] == 1)
                {
                    string isDevId = RestHelpers.GetDataSync(fullAddress + deviceIDEndpoint + locationID.ToString() + "," + device.ToString());
                    if (String.IsNullOrEmpty(isDevId))
                    {
                        return(false);
                    }

                    dynamic isDeviceId = JsonConvert.DeserializeObject(isDevId);
                    deviceID = isDeviceId["ID"];
                }

                //Provjeri jos sta ako imamo COUNT > 1;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #8
0
        private void DeleteOldBackupFiles(string backupPath, int deletionDays)
        {
            try
            {
                if (Directory.Exists(backupPath))
                {
                    FileInfo[] zipFiles = new DirectoryInfo(backupPath).GetFiles("*.zip");
                    foreach (FileInfo file in zipFiles)
                    {
                        if (DateTime.UtcNow - file.CreationTimeUtc > TimeSpan.FromDays(deletionDays))
                        {
                            File.Delete(file.FullName);
                        }
                    }

                    BackupCleanupDate = DateTime.Now;
                }
            }
            catch (Exception ex)
            {
                RestHelpers.PostDataSync(fullAddress + logsInsertEndpoint, JsonConvert.SerializeObject(new { Type = "Error - Brisanje starih Backupa", Message = "Greska pri brisanju starih Backup datoteka", DevicesID = deviceID, LogDate = DateTime.Now }));
            }
        }