Example #1
0
        private static int OnDuplcateUserData(int serialNumber, IntPtr pNativeUserData)
        {
            int      rc = 0;
            UserData ud = FromSerialNumber(serialNumber);

            if (ud != null)
            {
                try
                {
                    Type     t      = ud.GetType();
                    UserData new_ud = Activator.CreateInstance(t) as UserData;
                    if (new_ud != null)
                    {
                        // 5 March 2020 S. Baer (RH-56767)
                        // This is user data created from C++ and it's lifetime is managed
                        // by C++. No need to let this have it's lifetime managed by the GC
                        GC.SuppressFinalize(new_ud);
                        new_ud.m_serial_number  = g_next_serial_number++;
                        new_ud.m_native_pointer = pNativeUserData;
                        StoreInRuntimeList(new_ud);
                        new_ud.OnDuplicate(ud);
                        rc = new_ud.m_serial_number;
                    }
                }
                catch (Exception ex)
                {
                    Runtime.HostUtils.ExceptionReport(ex);
                }
            }
            return(rc);
        }
Example #2
0
        private static int OnDuplcateUserData(int serial_number, IntPtr pNativeUserData)
        {
            int      rc = 0;
            UserData ud = FromSerialNumber(serial_number);

            if (ud != null)
            {
                try
                {
                    Type     t      = ud.GetType();
                    UserData new_ud = System.Activator.CreateInstance(t) as UserData;
                    if (new_ud != null)
                    {
                        new_ud.m_serial_number  = UserData.m_next_serial_number++;
                        new_ud.m_pNativePointer = pNativeUserData;
                        UserData.StoreInRuntimeList(new_ud);
                        new_ud.OnDuplicate(ud);
                        rc = new_ud.m_serial_number;
                    }
                }
                catch (Exception ex)
                {
                    Runtime.HostUtils.ExceptionReport(ex);
                }
            }
            return(rc);
        }
Example #3
0
        /// <summary>
        /// If the userdata is already in a different UserDataList, it
        /// will be removed from that list and added to this list.
        /// </summary>
        /// <param name="userdata">Data element.</param>
        /// <returns>Whether this operation succeeded.</returns>
        public bool Add(UserData userdata)
        {
            if (!(userdata is SharedUserDictionary))
            {
                Type t = userdata.GetType();
                System.Reflection.ConstructorInfo constructor = t.GetConstructor(System.Type.EmptyTypes);
                if (!t.IsPublic || constructor == null)
                {
                    throw new ArgumentException("userdata must be a public class and have a parameterless constructor");
                }
            }
            IntPtr     pOnObject      = m_parent.ConstPointer();
            IntPtr     pUserData      = userdata.NonConstPointer(true);
            const bool detachIfNeeded = true;
            bool       rc             = UnsafeNativeMethods.ON_Object_AttachUserData(pOnObject, pUserData, detachIfNeeded);

            if (rc)
            {
                UserData.StoreInRuntimeList(userdata);
            }
            return(rc);
        }
Example #4
0
        private static int OnArchiveUserData(int serialNumber)
        {
            int      rc = 0; //FALSE
            UserData ud = FromSerialNumber(serialNumber);

            if (ud != null)
            {
                try
                {
                    // the user data class MUST have a GuidAttribute in order to write
                    object[] attr = ud.GetType().GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
                    if (attr.Length == 1)
                    {
                        rc = ud.ShouldWrite ? 1 : 0;
                    }
                }
                catch (Exception ex)
                {
                    Runtime.HostUtils.ExceptionReport(ex);
                }
            }
            return(rc);
        }
 /// <summary>
 /// If the userdata is already in a different UserDataList, it
 /// will be removed from that list and added to this list.
 /// </summary>
 /// <param name="userdata">Data element.</param>
 /// <returns>Whether this operation succeeded.</returns>
 public bool Add(UserData userdata)
 {
   if (!(userdata is SharedUserDictionary))
   {
     Type t = userdata.GetType();
     System.Reflection.ConstructorInfo constructor = t.GetConstructor(Type.EmptyTypes);
     if (!t.IsPublic || constructor == null)
       throw new ArgumentException("userdata must be a public class and have a parameterless constructor");
   }
   IntPtr const_ptr_onobject = m_parent.ConstPointer();
   IntPtr ptr_userdata = userdata.NonConstPointer(true);
   const bool detach_if_needed = true;
   bool rc = UnsafeNativeMethods.ON_Object_AttachUserData(const_ptr_onobject, ptr_userdata, detach_if_needed);
   if (rc)
     UserData.StoreInRuntimeList(userdata);
   return rc;
 }