Beispiel #1
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());
		}
Beispiel #2
0
		public ArrayList OutputVBF(int vInstId, string outputFolder, string user, bool withSDS, bool withBackups, string fileName)
		{
			string text = "";
			string text2 = "";
			ArrayList arrayList = new ArrayList();
			string protocol = "";
			ArrayList arrayList2 = new ArrayList();
			VehiclePrototype vehiclePrototype = new VehiclePrototype(vInstId);
			bool withSDS2 = withSDS && !vehiclePrototype.XCLSDS;
			IEnumerator enumerator = vehiclePrototype.Modules.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					VehicleModule vehicleModule = (VehicleModule)enumerator.get_Current();
					if (withBackups || vehicleModule.IsMaster)
					{
						text2 = fileName.Replace(".vbf", "_" + vehicleModule.Name + ".vbf");
						text = base.get_Server().MapPath(outputFolder + text2);
						string inputFile = base.get_Server().MapPath(Constants.Config.TemplateFolder + "/" + vehicleModule.VBFTemplate);
						VBFFile vBFFile = new VBFFile(vInstId, text, inputFile, user);
						vBFFile.VehicleName = vehiclePrototype.VehicleCode;
						vBFFile.PartNo = vehicleModule.PartNo;
						vBFFile.PartType = vehicleModule.PartType;
						vBFFile.Network = vehicleModule.Network;
						vBFFile.ECUName = vehicleModule.Name;
						vBFFile.ECUAddress = vehicleModule.ECUAddress;
						vBFFile.EraseStart = vehicleModule.EraseStart;
						vBFFile.NoOfBytes = vehicleModule.NoOfBytes;
						vBFFile.Protocol = vehicleModule.Protocol;
						vBFFile.SBLFilename = vehicleModule.SBLFilename;
						vBFFile.SecurityInterface = vehicleModule.SecurityInterface;
						vBFFile.Comment = string.Concat(new object[]
						{
							"\"",
							vehiclePrototype.Name,
							"\" - ",
							vBFFile.VehicleName,
							" ",
							vehicleModule.Name,
							" - Extracted ",
							DateTime.get_Now()
						});
						if (vehicleModule.IsMaster)
						{
							protocol = vehicleModule.Protocol;
						}
						if (vehiclePrototype.VBFType == 1)
						{
							vBFFile.EraseLength = vehicleModule.EraseLength;
							vBFFile.Params = vehicleModule.Parameters;
						}
						else
						{
							ArrayList arrayList3 = new ArrayList();
							IEnumerator enumerator2 = vehicleModule.BuildTypes.GetEnumerator();
							try
							{
								while (enumerator2.MoveNext())
								{
									BuildType buildType = (BuildType)enumerator2.get_Current();
									arrayList3.Add(new VDFBlock(buildType.BlockType, buildType.NoOfBytes));
								}
							}
							finally
							{
								IDisposable disposable = enumerator2 as IDisposable;
								if (disposable != null)
								{
									disposable.Dispose();
								}
							}
							VDF vDF = new VDF(vehiclePrototype.VDFVersion, vehicleModule.Parameters, vehicleModule.EraseLengthStored, arrayList3);
							vBFFile.Params = vDF.Data;
							vehicleModule.EraseLength = "0x" + vBFFile.Params.get_Count().ToString("x8");
							vBFFile.EraseLength = vehicleModule.EraseLength;
						}
						if (withSDS)
						{
							if (vehiclePrototype.XCLSDS)
							{
								string template = base.get_Server().MapPath(Constants.Config.TemplateFolder + "/" + vehicleModule.SDSTemplate);
								SDSNode sDSNode = new SDSNode(vehicleModule.Name, vehicleModule.ECUAddress, vehicleModule.SecurityInterface, vehicleModule.SBLFilename, text2, template);
								arrayList2.Add(sDSNode);
								arrayList.Add(new VBFLink(text2, outputFolder + text2, "Save VBF"));
							}
							else
							{
								vBFFile.SDSOutputFile = text.Replace(".vbf", ".sds");
								vBFFile.SDSTemplateFile = base.get_Server().MapPath(Constants.Config.TemplateFolder + "/" + vehicleModule.SDSTemplate);
								arrayList.Add(new VBFLink(text2, outputFolder + text2, "Save VBF", text2.Replace(".vbf", ".sds"), outputFolder + text2.Replace(".vbf", ".sds"), "Save SDS"));
							}
						}
						else
						{
							arrayList.Add(new VBFLink(text2, outputFolder + text2, "Save VBF"));
						}
						vBFFile.Output(withSDS2);
					}
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			if (withSDS && vehiclePrototype.XCLSDS)
			{
				string text3 = fileName.Replace(".vbf", ".sds");
				string outputFile = base.get_Server().MapPath(outputFolder + text3);
				string inputFile2 = base.get_Server().MapPath(Constants.Config.TemplateFolder + "/" + vehiclePrototype.SDSHeaderTemplate);
				SDSFile sDSFile = new SDSFile(vehiclePrototype.VehicleCode, protocol, outputFile, inputFile2, arrayList2);
				sDSFile.Output();
				arrayList.Add(new VBFLink(text3, outputFolder + text3, "Save SDS"));
			}
			return arrayList;
		}