Ejemplo n.º 1
0
        /// <summary>
        /// Gets a copy of all (user key string, user value string) pairs attached to this geometry.
        /// </summary>
        /// <returns>A new collection.</returns>
        internal System.Collections.Specialized.NameValueCollection _GetUserStrings()
        {
            System.Collections.Specialized.NameValueCollection rc = new System.Collections.Specialized.NameValueCollection();
            IntPtr const_ptr_this  = ConstPointer();
            int    count           = 0;
            IntPtr ptr_userstrings = UnsafeNativeMethods.ON_Object_GetUserStrings(const_ptr_this, ref count);

            using (var keyHolder = new StringHolder())
                using (var valueHolder = new StringHolder())
                {
                    IntPtr pKeyHolder   = keyHolder.NonConstPointer();
                    IntPtr pValueHolder = valueHolder.NonConstPointer();

                    for (int i = 0; i < count; i++)
                    {
                        UnsafeNativeMethods.ON_UserStringList_KeyValue(ptr_userstrings, i, true, pKeyHolder);
                        UnsafeNativeMethods.ON_UserStringList_KeyValue(ptr_userstrings, i, false, pValueHolder);
                        string key   = keyHolder.ToString();
                        string value = valueHolder.ToString();
                        if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                        {
                            rc.Add(key, value);
                        }
                    }
                }

            if (IntPtr.Zero != ptr_userstrings)
            {
                UnsafeNativeMethods.ON_UserStringList_Delete(ptr_userstrings);
            }

            return(rc);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the debug dumps. This is a text description of the geometric contents.
 /// DebugDump() is intended for debugging and is not suitable for creating high
 /// quality text descriptions of an object.
 /// </summary>
 /// <param name="bezierCurve">curve to evaluate</param>
 /// <returns>A debug dump text.</returns>
 public static string DebugDumpToString(Rhino.Geometry.BezierCurve bezierCurve)
 {
   IntPtr pConstThis = bezierCurve.ConstPointer();
   using (var sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.ON_BezierCurve_Dump(pConstThis, pString);
     return sh.ToString();
   }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets the debug dumps. This is a text description of the geometric contents.
 /// DebugDump() is intended for debugging and is not suitable for creating high
 /// quality text descriptions of an object.
 /// </summary>
 /// <param name="geometry">Some geometry.</param>
 /// <returns>A debug dump text.</returns>
 public static string DebugDumpToString(Rhino.Geometry.GeometryBase geometry)
 {
   IntPtr pConstThis = geometry.ConstPointer();
   using (var sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.ON_Object_Dump(pConstThis, pString);
     return sh.ToString();
   }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets user string from this geometry.
        /// </summary>
        /// <param name="key">id used to retrieve the string.</param>
        /// <returns>string associated with the key if successful. null if no key was found.</returns>
        internal string _GetUserString(string key)
        {
            IntPtr pThis = ConstPointer();

            using (var sh = new StringHolder())
            {
                IntPtr pStringHolder = sh.NonConstPointer();
                UnsafeNativeMethods.ON_Object_GetUserString(pThis, key, pStringHolder);
                return(sh.ToString());
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Determines if an object is valid. Also provides a report on errors if this
        /// object happens not to be valid.
        /// </summary>
        /// <param name="log">A textual log. This out parameter is assigned during this call.</param>
        /// <returns>true if this object is valid; false otherwise.</returns>
        public bool IsValidWithLog(out string log)
        {
            IntPtr const_ptr_this = ConstPointer();

            using (var sh = new StringHolder())
            {
                IntPtr ptr_string = sh.NonConstPointer();
                bool   rc         = UnsafeNativeMethods.ON_Object_IsValid(const_ptr_this, ptr_string);
                log = sh.ToString();
                return(rc);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets the debug dumps. This is a text description of the geometric contents.
 /// DebugDump() is intended for debugging and is not suitable for creating high
 /// quality text descriptions of an object.
 /// </summary>
 /// <param name="bezierCurve">curve to evaluate</param>
 /// <returns>A debug dump text.</returns>
 public static string DebugDumpToString(Rhino.Geometry.BezierCurve bezierCurve)
 {
   IntPtr pConstThis = bezierCurve.ConstPointer();
   using (Rhino.Runtime.StringHolder sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.ON_BezierCurve_Dump(pConstThis, pString);
     return sh.ToString();
   }
 }
Ejemplo n.º 7
0
    internal static void WriteIntoSerializationInfo(IntPtr pRhCmnProfileContext, System.Runtime.Serialization.SerializationInfo info, string prefixStrip)
    {
      const int _string = 1;
      const int _multistring = 2;
      const int _uuid = 3;
      const int _color = 4;
      const int _int = 5;
      const int _double = 6;
      const int _rect = 7;
      const int _point = 8;
      const int _3dpoint = 9;
      const int _xform = 10;
      const int _3dvector = 11;
      const int _meshparams = 12;
      const int _buffer = 13;
      const int _bool = 14;
      int count = UnsafeNativeMethods.CRhCmnProfileContext_Count(pRhCmnProfileContext);
      using (StringHolder sectionholder = new StringHolder())
      using (StringHolder entryholder = new StringHolder())
      {
        IntPtr pStringSection = sectionholder.NonConstPointer();
        IntPtr pStringEntry = entryholder.NonConstPointer();
        for (int i = 0; i < count; i++)
        {
          int pctype = 0;
          UnsafeNativeMethods.CRhCmnProfileContext_Item(pRhCmnProfileContext, i, pStringSection, pStringEntry, ref pctype);
          string section = sectionholder.ToString();
          string entry = entryholder.ToString();
          if (string.IsNullOrEmpty(entry))
            continue;
          string name = string.IsNullOrEmpty(section) ? entry : section + "\\" + entry;
          if (name.StartsWith(prefixStrip + "\\"))
            name = name.Substring(prefixStrip.Length + 1);
          name = name.Replace("\\", "::");

          switch (pctype)
          {
            case _string:
              {
                UnsafeNativeMethods.CRhinoProfileContext_LoadString(pRhCmnProfileContext, section, entry, pStringEntry);
                string val = entryholder.ToString();
                info.AddValue(name, val);
              }
              break;
            case _multistring:
              {
                IntPtr pStrings = UnsafeNativeMethods.ON_StringArray_New();
                int array_count = UnsafeNativeMethods.CRhinoProfileContext_LoadStrings(pRhCmnProfileContext, section, entry, pStrings);
                string[] s = new string[array_count];
                for( int j=0; j<array_count; j++ )
                {
                  UnsafeNativeMethods.ON_StringArray_Get(pStrings, j, pStringEntry);
                  s[j] = entryholder.ToString();
                }
                info.AddValue(name, s);
              }
              break;
            case _uuid:
              {
                Guid id = Guid.Empty;
                UnsafeNativeMethods.CRhinoProfileContext_LoadGuid(pRhCmnProfileContext, section, entry, ref id);
                info.AddValue(name, id);
              }
              break;
            case _color:
              {
                int abgr = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadColor(pRhCmnProfileContext, section, entry, ref abgr);
                System.Drawing.Color c = System.Drawing.ColorTranslator.FromWin32(abgr);
                //string s = System.Drawing.ColorTranslator.ToHtml(c);
                info.AddValue(name, c);
              }
              break;
            case _int:
              {
                int ival = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadInt(pRhCmnProfileContext, section, entry, ref ival);
                info.AddValue(name, ival);
              }
              break;
            case _double:
              {
                double dval = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadDouble(pRhCmnProfileContext, section, entry, ref dval);
                info.AddValue(name, dval);
              }
              break;
            case _rect:
              {
                int left = 0, top = 0, right = 0, bottom = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadRect(pRhCmnProfileContext, section, entry, ref left, ref top, ref right, ref bottom);
                System.Drawing.Rectangle r = System.Drawing.Rectangle.FromLTRB(left, top, right, bottom);
                info.AddValue(name, r);
              }
              break;
            case _point:
              {
                int x = 0, y = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadPoint(pRhCmnProfileContext, section, entry, ref x, ref y);
                System.Drawing.Point pt = new System.Drawing.Point(x, y);
                info.AddValue(name, pt);
              }
              break;
            case _3dpoint:
              {
                Rhino.Geometry.Point3d pt = new Geometry.Point3d();
                UnsafeNativeMethods.CRhinoProfileContext_LoadPoint3d(pRhCmnProfileContext, section, entry, ref pt);
                info.AddValue(name, pt);
              }
              break;
            case _xform:
              {
                Rhino.Geometry.Transform xf = new Geometry.Transform();
                UnsafeNativeMethods.CRhinoProfileContext_LoadXform(pRhCmnProfileContext, section, entry, ref xf);
                info.AddValue(name, xf);
              }
              break;
            case _3dvector:
              {
                Rhino.Geometry.Vector3d vec = new Geometry.Vector3d();
                UnsafeNativeMethods.CRhinoProfileContext_LoadVector3d(pRhCmnProfileContext, section, entry, ref vec);
                info.AddValue(name, vec);
              }
              break;
            case _meshparams:
              {
                Rhino.Geometry.MeshingParameters mp = new Geometry.MeshingParameters();
                UnsafeNativeMethods.CRhinoProfileContext_LoadMeshParameters(pRhCmnProfileContext, section, entry, mp.NonConstPointer());
                info.AddValue(name, mp);
                mp.Dispose();
              }
              break;
            case _buffer:
              {
                //not supported yet
                //int buffer_length = UnsafeNativeMethods.CRhinoProfileContext_BufferLength(pRhCmnProfileContext, section, entry);
                //byte[] buffer = new byte[buffer_length];
                //UnsafeNativeMethods.CRhinoProfileContext_LoadBuffer(pRhCmnProfileContext, section, entry, buffer_length, buffer);
                //info.AddValue(name, buffer);
              }
              break;
            case _bool:
              {
                bool b = false;
                UnsafeNativeMethods.CRhinoProfileContext_LoadBool(pRhCmnProfileContext, section, entry, ref b);
                info.AddValue(name, b);
              }
              break;
          }
        }
      }
    }
Ejemplo n.º 8
0
 /// <summary>
 /// Returns a list of output types which your renderer can write.
 /// <para>The default implementation returns bmp, jpg, png, tif, tga.</para>
 /// </summary>
 /// <returns>A list of file types.</returns>
 protected virtual List<Rhino.FileIO.FileType> SupportedOutputTypes()
 {
   using (StringHolder shExt = new StringHolder())
   using (StringHolder shDesc = new StringHolder())
   {
     var rc = new List<Rhino.FileIO.FileType>();
     int iIndex = 0;
     while (1 == UnsafeNativeMethods.Rdk_RenderPlugIn_BaseOutputTypeAtIndex(NonConstPointer(), iIndex++, shExt.NonConstPointer(), shDesc.NonConstPointer()))
     {
       rc.Add(new Rhino.FileIO.FileType(shExt.ToString(), shDesc.ToString()));
     }
     return rc;
   }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Gets a plug-in name for an installed plug-in given the path to that plug-in.
 /// </summary>
 /// <param name="pluginPath">The path of the plug-in.</param>
 /// <returns>The plug-in name.</returns>
 public static string NameFromPath(string pluginPath)
 {
   string rc;
   using (StringHolder sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.CRhinoPlugInManager_NameFromPath(pluginPath, pString);
     rc = sh.ToString();
   }
   if (string.IsNullOrEmpty(rc))
   {
     // 2-Nov-2011 Dale Fugier
     // Look in our local collection of plug-ins. We may be in "OnLoad"
     // and the plug-in hasn't officially been registered with Rhino.
     for (int i = 0; i < m_plugins.Count; i++)
     {
       if (string.Compare(m_plugins[i].Assembly.Location, pluginPath, StringComparison.OrdinalIgnoreCase) == 0)
       {
         rc = m_plugins[i].Name;
         break;
       }
     }
   }
   return rc;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Determines if an object is valid. Also provides a report on errors if this
 /// object happens not to be valid.
 /// </summary>
 /// <param name="log">A textual log. This out parameter is assigned during this call.</param>
 /// <returns>true if this object is valid; false otherwise.</returns>
 public bool IsValidWithLog(out string log)
 {
   IntPtr pConstThis = ConstPointer();
   using (StringHolder sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     bool rc = UnsafeNativeMethods.ON_Object_IsValid(pConstThis, pString);
     log = sh.ToString();
     return rc;
   }
 }
Ejemplo n.º 11
0
    internal static void WriteIntoSerializationInfo(IntPtr pRhCmnProfileContext, System.Runtime.Serialization.SerializationInfo info, string prefixStrip)
    {
      const int _string = 1;
      const int _multistring = 2;
      const int _uuid = 3;
      const int _color = 4;
      const int _int = 5;
      const int _double = 6;
      const int _rect = 7;
      const int _point = 8;
      const int _3dpoint = 9;
      const int _xform = 10;
      const int _3dvector = 11;
      const int _meshparams = 12;
      const int _buffer = 13;
      const int _bool = 14;
      int count = UnsafeNativeMethods.CRhCmnProfileContext_Count(pRhCmnProfileContext);
      using (StringHolder sectionholder = new StringHolder())
      using (StringHolder entryholder = new StringHolder())
      {
        IntPtr pStringSection = sectionholder.NonConstPointer();
        IntPtr pStringEntry = entryholder.NonConstPointer();
        for (int i = 0; i < count; i++)
        {
          int pctype = 0;
          UnsafeNativeMethods.CRhCmnProfileContext_Item(pRhCmnProfileContext, i, pStringSection, pStringEntry, ref pctype);
          string section = sectionholder.ToString();
          string entry = entryholder.ToString();
          if (string.IsNullOrEmpty(entry))
            continue;
          string name = string.IsNullOrEmpty(section) ? entry : section + "\\" + entry;
          if (name.StartsWith(prefixStrip + "\\"))
            name = name.Substring(prefixStrip.Length + 1);
          name = name.Replace("\\", "::");

          switch (pctype)
          {
            case _string:
              {
                UnsafeNativeMethods.CRhinoProfileContext_LoadString(pRhCmnProfileContext, section, entry, pStringEntry);
                string val = entryholder.ToString();
                info.AddValue(name, val);
              }
              break;
            case _multistring:
              {
                IntPtr pStrings = UnsafeNativeMethods.ON_StringArray_New();
                int array_count = UnsafeNativeMethods.CRhinoProfileContext_LoadStrings(pRhCmnProfileContext, section, entry, pStrings);
                string[] s = new string[array_count];
                for( int j=0; j<array_count; j++ )
                {
                  UnsafeNativeMethods.ON_StringArray_Get(pStrings, j, pStringEntry);
                  s[j] = entryholder.ToString();
                }
                info.AddValue(name, s);
              }
              break;
            case _uuid:
              {
                Guid id = Guid.Empty;
                UnsafeNativeMethods.CRhinoProfileContext_LoadGuid(pRhCmnProfileContext, section, entry, ref id);
                info.AddValue(name, id);
              }
              break;
            case _color:
              {
                int abgr = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadColor(pRhCmnProfileContext, section, entry, ref abgr);
                System.Drawing.Color c = Interop.ColorFromWin32(abgr);
                //string s = System.Drawing.ColorTranslator.ToHtml(c);
                info.AddValue(name, c);
              }
              break;
            case _int:
              {
                int ival = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadInt(pRhCmnProfileContext, section, entry, ref ival);
                info.AddValue(name, ival);
              }
              break;
            case _double:
              {
                double dval = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadDouble(pRhCmnProfileContext, section, entry, ref dval);
                info.AddValue(name, dval);
              }
              break;
            case _rect:
              {
                int left = 0, top = 0, right = 0, bottom = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadRect(pRhCmnProfileContext, section, entry, ref left, ref top, ref right, ref bottom);
                System.Drawing.Rectangle r = System.Drawing.Rectangle.FromLTRB(left, top, right, bottom);
                info.AddValue(name, r);
              }
              break;
            case _point:
              {
                int x = 0, y = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadPoint(pRhCmnProfileContext, section, entry, ref x, ref y);
                System.Drawing.Point pt = new System.Drawing.Point(x, y);
                info.AddValue(name, pt);
              }
              break;
            case _3dpoint:
              {
                Rhino.Geometry.Point3d pt = new Geometry.Point3d();
                UnsafeNativeMethods.CRhinoProfileContext_LoadPoint3d(pRhCmnProfileContext, section, entry, ref pt);
                info.AddValue(name, pt);
              }
              break;
            case _xform:
              {
                Rhino.Geometry.Transform xf = new Geometry.Transform();
                UnsafeNativeMethods.CRhinoProfileContext_LoadXform(pRhCmnProfileContext, section, entry, ref xf);
                info.AddValue(name, xf);
              }
              break;
            case _3dvector:
              {
                Rhino.Geometry.Vector3d vec = new Geometry.Vector3d();
                UnsafeNativeMethods.CRhinoProfileContext_LoadVector3d(pRhCmnProfileContext, section, entry, ref vec);
                info.AddValue(name, vec);
              }
              break;
            case _meshparams:
              {
                Rhino.Geometry.MeshingParameters mp = new Geometry.MeshingParameters();
                UnsafeNativeMethods.CRhinoProfileContext_LoadMeshParameters(pRhCmnProfileContext, section, entry, mp.NonConstPointer());
                info.AddValue(name, mp);
                mp.Dispose();
              }
              break;
            case _buffer:
              {
                //not supported yet
                //int buffer_length = UnsafeNativeMethods.CRhinoProfileContext_BufferLength(pRhCmnProfileContext, section, entry);
                //byte[] buffer = new byte[buffer_length];
                //UnsafeNativeMethods.CRhinoProfileContext_LoadBuffer(pRhCmnProfileContext, section, entry, buffer_length, buffer);
                //info.AddValue(name, buffer);
              }
              break;
            case _bool:
              {
                bool b = false;
                UnsafeNativeMethods.CRhinoProfileContext_LoadBool(pRhCmnProfileContext, section, entry, ref b);
                info.AddValue(name, b);
              }
              break;
          }
        }
      }
    }
Ejemplo n.º 12
0
            /// <summary>
            /// Passed as a delegate to LicenseUtils.GetLicense(), will call the C++
            /// ValidateProductKey() method then and copy CRhinoLicenseValidator C++
            /// data to the LicenseData output object.
            /// </summary>
            /// <param name="productKey"></param>
            /// <param name="licenseData">
            /// Key information is coppied to this object
            /// </param>
            /// <returns></returns>
            public ValidateResult ValidateProductKey(string productKey, out LicenseData licenseData)
            {
                // Create an empty LicenseData
                licenseData = new LicenseData();
                var rc = 0;

                // Call back into the C++ unmanaged function pointer
                if (IntPtr.Zero != _validator)
                {
                    rc = UnsafeNativeMethods.RHC_ValidateProductKey(productKey, _validator);
                }
                if (rc != 1)
                {
                    return(-1 == rc ? ValidateResult.ErrorHideMessage : ValidateResult.ErrorShowMessage);
                }
                // Copy unmanaged C++ validate data to the managed LicenseData
                var    year         = 0;
                var    month        = 0;
                var    day          = 0;
                var    hour         = 0;
                var    minute       = 0;
                var    second       = 0;
                var    licenseCount = 0;
                var    buildType    = 0;
                IntPtr hIcon;

                // String placeholders
                using (var shSerailNumber = new StringHolder())
                    using (var shLicenseTitle = new StringHolder())
                        using (var shProductLicense = new StringHolder())
                        {
                            // Get ON_wString pointers
                            var pSerialNumber   = shSerailNumber.NonConstPointer();
                            var pLicenseTitle   = shLicenseTitle.NonConstPointer();
                            var pProductLicense = shProductLicense.NonConstPointer();
                            hIcon = UnsafeNativeMethods.RHC_ExtractLicenseData(_validator,
                                                                               ref year,
                                                                               ref month,
                                                                               ref day,
                                                                               ref hour,
                                                                               ref minute,
                                                                               ref second,
                                                                               pSerialNumber,
                                                                               ref licenseCount,
                                                                               pLicenseTitle,
                                                                               pProductLicense,
                                                                               ref buildType);
                            // Copy ON_wString values to C# strings
                            licenseData.SerialNumber   = shSerailNumber.ToString();
                            licenseData.LicenseTitle   = shLicenseTitle.ToString();
                            licenseData.ProductLicense = shProductLicense.ToString();
                        }
                // Set the expiration date using the C++ date data
                if (year >= 2010)
                {
                    licenseData.DateToExpire = new DateTime(year, month, day, hour, minute, second);
                }
                licenseData.LicenseCount = licenseCount;
                licenseData.BuildType    = (LicenseBuildType)buildType;
                // Icon associated with the specified license type
                if (hIcon != IntPtr.Zero)
                {
                    // Create a new icon from the handle.
                    var newIcon = System.Drawing.Icon.FromHandle(hIcon);

                    // Set the LicenseData icon. Note, LicenseData creates it's own copy of the icon.
                    licenseData.ProductIcon = newIcon;

                    // When using Icon::FromHandle, you must dispose of the original icon by using the
                    // DestroyIcon method in the Win32 API to ensure that the resources are released.
                    DestroyIcon(newIcon.Handle);
                }

                return(ValidateResult.Success);
            }
Ejemplo n.º 13
0
      /// <summary>
      /// Passed as a delegate to LicenseUtils.GetLicense(), will call the C++
      /// ValidateProductKey() method then and copy CRhinoLicenseValidator C++
      /// data to the LicenseData output object.
      /// </summary>
      /// <param name="productKey"></param>
      /// <param name="licenseData">
      /// Key information is coppied to this object
      /// </param>
      /// <returns></returns>
      public ValidateResult ValidateProductKey(string productKey, out LicenseData licenseData)
      {
        // Create an empty LicenseData
        licenseData = new LicenseData();
        var rc = 0;
        // Call back into the C++ unmanaged function pointer
        if (IntPtr.Zero != _validator)
          rc = UnsafeNativeMethods.RHC_ValidateProductKey(productKey, _validator);
        if (rc != 1)
          return (-1 == rc ? ValidateResult.ErrorHideMessage : ValidateResult.ErrorShowMessage);
        // Copy unmanaged C++ validate data to the managed LicenseData
        var year = 0;
        var month = 0;
        var day = 0;
        var hour = 0;
        var minute = 0;
        var second = 0;
        var licenseCount = 0;
        var buildType = 0;
        IntPtr hIcon;
        // String placeholders
        using (var shSerailNumber = new StringHolder())
        using (var shLicenseTitle = new StringHolder())
        using (var shProductLicense = new StringHolder())
        {
          // Get ON_wString pointers
          var pSerialNumber = shSerailNumber.NonConstPointer();
          var pLicenseTitle = shLicenseTitle.NonConstPointer();
          var pProductLicense = shProductLicense.NonConstPointer();
          hIcon = UnsafeNativeMethods.RHC_ExtractLicenseData(_validator,
                                                             ref year,
                                                             ref month,
                                                             ref day,
                                                             ref hour,
                                                             ref minute,
                                                             ref second,
                                                             pSerialNumber,
                                                             ref licenseCount,
                                                             pLicenseTitle,
                                                             pProductLicense,
                                                             ref buildType);
          // Copy ON_wString values to C# strings
          licenseData.SerialNumber = shSerailNumber.ToString();
          licenseData.LicenseTitle = shLicenseTitle.ToString();
          licenseData.ProductLicense = shProductLicense.ToString();
        }
        // Set the expiration date using the C++ date data
        if (year >= 2010)
          licenseData.DateToExpire = new DateTime(year, month, day, hour, minute, second);
        licenseData.LicenseCount = licenseCount;
        licenseData.BuildType = (LicenseBuildType)buildType;
        // Icon associated with the specified license type
        if (hIcon != IntPtr.Zero)
        {
          // Create a new icon from the handle.
          var newIcon = System.Drawing.Icon.FromHandle(hIcon);

          // Set the LicenseData icon. Note, LicenseData creates it's own copy of the icon.
          licenseData.ProductIcon = newIcon;

          // When using Icon::FromHandle, you must dispose of the original icon by using the
          // DestroyIcon method in the Win32 API to ensure that the resources are released.
          DestroyIcon(newIcon.Handle);
        }

        return ValidateResult.Success;
      }
Ejemplo n.º 14
0
    /// <summary>
    /// Gets a copy of all (user key string, user value string) pairs attached to this geometry.
    /// </summary>
    /// <returns>A new collection.</returns>
    internal System.Collections.Specialized.NameValueCollection _GetUserStrings()
    {
      System.Collections.Specialized.NameValueCollection rc = new System.Collections.Specialized.NameValueCollection();
      IntPtr pThis = ConstPointer();
      int count = 0;
      IntPtr pUserStrings = UnsafeNativeMethods.ON_Object_GetUserStrings(pThis, ref count);

      using( var keyHolder = new StringHolder() )
      using( var valueHolder = new StringHolder() )
      {
        IntPtr pKeyHolder = keyHolder.NonConstPointer();
        IntPtr pValueHolder = valueHolder.NonConstPointer();

        for (int i = 0; i < count; i++)
        {
          UnsafeNativeMethods.ON_UserStringList_KeyValue(pUserStrings, i, true, pKeyHolder);
          UnsafeNativeMethods.ON_UserStringList_KeyValue(pUserStrings, i, false, pValueHolder);
          string key = keyHolder.ToString();
          string value = valueHolder.ToString();
          if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
            rc.Add(key, value);
        }
      }

      if (IntPtr.Zero != pUserStrings)
        UnsafeNativeMethods.ON_UserStringList_Delete(pUserStrings);

      return rc;
    }
Ejemplo n.º 15
0
 /// <summary>
 /// Gets user string from this geometry.
 /// </summary>
 /// <param name="key">id used to retrieve the string.</param>
 /// <returns>string associated with the key if successful. null if no key was found.</returns>
 internal string _GetUserString(string key)
 {
   IntPtr pThis = ConstPointer();
   using (var sh = new StringHolder())
   {
     IntPtr pStringHolder = sh.NonConstPointer();
     UnsafeNativeMethods.ON_Object_GetUserString(pThis, key, pStringHolder);
     return sh.ToString();
   }
 }