Esempio n. 1
0
		public VehiclePrototype(int vInstId)
		{
			DataSet vehicleInst = DataAccess.GetVehicleInst(vInstId.ToString());
			if (vehicleInst.get_Tables().get_Item(0).get_Rows().get_Count() == 0)
			{
				throw new CarConfigException("Vehicle Prototype ID " + vInstId.ToString() + " does not exist!");
			}
			DataRow dataRow = vehicleInst.get_Tables().get_Item(0).get_Rows().get_Item(0);
			this.ID = vInstId;
			this.Name = dataRow.get_Item("fldVehicleID").ToString();
			this.VehicleCode = dataRow.get_Item("fldVehicle").ToString();
			this.VBFType = Convert.ToInt32(dataRow.get_Item("fldVBFType"));
			this.VDFVersion = Convert.ToInt32(dataRow.get_Item("fldVDFVersion"));
			this.XCLSDS = Convert.ToBoolean(dataRow.get_Item("fldXCLSDS"));
			this.SDSHeaderTemplate = dataRow.get_Item("fldSDSHeaderTemplate").ToString();
			this.RulesetID = Convert.ToInt32(dataRow.get_Item("fldRulesetID"));
			DataSet buildType = DataAccess.GetBuildType(new Constants.VehicleInstCriteria(vInstId));
			if (buildType.get_Tables().get_Item(0).get_Rows().get_Count() > 0)
			{
				IEnumerator enumerator = buildType.get_Tables().get_Item(0).get_Rows().GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						DataRow dataRow2 = (DataRow)enumerator.get_Current();
						BuildType buildType2 = new BuildType(Convert.ToInt32(dataRow2.get_Item("fldID")), vInstId, Convert.ToInt32(dataRow2.get_Item("fldPadTo")), this.VBFType, Convert.ToBoolean(dataRow2.get_Item("fldFrameCount").ToString()), Convert.ToInt32(dataRow2.get_Item("fldBlockType")), this.RulesetID);
						buildType2.Name = dataRow2.get_Item("fldName").ToString();
						this.GenericBuildTypes.Add(buildType2);
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				DataSet module = DataAccess.GetModule(new Constants.VehicleInstCriteria(vInstId));
				if (module.get_Tables().get_Item(0).get_Rows().get_Count() > 0)
				{
					enumerator = module.get_Tables().get_Item(0).get_Rows().GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							DataRow dataRow3 = (DataRow)enumerator.get_Current();
							VehicleModule vehicleModule = new VehicleModule(Convert.ToInt32(dataRow3.get_Item("fldID")));
							IEnumerator enumerator2 = this.GenericBuildTypes.GetEnumerator();
							try
							{
								while (enumerator2.MoveNext())
								{
									BuildType buildType3 = (BuildType)enumerator2.get_Current();
									bool flag = true;
									IEnumerator enumerator3 = vehicleModule.BuildTypeExceptions.GetEnumerator();
									try
									{
										while (enumerator3.MoveNext())
										{
											int num = (int)enumerator3.get_Current();
											if (buildType3.ID == num)
											{
												flag = false;
												break;
											}
										}
									}
									finally
									{
										IDisposable disposable = enumerator3 as IDisposable;
										if (disposable != null)
										{
											disposable.Dispose();
										}
									}
									if (flag)
									{
										vehicleModule.BuildTypes.Add(buildType3);
										vehicleModule.Parameters.AddRange(buildType3.DataBytes);
									}
								}
							}
							finally
							{
								IDisposable disposable = enumerator2 as IDisposable;
								if (disposable != null)
								{
									disposable.Dispose();
								}
							}
							vehicleModule.NoOfBytes = vehicleModule.Parameters.get_Count();
							vehicleModule.EraseLength = "0x" + vehicleModule.NoOfBytes.ToString("x8");
							this.Modules.Add(vehicleModule);
						}
						return;
					}
					finally
					{
						IDisposable disposable = enumerator as IDisposable;
						if (disposable != null)
						{
							disposable.Dispose();
						}
					}
				}
				throw new CarConfigException("Database contains no ECUs to extract against");
			}
			throw new CarConfigException("No build types (CCF, EUCD etc) specified for this vehicle");
		}
