예제 #1
0
        public static void DeleteFile(SavedOpData operation)
        {
            var id = operation.filedata_app_id;
            var fullpath = Path.Combine(OpDirectory, id + ".data");

            try
            {
                if (File.Exists(fullpath))
                {
                    File.Delete(fullpath);
                    Logger.Log("Operation file deleted: {0}" , LogLevel.Info, fullpath);
                }
            }
            catch (Exception)
            {
                Logger.Log("Unable to delete Operation File, not found.", LogLevel.Error);
            }
        }
예제 #2
0
        public static void DeleteLocalUpdateBundleFolder(SavedOpData update)
        {
            try
            {
                var dir = string.Empty;

                if (Directory.Exists(Settings.UpdateDirectory))
                {
                    switch (update.operation)
                    {
                    case OperationValue.InstallWindowsUpdate:
                        dir = Path.Combine(Settings.UpdateDirectory, update.filedata_app_id);
                        Directory.Delete(dir, true);
                        Logger.Log("Deleted update folder for: {0}", LogLevel.Info, update.filedata_app_name);
                        break;

                    case OperationValue.InstallSupportedApp:
                        var supportedFilePath = @"supported\" + update.filedata_app_id;
                        dir = Path.Combine(Settings.UpdateDirectory, supportedFilePath);
                        Directory.Delete(dir, true);
                        Logger.Log("Deleted update folder for: {0}", LogLevel.Info, update.filedata_app_name);
                        break;

                    case OperationValue.InstallCustomApp:
                        var customFilePath = @"custom\" + update.filedata_app_id;
                        dir = Path.Combine(Settings.UpdateDirectory, customFilePath);
                        Directory.Delete(dir, true);
                        Logger.Log("Deleted update folder for: {0}", LogLevel.Info, update.filedata_app_name);
                        break;
                    }
                }
            }
            catch (Exception)
            {
                Logger.Log("Exception when attempting to delete update folder.");
            }
        }
예제 #3
0
        public static void DeleteLocalUpdateBundleFolder(SavedOpData update)
        {
            try
            {
                var dir = string.Empty;

                if (Directory.Exists(Settings.UpdateDirectory))
                {
                    switch (update.operation)
                    {
                        case OperationValue.InstallWindowsUpdate:
                             dir = Path.Combine(Settings.UpdateDirectory, update.filedata_app_id);
                             Directory.Delete(dir, true);
                             Logger.Log("Deleted update folder for: {0}", LogLevel.Info, update.filedata_app_name);
                             break;

                        case OperationValue.InstallSupportedApp:
                             var supportedFilePath = @"supported\" + update.filedata_app_id;
                             dir = Path.Combine(Settings.UpdateDirectory, supportedFilePath);
                             Directory.Delete(dir, true);
                             Logger.Log("Deleted update folder for: {0}", LogLevel.Info, update.filedata_app_name);
                             break;

                        case OperationValue.InstallCustomApp:
                             var customFilePath = @"custom\" + update.filedata_app_id;
                             dir = Path.Combine(Settings.UpdateDirectory, customFilePath);
                             Directory.Delete(dir, true);
                             Logger.Log("Deleted update folder for: {0}", LogLevel.Info, update.filedata_app_name);
                             break;
                    }
                }
            }
            catch (Exception)
            {
                Logger.Log("Exception when attempting to delete update folder.");
            }
        }
예제 #4
0
        public static void UpdateStatus(SavedOpData operation, OperationStatus opStatus)
        {
            var id       = operation.filedata_app_id;
            var fullpath = Path.Combine(OpDirectory, id + ".data");

            if (!File.Exists(fullpath))
            {
                Logger.Log("Attempting to update operation: {0} but it was not found.", LogLevel.Info, operation.filedata_app_name);
                return;
            }

            try
            {
                var deserialized = JsonConvert.DeserializeObject <SavedOpData>((File.ReadAllText(fullpath)));
                deserialized.operation_status = opStatus;

                var serialized = JsonConvert.SerializeObject(deserialized);
                File.WriteAllText(fullpath, serialized);
            }
            catch
            {
                Logger.Log("Error when attempting to Update operation status.");
            }
        }
예제 #5
0
        public static void UpdateOperation(SavedOpData operation, bool installSuccess, bool rebootNeeded, OperationStatus opStatus, string path = "")
        {
            var    id = operation.filedata_app_id;
            string fullpath;

            if (path != "")
            {
                fullpath = path;
            }
            else
            {
                fullpath = Path.Combine(Tools.GetOpDirectory(), id + ".data");
            }

            if (!File.Exists(fullpath))
            {
                return;
            }

            try
            {
                var deserialized = JsonConvert.DeserializeObject <SavedOpData>(Security.Decrypt(File.ReadAllText(fullpath)));
                deserialized.success          = installSuccess.ToString();
                deserialized.reboot_required  = rebootNeeded.ToString().ToLower();
                deserialized.operation_status = opStatus;
                deserialized.error            = operation.error;

                var serialized = JsonConvert.SerializeObject(deserialized);
                serialized = Security.Encrypt(serialized);

                File.WriteAllText(fullpath, serialized);
            }
            catch
            {
            }
        }
