예제 #1
0
        public void Build(CrestronMonoDebuggerPackage package)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // Get the DTE service
            var dte = Package.GetGlobalService(typeof(SDTE)) as DTE2;

            if (dte?.Solution == null)
            {
                package.OutputWindowWriteLine("Unable to locate the solution.");
                throw new InvalidOperationException("Unable to locate the solution.");
            }

            _solution = dte.Solution;

            string activeConfiguration = _solution.SolutionBuild.ActiveConfiguration.Name;

            if (activeConfiguration != "Debug" && activeConfiguration != "Release")
            {
                package.OutputWindowWriteLine("The active configuration must be either Debug or Release.");
                throw new InvalidOperationException("The active configuration must be either Debug or Release.");
            }

            // start the build
            _solution.SolutionBuild.Build();

            // wait until the status shows that the build is in progress
            while (_solution.SolutionBuild.BuildState != vsBuildState.vsBuildStateInProgress)
            {
                System.Threading.Thread.Sleep(100);
            }

            _buildTimer.Change(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(100));
        }
예제 #2
0
        public void CreateMdbFiles(CrestronMonoDebuggerPackage package, string localPath, List <FileListingItem> localFileListing)
        {
            // Get the DTE service
            var dte = Package.GetGlobalService(typeof(SDTE)) as DTE2;

            if (dte?.Solution == null)
            {
                package.OutputWindowWriteLine("Unable to locate the solution.");
                throw new InvalidOperationException("Unable to locate the solution.");
            }

            foreach (FileListingItem file in localFileListing)
            {
                // only convert dll and exe files
                if (Path.GetExtension(file.Name) != ".dll" && Path.GetExtension(file.Name) != ".exe")
                {
                    continue;
                }

                // check to if there is also a related pdb file.
                string pdbFile = Path.ChangeExtension(file.Name, ".pdb");
                if (!string.IsNullOrEmpty(pdbFile))
                {
                    string pdbFileFullPath = Path.Combine(localPath, pdbFile);
                    if (File.Exists(pdbFileFullPath))
                    {
                        // perform the conversion
                        Pdb2Mdb.Converter.Convert(Path.Combine(localPath, file.Name));
                    }
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PublishAndRunCommand"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private PublishAndRunCommand(CrestronMonoDebuggerPackage package, OleMenuCommandService commandService)
        {
            Package        = package ?? throw new ArgumentNullException(nameof(package));
            commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));

            Initialize(commandService);
        }
        public List <FileListingItem> GetFileListing(CrestronMonoDebuggerPackage package, string path)
        {
            try
            {
                IEnumerable <SftpFile> listing;

                using (var client = new SftpClient(_host, _port, _username, _password))
                {
                    client.Connect();
                    listing = client.ListDirectory(path);
                    client.Disconnect();
                }

                var fileListing = new List <FileListingItem>();

                foreach (var file in listing)
                {
                    if (file.IsRegularFile)
                    {
                        fileListing.Add(new FileListingItem(file.Name, file.LastWriteTime, file.Length));
                    }
                }

                package.OutputWindowWriteLine($"Found {fileListing.Count} file on control system.");

                return(fileListing);
            }
            catch (Exception e)
            {
                package.OutputWindowWriteLine("Unable to retrieve file listing from the control system.");
                package.DebugWriteLine(e);
                throw;
            }
        }
 public void StartProgram(CrestronMonoDebuggerPackage package)
 {
     try
     {
         using (var client = new SshClient(_host, _port, _username, _password))
         {
             client.Connect();
             SshCommand sshCommand = client.RunCommand("progres -p:0");
             if (sshCommand.ExitStatus == 0)
             {
                 package.OutputWindowWriteLine("Remote application starting.");
             }
             else
             {
                 package.OutputWindowWriteLine($"Unable to start the remote application. {sshCommand.Error}");
             }
             client.Disconnect();
         }
     }
     catch (Exception e)
     {
         package.OutputWindowWriteLine($"Unable to start the remote application.");
         package.DebugWriteLine(e);
         throw;
     }
 }
예제 #6
0
        public string GetOutputFolder(CrestronMonoDebuggerPackage package)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Project startupProject = GetStartupProject(package);

            return(GetFullOutputPath(startupProject));
        }
예제 #7
0
        public List <FileDeltaItem> CreateFileListingDelta(CrestronMonoDebuggerPackage package, List <FileListingItem> remoteFileListing, string localPath)
        {
            List <FileListingItem> localFileListingSorted = GetFileListing(package, localPath).OrderBy(x => x.Name).ToList();
            var remoteFileListingSorted = remoteFileListing.OrderBy(x => x.Name).ToList();

            List <FileDeltaItem> fileListingDelta = localFileListingSorted.Select(x => x.Name)
                                                    .Union(remoteFileListingSorted.Select(x => x.Name))
                                                    .Select(x => new FileDeltaItem {
                Name = x
            })
                                                    .OrderBy(x => x.Name)
                                                    .ToList();

            int i = 0, j = 0;
            int iMax = remoteFileListingSorted.Count;
            int jMax = localFileListingSorted.Count;

            foreach (FileDeltaItem deltaItem in fileListingDelta)
            {
                if (i < iMax && remoteFileListingSorted[i].Name == deltaItem.Name)
                {
                    if (j >= jMax || localFileListingSorted[j].Name != deltaItem.Name)
                    {
                        // The file needs to be deleted from the control system
                        deltaItem.Delete = true;
                        i++;
                        continue;
                    }
                }

                if (j < jMax && localFileListingSorted[j].Name == deltaItem.Name)
                {
                    if (i >= iMax || remoteFileListingSorted[i].Name != deltaItem.Name)
                    {
                        // The file needs to be added to the control system
                        deltaItem.New = true;
                        j++;
                        continue;
                    }
                }

                if (i < iMax && j < jMax)
                {
                    if ((remoteFileListingSorted[i].Name == deltaItem.Name && localFileListingSorted[j].Name == deltaItem.Name) &&
                        (remoteFileListingSorted[i].Timestamp != localFileListingSorted[j].Timestamp ||
                         remoteFileListingSorted[i].Size != localFileListingSorted[j].Size))
                    {
                        deltaItem.Changed = true;
                        i++;
                        j++;
                    }
                }
            }

            return(fileListingDelta);
        }
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        public static async Task InitializeAsync(CrestronMonoDebuggerPackage package)
        {
            // Switch to the main thread - the call to AddCommand in PublishAndRunCommand's constructor requires
            // the UI thread.
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

            OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            Instance = new PublishAndRunCommand(package, commandService);
        }
