public bool UpdateGtkFolder()
        {
            if (!SupportsDesigner(project))
            {
                return(false);
            }

            // This method synchronizes the current gtk project configuration info
            // with the needed support files in the gtk-gui folder.

            FileService.CreateDirectory(GtkGuiFolder);
            bool projectModified   = false;
            bool initialGeneration = false;

            if (!File.Exists(SteticFile))
            {
                initialGeneration = true;
                StreamWriter sw = new StreamWriter(SteticFile);
                sw.WriteLine("<stetic-interface />");
                sw.Close();
                FileService.NotifyFileChanged(SteticFile);
            }

            if (!project.IsFileInProject(SteticFile))
            {
                ProjectFile pf = project.AddFile(SteticFile, BuildAction.EmbeddedResource);
                pf.ResourceId   = "gui.stetic";
                projectModified = true;
            }

            StringCollection files         = GuiBuilderProject.GenerateFiles(GtkGuiFolder);
            DateTime         generatedTime = File.GetLastWriteTime(SteticFile).Subtract(TimeSpan.FromSeconds(2));

            foreach (string filename in files)
            {
                if (initialGeneration)
                {
                    // Ensure that the generation date of this file is < the date of the .stetic file
                    // In this way the code will be properly regenerated when building the project.
                    File.SetLastWriteTime(filename, generatedTime);
                }
                if (!project.IsFileInProject(filename))
                {
                    project.AddFile(filename, BuildAction.Compile);
                    projectModified = true;
                }
            }

            UpdateObjectsFile();
            files.Add(ObjectsFile);
            files.Add(SteticFile);

            if (CleanGtkFolder(files))
            {
                projectModified = true;
            }

            return(ReferenceManager.Update() || projectModified);
        }
Exemple #2
0
        public bool UpdateGtkFolder()
        {
            if (!SupportsDesigner(project))
            {
                return(false);
            }

            // This method synchronizes the current gtk project configuration info
            // with the needed support files in the gtk-gui folder.

            FileService.CreateDirectory(SteticFolder);
            bool projectModified = false;

            foreach (string filename in GetDesignerFiles())
            {
                ProjectFile pf = project.AddFile(filename, BuildAction.EmbeddedResource);
                pf.ResourceId = Path.GetFileName(filename);

                string componentFile = GetComponentFileFromDesigner(filename);

                if (componentFile != null && File.Exists(componentFile))
                {
                    pf.DependsOn = componentFile;

                    string buildFile = GetBuildFileFromComponent(componentFile);
                    if (buildFile != null && File.Exists(buildFile))
                    {
                        ProjectFile pf2 = project.AddFile(buildFile, BuildAction.Compile);
                        pf2.ResourceId = Path.GetFileName(buildFile);
                        pf2.DependsOn  = componentFile;
                    }
                }

                projectModified = true;
            }

            StringCollection files = GuiBuilderProject.GenerateFiles(SteticFolder);

            foreach (string filename in files)
            {
                if (!project.IsFileInProject(filename))
                {
                    project.AddFile(filename, BuildAction.Compile);
                    projectModified = true;
                }
            }

            UpdateObjectsFile();

            return(ReferenceManager.Update() || projectModified);
        }
        protected override async Task <string> GenerateDescriptionFiles(DotNetProject dotNetProject, FilePath basePath)
        {
            if (!dotNetProject.Items.GetAll <WebReferencesDir> ().Any())
            {
                var met = new WebReferencesDir(basePath.ParentDirectory);
                dotNetProject.Items.Add(met);
            }

            WebReferenceUrl wru = dotNetProject.Items.GetAll <WebReferenceUrl> ().FirstOrDefault(m => m.RelPath.CanonicalPath == basePath);

            if (wru == null)
            {
                wru         = new WebReferenceUrl(protocol.Url);
                wru.RelPath = basePath;
                dotNetProject.Items.Add(wru);
            }

            DiscoveryClientResultCollection files = await Task.Run(() => {
                protocol.ResolveAll();
                return(protocol.WriteAll(basePath, "Reference.map"));
            });

            foreach (DiscoveryClientResult dr in files)
            {
                dotNetProject.AddFile(new FilePath(Path.GetFileName(dr.Filename)).ToAbsolute(basePath), BuildAction.None);
            }

            return(Path.Combine(basePath, "Reference.map"));
        }