예제 #6
0
 public static void CleanAllOperationData(SavedOpData operation)
 {
     DeleteFile(operation);
     DeleteLocalUpdateBundleFolder(operation);
 }
예제 #7
0
 public static void CleanAllOperationData(SavedOpData operation)
 {
     DeleteFile(operation);
     DeleteLocalUpdateBundleFolder(operation);
 }
예제 #8
0
        /// <summary>
        /// Example of how a json from the server should look with an incoming operation.
        /// [
        ///    {
        ///        "cpu_throttle": "normal", 
        ///        "restart": "none", 
        ///        "agent_id": "a3521251-4308-402c-9f4c-4fe357a445aa", 
        ///        "plugin": "rv", 
        ///        "operation_id": "6daa65599-499f-4d33-8edf-ba5653584180", 
        ///        "operation": "install_agent_update", 
        ///        "data": [
        ///            {
        ///                "name": "TopPatch Agent", 
        ///                "uri": "https://toppatch.com/downloads/RVAgentUpdate_02_00_12.exe", 
        ///                "uris" :[                      
        ///                         "file_uris": "https://toppatch.com/downloads/RVAgentUpdate_02_00_12.exe",
        ///                         "file_uris": "https://toppatch.com/downloads/RVAgentUpdate_02_00_12.exe"
        ///                     ]
        ///                "cli_options": "/qn UPDATE=\"true\" ",
        ///                "id": "06676211e6b5ebd53df167cb837eefe53c75fa7127946b115bd32cc6c84f5e06"
        ///            }
        ///        ], 
        ///        "net_throttle": "0"  
        ///        "server_queue_ttl": "123456789",       
        ///        "agent_queue_ttl" : "123456789"
        ///    }
        ///]
        /// </summary>
        /// <param name="operationJson">Message from the server.</param>
        private static void Serialize(string operationJson)
        {
            var parsed = JObject.Parse(operationJson);
            var deserialized = JsonConvert.DeserializeObject<IncomingData>(parsed.ToString());
            var directoryname = OpDirectory;

            foreach (var data in deserialized.file_data)
            {
                var opdata = new SavedOpData();
                var filename = Path.Combine(directoryname, data.app_id) + ".data";
                if (File.Exists(filename))
                {
                    Logger.Log("Operation {0} already exists on disk, will not overwrite.", LogLevel.Info, data.app_name);
                    continue;
                }

                Logger.Log("Saving {0} operation to disk.", LogLevel.Info, data.app_name);
                opdata.app_id = (String.IsNullOrEmpty(data.app_id)) ? String.Empty : data.app_id;
                opdata.cpu_throttle = (String.IsNullOrEmpty(deserialized.cpu_throttle)) ? String.Empty : deserialized.cpu_throttle;
                opdata.agent_id = (String.IsNullOrEmpty(deserialized.agent_id)) ? String.Empty : deserialized.agent_id;
                opdata.plugin = (String.IsNullOrEmpty(deserialized.plugin)) ? String.Empty : deserialized.plugin;
                opdata.operation_id = (String.IsNullOrEmpty(deserialized.operation_id)) ? String.Empty : deserialized.operation_id;
                opdata.operation = (String.IsNullOrEmpty(deserialized.operation)) ? String.Empty : deserialized.operation;
                opdata.restart = (String.IsNullOrEmpty(deserialized.restart)) ? String.Empty : deserialized.restart;
                opdata.net_throttle = deserialized.net_throttle.ToString(CultureInfo.InvariantCulture);
                opdata.filedata_app_id = (String.IsNullOrEmpty(data.app_id)) ? String.Empty : data.app_id;
                opdata.filedata_app_name = (String.IsNullOrEmpty(data.app_name)) ? String.Empty : data.app_name;
                opdata.filedata_app_clioptions = (String.IsNullOrEmpty(data.cli_options)) ? String.Empty : data.cli_options;
                opdata.error = string.Empty;
                opdata.reboot_required = false.ToString().ToLower();
                opdata.success = false.ToString().ToLower();
                opdata.operation_status = OperationStatus.Pending;
                //ttl
                opdata.server_queue_ttl = (String.IsNullOrEmpty(deserialized.server_queue_ttl)) ? String.Empty : deserialized.server_queue_ttl;
                opdata.agent_queue_ttl = (String.IsNullOrEmpty(deserialized.agent_queue_ttl)) ? String.Empty : deserialized.agent_queue_ttl;

                foreach (var uridata in data.app_uris)
                {
                    var appUri = new SavedOpData.AppUri();
                    appUri.file_name = (String.IsNullOrEmpty(uridata.file_name)) ? String.Empty : uridata.file_name;
                    appUri.file_size = uridata.file_size;
                    appUri.file_uri = (String.IsNullOrEmpty(uridata.file_uri)) ? String.Empty : uridata.file_uri;
                    foreach (var link in uridata.file_uris)
                    {
                        appUri.file_uris.Add(link);
                    }
                    appUri.file_hash = (String.IsNullOrEmpty(uridata.file_hash)) ? String.Empty : uridata.file_hash;
                    opdata.filedata_app_uris.Add(appUri);
                    }

                var serialized = JsonConvert.SerializeObject(opdata);
                File.WriteAllText(filename, serialized);
            }
        }