Esempio n. 2
0
		public string Import(out bool error)
		{
			error = false;
			int num = 0;
			int num2 = 0;
			string text = "";
			string reason = "Imported " + DateTime.get_Now();
			VehicleModule vehicleModule = new VehicleModule();
			this.ImportVBF();
			num2 = this.Params.get_Count();
			if (num2 <= 0)
			{
				throw new CarConfigException("No bytes loaded, invalid VBF file?");
			}
			VehiclePrototype vehiclePrototype = new VehiclePrototype(this.VehicleInstId);
			IEnumerator enumerator = vehiclePrototype.Modules.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					VehicleModule vehicleModule2 = (VehicleModule)enumerator.get_Current();
					if (vehicleModule2.ID == this.ModuleID)
					{
						vehicleModule = vehicleModule2;
						break;
					}
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			int noOfBytes = vehicleModule.NoOfBytes;
			if (noOfBytes > 0)
			{
				if (vehiclePrototype.VBFType == 1)
				{
					if (noOfBytes > num2)
					{
						text = "More bytes in database than imported, database records will remain unchanged for extra bytes [00].  File loaded.";
					}
					else if (num2 > noOfBytes)
					{
						text = "More bytes imported than available in the database, " + (num2 - noOfBytes).ToString() + " ignored!  Check you selected the correct module!";
						error = true;
					}
					enumerator = vehicleModule.Parameters.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							ConfigByte configByte = (ConfigByte)enumerator.get_Current();
							if (num >= num2)
							{
								break;
							}
							configByte.Update(this.VehicleInstId, ((ConfigByte)this.Params.get_Item(num)).ParamValue, this.UserName, reason);
							num++;
						}
						goto IL_7D3;
					}
					finally
					{
						IDisposable disposable = enumerator as IDisposable;
						if (disposable != null)
						{
							disposable.Dispose();
						}
					}
				}
				int num3 = 1;
				int num4 = 0;
				int num5 = 8;
				int num6 = 0;
				int num7 = 0;
				int num8 = 1;
				DataSet dataSet = new DataSet();
				VDF vDF = new VDF();
				ArrayList arrayList = new ArrayList();
				VDFBlock vDFBlock = new VDFBlock();
				enumerator = this.Params.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						ConfigByte configByte2 = (ConfigByte)enumerator.get_Current();
						if (num3 == 1)
						{
							vDF.CRC = (ushort)(configByte2.ParamValue << 8);
						}
						else if (num3 == 2)
						{
							vDF.CRC = (ushort)((int)vDF.CRC | configByte2.ParamValue);
						}
						else if (num3 == 3)
						{
							vDF.DataBlockSize = configByte2.ParamValue << 8;
						}
						else if (num3 == 4)
						{
							vDF.DataBlockSize |= configByte2.ParamValue;
						}
						else if (num3 == 5)
						{
							vDF.VDFVersion = configByte2.ParamValue << 8;
						}
						else if (num3 == 6)
						{
							vDF.VDFVersion |= configByte2.ParamValue;
						}
						else if (num3 == 7)
						{
							vDF.Blocksize = configByte2.ParamValue << 8;
						}
						else if (num3 == 8)
						{
							vDF.Blocksize |= configByte2.ParamValue;
						}
						else if (num3 == 9)
						{
							vDFBlock.Type = configByte2.ParamValue << 8;
						}
						else if (num3 == 10)
						{
							vDFBlock.Type |= configByte2.ParamValue;
						}
						else if (num3 == 11)
						{
							num6 = configByte2.ParamValue << 8;
							vDFBlock.Offset = num6;
						}
						else if (num3 == 12)
						{
							num6 |= configByte2.ParamValue;
							vDFBlock.Offset = num6;
							if (num6 == num3)
							{
								num7 = 1;
								vDFBlock.Size = vDF.DataBlockSize - num5;
							}
							else
							{
								num7 = (num6 - num5) / 4;
							}
							arrayList.Add(vDFBlock);
						}
						else
						{
							if (num3 > num6)
							{
								break;
							}
							int num9 = num3 - num5;
							switch (num9 % 4)
							{
							case 0:
							{
								vDFBlock.Offset |= configByte2.ParamValue;
								VDFBlock vDFBlock2 = (VDFBlock)arrayList.get_Item(num8 - 2);
								vDFBlock2.Size = vDFBlock.Offset - vDFBlock2.Offset;
								if (num8 == num7)
								{
									vDFBlock.Size = vDF.DataBlockSize - vDFBlock.Offset;
								}
								arrayList.Add(vDFBlock);
								break;
							}
							case 1:
								num8++;
								vDFBlock = new VDFBlock();
								vDFBlock.Type = configByte2.ParamValue << 8;
								break;
							case 2:
								vDFBlock.Type |= configByte2.ParamValue;
								break;
							case 3:
								vDFBlock.Offset = configByte2.ParamValue << 8;
								break;
							}
						}
						num3++;
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				if (vehicleModule.BuildTypes.get_Count() != arrayList.get_Count())
				{
					throw new CarConfigException("Incorrect no of blocks in import file compared to those in the database.");
				}
				int i = 1;
				for (int j = 0; j < vehicleModule.BuildTypes.get_Count(); j++)
				{
					int num10 = 1;
					BuildType buildType = (BuildType)vehicleModule.BuildTypes.get_Item(j);
					VDFBlock vDFBlock3 = (VDFBlock)arrayList.get_Item(j);
					int size = vDFBlock3.Size;
					if (buildType.FrameCount)
					{
						for (i = num3; i < size + num3; i++)
						{
							ConfigByte configByte3 = (ConfigByte)this.Params.get_Item(i - 1);
							if (num10 == 1)
							{
								dataSet = DataAccess.GetVehicleFrameParameterIDs(configByte3.ParamValue.ToString(), buildType.ID, this.VehicleInstId);
								if (dataSet.get_Tables().get_Item(0).get_Rows().get_Count() == 0)
								{
									text = text + "Frame 0x" + configByte3.ParamValueHex.ToString() + " does not exist in the database.  All bytes will not be imported.<br>";
									error = true;
								}
								else
								{
									num4 = configByte3.ParamValue;
								}
							}
							else if (dataSet.get_Tables().get_Item(0).get_Rows().get_Count() > 0)
							{
								try
								{
									DataRow dataRow = dataSet.get_Tables().get_Item(0).get_Rows().get_Item(num10 - 2);
									DataAccess.UpdateParamInst(this.VehicleInstId.ToString(), dataRow.get_Item(0).ToString(), configByte3.ParamValue.ToString(), 1, this.UserName, reason);
								}
								catch (SqlException)
								{
									throw;
								}
								catch
								{
									string text2 = text;
									text = string.Concat(new string[]
									{
										text2,
										"Frame 0x",
										num4.ToString("x2"),
										" byte ",
										(num10 - 1).ToString(),
										" missing from the database.<br>"
									});
									error = true;
								}
							}
							if (num10 == 8)
							{
								num10 = 1;
								dataSet.Dispose();
							}
							else
							{
								num10++;
							}
						}
					}
					else
					{
						if (buildType.DataBytes.get_Count() > vDFBlock3.Size)
						{
							text = "More bytes in database for [" + buildType.Name + "] than imported, database records will remain unchanged for extra bytes [00].  File loaded.";
						}
						else if (vDFBlock3.Size > buildType.DataBytes.get_Count())
						{
							text = string.Concat(new string[]
							{
								"More bytes imported than available in the database for [",
								buildType.Name,
								"], ",
								(vDFBlock3.Size - buildType.DataBytes.get_Count()).ToString(),
								" ignored!  Check you selected the correct module!"
							});
							error = true;
						}
						enumerator = buildType.DataBytes.GetEnumerator();
						try
						{
							while (enumerator.MoveNext())
							{
								ConfigByte configByte4 = (ConfigByte)enumerator.get_Current();
								if (i >= size + num3)
								{
									break;
								}
								configByte4.Update(this.VehicleInstId, ((ConfigByte)this.Params.get_Item(i - 1)).ParamValue, this.UserName, reason);
								i++;
							}
						}
						finally
						{
							IDisposable disposable = enumerator as IDisposable;
							if (disposable != null)
							{
								disposable.Dispose();
							}
						}
					}
					num3 = i;
					if (buildType.BlockType != vDFBlock3.Type)
					{
						DataAccess.UpdateBuildType(buildType.ID, vDFBlock3.Type);
					}
				}
				int vehicleBuildID = DataAccess.GetVehicleBuildID(this.VehicleInstId.ToString());
				DataAccess.UpdateVehicle(vehicleBuildID, vDF.VDFVersion, this.UserName);
				IL_7D3:
				DataAccess.UpdateVehicleInst(this.VehicleInstId.ToString(), "", string.Concat(new object[]
				{
					"Imported ",
					DateTime.get_Now(),
					" by ",
					this.UserName
				}), 1, this.UserName);
				return text;
			}
			throw new CarConfigException("No parameter records found for Vehicle ID " + this.VehicleInstId.ToString());
		}