Exemple #4
0
        public void Store()
        {
            DotNetProject project = entry as DotNetProject;

            if (project == null)
            {
                return;
            }

            LinuxDeployData data = LinuxDeployData.GetLinuxDeployData(project);

            data.GenerateScript = checkScript.Active;
            data.ScriptName     = entryScript.Text;
            data.GeneratePcFile = checkPcFile.Active;

            if (checkDesktop.Active)
            {
                DesktopEntry de = new DesktopEntry();
                de.SetEntry("Encoding", "UTF-8");
                de.Type     = DesktopEntryType.Application;
                de.Name     = entry.Name;
                de.Exec     = entryScript.Text;
                de.Terminal = false;
                string file = System.IO.Path.Combine(entry.BaseDirectory, "app.desktop");
                de.Save(file);
                ProjectFile      pfile = project.AddFile(file, BuildAction.Content);
                DeployProperties props = DeployService.GetDeployProperties(pfile);
                props.TargetDirectory = LinuxTargetDirectory.DesktopApplications;
            }
        }
Exemple #5
0
        protected override string GenerateDescriptionFiles(DotNetProject project, FilePath basePath)
        {
            if (!project.Items.GetAll <WebReferencesDir> ().Any())
            {
                WebReferencesDir met = new WebReferencesDir();
                met.Path = basePath.ParentDirectory;
                project.Items.Add(met);
            }

            WebReferenceUrl wru = project.Items.GetAll <WebReferenceUrl> ().FirstOrDefault(m => m.RelPath.CanonicalPath == basePath);

            if (wru == null)
            {
                wru         = new WebReferenceUrl(protocol.Url);
                wru.RelPath = basePath;
                project.Items.Add(wru);
            }

            protocol.ResolveAll();
            DiscoveryClientResultCollection files = protocol.WriteAll(basePath, "Reference.map");

            foreach (DiscoveryClientResult dr in files)
            {
                project.AddFile(new FilePath(dr.Filename).ToAbsolute(basePath), BuildAction.None);
            }

            return(Path.Combine(basePath, "Reference.map"));
        }
Exemple #6
0
        void AddFileProjectItemToProject(string path)
        {
            ProjectFile fileItem = CreateFileProjectItem(path);

            project.AddFile(fileItem);
            projectService.Save(project);
        }