예제 #9
0
        public static void UpdateStatus(SavedOpData operation, OperationStatus opStatus)
        {
            var id = operation.filedata_app_id;
            var fullpath = Path.Combine(OpDirectory, id + ".data");

            if (!File.Exists(fullpath))
            {
                Logger.Log("Attempting to update operation: {0} but it was not found.", LogLevel.Info, operation.filedata_app_name);
                return;
            }

            try
            {
                var deserialized = JsonConvert.DeserializeObject<SavedOpData>((File.ReadAllText(fullpath)));
                deserialized.operation_status = opStatus;

                var serialized = JsonConvert.SerializeObject(deserialized);
                File.WriteAllText(fullpath, serialized);
            }
            catch
            {
                Logger.Log("Error when attempting to Update operation status.");
            }
        }
예제 #10
0
        public static void UpdateOperation(SavedOpData operation, bool installSuccess, bool rebootNeeded, OperationStatus opStatus)
        {
            var id       = operation.filedata_app_id;
            var fullpath = Path.Combine(OpDirectory, id + ".data");

            if (!File.Exists(fullpath))
            {
                Logger.Log("Attempting to update operation: {0} but it was not found.", LogLevel.Info, operation.filedata_app_name);
                return;
            }

            try
            {
                var deserialized                = JsonConvert.DeserializeObject<SavedOpData>((File.ReadAllText(fullpath)));
                deserialized.success            = installSuccess.ToString().ToLower();
                deserialized.reboot_required    = rebootNeeded.ToString().ToLower();
                deserialized.operation_status   = opStatus;

                var serialized = JsonConvert.SerializeObject(deserialized);
                File.WriteAllText(fullpath, serialized);
            }
            catch (Exception)
            {
                Logger.Log("Error when attempting to Update operation: {0}, with install success of:{1}, reboot:{2}", LogLevel.Info, operation.filedata_app_name, operation.success, operation.restart);
            }
        }
예제 #11
0
        public static string GetRawOperation(SavedOpData operation)
        {
            var id = operation.filedata_app_id;
            var fullpath = Path.Combine(OpDirectory, id + ".data");

            if (!File.Exists(fullpath))
            {
                Logger.Log("Attempting to update operation: {0} but it was not found.", LogLevel.Info, operation.filedata_app_name);
                return string.Empty;
            }

            try
            {
                var rawjson = File.ReadAllText(fullpath);
                if (rawjson.Count() > 1)
                    return rawjson;
                return string.Empty;
            }
            catch(Exception e)
            {
                Logger.Log("Error when attempting to retrieve raw json from operation file, Exception: {0}", LogLevel.Error, e.Message);
                return string.Empty;
            }
        }
예제 #12
0
        public static string GetCreationTime(SavedOpData operation)
        {
            var id = operation.filedata_app_id;
            var fullpath = Path.Combine(OpDirectory, id + ".data");

            try
            {
                if (File.Exists(fullpath))
                {
                    return File.GetCreationTime(fullpath).TimeOfDay.ToString();
                }
            }
            catch (Exception)
            {
                Logger.Log("Unable to retrieve Creation time of file..", LogLevel.Error);
            }

            return null;
        }
예제 #13
0
        public static void UpdateOperation(SavedOpData operation, bool installSuccess, bool rebootNeeded, OperationStatus opStatus, string path = "")
        {
            var id = operation.filedata_app_id;
            string fullpath;

            if (path != "")
                fullpath = path;
            else
                fullpath = Path.Combine(Tools.GetOpDirectory(), id + ".data");

            if (!File.Exists(fullpath))
                return;

            try
            {
                var deserialized = JsonConvert.DeserializeObject<SavedOpData>(Security.Decrypt(File.ReadAllText(fullpath)));
                deserialized.success = installSuccess.ToString();
                deserialized.reboot_required = rebootNeeded.ToString().ToLower();
                deserialized.operation_status = opStatus;
                deserialized.error = operation.error;

                var serialized = JsonConvert.SerializeObject(deserialized);
                serialized = Security.Encrypt(serialized);

                File.WriteAllText(fullpath, serialized);
            }
            catch
            {
            }
        }