Ejemplo n.º 1
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;
			}
		}
Ejemplo 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];
		}