Exemple #7
0
        public static bool CreatePublishProfileFile(this DotNetProject project, ProjectPublishProfile profile)
        {
            string profileFileContents = ProjectPublishProfile.WriteModel(profile);

            var profileFileName = project.BaseDirectory.Combine("Properties", "PublishProfiles", project.GetNextPubXmlFileName());

            string publishProfilesDirectory = Path.GetDirectoryName(profileFileName);

            Directory.CreateDirectory(publishProfilesDirectory);

            File.WriteAllText(profileFileName, profileFileContents);

            project.AddFile(profileFileName);

            return(true);
        }
        public Task AddFileToProjectAsync(string filePath)
        {
            if (project.IsFileInProject(filePath))
            {
                return(Task.CompletedTask);
            }

            return(Runtime.RunInMainThread(async() => {
                var fullPath = GetFullPath(filePath);
                string buildAction = project.GetDefaultBuildAction(fullPath);
                var fileItem = new ProjectFile(fullPath)
                {
                    BuildAction = buildAction
                };
                project.AddFile(fileItem);
                await SaveProject();
            }));
        }
        protected override string GenerateDescriptionFiles(DotNetProject project, FilePath basePath)
        {
            if (!project.Items.GetAll <WCFMetadata> ().Any())
            {
                WCFMetadata met = new WCFMetadata();
                met.Path = basePath.ParentDirectory;
                project.Items.Add(met);
            }

            WCFMetadataStorage metStor = project.Items.GetAll <WCFMetadataStorage> ().FirstOrDefault(m => m.Path.CanonicalPath == basePath);

            if (metStor == null)
            {
                project.Items.Add(new WCFMetadataStorage()
                {
                    Path = basePath
                });
            }

            string file = Path.Combine(basePath, "Reference.svcmap");

            if (protocol != null)
            {
                protocol.ResolveAll();
                protocol.WriteAll(basePath, "Reference.svcmap");
                refGroup = ConvertMapFile(file);
            }
            else
            {
                // TODO
                ReferenceGroup map = new ReferenceGroup();
                map.ClientOptions = InitialClientOptions;
                map.Save(file);
                map.ID   = Guid.NewGuid().ToString();
                refGroup = map;
            }
            foreach (MetadataFile mfile in refGroup.Metadata)
            {
                project.AddFile(new FilePath(mfile.FileName).ToAbsolute(basePath), BuildAction.None);
            }

            return(file);
        }
 public void AddFile(ProjectFile projectFile)
 {
     project.AddFile(projectFile);
 }
        public static void AddView(DotNetProject project, string path, string name)
        {
            var provider = project.LanguageBinding.GetCodeDomProvider();

            if (provider == null)
            {
                throw new InvalidOperationException("Project language has null CodeDOM provider");
            }

            string outputFile          = null;
            MvcTextTemplateHost host   = null;
            AddViewDialog       dialog = null;

            try {
                dialog          = new AddViewDialog(project);
                dialog.ViewName = name;

                bool fileGood = false;
                while (!fileGood)
                {
                    var resp = (Gtk.ResponseType)MessageService.RunCustomDialog(dialog);
                    dialog.Hide();
                    if (resp != Gtk.ResponseType.Ok || !dialog.IsValid())
                    {
                        return;
                    }

                    string ext = ".cshtml";
                    if (dialog.ActiveViewEngine == "Aspx")
                    {
                        ext = dialog.IsPartialView ? ".ascx" : ".aspx";
                    }

                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }

                    outputFile = System.IO.Path.Combine(path, dialog.ViewName) + ext;

                    if (System.IO.File.Exists(outputFile))
                    {
                        fileGood = MessageService.AskQuestion(GettextCatalog.GetString("Overwrite file?"),
                                                              GettextCatalog.GetString("The file '{0}' already exists.\n", dialog.ViewName) +
                                                              GettextCatalog.GetString("Would you like to overwrite it?"), AlertButton.OverwriteFile, AlertButton.Cancel)
                                   != AlertButton.Cancel;
                    }
                    else
                    {
                        break;
                    }
                }

                host = new MvcTextTemplateHost {
                    LanguageExtension  = provider.FileExtension,
                    ItemName           = dialog.ViewName,
                    ViewDataTypeString = ""
                };

                if (dialog.HasMaster)
                {
                    host.IsViewContentPage   = true;
                    host.ContentPlaceholder  = dialog.PrimaryPlaceHolder;
                    host.MasterPage          = dialog.MasterFile;
                    host.ContentPlaceHolders = dialog.ContentPlaceHolders;
                }
                else if (dialog.IsPartialView)
                {
                    host.IsViewUserControl = true;
                }
                else
                {
                    host.IsViewPage = true;
                }

                if (dialog.IsStronglyTyped)
                {
                    host.ViewDataTypeString = dialog.ViewDataTypeString;
                }

                host.ProcessTemplate(dialog.TemplateFile, outputFile);
                MonoDevelop.TextTemplating.TextTemplatingService.ShowTemplateHostErrors(host.Errors);
            } finally {
                if (host != null)
                {
                    host.Dispose();
                }
                if (dialog != null)
                {
                    dialog.Destroy();
                    dialog.Dispose();
                }
            }

            if (System.IO.File.Exists(outputFile))
            {
                project.AddFile(outputFile);
                IdeApp.ProjectOperations.SaveAsync(project);
            }
        }
        protected override void Run()
        {
            DotNetProject project            = IdeApp.ProjectOperations.CurrentSelectedProject as DotNetProject;
            var           dotNetProjectProxy = new DotNetProjectProxy(project);

            if (project == null)
            {
                return;
            }
            INativeTypesHandler nativeTypesHandler = null;

            //SupportedLanguage names currently returns an empty item and the 'languageName' the DotNetProject
            //is initialized with. This might be an array to enable extension for other projects? DotNetProject
            //only returns an empty and languageName. See source link.
            // https://github.com/mono/monodevelop/blob/dcafac668cbe8f63b4e42ea7f8f032f13aba8221/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProject.cs#L198
            if (project.SupportedLanguages.Contains("C#"))
            {
                nativeTypesHandler = NativeTypeHandlers.CSharpNativeTypesHandler;
            }

            if (project.SupportedLanguages.Contains("F#"))
            {
                nativeTypesHandler = NativeTypeHandlers.FSharpNativeTypesHandler;
            }

            if (project.SupportedLanguages.Contains("VBNet"))
            {
                nativeTypesHandler = NativeTypeHandlers.VbNetNativeTypesHandler;
            }

            if (nativeTypesHandler == null)
            {
                throw new ArgumentNullException("No supported languages found");
            }

            string fileName = "ServiceReference";

            int  count  = 0;
            bool exists = true;

            while (exists)
            {
                count++;
                var existingFile = project.Files.FirstOrDefault(x => x.FilePath.FileName == fileName + count.ToString() + nativeTypesHandler.CodeFileExtension);
                exists = existingFile != null;
            }

            var dialog = new AddReferenceDialog(fileName + count.ToString(), nativeTypesHandler);

            dialog.Run();
            string finalFileName = dialog.ReferenceName + nativeTypesHandler.CodeFileExtension;
            string code          = dialog.CodeTemplate;

            dialog.Destroy();
            if (!dialog.AddReferenceSucceeded)
            {
                return;
            }
            IdeApp.Workbench.StatusBar.ShowReady();
            IdeApp.Workbench.StatusBar.ShowMessage("Adding ServiceStack Reference...");
            IdeApp.Workbench.StatusBar.Pulse();
            string fullPath = Path.Combine(project.BaseDirectory.FullPath.ToString(), finalFileName);

            using (var streamWriter = File.CreateText(fullPath)) {
                streamWriter.Write(code);
                streamWriter.Flush();
            }

            project.AddFile(fullPath, BuildAction.Compile);

            try {
                Task.Run(() => {
                    AddNuGetPackageReference(dotNetProjectProxy, "ServiceStack.Client");
                    AddNuGetPackageReference(dotNetProjectProxy, "ServiceStack.Interfaces");
                    AddNuGetPackageReference(dotNetProjectProxy, "ServiceStack.Text");
                }).ContinueWith(task => {
                    IdeApp.Workbench.StatusBar.ShowReady();
                    IdeApp.Workbench.StatusBar.Pulse();
                }, TaskScheduler.FromCurrentSynchronizationContext());
            } catch (Exception ex) {
                //TODO Error message for user
                var messageDialog = new MessageDialog(
                    (Gtk.Window)IdeApp.Workbench.RootWindow.Toplevel,
                    DialogFlags.Modal,
                    MessageType.Warning,
                    ButtonsType.Close,
                    "An error occurred trying to add required NuGet packages. Error : " + ex.Message +
                    "\r\n\r\nGenerated service reference will require ServiceStack.Interfaces as a minimum.");
                messageDialog.Run();
                messageDialog.Destroy();
                IdeApp.Workbench.StatusBar.ShowReady();
                IdeApp.Workbench.StatusBar.Pulse();
            }
        }
