Example #1
0
        public void TestCopy(CopyDelegate copy)
        {
            Assert.IsNull(copy(null));
            Assert.IsTrue(AreSame(
                              new CopyListWithRandomPointer.RandomListNode(5),
                              copy(new CopyListWithRandomPointer.RandomListNode(5))));

            var l1 = new CopyListWithRandomPointer.RandomListNode(5)
            {
                next = new CopyListWithRandomPointer.RandomListNode(6)
                {
                    next = new CopyListWithRandomPointer.RandomListNode(7)
                    {
                        next = new CopyListWithRandomPointer.RandomListNode(8)
                    }
                }
            };

            l1.random           = l1.next.next;
            l1.next.random      = null;
            l1.next.next.random = l1.next;
            l1.next.next.random = l1;

            Assert.IsTrue(AreSame(
                              l1,
                              copy(l1)));
        }
Example #2
0
        static Unsafe()
        {
            #if Mono

            #else
            try
            {
                if (System.Environment.Is64BitProcess)
                {
                    _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.dll");
                }
                else
                {
                    _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.dll");
                }

                _copy = _nativeLibraryManager.GetMethod<CopyDelegate>("copy");
                _equals = _nativeLibraryManager.GetMethod<EqualsDelegate>("equals");
                _compare = _nativeLibraryManager.GetMethod<CompareDelegate>("compare");
                _xor = _nativeLibraryManager.GetMethod<XorDelegate>("xor");
            }
            catch (Exception e)
            {
                Log.Warning(e);
            }
            #endif
        }
        public void Enqueue <T>(T source, int count, CopyDelegate <T, byte[]> copyFrom)
        {
            if (count == 0)
            {
                return;
            }

            lock (this) {
                EnsureCapacity(this.length + count);

                if (head < tail)
                {
                    int rightLength = buffer.Length - tail;

                    if (rightLength >= count)
                    {
                        copyFrom(source, 0, buffer, tail, count);
                    }
                    else
                    {
                        copyFrom(source, 0, buffer, tail, rightLength);
                        copyFrom(source, rightLength, buffer, 0, count - rightLength);
                    }
                }
                else
                {
                    copyFrom(source, 0, buffer, tail, count);
                }
                tail         = (tail + count) % buffer.Length;
                this.length += count;
            }
        }
Example #4
0
        static Unsafe()
        {
#if Mono
#else
            try
            {
                if (System.Environment.Is64BitProcess)
                {
                    _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.dll");
                }
                else
                {
                    _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.dll");
                }

                _copy    = _nativeLibraryManager.GetMethod <CopyDelegate>("copy");
                _equals  = _nativeLibraryManager.GetMethod <EqualsDelegate>("equals");
                _compare = _nativeLibraryManager.GetMethod <CompareDelegate>("compare");
                _xor     = _nativeLibraryManager.GetMethod <XorDelegate>("xor");
            }
            catch (Exception e)
            {
                Log.Warning(e);
            }
#endif
        }
Example #5
0
 internal static void LoadPureUnsafeMethods()
 {
     _zero    = PureUnsafeMethods.Zero;
     _copy    = PureUnsafeMethods.Copy;
     _equals  = PureUnsafeMethods.Equals;
     _compare = PureUnsafeMethods.Compare;
     _and     = PureUnsafeMethods.And;
     _or      = PureUnsafeMethods.Or;
     _xor     = PureUnsafeMethods.Xor;
 }
