/// <summary> /// Initializes a new instance of the <see cref="InnerPlugin{T}" /> class. /// </summary> /// <param name="openDelegate">Open method delegate.</param> /// <param name="saveDelegate">Save method delegate.</param> public InnerPlugin(OpenDelegate <string, T> openDelegate, SaveDelegate <string, T> saveDelegate) { this._openDelegate = openDelegate; this._saveDelegate = saveDelegate; this.ConfigObjectType = typeof(T); }
static Native() { //RuntimeCil.Generate(typeof(MemoryMapped).Assembly); Create = Marshal.GetDelegateForFunctionPointer <CreateDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "Create")); CreateAndOpen = Marshal.GetDelegateForFunctionPointer <CreateAndOpenDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "CreateAndOpen")); Destory = Marshal.GetDelegateForFunctionPointer <DestoryDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "Destory")); Open = Marshal.GetDelegateForFunctionPointer <OpenDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "Open")); Close = Marshal.GetDelegateForFunctionPointer <CloseDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "Close")); At = Marshal.GetDelegateForFunctionPointer <AtDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "At")); GetData = Marshal.GetDelegateForFunctionPointer <GetDataDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "GetData")); IsValid = Marshal.GetDelegateForFunctionPointer <IsValidDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "IsValid")); Size = Marshal.GetDelegateForFunctionPointer <SizeDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "Size")); MappedSize = Marshal.GetDelegateForFunctionPointer <MappedSizeDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "MappedSize")); Remap = Marshal.GetDelegateForFunctionPointer <RemapDelegate>(PlatformApi.NativeLibrary.GetExport(KokkosLibrary.ModuleHandle, "Remap")); }
private void OpenExcle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "选择文件"; openFileDialog.Filter = "xls,xlsx文件|*.xls;*.xlsx"; openFileDialog.FileName = string.Empty; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; openFileDialog.DefaultExt = "xls"; if (openFileDialog.ShowDialog() == true) { ExcelDataController edc = new ExcelDataController(); OpenDelegate od = new OpenDelegate(OpenExcel); loading.Visibility = Visibility.Visible; IAsyncResult asyncResult = od.BeginInvoke(openFileDialog.FileName, OpenExcelCompleted, od); //List<DealListEntity> DLEL = od.EndInvoke(asyncResult); //loading.Visibility = Visibility.Collapsed; //DBSyncController.Handler().DealListAdd(DLEL); //DBDataThreadController.DBDataThreadControllerHandler(DBSyncController.Handler()).DealListAdd(DLEL); //StockStateBoxController.Handler().StockBoxInit(); } else { return; } }
// Dispose(bool disposing) executes in two distinct scenarios. // If disposing equals true, the method has been called directly // or indirectly by a user's code. Managed and unmanaged resources // can be disposed. // If disposing equals false, the method has been called by the // runtime from inside the finalizer and you should not reference // other objects. Only unmanaged resources can be disposed. private void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (_disposed) { return; } // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Dispose managed resources. _dllhandle = IntPtr.Zero; _open = null; _close = null; _start = null; _reset = null; _config = null; _read = null; _write = null; _checkTx = null; _getDeviceList = null; } // Dispose native ( unmanaged ) resources, if exits // Note disposing has been done. _disposed = true; }
internal static void Bind() { _closeDelegate = Library.GetProcAddress <CloseDelegate>("mdbx_cursor_close") as CloseDelegate; _openDelegate = Library.GetProcAddress <OpenDelegate>("mdbx_cursor_open") as OpenDelegate; _getDelegate = Library.GetProcAddress <GetDelegate>("mdbx_cursor_get") as GetDelegate; _putDelegate = Library.GetProcAddress <PutDelegate>("mdbx_cursor_put") as PutDelegate; _delDelegate = Library.GetProcAddress <DelDelegate>("mdbx_cursor_del") as DelDelegate; _countDelegate = Library.GetProcAddress <CountDelegate>("mdbx_cursor_count") as CountDelegate; }
/// <summary> /// Add configuration editor plugin. /// </summary> /// <typeparam name="T">Type of configuration object.</typeparam> /// <param name="openDelegate">How to get configuration object from a file.</param> /// <param name="saveDelegate">How to save configuration object to a file.</param> /// <param name="configEditorPluginName">IWinFormConfigEditorPlugin PluginName.</param> public void AddPlugin <T>(OpenDelegate <string, T> openDelegate, SaveDelegate <string, T> saveDelegate, string configEditorPluginName = null) { IWinFormConfigEditorPlugin configEditorPlugin = new InnerPlugin <T>(openDelegate, saveDelegate); configEditorPlugin.PluginName = configEditorPluginName; this._configEditorPluginList.Add(configEditorPlugin); this.toolStripComboBoxConfigEditorPlugin.Items.Add(configEditorPlugin.PluginName); this.toolStripComboBoxConfigEditorPlugin.SelectedIndex = this._configEditorPluginList.IndexOf(configEditorPlugin); }
internal static void Bind() { _openDelegate = Library.GetProcAddress <OpenDelegate>("mdbx_dbi_open") as OpenDelegate; _closeDelegate = Library.GetProcAddress <CloseDelegate>("mdbx_dbi_close") as CloseDelegate; _putDelegate = Library.GetProcAddress <PutDelegate>("mdbx_put") as PutDelegate; _getDelegate = Library.GetProcAddress <GetDelegate>("mdbx_get") as GetDelegate; _delDelegate = Library.GetProcAddress <DelDelegate>("mdbx_del") as DelDelegate; _dropDelegate = Library.GetProcAddress <DropDelegate>("mdbx_drop") as DropDelegate; }
/// <summary> /// Add an entry, for which the application will provide a stream /// containing the entry data, on a just-in-time basis. /// </summary> /// /// <remarks> /// <para> /// In cases where the application wishes to open the stream that /// holds the content for the ZipEntry, on a just-in-time basis, the /// application can use this method. The application provides an /// opener delegate that will be called by the DotNetZip library to /// obtain a readable stream that can be read to get the bytes for /// the given entry. Typically, this delegate opens a stream. /// Optionally, the application can provide a closer delegate as /// well, which will be called by DotNetZip when all bytes have been /// read from the entry. /// </para> /// /// <para> /// These delegates are called from within the scope of the call to /// ZipFile.Save(). /// </para> /// /// <para> /// For <c>ZipFile</c> properties including <see cref="Encryption"/>, <see /// cref="Password"/>, <see cref="SetCompression"/>, <see /// cref="ProvisionalAlternateEncoding"/>, <see cref="ExtractExistingFile"/>, /// <see cref="ZipErrorAction"/>, and <see cref="CompressionLevel"/>, their /// respective values at the time of this call will be applied to the /// <c>ZipEntry</c> added. /// </para> /// /// </remarks> /// /// <example> /// /// This example uses anonymous methods in C# to open and close the /// source stream for the content for a zip entry. /// /// <code lang="C#"> /// using(Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile()) /// { /// zip.AddEntry(zipEntryName, /// (name) => File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite ), /// (name, stream) => stream.Close() /// ); /// /// zip.Save(zipFileName); /// } /// </code> /// /// </example> /// /// <example> /// /// This example uses delegates in VB.NET to open and close the /// the source stream for the content for a zip entry. VB 9.0 lacks /// support for "Sub" lambda expressions, and so the CloseDelegate must /// be an actual, named Sub. /// /// <code lang="VB"> /// /// Function MyStreamOpener(ByVal entryName As String) As Stream /// '' This simply opens a file. You probably want to do somethinig /// '' more involved here: open a stream to read from a database, /// '' open a stream on an HTTP connection, and so on. /// Return File.OpenRead(entryName) /// End Function /// /// Sub MyStreamCloser(entryName As String, stream As Stream) /// stream.Close() /// End Sub /// /// Public Sub Run() /// Dim dirToZip As String = "fodder" /// Dim zipFileToCreate As String = "Archive.zip" /// Dim opener As OpenDelegate = AddressOf MyStreamOpener /// Dim closer As CloseDelegate = AddressOf MyStreamCloser /// Dim numFilestoAdd As Int32 = 4 /// Using zip As ZipFile = New ZipFile /// Dim i As Integer /// For i = 0 To numFilesToAdd - 1 /// zip.AddEntry(String.Format("content-{0:000}.txt"), opener, closer) /// Next i /// zip.Save(zipFileToCreate) /// End Using /// End Sub /// /// </code> /// </example> /// /// <param name="entryName">the name of the entry to add</param> /// <param name="opener"> /// the delegate that will be invoked by ZipFile.Save() to get the /// readable stream for the given entry. ZipFile.Save() will call /// read on this stream to obtain the data for the entry. This data /// will then be compressed and written to the newly created zip /// file. /// </param> /// <param name="closer"> /// the delegate that will be invoked to close the stream. This may /// be null (Nothing in VB), in which case no call is makde to close /// the stream. /// </param> /// <returns>the ZipEntry added</returns> /// public ZipEntry AddEntry(string entryName, OpenDelegate opener, CloseDelegate closer) { ZipEntry ze = ZipEntry.CreateForJitStreamProvider(entryName, opener, closer); ze.SetEntryTimes(DateTime.Now, DateTime.Now, DateTime.Now); if (Verbose) { StatusMessageTextWriter.WriteLine("adding {0}...", entryName); } return(_InternalAddEntry(ze)); }
static CallbackHandler() { loadCallback = new LoadDelegate(load); unloadCallback = new UnloadDelegate(unload); openCallback = new OpenDelegate(open); listCallback = new ListDelegate(list); listFileInfoCallback = new ListFileInfoDelegate(listFileInfo); findCallback = new FindDelegate(find); findFileInfoCallback = new FindFileInfoDelegate(findFileInfo); existsCallback = new ExistsDelegate(exists); }
internal static void Bind() { _createDelegate = Library.GetProcAddress <CreateDelegate>("mdbx_env_create") as CreateDelegate; _closeDelegate = Library.GetProcAddress <CloseDelegate>("mdbx_env_close") as CloseDelegate; _closeExDelegate = Library.GetProcAddress <CloseExDelegate>("mdbx_env_close_ex") as CloseExDelegate; _openDelegate = Library.GetProcAddress <OpenDelegate>("mdbx_env_open") as OpenDelegate; _statDelegate = Library.GetProcAddress <StatDelegate>("mdbx_env_stat") as StatDelegate; _infoDelegate = Library.GetProcAddress <InfoDelegate>("mdbx_env_info") as InfoDelegate; _syncDelegate = Library.GetProcAddress <SyncDelegate>("mdbx_env_sync") as SyncDelegate; _setMaxDbsDelegate = Library.GetProcAddress <SetMaxDbsDelegate>("mdbx_env_set_maxdbs") as SetMaxDbsDelegate; _setFlagsDelegate = Library.GetProcAddress <SetFlagsDelegate>("mdbx_env_set_flags") as SetFlagsDelegate; _getFlagsDelegate = Library.GetProcAddress <GetFlagsDelegate>("mdbx_env_get_flags") as GetFlagsDelegate; _setMapSizeDelegate = Library.GetProcAddress <SetMapSizeDelegate>("mdbx_env_set_mapsize") as SetMapSizeDelegate; _setMaxReadersDelegate = Library.GetProcAddress <SetMaxReadersDelegate>("mdbx_env_set_maxreaders") as SetMaxReadersDelegate; _getMaxReadersDelegate = Library.GetProcAddress <GetMaxReadersDelegate>("mdbx_env_get_maxreaders") as GetMaxReadersDelegate; _getMaxKeySizeDelegate = Library.GetProcAddress <GetMaxKeySizeDelegate>("mdbx_env_get_maxkeysize") as GetMaxKeySizeDelegate; }
private CustomApplicationContext(string _DefaultTooltip , Bitmap _bmpIconFileName , ContextMenuBuilderDelegate _ContextMenuBuilderDelegate , OpenDelegate _OpenDelegate , DoubleClickDelegate _DoubleClickDelegate , OnExitAppDelegate _OnExitAppDelegate , string _sOpenMenueItemDisplayText) { m_bmpIconFileName = _bmpIconFileName; m_DefaultTooltip = _DefaultTooltip; m_ContextMenuBuilderDelegate = _ContextMenuBuilderDelegate; m_OpenDelegate = _OpenDelegate; m_DoubleClickDelegate = _DoubleClickDelegate; m_OnExitAppDelegate = _OnExitAppDelegate; m_sOpenMenueItemDisplayText = _sOpenMenueItemDisplayText; InitializeContext(); }
private static void GetStateDelegate(StateInfo state, Type type) { var method = type.GetMethod(state.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(float) }, null); if (method != null) { state.InvokeWithTimeDelegate = (OpenDelegate <float>)OpenDelegate.Create(method as MethodInfo); return; } method = type.GetMethod(state.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null); if (method != null) { state.InvokeDelegate = (OpenDelegate)OpenDelegate.Create(method as MethodInfo); return; } if (type.BaseType != null) { GetStateDelegate(state, type.BaseType); } }
public static void InitCustomApplicationContext(string _DefaultTooltip , Bitmap _bmpIconFileName , ContextMenuBuilderDelegate _ContextMenuBuilderDelegate , OpenDelegate _OpenDelegate , DoubleClickDelegate _DoubleClickDelegate , OnExitAppDelegate _OnExitAppDelegate , string _sOpenMenueItemDisplayText) { try { instance = new CustomApplicationContext(_DefaultTooltip , _bmpIconFileName , _ContextMenuBuilderDelegate , _OpenDelegate , _DoubleClickDelegate , _OnExitAppDelegate , _sOpenMenueItemDisplayText); } catch (Exception exp) { Logger.WriteError(exp, "99fa623c-2fd1-40dd-93ba-752d1d69c857"); } }
/// <summary> /// Attempt to add a transition to the given transitions list /// </summary> private static StateTransitionInfo CreateTransition(StateMachineInfo info, StateInfo from, StateInfo to) { if (from == to) { return(null); } // Check for the transition method var methodInfo = info.TargetType.GetMethod( $"On{from?.Name??"Any"}To{to?.Name??"Any"}", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (methodInfo == null) { return(null); } return(new StateTransitionInfo { From = from, To = to, InvokeDelegate = OpenDelegate.Create(methodInfo) }); }
public SourceVirtualFile(string virtualPath, OpenDelegate streamDelegate) { this.path = virtualPath; this.stream = streamDelegate; }
private static void GetInfo(Type type, List <StateInfo> states, List <StateTriggerInfo> triggers, List <StateTransitionInfo> transitions) { // Recurse through all parent types as well if (type.BaseType != null) { GetInfo(type.BaseType, states, triggers, transitions); } // Get all public and private methods var members = type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (var member in members) { switch (member.MemberType) { case MemberTypes.Field: case MemberTypes.Property: { foreach (var attr in member.GetCustomAttributes <StateTriggerAttribute>()) { var trigger = new StateTriggerInfo(); trigger.From = GetState(states, attr.From); trigger.To = GetState(states, attr.To); trigger.TargetValue = attr.Value; trigger.Getter = (FastGetter <bool>)FastGetter.Create(member); if (trigger.To == null) { throw new InvalidOperationException("trigger to state must not be null"); } triggers.Add(trigger); } break; } case MemberTypes.Method: { // Get transitions foreach (var attr in member.GetCustomAttributes <StateTransitionAttribute>()) { var trans = new StateTransitionInfo(); trans.From = GetState(states, attr.From); trans.To = GetState(states, attr.To); if (((member as MethodInfo).GetParameters()).Length == 0) { trans.InvokeDelegate = (OpenDelegate)OpenDelegate.Create(member as MethodInfo); } else { throw new InvalidOperationException("state transitions must return void and take no parameter or one parameter as a float"); } if (trans.To == null) { throw new InvalidOperationException("transition to state must not be null"); } transitions.Add(trans); } #if false // Get states foreach (var attr in member.GetCustomAttributes <StateAttribute>()) { var state = GetState(states, attr.Name ?? member.Name); var parameters = (member as MethodInfo).GetParameters(); if (parameters.Length == 0) { state.InvokeDelegate = (OpenDelegate)OpenDelegate.Create(member as MethodInfo); } else if (parameters.Length == 1 && parameters[0].ParameterType == typeof(float)) { state.InvokeWithTimeDelegate = (OpenDelegate <float>)OpenDelegate.Create(member as MethodInfo); } else { throw new InvalidOperationException("states must return void and take no parameter or one parameter as a float"); } } #endif break; } } } }
/// <summary> /// Binds the class instance methods to the dll functions. /// </summary> /// <param name="hDll">A dll to bind to.</param> private void BindToDll(IntPtr hDll) { IntPtr pProcPtr = GetProcAddress(hDll, "Initialize"); _initialize = (InitializeDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(InitializeDelegate)); pProcPtr = GetProcAddress(hDll, "Open"); _open = (OpenDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(OpenDelegate)); pProcPtr = GetProcAddress(hDll, "Play"); _play = (PlayDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(PlayDelegate)); pProcPtr = GetProcAddress(hDll, "GetCurrentFrame"); _getCurrentFrame = (GetCurrentFrameDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(GetCurrentFrameDelegate)); pProcPtr = GetProcAddress(hDll, "GetFrameSize"); _getFrameSize = (GetFrameSizeDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(GetFrameSizeDelegate)); pProcPtr = GetProcAddress(hDll, "Stop"); _stop = (StopDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(StopDelegate)); pProcPtr = GetProcAddress(hDll, "Uninitialize"); _uninitialize = (UninitializeDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(UninitializeDelegate)); }
public SourceVirtualFile(string virtualPath, OpenDelegate streamDelegate) { this.path = virtualPath; this.stream = streamDelegate; }
protected SubSocketBase(OpenDelegate open) : base(open) { }
protected override void OnEndOpen(IAsyncResult result) { OpenDelegate d = new OpenDelegate(this.Open); d.EndInvoke(result); }
/// <summary> /// Add an entry, for which the application will provide a stream, /// just-in-time. /// </summary> /// /// <remarks> /// <para> /// In cases where the application wishes to open the stream that holds /// the content for the ZipEntry, on a just-in-time basis, the application /// can use this method and provide delegates to open and close the /// stream. /// </para> /// /// <para> /// For <c>ZipFile</c> properties including <see cref="Encryption"/>, <see /// cref="Password"/>, <see cref="SetCompression"/>, <see /// cref="ProvisionalAlternateEncoding"/>, <see cref="ExtractExistingFile"/>, /// <see cref="ZipErrorAction"/>, and <see cref="CompressionLevel"/>, their /// respective values at the time of this call will be applied to the /// <c>ZipEntry</c> added. /// </para> /// /// </remarks> /// /// <example> /// /// This example uses anonymous methods in C# to open and close the /// source stream for the content for a zip entry. In a real /// application, the logic for the OpenDelegate would probably be more /// involved. /// /// <code lang="C#"> /// using(Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile()) /// { /// zip.AddEntry(zipEntryName, /// (name) => File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite ), /// (name, stream) => stream.Close() /// ); /// /// zip.Save(zipFileName); /// } /// </code> /// /// </example> /// /// <example> /// /// This example uses delegates in VB.NET to open and close the /// the source stream for the content for a zip entry. VB 9.0 lacks /// support for "Sub" lambda expressions, and so the CloseDelegate must /// be an actual, named Sub. /// /// <code lang="VB"> /// /// Function MyStreamOpener(ByVal entryName As String) As Stream /// '' This simply opens a file. You probably want to do somethinig /// '' more involved here: open a stream to read from a database, /// '' open a stream on an HTTP connection, and so on. /// Return File.OpenRead(entryName) /// End Function /// /// Sub MyStreamCloser(entryName As String, stream As Stream) /// stream.Close() /// End Sub /// /// Public Sub Run() /// Dim dirToZip As String = "fodder" /// Dim zipFileToCreate As String = "Archive.zip" /// Dim opener As OpenDelegate = AddressOf MyStreamOpener /// Dim closer As CloseDelegate = AddressOf MyStreamCloser /// Dim numFilestoAdd As Int32 = 4 /// Using zip As ZipFile = New ZipFile /// Dim i As Integer /// For i = 0 To numFilesToAdd - 1 /// zip.AddEntry(String.Format("content-{0:000}.txt"), opener, closer) /// Next i /// zip.Save(zipFileToCreate) /// End Using /// End Sub /// /// </code> /// </example> /// /// <param name="entryName">the name of the entry to add</param> /// <param name="opener"> /// the delegate that will be invoked to open the stream /// </param> /// <param name="closer"> /// the delegate that will be invoked to close the stream /// </param> /// <returns>the ZipEntry added</returns> /// public ZipEntry AddEntry(string entryName, OpenDelegate opener, CloseDelegate closer) { ZipEntry ze = ZipEntry.CreateForJitStreamProvider(entryName, opener, closer); ze.SetEntryTimes(DateTime.Now,DateTime.Now,DateTime.Now); if (Verbose) StatusMessageTextWriter.WriteLine("adding {0}...", entryName); return _InternalAddEntry(ze); }
[TestMethod, Timeout(7200000)] // 3600000 - 1 hour public void Create_LargeSegmentedArchive() { // There was a claim that large archives (around or above // 1gb) did not work well with archive splitting. This test // attempts to verify that behavior. #if REMOTE_FILESYSTEM string parentDir = Path.Combine("t:\\tdir", Path.GetFileNameWithoutExtension(TopLevelDir)); _FilesToRemove.Add(parentDir); Directory.CreateDirectory(parentDir); string zipFileToCreate = Path.Combine(parentDir, "Create_LargeSegmentedArchive.zip"); #else string zipFileToCreate = Path.Combine(TopLevelDir, "Create_LargeSegmentedArchive.zip"); #endif TestContext.WriteLine("Creating file {0}", zipFileToCreate); // int maxSegSize = 4*1024*1024; // int sizeBase = 10 * 1024 * 1024; // int sizeRandom = 1 * 1024 * 1024; // int numFiles = 3; int maxSegSize = 120*1024*1024; int sizeBase = 420 * 1024 * 1024; int sizeRandom = 16 * 1024 * 1024; int numFiles = _rnd.Next(4) + 12; int numSaving= 0, totalToSave = 0, numSegs= 0; bool pb1set = false; OpenDelegate opener = (name) => { return new Ionic.Zip.Tests.Utilities.RandomTextInputStream(sizeBase + _rnd.Next(sizeRandom)); }; CloseDelegate closer = (name, s) => { var rtg = (Ionic.Zip.Tests.Utilities.RandomTextInputStream) s; }; System.EventHandler<Ionic.Zip.SaveProgressEventArgs> sp = (sender1, e1) => { switch (e1.EventType) { case ZipProgressEventType.Saving_Started: numSaving= 0; break; case ZipProgressEventType.Saving_BeforeWriteEntry: _txrx.Send(String.Format("test Large Segmented ZIP"); _txrx.Send(String.Format("status saving {0}", e1.CurrentEntry.FileName)); pb1set= false; totalToSave = e1.EntriesTotal; numSaving++; break; case ZipProgressEventType.Saving_EntryBytesRead: if (!pb1set) { _txrx.Send(String.Format("pb 1 max {0}", e1.TotalBytesToTransfer)); pb1set = true; } _txrx.Send(String.Format("status Saving entry {0}/{1} {2} :: {3}/{4}mb {5:N0}%", numSaving, totalToSave, e1.CurrentEntry.FileName, e1.BytesTransferred/(1024*1024), e1.TotalBytesToTransfer/(1024*1024), ((double)e1.BytesTransferred) / (0.01 * e1.TotalBytesToTransfer))); string msg = String.Format("pb 1 value {0}", e1.BytesTransferred); _txrx.Send(msg); break; case ZipProgressEventType.Saving_AfterWriteEntry: TestContext.WriteLine("Saved entry {0}, {1} bytes", e1.CurrentEntry.FileName, e1.CurrentEntry.UncompressedSize); _txrx.Send("pb 0 step"); pb1set = false; break; } }; string progressChannel = "largesegmentedzip"; StartProgressMonitor(progressChannel); StartProgressClient(progressChannel, "Large Segmented ZIP", "Creating files"); _txrx.Send(String.Format("pb 0 max {0}", numFiles)); // build a large zip file out of thin air var sw = new StringWriter(); using (ZipFile zip = new ZipFile()) { zip.StatusMessageTextWriter = sw; zip.BufferSize = 0x8000; zip.CodecBufferSize = 0x8000; zip.MaxOutputSegmentSize = maxSegSize; zip.SaveProgress += sp; for (int i = 0; i < numFiles; i++) { string filename = TestUtilities.GetOneRandomUppercaseAsciiChar() + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".txt"; zip.AddEntry(filename, opener, closer); } zip.Save(zipFileToCreate); numSegs = zip.NumberOfSegmentsForMostRecentSave; } if (((long)numSegs*maxSegSize) < (long)(1024*1024*1024L)) { _FilesToRemove.Remove(parentDir); Assert.IsTrue(false, "There were not enough segments in that zip. numsegs({0}) maxsize({1}).", numSegs, maxSegSize); } _txrx.Send("status Verifying that zip (this will take a while)..."); BasicVerifyZip(zipFileToCreate); }
private static extern IntPtr OgreManagedArchive_Create(String name, String archType, LoadDelegate loadCallback, UnloadDelegate unloadCallback, OpenDelegate openCallback, ListDelegate listCallback, ListFileInfoDelegate listFileInfoCallback, FindDelegate findCallback, FindFileInfoDelegate findFileInfoCallback, ExistsDelegate existsCallback #if FULL_AOT_COMPILE , IntPtr instanceHandle #endif );
private void OpenExcle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "选择文件"; openFileDialog.Filter = "xls,xlsx文件|*.xls;*.xlsx"; openFileDialog.FileName = string.Empty; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; openFileDialog.DefaultExt = "xls"; if (openFileDialog.ShowDialog() == true) { ExcelDataController edc = new ExcelDataController(); OpenDelegate od = new OpenDelegate(OpenExcel); loading.Visibility = Visibility.Visible; IAsyncResult asyncResult = od.BeginInvoke(openFileDialog.FileName, OpenExcelCompleted, od); //List<DealListEntity> DLEL = od.EndInvoke(asyncResult); //loading.Visibility = Visibility.Collapsed; //DBSyncController.Handler().DealListAdd(DLEL); //DBDataThreadController.DBDataThreadControllerHandler(DBSyncController.Handler()).DealListAdd(DLEL); //StockStateBoxController.Handler().StockBoxInit(); } else { return; } }
/// <summary> /// Подпрограмма открытия платы /// </summary> /// <param name="serialNumber"></param> public int Open(ushort serialNumber) { // Выделение памяти в неуправляемой памяти процесса // var pnt = Marshal.AllocHGlobal( Marshal.SizeOf( zzz ) ); // Копирование структуры zzz в неуправляемую память // Marshal.StructureToPtr( zzz, pnt, false ); // Возврат структуры из неупраяляемой памяти // var zzz1 = ( pci429_4_tag) Marshal.PtrToStructure( pnt, typeof( pci429_4_tag ) ); // Освобождение неуправляемой памяти // Marshal.FreeHGlobal( pnt ); var error = 0; // Synchronously wait to enter the Semaphore. SemaphoreSlim.Wait(); // Get handle to .dll file _dllhandle = NativeMethods.LoadLibrary(NameDll); if (_dllhandle == IntPtr.Zero) { // Handle error loading error = 1; } else { // Get handle to Open method in .dll file var open_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_open"); if (open_handle == IntPtr.Zero) { error = 2; } else { _open = ( OpenDelegate )Marshal.GetDelegateForFunctionPointer( open_handle, typeof(OpenDelegate)); if (_open == null) { error = 3; } } // Get handle to Close method in .dll file var close_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_close"); if (close_handle == IntPtr.Zero) { error = 4; } else { _close = ( CloseDelegate )Marshal.GetDelegateForFunctionPointer(close_handle, typeof(CloseDelegate)); if (_close == null) { error = 5; } } // Get handle to Start method in .dll file var start_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_start"); if (start_handle == IntPtr.Zero) { error = 6; } else { _start = ( StartDelegate )Marshal.GetDelegateForFunctionPointer(start_handle, typeof(StartDelegate)); if (_start == null) { error = 7; } } // Get handle to Reset method in .dll file var reset_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_reset"); if (reset_handle == IntPtr.Zero) { error = 8; } else { _reset = ( ResetDelegate )Marshal.GetDelegateForFunctionPointer(reset_handle, typeof(ResetDelegate)); if (_reset == null) { error = 9; } } // Get handle to Config method in .dll file var config_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_set_freq"); if (config_handle == IntPtr.Zero) { error = 10; } else { _config = ( ConfigDelegate )Marshal.GetDelegateForFunctionPointer(config_handle, typeof(ConfigDelegate)); if (_config == null) { error = 11; } } // Get handle to Read method in .dll file var read_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_read_rx"); if (read_handle == IntPtr.Zero) { error = 12; } else { _read = ( ReadDelegate )Marshal.GetDelegateForFunctionPointer(read_handle, typeof(ReadDelegate)); if (_read == null) { error = 13; } } // Get handle to Write method in .dll file var write_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_write_tx"); if (write_handle == IntPtr.Zero) { error = 14; } else { _write = ( WriteDelegate )Marshal.GetDelegateForFunctionPointer(write_handle, typeof(WriteDelegate)); if (_write == null) { error = 15; } } // Get handle to CheckTx method in .dll file var check_tx_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_check_tx"); if (check_tx_handle == IntPtr.Zero) { error = 16; } else { _checkTx = ( CheckTxDelegate )Marshal.GetDelegateForFunctionPointer(check_tx_handle, typeof(CheckTxDelegate)); if (_checkTx == null) { error = 17; } } // Get handle to GetDevice method in .dll file var get_device_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_get_dev_list"); if (get_device_handle == IntPtr.Zero) { error = 18; } else { _getDeviceList = ( GetDeviceDelegate )Marshal.GetDelegateForFunctionPointer(get_device_handle, typeof(GetDeviceDelegate)); if (_getDeviceList == null) { error = 19; } } // Открытие устройства error += _open?.Invoke(serialNumber, out _device) ?? int.MaxValue; if (_device.handle == ( IntPtr )0) { error = 18; } } // Release the Semaphore. SemaphoreSlim.Release(); return(error); }
/// <summary> /// Create state machine info for a given type /// </summary> /// <param name="type"></param> /// <returns></returns> public static StateMachineInfo Create(Type type, Type statesType) { var typeName = type.FullName; if (_cache.TryGetValue(typeName, out var info)) { return(info); } var values = Enum.GetValues(statesType); var states = new StateInfo[values.Length]; foreach (var value in values) { var index = (int)value; var name = value.ToString(); if (index < 0 || index >= states.Length) { throw new UnityException("State enum must be sequential and start from zero"); } states[index] = new StateInfo { Name = value.ToString(), Mask = (1UL << index), Index = index }; } // Create a new state machine info info = new StateMachineInfo(); info.TargetType = type; info.States = states; info._transitionStride = states.Length + 1; _cache.Add(typeName, info); // Get state method and transitions info._transitions = new StateTransitionInfo[states.Length * info._transitionStride]; foreach (var stateToInfo in states) { // State method? var stateMethod = type.GetMethod($"On{stateToInfo.Name}", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (null != stateMethod) { var parameters = stateMethod.GetParameters(); if (parameters.Length == 0) { stateToInfo.InvokeDelegate = OpenDelegate.Create(stateMethod); } else if (parameters.Length == 1 && parameters[0].ParameterType == typeof(float)) { stateToInfo.InvokeWithTimeDelegate = OpenDelegate <float> .Create(stateMethod); } else { throw new UnityException($"method for state '{stateToInfo.Name}' does not match a valid state signature"); } } // Add the "Any" to state transition info._transitions[info.GetTransitionIndex(-1, stateToInfo.Index)] = CreateTransition(info, null, stateToInfo); // Add transition from all other states foreach (var stateFromInfo in states) { info._transitions[info.GetTransitionIndex(stateFromInfo.Index, stateToInfo.Index)] = CreateTransition(info, stateFromInfo, stateToInfo); } } return(info); }
/// <summary> /// Updates the given entry in the <c>ZipFile</c>, using the given delegates /// to open and close the stream that provides the content for the <c>ZipEntry</c>. /// </summary> /// /// <remarks> /// Calling this method is equivalent to removing the <c>ZipEntry</c> for the /// given file name and directory path, if it exists, and then calling <see /// cref="AddEntry(String,OpenDelegate, CloseDelegate)" />. See the /// documentation for that method for further explanation. /// </remarks> /// /// <param name="entryName"> /// The name, including any path, to use within the archive for the entry. /// </param> /// /// <param name="opener"> /// the delegate that will be invoked to open the stream /// </param> /// <param name="closer"> /// the delegate that will be invoked to close the stream /// </param> /// /// <returns>The <c>ZipEntry</c> added or updated.</returns> /// public ZipEntry UpdateEntry(string entryName, OpenDelegate opener, CloseDelegate closer) { RemoveEntryForUpdate(entryName); return AddEntry(entryName, opener, closer); }
/// <summary> /// Let the caller override our delegates with their own functions... /// </summary> /// <param name="a_closedelegate">use this to close the logging session</param> /// <param name="a_getleveldelegate">get the current log level</param> /// <param name="a_opendelegate">open the logging session</param> /// <param name="a_registertwaindelegate">not needed at this time</param> /// <param name="a_setflushdelegate">turn flushing on and off</param> /// <param name="a_setleveldelegate">set the new log level</param> /// <param name="a_writeentrydelegate">the function that actually writes to the log</param> /// <param name="a_getstatedelegate">returns a way to get the current TWAIN state</param> public static void Override ( CloseDelegate a_closedelegate, GetLevelDelegate a_getleveldelegate, OpenDelegate a_opendelegate, RegisterTwainDelegate a_registertwaindelegate, SetFlushDelegate a_setflushdelegate, SetLevelDelegate a_setleveldelegate, WriteEntryDelegate a_writeentrydelegate, out GetStateDelegate a_getstatedelegate ) { Close = (a_closedelegate != null) ? a_closedelegate : CloseLocal; GetLevel = (a_getleveldelegate != null) ? a_getleveldelegate : GetLevelLocal; Open = (a_opendelegate != null) ? a_opendelegate : OpenLocal; RegisterTwain = (a_registertwaindelegate != null) ? a_registertwaindelegate : RegisterTwainLocal; SetFlush = (a_setflushdelegate != null) ? a_setflushdelegate : SetFlushLocal; SetLevel = (a_setleveldelegate != null) ? a_setleveldelegate : SetLevelLocal; WriteEntry = (a_writeentrydelegate != null) ? a_writeentrydelegate : WriteEntryLocal; a_getstatedelegate = GetStateLocal; }
protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) { OpenDelegate d = new OpenDelegate(this.Open); return(d.BeginInvoke(timeout, callback, state)); }
/// <summary> /// Updates the given entry in the <c>ZipFile</c>, using the given delegates /// to open and close the stream that provides the content for the <c>ZipEntry</c>. /// </summary> /// /// <remarks> /// Calling this method is equivalent to removing the <c>ZipEntry</c> for the /// given file name and directory path, if it exists, and then calling <see /// cref="AddEntry(String,OpenDelegate, CloseDelegate)" />. See the /// documentation for that method for further explanation. /// </remarks> /// /// <param name="entryName"> /// The name, including any path, to use within the archive for the entry. /// </param> /// /// <param name="opener"> /// the delegate that will be invoked to open the stream /// </param> /// <param name="closer"> /// the delegate that will be invoked to close the stream /// </param> /// /// <returns>The <c>ZipEntry</c> added or updated.</returns> /// public ZipEntry UpdateEntry(string entryName, OpenDelegate opener, CloseDelegate closer) { RemoveEntryForUpdate(entryName); return(AddEntry(entryName, opener, closer)); }
internal static ZipEntry CreateForJitStreamProvider(string nameInArchive, OpenDelegate opener, CloseDelegate closer) { return Create(nameInArchive, ZipEntrySource.JitStream, opener, closer); }
protected Socket(OpenDelegate open) { DefaultInvoker.InvokeWithDefaultErrorHandling(() => open(ref _sid)); Options = PrivateOptions = new OptionReaderWriter(); Configure(_sid); }