Author Topic: UserConfigurationManager?  (Read 5301 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
UserConfigurationManager?
« on: May 09, 2008, 01:44:39 PM »
Continued From this thread http://www.theswamp.org/index.php?topic=22942.msg275946#msg275946

So what good is it? The code below will add a search path to the current profile. But, it seems that the profile is cached so when a user opens the option dialog, the changes are not shown. If the user does make a change, it overwrites the changes the code made, when AutoCAD closes, it overwrites the changes the code made. Am I missing something?

Code: [Select]
namespace ExecMethod
{
  public class Commands
  {
    [CommandMethod("doit")]
    public void doit()
    {
      Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
      try
      {
        string path = @"c:\temp";
        AppendFilePaths(path);
        List<string> strList = GetFilePaths() as List<string>;
        ed.WriteMessage(PathBuilder(strList));
      }
      catch (System.Exception ex)
      {
        ed.WriteMessage(ex.Message);
        ed.WriteMessage(ex.StackTrace);
      }
    }

    //
    public void AppendFilePaths(string path)
    {
      string[] strings = new string[] { path };
      AppendFilePaths(strings);
    }

    //
    public void AppendFilePaths(IEnumerable<string> paths)
    {
      List<string> strList = this.GetFilePaths() as List<string>;
      foreach (string str in paths)
      {
        strList.Add(str);
      }
      string newpaths = this.PathBuilder(strList);
      using (IConfigurationSection profile =
                 Application.UserConfigurationManager.OpenCurrentProfile())
      {
        if (profile.ContainsSubsection("General"))
        {
          using (IConfigurationSection general = profile.OpenSubsection("General"))
          {
            if (general.Contains("ACAD"))
            {
              general.WriteProperty("ACAD", newpaths);
            }
            general.Close();
          }
        }
        profile.Close();
      }
    }

    //
    public string PathBuilder(IEnumerable<string> strings)
    {
      if (strings == null)
      {
        throw new ArgumentNullException("strings");
      }
      StringBuilder sb = new StringBuilder();
      foreach (string str in strings)
      {
        sb.Append(str);
        sb.Append(';');
      }
      return sb.ToString();
    }

    //
    public IEnumerable<string> GetFilePaths()
    {
      UserConfigurationManager userConfigurationManager =
                                         Application.UserConfigurationManager; 
      List<string> stringList = new List<string>();
      using (IConfigurationSection profile =
                            userConfigurationManager.OpenCurrentProfile())
      {
        if (!profile.ContainsSubsection("General"))
        {
          return stringList;
        }
        using (IConfigurationSection general = profile.OpenSubsection("General"))
        {
          if (general.Contains("ACAD"))
          {
            string paths = (string)general.ReadProperty("ACAD", string.Empty);
            foreach (string str in paths.Split(new char[] { ';' }))
            {  //got a extra space somewhere
              if (str.Length > 2)
              {
                stringList.Add(str);
              }
            }
          }
          general.Close();
        }
        profile.Close();
      }
      return stringList;
    }
 
  }
}

Glenn R

  • Guest
Re: UserConfigurationManager?
« Reply #1 on: May 09, 2008, 02:14:08 PM »
Nope - that's what I mentioned in that previous thread.

Adesk needs to consolidate the registry profile and cui and move the whole thing to an xml file in my opinion that is dynamically read and written to - they store too many things in different places.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: UserConfigurationManager?
« Reply #2 on: May 10, 2008, 12:16:53 AM »
Not only that, if the data is going to be cached, give a way to update the cache …like..

Code: [Select]
UserConfigurationManager.UpdateCurrentProfile(); //Wish List

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: UserConfigurationManager?
« Reply #3 on: May 10, 2008, 12:18:50 AM »
Not only that, if the data is going to be cached, give a way to update the cache …like..

Code: [Select]
UserConfigurationManager.UpdateCurrentProfile(); //Wish List

OH, YES .. that WOULD be nice ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: UserConfigurationManager?
« Reply #4 on: May 10, 2008, 04:14:04 AM »
Add to that list the profile.aws and workspaces in general

sinc

  • Guest
Re: UserConfigurationManager?
« Reply #5 on: May 10, 2008, 11:38:34 AM »
Does anyone have C3D 2009?

I'm having a problem with this thing, only on C3D 2009.  I did not have the problem in the 2009 beta.

The following code blows up on an an exception that says "Value exist but it is not a string" (that's not a typo - it actually says "value exist").  It worked fine in C3D 2008 and the C3D 2009 Beta.

Code: [Select]
            UserConfigurationManager ucm = Application.UserConfigurationManager;
            IConfigurationSection regbase = ucm.OpenCurrentProfile();
            // the next line throws an exception
            if (regbase.Contains("IsPureAcadProfile"))
            {
                // code never gets here
            }

Glenn R

  • Guest
Re: UserConfigurationManager?
« Reply #6 on: May 10, 2008, 02:45:47 PM »
I think you will find, as reported by Kean Walmsley, that this API ONLY works with strings - not REG_DWORD values etc.

He had a post recently about this and somebody mentioned they couldn't write something that wasn't a string - I believe this is the same thing and wouldn't surprise me, given your "jingrish" error message.

sinc

  • Guest
Re: UserConfigurationManager?
« Reply #7 on: May 10, 2008, 04:13:40 PM »
But it works fine in 2008 and in the 2009 beta...   :-o

sinc

  • Guest
Re: UserConfigurationManager?
« Reply #8 on: May 10, 2008, 04:38:28 PM »
OK, I went back and checked...

It looks like it DOES NOT work in 2008.  The only reason it *seemed* to work is that in 2008, and evidently in the 2009 beta, Autodesk did not create an "IsPureAcadProfile" registry entry in the default C3D profile.  In my code, if there was no entry, I assumed it was set to false, and everything worked.

Now, in 2009, they have added a registry entry with IsPureAcadProfile set to 0x00.  When I try creating a similar entry in 2008, it blows up 2008 as well.

Well, once again, Autodesk has taken something simple and made it complicated.  All I want to do is find out if the current application instance is running as Civil-3D or as "Civil-3D as Autocad".  I thought the UserConfigurationManager was the easy way to do this, checking for the "IsPureAcadProfile" registry entry.  But that entry is a DWORD, and the UserConfigurationManager evidently cannot read DWORDS.

Thanks again, Autodesk.  But i've been working with Autodesk software long enough that I'm not surprised - I just need to follow the usual routine, and spend the next X hours trying to come up with a workaround, instead of working on what I wanted to do...   :-P
« Last Edit: May 10, 2008, 04:44:25 PM by sinc »

sinc

  • Guest
Re: UserConfigurationManager?
« Reply #9 on: May 10, 2008, 04:42:59 PM »
Oh, maybe I can do this easily, after all...

It looks like I can check to see if the current profile contains the subsection named "AeccMgr"...  If that registry subsection doesn't exist in the current profile, I can safely assume it's "Civil-3D as Autocad".  At least, I think it will work...     :whistle:

Glenn R

  • Guest
Re: UserConfigurationManager?
« Reply #10 on: May 10, 2008, 05:13:08 PM »
Famous last words... ;)

Just use standard .net reg functions and you should be fine...you might even extend the adesk ones so they actually work...?

Glenn R

  • Guest
Re: UserConfigurationManager?
« Reply #11 on: May 10, 2008, 05:14:54 PM »
However, having said all this, I've always found the civ proggies from adesk to the buggiest pieces of software on the planet...great ideas, just poorly implemented.

sinc

  • Guest
Re: UserConfigurationManager?
« Reply #12 on: May 10, 2008, 06:02:07 PM »
Famous last words... ;)

Just use standard .net reg functions and you should be fine...you might even extend the adesk ones so they actually work...?

Yeah, but that means manually identifying the exact profile path for every version, and then figuring out which of the available profiles is the current one, etc., which is something the UCM was supposed to do for us (I think)...

But I suppose that's a possibility.  Right now, I'm just checking for the existence of the AeccMgr subsection, which I think works, and is a nice, easy solution...  Of course, since it's "indirect", it might go wrong...  It probably would be better to use the .NET registry stuff instead of Adesk's, but that's more work...

Ah well, it's something I can push until later.  The way I have it now, it's working.  I'll just leave it like that for the time being, unless it starts creating problems.

Glenn R

  • Guest
Re: UserConfigurationManager?
« Reply #13 on: May 10, 2008, 06:15:54 PM »
No two ways about it - it blows chunks.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: UserConfigurationManager?
« Reply #14 on: May 10, 2008, 11:35:28 PM »
No two ways about it - it blows chunks.

Agreed, its’ easy enough to party on the registry directly..  so, I will be avoiding this “feature”