Exemple #13
0
        internal static ProjectFile MigrateToProjectJson(DotNetProject project)
        {
            var projectJsonName = project.BaseDirectory.Combine("project.json");
            var projectJsonFile = new ProjectFile(projectJsonName, BuildAction.None);

            bool          isOpen = false;
            JObject       json;
            ITextDocument file;

            if (System.IO.File.Exists(projectJsonName))
            {
                file = TextFileProvider.Instance.GetTextEditorData(projectJsonFile.FilePath.ToString(), out isOpen);
                using (var tr = file.CreateReader())
                    using (var jr = new Newtonsoft.Json.JsonTextReader(tr)) {
                        json = (JObject)JToken.Load(jr);
                    }
            }
            else
            {
                file          = TextEditorFactory.CreateNewDocument();
                file.FileName = projectJsonName;
                file.Encoding = Encoding.UTF8;
                json          = new JObject(
                    new JProperty("dependencies", new JObject()),
                    new JProperty("frameworks", new JObject())
                    );
            }

            List <string> packages           = null;
            var           packagesConfigFile = project.GetProjectFile(project.BaseDirectory.Combine("packages.config"));

            if (packagesConfigFile != null)
            {
                //NOTE: it might also be open and unsaved, but that's an unimportant edge case, ignore it
                var configDoc = System.Xml.Linq.XDocument.Load(packagesConfigFile.FilePath);
                if (configDoc.Root != null)
                {
                    var deps = (json ["dependencies"] as JObject) ?? ((JObject)(json ["dependencies"] = new JObject()));
                    foreach (var packagelEl in configDoc.Root.Elements("package"))
                    {
                        var packageId      = (string)packagelEl.Attribute("id");
                        var packageVersion = (string)packagelEl.Attribute("version");
                        deps [packageId] = packageVersion;

                        if (packages == null)
                        {
                            packages = new List <string> ();
                        }
                        packages.Add(packageId + "." + packageVersion);
                    }
                }
            }

            var framework = GetPclProfileFullName(project.TargetFramework.Id) ?? NetStandardDefaultFramework;

            json ["frameworks"] = new JObject(
                new JProperty(framework, new JObject())
                );

            file.Text = json.ToString();

            if (!isOpen)
            {
                file.Save();
            }

            project.AddFile(projectJsonFile);
            if (packagesConfigFile != null)
            {
                project.Files.Remove(packagesConfigFile);

                //we have to delete the packages.config, or the NuGet addin will try to retarget its packages
                FileService.DeleteFile(packagesConfigFile.FilePath);

                //remove the package refs nuget put in the file, project.json doesn't use those
                project.References.RemoveRange(project.References.Where(IsFromPackage).ToArray());

                // Remove any imports from NuGet packages. These will be added by NuGet into the generated
                // ProjectName.nuget.props and ProjectName.nuget.targets files when using project.json.
                if (packages != null)
                {
                    foreach (var import in project.MSBuildProject.Imports.ToArray())
                    {
                        if (packages.Any(p => import.Project.IndexOf(p, StringComparison.OrdinalIgnoreCase) >= 0))
                        {
                            import.ParentObject.ParentProject.Remove(import);
                        }
                    }
                }
            }

            return(projectJsonFile);
        }
        /// <summary>
        /// Adds the custom classes from user interface definition files.
        /// </summary>
        /// <returns>
        /// <c>true</c> if new types were added to the project, or <c>false</c> otherwise.
        /// </returns>
        /// <param name='monitor'>
        /// A progress monitor.
        /// </param>
        /// <param name='context'>
        /// A sync-back context.
        /// </param>
        bool AddCustomClassesFromUIDefinitionFiles(IProgressMonitor monitor, XcodeSyncBackContext context)
        {
            var provider = dnp.LanguageBinding.GetCodeDomProvider();
            var options  = new System.CodeDom.Compiler.CodeGeneratorOptions();
            var writer   = MonoDevelop.DesignerSupport.CodeBehindWriter.CreateForProject(
                new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor(), dnp);
            bool addedTypes = false;

            monitor.BeginTask(GettextCatalog.GetString("Generating custom classes defined in UI definition files"), 0);

            // Collect our list of custom classes from UI definition files
            foreach (var job in context.FileSyncJobs)
            {
                if (!HasInterfaceDefinitionExtension(job.Original))
                {
                    continue;
                }

                string relative = job.SyncedRelative.ParentDirectory;
                string dir      = dnp.BaseDirectory;

                if (!string.IsNullOrEmpty(relative))
                {
                    dir = Path.Combine(dir, relative);
                }

                foreach (var type in GetCustomTypesFromUIDefinition(job.Original))
                {
                    if (context.ProjectInfo.ContainsType(type.ObjCName))
                    {
                        continue;
                    }

                    string designerPath = Path.Combine(dir, type.ObjCName + ".designer." + provider.FileExtension);
                    string path         = Path.Combine(dir, type.ObjCName + "." + provider.FileExtension);
                    string ns           = dnp.GetDefaultNamespace(path);

                    type.CliName = ns + "." + provider.CreateValidIdentifier(type.ObjCName);

                    if (provider is Microsoft.CSharp.CSharpCodeProvider)
                    {
                        CodebehindTemplateBase cs = new CSharpCodeTypeDefinition()
                        {
                            WrapperNamespace = infoService.WrapperRoot,
                            Provider         = provider,
                            Type             = type,
                        };

                        writer.WriteFile(path, cs.TransformText());

                        List <NSObjectTypeInfo> types = new List <NSObjectTypeInfo> ();
                        types.Add(type);

                        cs = new CSharpCodeCodebehind()
                        {
                            WrapperNamespace = infoService.WrapperRoot,
                            Provider         = provider,
                            Types            = types,
                        };

                        writer.WriteFile(designerPath, cs.TransformText());

                        context.ProjectInfo.InsertUpdatedType(type);
                    }
                    else
                    {
                        // FIXME: implement support for non-C# languages
                    }

                    dnp.AddFile(new ProjectFile(path));
                    dnp.AddFile(new ProjectFile(designerPath)
                    {
                        DependsOn = path
                    });
                    addedTypes = true;
                }
            }

            writer.WriteOpenFiles();

            monitor.EndTask();

            return(addedTypes);
        }
