Beispiel #1
0
        internal static MainboardDefinition GetLastUsedMainboardDefinition(string netMFVersion)
        {
            MainboardDefinition definition = null;

            try
            {
                using (RegistryKey key = Registry.CurrentUser.OpenSubKey(GadgeteerDefinitionsManager.RegistryRoot, false))
                {
                    if (key == null)
                    {
                        return(null);
                    }

                    string lastUsedMBType = key.GetValue(LastUsedMainboardKeyPrefix + netMFVersion) as string;
                    if (!string.IsNullOrWhiteSpace(lastUsedMBType))
                    {
                        definition = GadgeteerDefinitionsManager.Instance.Mainboards.Where(d => d.Type == lastUsedMBType).FirstOrDefault();
                    }
                }
            }
            catch (SecurityException e) { Log.WriteError(e); }
            catch (UnauthorizedAccessException e) { Log.WriteError(e); }
            catch (IOException e) { Log.WriteError(e); }
            return(definition);
        }
Beispiel #2
0
        internal static void StoreLastUsedMainboardDefinition(MainboardDefinition definition, string netMFVersion)
        {
            Log.WriteErrorIf(definition == null, "StoreLastUsedMainboardDefinition called with a null definition");
            Log.WriteErrorIf(string.IsNullOrWhiteSpace(netMFVersion), "StoreLastUsedMainboardDefinition called with an empty .NET MF Version");

            if (definition == null || string.IsNullOrWhiteSpace(netMFVersion))
            {
                return;
            }

            RegistryKey key = null;

            try
            {
                key = Registry.CurrentUser.OpenSubKey(GadgeteerDefinitionsManager.RegistryRoot, true);

                if (key == null)
                {
                    key = Registry.CurrentUser.CreateSubKey(GadgeteerDefinitionsManager.RegistryRoot, RegistryKeyPermissionCheck.ReadWriteSubTree);
                }

                key.SetValue(LastUsedMainboardKeyPrefix + netMFVersion, definition.Type);
            }
            catch (SecurityException e) { Log.WriteError(e); }
            catch (UnauthorizedAccessException e) { Log.WriteError(e); }
            catch (IOException e) { Log.WriteError(e); }
            finally
            {
                if (key != null)
                {
                    key.Dispose();
                }
            }
        }
        private Mainboard GetDefaultMainboard(Store store, string netMFVersion)
        {
            if (string.IsNullOrWhiteSpace(netMFVersion))
            {
                return(null);
            }

            MainboardDefinition definition = GadgeteerModel.GetLastUsedMainboardDefinition(netMFVersion);

            if (definition == null)
            {
                definition = GadgeteerDefinitionsManager.Instance.Mainboards.Where(d => d.SupportedMicroframeworkVersions.Contains(netMFVersion)).FirstOrDefault();
            }

            if (definition == null)
            {
                return(null);
            }


            return(new Mainboard(store, true /*Flag this was created as part of a new model */)
            {
                Name = definition.Name
            });
        }
Beispiel #4
0
        public static MainboardDefinition CreateMainboardDef(string name, Collection <ProvidedSocket> providedSockets)
        {
            var mbDef = new MainboardDefinition();

            mbDef.Name            = name;
            mbDef.ProvidedSockets = providedSockets;
            return(mbDef);
        }
Beispiel #5
0
        private static ElementGroupPrototype GeneratePrototype(MainboardDefinition part, Store store)
        {
            var element = store.ElementFactory.CreateElement(Mainboard.DomainClassId) as Mainboard;

            element.Name = part.Name;

            return(MakePrototype(element));
        }
Beispiel #6
0
        public static GadgeteerToolboxItem CreateFor(GadgeteerPart part, Store store, string mfVersion, Version gVersion, int position = 2)
        {
            Bitmap icon         = ToolboxIcon;
            string errorMessage = null;

            if (part.HasErrors)
            {
                errorMessage = string.Format(Resources.PackageUI.DefinitionError, string.Join(Environment.NewLine, part.GetErrors()));

                icon = ToolboxIconError;
            }
            else
            {
                if (gVersion != null && gVersion < System.Version.Parse(part.MinimumGadgeteerCoreVersion))
                {
                    // do not block the designer if Gadgeteer version cannot be found (e.g. referenced as project)
                    // if (gVersion == null)
                    //     errorMessage = string.Format(Resources.PackageUI.WarningNoG, part.MinimumGadgeteerCoreVersion);
                    // else
                    errorMessage = string.Format(Resources.PackageUI.WarningGVersion, part.MinimumGadgeteerCoreVersion, gVersion);

                    icon = ToolboxIconWarning;
                }

                else if (!part.SupportedMicroframeworkVersions.Contains(mfVersion))
                {
                    errorMessage = string.Format(Resources.PackageUI.WarningMFVersion, string.Join(", ", part.SupportedMicroframeworkVersions), mfVersion);

                    icon = ToolboxIconWarning;
                }
            }

            part.ErrorMessage = errorMessage;

            ModuleDefinition module = part as ModuleDefinition;

            if (module != null)
            {
                return(new GadgeteerToolboxItem(module, store, icon, position, errorMessage));
            }

            MainboardDefinition mainboard = part as MainboardDefinition;

            if (mainboard != null)
            {
                return(new GadgeteerToolboxItem(mainboard, store, icon, position, errorMessage));
            }

            throw new NotSupportedException();
        }
Beispiel #7
0
 private GadgeteerToolboxItem(MainboardDefinition part, Store store, Bitmap bitmap, int position, string error = null)
     : base(
         GenerateId(part),                      // Unique identifier (non-localized) for the toolbox item.
         position,                              // Position relative to other items in the same toolbox tab.
         GenerateName(part),
         bitmap,                                // Image displayed next to the toolbox item.
         ToolboxItemTabName,                    // Unique identifier (non-localized) for the toolbox item tab.
         Resources.PackageUI.MainboardsTabName, // Localized display name for the toolbox tab.
         part.Name,                             // F1 help keyword for the toolbox item.
         GenerateDescription(part, error),      // Localized tooltip text for the toolbox item.
         GeneratePrototype(part, store),
         FilterAttributes)
 {
     Initialize(part, store);
 }
Beispiel #8
0
        private static ElementGroupPrototype CreateMainboardToolPrototype(Store store, MainboardDefinition mainboardDefinition)
        {
            var element = store.ElementFactory.CreateElement(Mainboard.DomainClassId) as Mainboard;

            element.Name = mainboardDefinition.Name;

            return(MakePrototype(element));
        }
Beispiel #9
0
 private static string GenerateId(MainboardDefinition part)
 {
     return(string.Concat(part.Name, "_", "_ToolboxItem"));
 }