/// <summary> /// Called automatically. Calls initialization functions. /// </summary> private void initialize() { // create a full path to the Efz configuration string path = Fs.Combine(AppDomain.CurrentDomain.BaseDirectory, ".Efz"); // add tasks to load and save the configuration if (SingletonConfiguration) { // add a start event that will load the config with this type as the key and run the Setup method ManagerUpdate.OnStart.Add( SingletonType.Name, ActionSet.New(Setup, ManagerResources.LoadNode(path, SingletonType.Name.Replace("Manager", string.Empty))) ); // add end event that will add the actual end event to ensure it's the last called ManagerUpdate.OnEnd.Add( new ActionSet <string, IAction>( onEndAdd, SingletonType.Name, ActionSet.New(End, ManagerResources.LoadNode(path, SingletonType.Name.Replace("Manager", string.Empty))) ) ); } // add on done event ManagerUpdate.OnStart.AddOnDone(Start); }
/// <summary> /// Get a stream as the result of the specified stream being compressed using the specified method. Optionally specify a length /// for the number of bytes to read, and dispose of the original stream. The decompressed stream is returned using the specified /// callback method. /// </summary> public static void Compress(IAction <MemoryStream> callback, System.Net.DecompressionMethods method, CompressionLevel level, Stream source, int length = -1, bool dispose = true) { // create a new memory stream to receive the compressed stream MemoryStream memStream = new MemoryStream(); // set the callback parameter callback.ArgA = memStream; // resolve the compression stream Stream compressionStream; switch (method) { case System.Net.DecompressionMethods.Deflate: compressionStream = new DeflateStream(memStream, level, true); break; case System.Net.DecompressionMethods.GZip: compressionStream = new GZipStream(memStream, level, true); break; default: // no compression - copy unchanged source.CopyTo(memStream); // run the callback callback.Run(); return; } // add a compress task ManagerUpdate.Control.AddSingle(ActionSet.New(Compress, callback, memStream, compressionStream, source, length, dispose)); }
//-------------------------------------------// /// <summary> /// Try remove a local file. /// </summary> protected static void TryRemoveFile(string path, int count) { try { File.Delete(path); return; } catch (Exception ex) { Log.Debug("Couldn't delete file. " + ex); } if (--count == 0) { Log.Error("Couldn't remove file '" + path + "'."); return; } _toRemove.Add(path, count); new Timer(2000, ActionSet.New(_removeSequence.AddRun, _toRemove)); }