Exemplo n.º 1
0
		/// <summary>
		/// Get existing versions of module.
		/// </summary>
		/// <param name="module">Module identifier.</param>
		/// <returns>Array of <c>ModuleVersionItem</c>.</returns>
		public ModuleVersionItem[] GetModuleVerionsList(string module)
		{
			int moduleId;
			if (!int.TryParse(module, out moduleId))
				return new ModuleVersionItem[0];

			using (MasterContext masterDb = new MasterContext())
			{

				IEnumerable<ModuleVersion> moduleVersions = masterDb.ModuleVersions.Where(mv => mv.ModuleId == moduleId);
				ModuleVersionItem[] result = new ModuleVersionItem[moduleVersions.Count()];

				int index = 0;
				foreach (ModuleVersion moduleVersion in moduleVersions)
				{
					ModuleVersionItem moduleVersionItem = new ModuleVersionItem
					{
						ModuleId = moduleId,
						Major = moduleVersion.Major,
						Minor = moduleVersion.Minor,
						Build = moduleVersion.Build,
						Revision = moduleVersion.Revision
					};
					result[index] = moduleVersionItem;
					index++;
				}
				return result;
			}
		}
Exemplo n.º 2
0
		/// <summary>
		/// Remove module from system.
		/// </summary>
		/// <param name="module">Module identifier.</param>
		/// <returns>Array of <c>AssignedModule</c> if module wasn't assigned. Empty array in case of sucessful unregistration.</returns>
		public AssignedModule[] UnregisterModule(string module)
		{
			int moduleId;

			if (string.IsNullOrEmpty(module))
				return new AssignedModule[0];

			if (!int.TryParse(module, out moduleId))
				return new AssignedModule[0];

			using (MasterContext masterDb = new MasterContext())
			{
				IEnumerable<SlaveModule> slaveModules = masterDb.SlaveModules.Where(s => s.ModuleId == moduleId);
				AssignedModule[] assignedModules = new AssignedModule[slaveModules.Count()];
				int index = 0;
				foreach (SlaveModule slaveModule in slaveModules)
				{
					AssignedModule assignedModule = new AssignedModule();
					assignedModule.SlaveId = slaveModule.SlaveId;

					ModuleVersionItem moduleVersionItem = new ModuleVersionItem { ModuleId = moduleId };

					ModuleVersion moduleVersion = masterDb.ModuleVersions.Where(mv => mv.ModuleId == moduleId)
						.OrderByDescending(mv => mv.Major)
						.ThenByDescending(mv => mv.Minor)
						.ThenByDescending(mv => mv.Build)
						.ThenByDescending(mv => mv.Revision)
						.FirstOrDefault();

					if (moduleVersion != null)
					{
						moduleVersionItem.Major = moduleVersion.Major;
						moduleVersionItem.Minor = moduleVersion.Minor;
						moduleVersionItem.Build = moduleVersion.Build;
						moduleVersionItem.Revision = moduleVersion.Revision;
					};

					assignedModule.ModuleVersion = moduleVersionItem;

					assignedModules[index] = assignedModule;
					index++;
				}
			}

			return new AssignedModule[0];
		}
Exemplo n.º 3
0
		/// <summary>
		/// Assugn module to slave.
		/// </summary>
		/// <param name="slave">Slave identifier.</param>
		/// <param name="module">Module identifier.</param>
		/// <returns></returns>
		public AssignedModule AssignModule(string slave, string module)
		{
			Guid slaveId;
			int moduleId;

			if (string.IsNullOrEmpty(slave))
				return null;

			if (!Guid.TryParse(slave, out slaveId))
				return null;

			if (string.IsNullOrEmpty(module))
				return null;

			if (!int.TryParse(module, out moduleId))
				return null;

			using (MasterContext masterDb = new MasterContext())
			{
				SlaveModule slaveModule = masterDb.SlaveModules.FirstOrDefault(s => s.SlaveId == slaveId && s.ModuleId == moduleId);
				if (slaveModule == null)
				{
					slaveModule = new SlaveModule()
					{
						ModuleId = moduleId,
						SlaveId = slaveId
					};
					masterDb.SlaveModules.Add(slaveModule);
					masterDb.SaveChanges();
				}
				ModuleVersionItem moduleVersionItem = new ModuleVersionItem { ModuleId = moduleId };

				ModuleVersion moduleVersion = masterDb.ModuleVersions.Where(mv => mv.ModuleId == moduleId)
					.OrderByDescending(mv => mv.Major)
					.ThenByDescending(mv => mv.Minor)
					.ThenByDescending(mv => mv.Build)
					.ThenByDescending(mv => mv.Revision)
					.FirstOrDefault();

				if (moduleVersion != null)
				{
					moduleVersionItem.Major = moduleVersion.Major;
					moduleVersionItem.Minor = moduleVersion.Minor;
					moduleVersionItem.Build = moduleVersion.Build;
					moduleVersionItem.Revision = moduleVersion.Revision;
				};

				_orationiEngine.PushModule(slaveId, moduleVersion);

				AssignedModule assignedModule = new AssignedModule
				{
					SlaveId = slaveId,
					ModuleVersion = moduleVersionItem
				};

				return assignedModule;
			}
		}
Exemplo n.º 4
0
		public SlaveConfiguration GetConfiguration()
		{
			SlaveConfiguration configuration = new SlaveConfiguration();

			using (MasterContext masterDb = new MasterContext())
			{
				IEnumerable<SlaveModule> slaveModules = masterDb.SlaveModules.Where(s => s.SlaveId == SlaveId);
				configuration.Modules = new ModuleVersionItem[slaveModules.Count()];

				int index = 0;
				foreach (SlaveModule slaveModule in slaveModules)
				{
					ModuleVersion moduleVersion = masterDb.ModuleVersions.Where(m => m.ModuleId == slaveModule.ModuleId)
																			.OrderByDescending(m => m.Major)
																			.ThenByDescending(m => m.Minor)
																			.ThenByDescending(m => m.Build)
																			.ThenByDescending(m => m.Revision)
																			.FirstOrDefault();

					if (moduleVersion == null)
						continue;

					ModuleVersionItem moduleVersionItem = new ModuleVersionItem
					{
						ModuleId = slaveModule.ModuleId,
						Major = moduleVersion.Major,
						Minor = moduleVersion.Minor,
						Build = moduleVersion.Build,
						Revision = moduleVersion.Revision
					};

					configuration.Modules[index] = moduleVersionItem;
					index++;
				}
			}
			return configuration;
		}