Example #6
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            int iThreads;

            iThreads = int.Parse(txtThreads.Text);
            clsC     = new clsCopy(txtSourceTable.Text, txtDestinationTable.Text, txtSource.Text, txtDestination.Text, iThreads);

            clsC.SourceTableScheme = txtSourceScheme.Text;

            clsC.CheckConstraints = chkCheckConstraints.Checked;
            clsC.FireTriggers     = chkFireTriggers.Checked;
            clsC.KeepIdentity     = chkKeepIdentity.Checked;
            clsC.KeepNulls        = chkKeepNulls.Checked;
            clsC.TabLock          = chkTablock.Checked;
            clsC.NoLock           = chkNoLock.Checked;
            clsC.HeapMethod       = chkHeap.Checked;
            if (DestBox.SelectedItem.ToString() == "SQL Server")
            {
                clsC.DestinationBBDDType = BBDDType.SqlServer;
            }
            else
            {
                clsC.DestinationBBDDType = BBDDType.Oracle;
            }

            if (SourceBox.SelectedItem.ToString() == "SQL Server")
            {
                clsC.SourceBBDDType = BBDDType.SqlServer;
            }
            else
            {
                clsC.SourceBBDDType = BBDDType.Oracle;
            }

            clsC.SelectFilter = txtSelectFilter.Text;

            clsC.NotifyAfter     = int.Parse(txtNotifyAfter.Text);
            clsC.SqlRowsCopied  += new clsCopy.SqlRowsCopiedDelegate(OnSqlRowsCopied);
            clsC.ThreadFinished += new clsCopy.SqlThreadFinishedDelegate(OnThreadEnd);



            listBox1.Items.Clear();
            for (int i = 0; i < iThreads; i++)
            {
                listBox1.Items.Add("Thread " + i);
            }

            this.Enabled = false;

            CopyDelegate  dlgt = new CopyDelegate(this.StartCopy);
            AsyncCallback cb   = new AsyncCallback(CopyFinished);
            String        ret;
            IAsyncResult  ar = dlgt.BeginInvoke(chkAppend.Checked, out ret, cb, dlgt);
        }
Example #7
0
 /// <summary>
 /// 对象赋值
 /// </summary>
 /// <param name="objSource">原对象</param>
 /// <returns>返回的对象</returns>
 public static TTarget Copy(TSource objSource)
 {
     if (objSource == null)
     {
         return(default(TTarget));
     }
     if (objCopyDelegate == null)
     {
         objCopyDelegate = CreateCopyDelegate(typeof(TTarget), typeof(TSource));
     }
     return(objCopyDelegate(objSource));
 }
Example #8
0
        public TypeCloner(
            CreateDelegate creatorDelegate,
            CopyDelegate copierDelegate)
        {
            if (creatorDelegate == null)
            {
                throw new ArgumentNullException(nameof(creatorDelegate));
            }

            this.CreatorDelegate = creatorDelegate;
            this.CopierDelegate  = copierDelegate;
        }
Example #9
0
        internal static void LoadNativeMethods()
        {
            _nativeLibraryManager?.Dispose();

            try
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
                    {
                        _nativeLibraryManager = new NativeLibraryManager("Assemblies/Omnix.Base.win-x64.dll");
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
                    {
                        _nativeLibraryManager = new NativeLibraryManager("Assemblies/Omnix.Base.linux-x64.so");
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }

                _zero    = _nativeLibraryManager.GetMethod <ZeroDelegate>("zero");
                _copy    = _nativeLibraryManager.GetMethod <CopyDelegate>("copy");
                _equals  = _nativeLibraryManager.GetMethod <EqualsDelegate>("equals");
                _compare = _nativeLibraryManager.GetMethod <CompareDelegate>("compare");
                _and     = _nativeLibraryManager.GetMethod <BitwiseOperationDelegate>("math_and");
                _or      = _nativeLibraryManager.GetMethod <BitwiseOperationDelegate>("math_or");
                _xor     = _nativeLibraryManager.GetMethod <BitwiseOperationDelegate>("math_xor");
            }
            catch (Exception)
            {
                _nativeLibraryManager?.Dispose();
                _nativeLibraryManager = null;

                throw;
            }
        }
Example #10
0
        public void CopyFinished(IAsyncResult ar)
        {
            String ret;

            CopyDelegate dlgt = (CopyDelegate)ar.AsyncState;

            dlgt.EndInvoke(out ret, ar);

            if (ret != "")
            {
                MessageBox.Show(ret);
            }

            SetFormEnabled();
        }
Example #11
0
        private void CopyText(CopyDelegate d)
        {
            string strText = this.txt_Input.Text;
               for (int i = 0; i < strText.Length; i++)
               {
               d(strText[i]);
               //时间间隔
               DateTime now = DateTime.Now;
               while (now.AddSeconds(1) > DateTime.Now)
               {

               }

               }
        }
