Exemplo n.º 1
0
        /// <summary>
        /// Copies resource files from the Xcode project (back) to the MonoDevelop project directory.
        /// </summary>
        /// <param name='monitor'>
        /// A progress monitor.
        /// </param>
        /// <param name='context'>
        /// The sync context.
        /// </param>
        void CopyFilesToMD(IProgressMonitor monitor, XcodeSyncBackContext context)
        {
            if (context.FileSyncJobs.Count == 0)
            {
                return;
            }

            monitor.BeginStepTask("Copying files from Xcode back to MonoDevelop...", context.FileSyncJobs.Count, 1);

            foreach (var file in context.FileSyncJobs)
            {
                monitor.Log.WriteLine("Copying {0} file from Xcode: {1}", file.IsFreshlyAdded ? "new" : "changed", file.SyncedRelative);

                if (!Directory.Exists(file.Original.ParentDirectory))
                {
                    Directory.CreateDirectory(file.Original.ParentDirectory);
                }

                var      tempFile = file.Original.ParentDirectory.Combine(".#" + file.Original.ParentDirectory.FileName);
                FilePath path     = context.ProjectDir.Combine(file.SyncedRelative);

                if (File.Exists(path))
                {
                    File.Copy(path, tempFile);
                    FileService.SystemRename(tempFile, file.Original);

                    DateTime mtime = File.GetLastWriteTime(file.Original);
                    context.SetSyncTime(file.SyncedRelative, mtime);
                }
                else
                {
                    monitor.ReportWarning(string.Format("'{0}' does not exist.", file.SyncedRelative));
                }

                monitor.Step(1);
            }

            monitor.EndTask();
        }
Exemplo n.º 2
0
		/// <summary>
		/// Updates the cli types.
		/// </summary>
		/// <returns>
		/// Returns whether or not any files were added to the project.
		/// </returns>
		/// <param name='monitor'>
		/// A progress monitor.
		/// </param>
		/// <param name='context'>
		/// A sync-back context.
		/// </param>
		/// <param name='typesAdded'>
		/// An output variable specifying whether or not any types were added to the project.
		/// </param>
		bool UpdateCliTypes (IProgressMonitor monitor, XcodeSyncBackContext context, out bool typesAdded)
		{
			var provider = dnp.LanguageBinding.GetCodeDomProvider ();
			var options = new System.CodeDom.Compiler.CodeGeneratorOptions ();
			var writer = MonoDevelop.DesignerSupport.CodeBehindWriter.CreateForProject (
				new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor (), dnp);
			
			monitor.BeginTask (GettextCatalog.GetString ("Detecting changes made in Xcode to custom user types..."), 0);
			Dictionary<string, NSObjectTypeInfo> newTypes;
			Dictionary<string, ProjectFile> newFiles;
			var updates = context.GetTypeUpdates (monitor, provider, out newTypes, out newFiles);
			if ((updates == null || updates.Count == 0) && newTypes == null && newFiles == null) {
				monitor.Log.WriteLine ("No changes found.");
				monitor.EndTask ();
				typesAdded = false;
				return false;
			}
			monitor.EndTask ();
			
			int count = updates.Count + (newTypes != null ? newTypes.Count : 0);
			monitor.BeginTask (GettextCatalog.GetString ("Updating custom user types in MonoDevelop..."), count);
			
			// First, add new types...
			if (newTypes != null && newTypes.Count > 0) {
				foreach (var nt in newTypes) {
					monitor.Log.WriteLine ("Adding new type: {0}", nt.Value.CliName);
					
					if (provider is Microsoft.CSharp.CSharpCodeProvider) {
						var cs = new CSharpCodeTypeDefinition () {
							WrapperNamespace = infoService.WrapperRoot,
							Provider = provider,
							Type = nt.Value,
						};
						
						string baseDir = Path.GetDirectoryName (nt.Key);
						if (!Directory.Exists (baseDir))
							Directory.CreateDirectory (baseDir);
						
						writer.WriteFile (nt.Key, cs.TransformText ());
					} else {
						// FIXME: implement support for non-C# languages
					}
					
					monitor.Step (1);
				}
				
				typesAdded = true;
			} else {
				typesAdded = false;
			}
			
			// Next, generate the designer files for any added/changed types
			foreach (var df in updates) {
				monitor.Log.WriteLine ("Generating designer file: {0}", df.Key);
				if (provider is Microsoft.CSharp.CSharpCodeProvider) {
					var cs = new CSharpCodeCodebehind () {
						Types = df.Value,
						WrapperNamespace = infoService.WrapperRoot,
						Provider = provider,
					};
					writer.WriteFile (df.Key, cs.TransformText ());
				} else {
					var ccu = GenerateCompileUnit (provider, options, df.Key, df.Value);
					writer.WriteFile (df.Key, ccu);
				}
				
				monitor.Step (1);
			}
			
			writer.WriteOpenFiles ();
			
			// Update sync timestamps
			foreach (var df in updates) {
				foreach (var type in df.Value)
					context.SetSyncTime (type.ObjCName + ".h", DateTime.Now);
			}
			
			// Add new files to the DotNetProject
			if (newFiles != null) {
				foreach (var f in newFiles) {
					monitor.Log.WriteLine ("Added new designer file: {0}", f.Key);
					dnp.AddFile (f.Value);
				}
			}
			
			monitor.EndTask ();
			
			return newFiles != null && newFiles.Count > 0;
		}