Exemple #15
0
        public static void AddController(DotNetProject project, string path, string name)
        {
            var provider = project.LanguageBinding.GetCodeDomProvider();

            if (provider == null)
            {
                throw new InvalidOperationException("Project language has null CodeDOM provider");
            }

            string outputFile          = null;
            MvcTextTemplateHost host   = null;
            AddControllerDialog dialog = null;

            try {
                dialog = new AddControllerDialog(project);
                if (!String.IsNullOrEmpty(name))
                {
                    dialog.ControllerName = name;
                }

                bool fileGood = false;
                while (!fileGood)
                {
                    var resp = (Gtk.ResponseType)MessageService.RunCustomDialog(dialog);
                    dialog.Hide();
                    if (resp != Gtk.ResponseType.Ok || !dialog.IsValid())
                    {
                        return;
                    }

                    outputFile = System.IO.Path.Combine(path, dialog.ControllerName) + ".cs";

                    if (System.IO.File.Exists(outputFile))
                    {
                        fileGood = MessageService.AskQuestion("Overwrite file?",
                                                              String.Format("The file '{0}' already exists.\n", dialog.ControllerName) +
                                                              "Would you like to overwrite it?", AlertButton.OverwriteFile, AlertButton.Cancel)
                                   != AlertButton.Cancel;
                    }
                    else
                    {
                        break;
                    }
                }

                host = new MvcTextTemplateHost {
                    LanguageExtension = provider.FileExtension,
                    ItemName          = dialog.ControllerName,
                    NameSpace         = project.DefaultNamespace + ".Controllers"
                };

                host.ProcessTemplate(dialog.TemplateFile, outputFile);
                MonoDevelop.TextTemplating.TextTemplatingService.ShowTemplateHostErrors(host.Errors);
            } finally {
                if (host != null)
                {
                    host.Dispose();
                }
                if (dialog != null)
                {
                    dialog.Destroy();
                    dialog.Dispose();
                }
            }

            if (System.IO.File.Exists(outputFile))
            {
                project.AddFile(outputFile);
                IdeApp.ProjectOperations.SaveAsync(project);
            }
        }
 void AddProjectItemToMSBuildProject(MD.ProjectFile projectItem)
 {
     DotNetProject.AddFile(projectItem);
 }