public void InitializeField(MigrationContext context)
		{
			object current = context.CurrentObject;
			FieldInfo field = context.CurrentField;			

			field.SetValue(current, Guid.NewGuid());
		}
		public void InitializeField(MigrationContext context)
		{
			object current = context.CurrentObject;
			FieldInfo field = context.CurrentField;			
			field.SetValue(current, _value);
			++_value;
		}
		public void InitializeField(MigrationContext context)
		{
			object current = context.CurrentObject;
			FieldInfo field = context.CurrentField;			

			field.SetValue(current, Activator.CreateInstance(field.FieldType, _args));
		}
		public void InitializeField(MigrationContext context)
		{			
			FieldInfo field = context.CurrentField;
			SerializationInfo info = context.CurrentSerializationInfo;

			object value = info.GetValue(_fieldName, field.FieldType);
			field.SetValue(context.CurrentObject, context.ChangeType(value, field.FieldType));
			context.Trace("Field {0} set to \"{1}\" loaded from field {2}.", field.Name, value, _fieldName);
		}
		public void InitializeField(MigrationContext context)
		{			
			FieldInfo field = context.CurrentField;
			SerializationInfo info = context.CurrentSerializationInfo;

			try
			{
				field.SetValue(context.CurrentObject, info.GetValue(field.Name, field.FieldType));
			}
			catch (InvalidCastException)
			{
				object value = info.GetValue(field.Name, typeof(object));
				context.Trace("Failed to deserialize field {0} of type {1} from value {2} of type {3}!", field.Name, field.FieldType, value, null != value ? value.GetType().ToString() : "null");
				throw;
			}
		}
Esempio n. 6
0
		static int Main(string[] args)
		{				
			try
			{
				MigrationProject project = ParseCommandLine(args);
				WriteLine("Bamboo.Prevalence Version Migrator 1.0");
				MigrationContext context = new MigrationContext(project);			
				context.Migrate();			
			}
			catch (Exception x)
			{
				WriteLine(x.Message);
				return -1;
			}
			
			return 0;
		}
		public virtual void InitializeObject(MigrationContext context)
		{
			Type type = context.CurrentObject.GetType();
			TypeMapping mapping = context.GetTypeMapping(type);
			if (null == mapping)
			{
				mapping = TypeMapping.Default;
			}

			FieldInfo[] fields = context.GetSerializableFields(type);
			foreach (FieldInfo field in fields)
			{								
				context.EnterField(field);

				IFieldInitializer initializer = mapping.GetFieldInitializer(field.Name);
				initializer.InitializeField(context);

				context.LeaveField();
			}
		}
		public void InitializeField(MigrationContext context)
		{			
			_custom.InitializeField(context);
		}
Esempio n. 9
0
		internal void SetUpScripts(MigrationContext context)
		{			
			string classNameFormat = "__script{0}__";
			for (int i=0; i<_scripts.Count; ++i)
			{
				string className = string.Format(classNameFormat, i);
				_scripts[i].SetUp(className, context);
			}			
		}
Esempio n. 10
0
		internal object Deserialize(MigrationContext context)
		{
			FileStream stream = File.OpenRead(context.SourceFile);

			BinaryFormatter formatter = new BinaryFormatter();			
			formatter.SurrogateSelector = new MigrationSurrogateSelector(context);
			formatter.Binder = new MigrationBinder(context);
			formatter.Context = new StreamingContext(StreamingContextStates.Persistence);

			return formatter.Deserialize(stream);
		}
Esempio n. 11
0
		CompilerResults Compile(MigrationContext context, CodeCompileUnit dom)
		{
			CompilerParameters parameters = new CompilerParameters();
			parameters.GenerateInMemory = true;
			parameters.ReferencedAssemblies.Add(GetType().Assembly.Location);
			parameters.ReferencedAssemblies.Add(context.TargetAssembly.Location);
			
			if (_references.Length > 0)
			{
				foreach (string reference in _references.Split(';'))
				{
					string assemblyName = reference.Trim();
					parameters.ReferencedAssemblies.Add(Assembly.Load(assemblyName).Location);
				}
			}
			
			CodeDomProvider provider = new Microsoft.CSharp.CSharpCodeProvider();
			ICodeCompiler compiler = provider.CreateCompiler();
			return compiler.CompileAssemblyFromDom(parameters, dom);
		}
Esempio n. 12
0
		private void Migrate()
		{
			MigrationContext context = new MigrationContext(_project);
			
			context.ResolveAssembly += new ResolveEventHandler(HandleResolveAssembly);

			try
			{
				context.Migrate();
			}
			finally
			{
				_resolvedAssemblies.Clear();
			}
		}
Esempio n. 13
0
		public MigrationBinder(MigrationContext context)
		{
			_context = context;
		}
Esempio n. 14
0
		public void InitializeField(MigrationContext context)
		{			
			FieldInfo field = context.CurrentField;			
			field.SetValue(context.CurrentObject, context.ChangeType(_constValue, field.FieldType));
		}
Esempio n. 15
0
		internal void SetUp(string className, MigrationContext context)
		{	
			CodeNamespace ns = new CodeNamespace("__MigrationPlan__");
			foreach (ScriptImport si in _imports)
			{
				ns.Imports.Add(new CodeNamespaceImport(si.Namespace));
			}
			
			ns.Types.Add(GetTypeDeclaration(className));
			
			CodeCompileUnit unit = new CodeCompileUnit();
			unit.Namespaces.Add(ns);
			
			CompilerResults results = Compile(context, unit);
			if (0 == results.Errors.Count)
			{
				context.Trace("script compiled successfully.");
				Assembly assembly = results.CompiledAssembly;
				Type type = assembly.GetType(string.Format("__MigrationPlan__.{0}", className), true);
				Activator.CreateInstance(type, new object[] { context });
			}
			else
			{
				context.Trace("{0} script compilation error(s)!", results.Errors.Count);
				foreach (CompilerError error in results.Errors)
				{
					context.Trace(error.ToString());
				}
				throw new ApplicationException(results.Errors[0].ToString());
			}
		}		
		public MigrationSurrogateSelector(MigrationContext context)
		{
			_context = context;
		}
Esempio n. 17
0
 public MigrationBinder(MigrationContext context)
 {
     _context = context;
 }