Exemplo n.º 3
0
		/// <summary>
		/// Copies resource files from the Xcode project (back) to the MonoDevelop project directory.
		/// </summary>
		/// <param name='monitor'>
		/// A progress monitor.
		/// </param>
		/// <param name='context'>
		/// The sync context.
		/// </param>
		void CopyFilesToMD (IProgressMonitor monitor, XcodeSyncBackContext context)
		{
			if (context.FileSyncJobs.Count == 0)
				return;
			
			monitor.BeginStepTask ("Copying files from Xcode back to MonoDevelop...", context.FileSyncJobs.Count, 1);
			
			foreach (var file in context.FileSyncJobs) {
				monitor.Log.WriteLine ("Copying {0} file from Xcode: {1}", file.IsFreshlyAdded ? "new" : "changed", file.SyncedRelative);
				
				if (!Directory.Exists (file.Original.ParentDirectory))
					Directory.CreateDirectory (file.Original.ParentDirectory);
				
				var tempFile = file.Original.ParentDirectory.Combine (".#" + file.Original.ParentDirectory.FileName);
				FilePath path = context.ProjectDir.Combine (file.SyncedRelative);
				
				if (File.Exists (path)) {
					File.Copy (path, tempFile);
					FileService.SystemRename (tempFile, file.Original);
					
					DateTime mtime = File.GetLastWriteTime (file.Original);
					context.SetSyncTime (file.SyncedRelative, mtime);
				} else {
					monitor.ReportWarning (string.Format ("'{0}' does not exist.", file.SyncedRelative));
				}
				
				monitor.Step (1);
			}
			
			monitor.EndTask ();
		}
Exemplo n.º 4
0
		static bool SyncFile (IProgressMonitor monitor, XcodeSyncBackContext context, XcodeSyncFileBackJob file)
		{
			if (!Directory.Exists (file.Original.ParentDirectory))
				Directory.CreateDirectory (file.Original.ParentDirectory);
			
			var tempFile = file.Original.ParentDirectory.Combine (".#" + file.Original.ParentDirectory.FileName);
			FilePath path = context.ProjectDir.Combine (file.SyncedRelative);
			
			if (File.Exists (path)) {
				File.Copy (path, tempFile);
				FileService.SystemRename (tempFile, file.Original);
				
				DateTime mtime = File.GetLastWriteTime (file.Original);
				context.SetSyncTime (file.SyncedRelative, mtime);
				return true;
			} else {
				monitor.ReportWarning (string.Format ("'{0}' does not exist.", file.SyncedRelative));
				return false;
			}
		}