Example #12
0
        private void btn_Copy2_Click(object sender, EventArgs e)
        {
            if (rb_CopyTo1.Checked == true)
            {
                //实例化委托
                m_copyDelegate = new CopyDelegate(DelegateCopyToText1);
                CopyText(m_copyDelegate);

            }
            if (rb_CopyTo2.Checked == true)
            {
                m_copyDelegate = new CopyDelegate(DelegateCopyToText2);
                CopyText(m_copyDelegate);
            }
        }
        public int Dequeue <T>(T destination, int count, CopyDelegate <byte[], T> copyTo)
        {
            lock (this) {
                if (count > this.length)
                {
                    count = this.length;
                }

                if (count == 0)
                {
                    return(0);
                }

                if (head < tail)
                {
                    copyTo(buffer, head, destination, 0, count);
                }
                else
                {
                    int rightLength = (buffer.Length - head);

                    if (rightLength >= count)
                    {
                        copyTo(buffer, head, destination, 0, count);
                    }
                    else
                    {
                        copyTo(buffer, head, destination, 0, rightLength);
                        copyTo(buffer, 0, destination, rightLength, count - rightLength);
                    }
                }

                head         = (head + count) % buffer.Length;
                this.length -= count;

                if (this.length == 0)
                {
                    head = 0;
                    tail = 0;
                }
                return(count);
            }
        }
Example #14
0
        static Unsafe()
        {
            try
            {
            #if Windows
                if (System.Environment.Is64BitProcess)
                {
                    _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.dll");
                }
                else
                {
                    _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.dll");
                }
            #endif

            #if Unix
                if (System.Environment.Is64BitProcess)
                {
                    _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.so");
                }
                else
                {
                    _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.so");
                }
            #endif

                _copy = _nativeLibraryManager.GetMethod<CopyDelegate>("copy");
                _equals = _nativeLibraryManager.GetMethod<EqualsDelegate>("equals");
                _compare = _nativeLibraryManager.GetMethod<CompareDelegate>("compare");
                _and = _nativeLibraryManager.GetMethod<BitwiseOperationDelegate>("math_and");
                _or = _nativeLibraryManager.GetMethod<BitwiseOperationDelegate>("math_or");
                _xor = _nativeLibraryManager.GetMethod<BitwiseOperationDelegate>("math_xor");
            }
            catch (Exception e)
            {
                Log.Warning(e);
            }
        }
Example #15
0
        /// <summary>
        /// Ensure <see cref="MemoryCopy"/> functionality.
        /// </summary>
        private static void EnsureCopy()
        {
            if (_CopyPointer != null)
            {
                return;
            }

            IntPtr memoryCopyPtr;

            switch (Platform.CurrentPlatformId)
            {
            case Platform.Id.WindowsNT:
                memoryCopyPtr = GetProcAddressOS.GetProcAddress("msvcrt.dll", "memcpy");
                if (memoryCopyPtr == IntPtr.Zero)
                {
                    throw new NotSupportedException("no suitable memcpy support");
                }
                _CopyPointer = (CopyDelegate)Marshal.GetDelegateForFunctionPointer(memoryCopyPtr, typeof(CopyDelegate));
                return;

            case Platform.Id.Linux:
                memoryCopyPtr = GetProcAddressOS.GetProcAddress("libc.so.6", "memcpy");
                if (memoryCopyPtr == IntPtr.Zero)
                {
                    throw new NotSupportedException("no suitable memcpy support");
                }
                _CopyPointer = (CopyDelegate)Marshal.GetDelegateForFunctionPointer(memoryCopyPtr, typeof(CopyDelegate));
                return;

            case Platform.Id.Android:
                _CopyPointer = CopyDelegate_Managed;
                break;

            default:
                throw new NotSupportedException("no suitable memcpy support");
            }
        }
Example #16
0
 public static void AsynFileCopy(string sourceFile, string destFile)
 {
     CopyDelegate del    = new CopyDelegate(FileCopy);
     IAsyncResult result = del.BeginInvoke(sourceFile, destFile, CallBackAfterFileCopied, null);
 }