Esempio n. 1
0
        private void AddAssemblyReference(GadgeteerHardware hw, Assembly assembly)
        {
            try
            {
                var vsproject = (VSProject2)project.Object;
                //This is a no-op if the reference already exists
                var reference = (Reference3)vsproject.References.Add(assembly.Name);
                reference.SpecificVersion = false;
            }
            catch (COMException ex)
            {
                string message = assembly.ErrorMessage;
                if (string.IsNullOrWhiteSpace(message))
                {
                    message = string.Format(PackageUI.MissingAssembly, hw.GetType().Name.ToLower(CultureInfo.CurrentCulture), ProjectMFVersion);
                }

                MessageBox.Show(message, PackageUI.ErrorDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log.WriteError("Could not add a reference to assembly '{0}': {1}", assembly.Name, ex.Message);

                //TODO: Is it possible to rollback the addition of the module? Doing Undo and FlushRedoStack here results in a null
                //reference exception. Need to investigate why. Also if this happens during the opening of the designer because
                //of an improperly configured mainboard the designer fails to open.  Overall seems like the DSL framework is not too
                //happy about us calling Undo here.
                //Store.UndoManager.Undo();
                //Store.UndoManager.FlushRedoStack();
            }
        }
Esempio n. 2
0
        private void RemoveAssemblyReferences(GadgeteerHardware hw)
        {
            var delAssemblies = GetAssemblyDefinitions(hw);

            foreach (Assembly assembly in delAssemblies)
            {
                bool assemblyInUse = false;
                // check if there are any more elements of the same kind before removing the reference
                var elements = this.Store.ElementDirectory.FindElements(GadgeteerHardware.DomainClassId);
                foreach (var element in elements)
                {
                    var curAssemblies = GetAssemblyDefinitions(element as GadgeteerHardware);
                    if (curAssemblies.Select(a => a.Name).Contains(assembly.Name))
                    {
                        assemblyInUse = true;
                        break;
                    }
                }

                if (!assemblyInUse)
                {
                    var reference = GetAssemblyReference(assembly.Name);
                    if (reference != null)
                    {
                        reference.Remove();
                    }
                }
            }
        }
Esempio n. 3
0
        private static ElementGroupPrototype MakePrototype(GadgeteerHardware element)
        {
            var elementGroup = new ElementGroup(element.Store.DefaultPartition);

            elementGroup.AddGraph(element, true);
            return(elementGroup.CreatePrototype());
        }
Esempio n. 4
0
        private static bool CheckGadgeteerMinimumVersion(GadgeteerHardware hardware, Store store)
        {
            object gadgeteerVersion = null;
            bool   result           = false;

            if (store.PropertyBag.TryGetValue(GadgeteerModel.GadgeteerCoreVersionKey, out gadgeteerVersion))
            {
                if (hardware.GadgeteerPartDefinition == null || string.IsNullOrWhiteSpace(hardware.GadgeteerPartDefinition.MinimumGadgeteerCoreVersion))
                {
                    Log.WriteError("Can't find the MinimumGadgeteerCoreVersion for " + hardware);
                    result = true; //Nothing to compare to. Not good but make sure we don't block all modules
                }
                else
                {
                    var version = (Version)gadgeteerVersion;
                    result = (new Version(hardware.GadgeteerPartDefinition.MinimumGadgeteerCoreVersion)) <= version;
                }
            }
            else
            {
                Log.WriteError("We don't know the version Gadgeteer.dll being referenced");
                result = true; // and we don't want to block
            }
            return(result);
        }
Esempio n. 5
0
 /// <summary>
 /// Recursively adds the modules attached to the given GadgeteerHardware in depth first order
 /// </summary>
 private static void GetConnectedModules(GadgeteerHardware hw, List <Module> modules)
 {
     foreach (Socket s in hw.Sockets)
     {
         if (s.SocketUse != null && s.SocketUse.Module != null)
         {
             modules.Add(s.SocketUse.Module);
             GetConnectedModules(s.SocketUse.Module, modules);
         }
     }
 }
Esempio n. 6
0
        private IEnumerable <Assembly> GetAssemblyDefinitions(GadgeteerHardware hw)
        {
            GadgeteerPart definition = hw.GadgeteerPartDefinition;

            if (definition == null || definition.Assemblies == null)
            {
                Log.WriteError("Could not find definition for module {0}", hw);
                return(new Assembly[0]);
            }

            return(definition.Assemblies.Where(assembly => assembly.MFVersion == ProjectMFVersion));
        }
Esempio n. 7
0
        private void AddAssemblyReferences(GadgeteerHardware hw)
        {
            IEnumerable <Assembly> assemblies = GetAssemblyDefinitions(hw);

            if (assemblies.Count() > 0)
            {
                foreach (Assembly assembly in assemblies)
                {
                    AddAssemblyReference(hw, assembly);
                }
            }
            else
            {
                Log.WriteError("Could not find a suitable assembly for module '{0}' and MF Version {1}", hw, ProjectMFVersion);
            }
        }
Esempio n. 8
0
        protected bool VerifyMinimumGadgeteerVersion(GadgeteerHardware hardware, Store store)
        {
            //Don't check if this is the toolbox loading code executing or the code generation. None of this execute in the context of a project.
            if (!store.PropertyBag.ContainsKey(GadgeteerModel.DesignerStoreCookie))
            {
                return(true);
            }

            bool result = CheckGadgeteerMinimumVersion(hardware, store);

            if (!result)
            {
                Fail(string.Format(Resources.UI.MinimumGadgeteerVersionNotMet, hardware.GadgeteerPartDefinition.Name,
                                   hardware.GetType().Name.ToLowerInvariant(),
                                   hardware.GadgeteerPartDefinition.MinimumGadgeteerCoreVersion), store);
            }
            return(result);
        }
Esempio n. 9
0
        private void RemoveUsingStatements(GadgeteerHardware hw)
        {
            var ns       = GadgeteerModel.GetNamespace(hw.GadgeteerPartDefinition.Type);
            var elements = this.Store.ElementDirectory.FindElements(GadgeteerHardware.DomainClassId);

            // check for other elements that have the same namespace before removing the using statement
            foreach (var element in elements)
            {
                if (GadgeteerModel.GetNamespace(((GadgeteerHardware)element).GadgeteerPartDefinition.Type) == ns)
                {
                    return;
                }
            }

            var vsp          = (VSProject2)project.Object;
            var userCodeItem = vsp.DTE.Solution.FindProjectItem(this.GetCodeFileName());

            if (userCodeItem == null)
            {
                return;
            }

            var fcm = (FileCodeModel2)userCodeItem.FileCodeModel;

            foreach (CodeElement codeElement in fcm.CodeElements)
            {
                if (codeElement.Kind == vsCMElement.vsCMElementImportStmt)
                {
                    var s = ((CodeImport)codeElement).Namespace;
                    if (s == ns)
                    {
                        fcm.Remove(codeElement);
                    }
                }
            }
        }
Esempio n. 10
0
 internal IEnumerable <Reference> GetAssemblyReferences(GadgeteerHardware hw)
 {
     return(GetAssemblyDefinitions(hw).Select(asmDef => GetAssemblyReference(asmDef.Name)));
 }