예제 #9
0
        private bool IsCSharpProject(CrestronMonoDebuggerPackage package, Project project)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try
            {
                return(project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageCSharp);
            }
            catch (Exception ex)
            {
                package.OutputWindowWriteLine($"Project doesn't support property project.CodeModel.Language! No CSharp project. {ex.Message}");
                return(false);
            }
        }
예제 #10
0
        public List <FileListingItem> GetFileListing(CrestronMonoDebuggerPackage package, string localPath)
        {
            string[] fileNames = Directory.GetFiles(localPath);

            var fileListing = new List <FileListingItem>();

            foreach (var filename in fileNames)
            {
                var fileInfo = new FileInfo(filename);

                fileListing.Add(new FileListingItem(fileInfo.Name, fileInfo.LastWriteTime, fileInfo.Length));
            }

            package.OutputWindowWriteLine($"Found {fileListing.Count} file on control system.");

            return(fileListing);
        }
        public void Sync(CrestronMonoDebuggerPackage package, string localPath, List <FileDeltaItem> fileListingDelta)
        {
            using (var client = new SftpClient(_host, _port, _username, _password))
            {
                client.Connect();

                foreach (FileDeltaItem deltaItem in fileListingDelta)
                {
                    try
                    {
                        if (deltaItem.Delete)
                        {
                            package.OutputWindowWriteLine($"Deleting remote file {deltaItem.Name}");
                            client.Delete($"{package.Settings.RelativePath}/{deltaItem.Name}");
                        }
                        else if (deltaItem.New)
                        {
                            package.OutputWindowWriteLine($"Uploading new file {deltaItem.Name}");
                            using (var stream = new FileStream(Path.Combine(localPath, deltaItem.Name), FileMode.Open))
                            {
                                client.UploadFile(stream, $"{package.Settings.RelativePath}/{deltaItem.Name}", true);
                            }
                        }
                        else if (deltaItem.Changed)
                        {
                            package.OutputWindowWriteLine($"Uploading changed file {deltaItem.Name}");
                            using (var stream = new FileStream(Path.Combine(localPath, deltaItem.Name), FileMode.Open))
                            {
                                client.UploadFile(stream, $"{package.Settings.RelativePath}/{deltaItem.Name}", true);
                            }
                        }
                        else
                        {
                            package.OutputWindowWriteLine($"File is unchanged: {deltaItem.Name}");
                        }
                    }
                    catch (Exception e)
                    {
                        package.OutputWindowWriteLine($"The was a problem {(deltaItem.Delete ? "deleting" : "uploading")} the file {deltaItem.Name}.");
                        package.DebugWriteLine(e);
                    }
                }

                client.Disconnect();
            }
        }
예제 #12
0
        private Project GetStartupProject(CrestronMonoDebuggerPackage package)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var dte = Package.GetGlobalService(typeof(SDTE)) as DTE2;

            if (dte?.Solution == null)
            {
                package.OutputWindowWriteLine("Unable to locate the solution.");
                throw new InvalidOperationException("Unable to locate the solution.");
            }

            SolutionBuild2 sb = (SolutionBuild2)dte.Solution.SolutionBuild;
            List <string>  startupProjects = ((Array)sb.StartupProjects).Cast <string>().ToList();

            try
            {
                var projects = Projects(dte.Solution);
                foreach (var project in projects)
                {
                    if (startupProjects.Contains(project.UniqueName))
                    {
                        if (IsCSharpProject(package, project))
                        {
                            // We are only support one C# project at once
                            return(project);
                        }
                        else
                        {
                            package.DebugWriteLine($"Only C# projects are supported as startup project! ProjectName = {project.Name} Language = {project.CodeModel.Language}");
                        }
                    }
                }
            }
            catch (ArgumentException aex)
            {
                package.OutputWindowWriteLine($"No startup project extracted! The parameter StartupProjects = '{string.Join(",", startupProjects.ToArray())}' is incorrect.");
                package.DebugWriteLine(aex);
                throw new ArgumentException($"No startup project extracted! The parameter StartupProjects = '{string.Join(",", startupProjects.ToArray())}' is incorrect.", aex);
            }

            package.OutputWindowWriteLine($"No startup project found! Checked projects in StartupProjects = '{string.Join(",", startupProjects.ToArray())}'");
            throw new ArgumentException($"No startup project found! Checked projects in StartupProjects = '{string.Join(",", startupProjects.ToArray())}'");
        }