Exemplo n.º 5
0
        /// <summary>
        /// Updates the cli types.
        /// </summary>
        /// <returns>
        /// Returns whether or not any files were added to the project.
        /// </returns>
        /// <param name='monitor'>
        /// A progress monitor.
        /// </param>
        /// <param name='context'>
        /// A sync-back context.
        /// </param>
        /// <param name='typesAdded'>
        /// An output variable specifying whether or not any types were added to the project.
        /// </param>
        bool UpdateCliTypes(IProgressMonitor monitor, XcodeSyncBackContext context, out bool typesAdded)
        {
            var provider = dnp.LanguageBinding.GetCodeDomProvider();
            var options  = new System.CodeDom.Compiler.CodeGeneratorOptions();
            var writer   = MonoDevelop.DesignerSupport.CodeBehindWriter.CreateForProject(
                new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor(), dnp);

            monitor.BeginTask(GettextCatalog.GetString("Detecting changes made in Xcode to custom user types..."), 0);
            Dictionary <string, NSObjectTypeInfo> newTypes;
            Dictionary <string, ProjectFile>      newFiles;
            var updates = context.GetTypeUpdates(monitor, provider, out newTypes, out newFiles);

            if ((updates == null || updates.Count == 0) && newTypes == null && newFiles == null)
            {
                monitor.Log.WriteLine("No changes found.");
                monitor.EndTask();
                typesAdded = false;
                return(false);
            }
            monitor.EndTask();

            int count = updates.Count + (newTypes != null ? newTypes.Count : 0);

            monitor.BeginTask(GettextCatalog.GetString("Updating custom user types in MonoDevelop..."), count);

            // First, add new types...
            if (newTypes != null && newTypes.Count > 0)
            {
                foreach (var nt in newTypes)
                {
                    monitor.Log.WriteLine("Adding new type: {0}", nt.Value.CliName);

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

                        string baseDir = Path.GetDirectoryName(nt.Key);
                        if (!Directory.Exists(baseDir))
                        {
                            Directory.CreateDirectory(baseDir);
                        }

                        writer.WriteFile(nt.Key, cs.TransformText());
                    }
                    else
                    {
                        // FIXME: implement support for non-C# languages
                    }

                    monitor.Step(1);
                }

                typesAdded = true;
            }
            else
            {
                typesAdded = false;
            }

            // Next, generate the designer files for any added/changed types
            foreach (var df in updates)
            {
                monitor.Log.WriteLine("Generating designer file: {0}", df.Key);
                if (provider is Microsoft.CSharp.CSharpCodeProvider)
                {
                    var cs = new CSharpCodeCodebehind()
                    {
                        Types            = df.Value,
                        WrapperNamespace = infoService.WrapperRoot,
                        Provider         = provider,
                    };
                    writer.WriteFile(df.Key, cs.TransformText());
                }
                else
                {
                    var ccu = GenerateCompileUnit(provider, options, df.Key, df.Value);
                    writer.WriteFile(df.Key, ccu);
                }

                monitor.Step(1);
            }

            writer.WriteOpenFiles();

            // Update sync timestamps
            foreach (var df in updates)
            {
                foreach (var type in df.Value)
                {
                    context.SetSyncTime(type.ObjCName + ".h", DateTime.Now);
                }
            }

            // Add new files to the DotNetProject
            if (newFiles != null)
            {
                foreach (var f in newFiles)
                {
                    monitor.Log.WriteLine("Added new designer file: {0}", f.Key);
                    dnp.AddFile(f.Value);
                }
            }

            monitor.EndTask();

            return(newFiles != null && newFiles.Count > 0);
        }