private void CheckFlags(DataIdentifier _stepDataIdentifier1, Packet packet, DataIdentifier _stepDataIdentifier2 = DataIdentifier.Null, int WaitingTime = 1000) { stepDataIdentifier1 = _stepDataIdentifier1; stepDataIdentifier2 = _stepDataIdentifier2; receivePacket.dataIdentifier = DataIdentifier.CLOSE; ChangeProgressData(stepDataIdentifier1.ToString()); while (receivePacket.dataIdentifier != stepDataIdentifier1 && receivePacket.dataIdentifier != stepDataIdentifier2 && !stopped) { if (stopped || failed) { return; } try { if (client != null) { client.SendMessage(packet); } } catch { client = null; } Thread.Sleep(WaitingTime); } if (!failed && !stopped) { SaveProgress(new ProgressComputerData("Images/Done.ico", computer.Name, receivePacket.dataIdentifier.ToString())); } }
//Default Contructor public Packet() { identifier = DataIdentifier.Null; message = null; sender = null; receiver = null; }
private void saveSignalData(DataIdentifier identifier) { string signalDataStore = ConfigurationManager.AppSettings.Get("DefaultSignalDataStore"); signalDataStore = signalDataStore.EndsWith("\\") ? signalDataStore.Substring(0, (signalDataStore.Length - 1)) : signalDataStore; if (!Directory.Exists(signalDataStore)) { Directory.CreateDirectory(signalDataStore); } string signalDataDirectory = String.Format("{0}\\{1}", signalDataStore, identifier.DataUniqueID); if (!Directory.Exists(signalDataDirectory)) { Directory.CreateDirectory(signalDataDirectory); } string filePath = String.Format("{0}\\{1}.bmp", signalDataDirectory, DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss")); using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write)) { byte[] rawDataByte = ((object[])(identifier.RawData))[0] as byte[]; fileStream.Write(rawDataByte, 0, rawDataByte.Length); } this.currentSignalFile = filePath; }
private void startListener() { this.communicationManager = new CommunicationManager() { LocalAddress = ConfigurationManager.AppSettings.Get("LocalAddress"), RemoteAddress = ConfigurationManager.AppSettings.Get("RemoteAddress"), LocalPort = int.Parse(ConfigurationManager.AppSettings.Get("LocalPort")), RemotePort = int.Parse(ConfigurationManager.AppSettings.Get("RemotePort")), TimeToLive = int.Parse(ConfigurationManager.AppSettings.Get("TimeToLive")) }; this.communicationManager.Start(); byte[] bytesReceived = null; int bytesCount = -1; while (true) { bytesReceived = this.communicationManager.Receive(out bytesCount); if ((bytesCount > 0) && (bytesReceived != null) && (bytesReceived.Length > 0)) { DataIdentifier identifier = CommonUtility.BinaryDeserialize(bytesReceived) as DataIdentifier; //JsonUtility.JsonDeserialize(bytesReceived, typeof(DataIdentifier), null, null) as DataIdentifier; DataPair pair = this.doAcquisition(identifier); this.saveDataPair(pair); Thread thread = new Thread(this.threadProcSafe); thread.Start(pair); } } }
public void Read(BinaryReader reader, ModSaveInfo info) { dataLength = reader.ReadInt64(); dataID = DataIdentifier.Read(reader); IsCustomModel = reader.ReadBoolean(); switch (dataID.Type) { case IdentifierType.ACTOR: ReadData <CustomActorData, VanillaActorData>(reader, info); break; case IdentifierType.GADGET: ReadData <CustomGadgetData, VanillaGadgetData>(reader, info); break; case IdentifierType.LANDPLOT: ReadData <CustomLandPlotData, VanillaPlotData>(reader, info); break; case IdentifierType.GORDO: ReadData <GordoV01>(reader); break; case IdentifierType.TREASUREPOD: ReadData <TreasurePodV01>(reader); break; case IdentifierType.EXCHANGEOFFER: ReadData <ExchangeOfferV04>(reader); break; default: throw new NotImplementedException(); } }
public virtual void Notify(DataIdentifier Identifier) { this.DataIdentifier = Identifier; if (this.communicationManager == null) { this.communicationManager = new CommunicationManager() { RemoteAddress = ModuleConfiguration.Default_MulticastAddress, RemotePort = ModuleConfiguration.Default_MulticastPort, LocalAddress = ModuleConfiguration.Default_LocalAddress, LocalPort = ModuleConfiguration.Default_LocalPort, TimeToLive = ModuleConfiguration.Default_TimeToLive, PipeName = ModuleConfiguration.Default_PipeName }; //this.communicationManager.Start(); this.communicationManager.Start((int)(ModuleConfiguration.Default_CommunicationType)); } byte[] data = CommonUtility.BinarySerialize(Identifier); //JsonUtility.JsonSerialize(Identifier, null, null); this.communicationManager.Send(data); }
/// <summary> /// Read a specified clipboard data, encrypt and save it into a file. /// </summary> /// <param name="clipboardReader">The <see cref="ClipboardReader"/> used to read the data.</param> /// <param name="identifier">The data identifier.</param> /// <param name="clipboardDataPath">The full path to the clipboard data folder.</param> private void WriteClipboardDataToFile(ClipboardReader clipboardReader, DataIdentifier identifier, string clipboardDataPath) { Requires.NotNull(clipboardReader, nameof(clipboardReader)); Requires.NotNull(identifier, nameof(identifier)); Requires.NotNullOrWhiteSpace(clipboardDataPath, nameof(clipboardDataPath)); var dataFilePath = Path.Combine(clipboardDataPath, $"{identifier.Identifier}.dat"); if (File.Exists(dataFilePath)) { Logger.Instance.Fatal(new FileLoadException($"The file {dataFilePath} already exists.")); } var dataPassword = SecurityHelper.ToSecureString(SecurityHelper.EncryptString(SecurityHelper.ToSecureString(identifier.Identifier.ToString()))); Requires.NotNull(dataPassword, nameof(dataPassword)); clipboardReader.BeginRead(identifier.FormatName); Requires.IsTrue(clipboardReader.IsReadable); Requires.IsTrue(clipboardReader.CanReadNextBlock()); using (var fileStream = File.OpenWrite(dataFilePath)) using (var aesStream = new AesStream(fileStream, dataPassword, SecurityHelper.GetSaltKeys(dataPassword).GetBytes(16))) { aesStream.AutoDisposeBaseStream = false; while (clipboardReader.CanReadNextBlock()) { var buffer = clipboardReader.ReadNextBlock(); aesStream.Write(buffer, 0, buffer.Length); } aesStream.Position = 0; } clipboardReader.EndRead(); }
void timer_Elapsed(object sender, ElapsedEventArgs e) { string data = e.SignalTime.ToString("yyyy-MM-dd-hh-mm-ss-ffffzzz").Replace("+", "A").Replace(":", "-");//e.SignalTime.ToLongDateString(); DataIdentifier dataIdentifier = new DataIdentifier() { DataUniqueID = Guid.NewGuid().ToString(), RawData = new object[] { data } }; if (!this.isTesting) { base.Notify(dataIdentifier); } if (this.TimerCallBack != null) { this.TimerCallBack(this, new TimerDetectorEventArgs() { DataIdentifier = dataIdentifier }); } //else //{ // base.Notify(dataIdentifier); //} }
public Packet(DataIdentifier _ID, ComputerDetailsData _computerDetailsData, string _message) { this.dataIdentifier = _ID; this.computerDetailsData = _computerDetailsData; this.IDTime = DateTime.Now; this.clonningMessage = _message; }
private void OnEntitySelected(Data entity) { this.selectedEntity = entity; this.selectedDataIdentifier = null; this.selectedDataIdentifierKey = null; this.wasDataIdentifierSelected = false; }
public void Write(BinaryWriter writer, ModSaveInfo info) { long start = writer.BaseStream.Position; writer.Write(0L); IsCustomModel = info.BelongsToMe(data); DataIdentifier.Write(writer, dataID); writer.Write(IsCustomModel); switch (dataID.Type) { case IdentifierType.ACTOR: WriteData <CustomActorData>(writer, info); break; case IdentifierType.GADGET: WriteData <CustomGadgetData>(writer, info); break; default: throw new NotImplementedException(); } long current = writer.BaseStream.Position; writer.BaseStream.Seek(start, SeekOrigin.Begin); dataLength = current - start; writer.Write(dataLength); writer.BaseStream.Seek(current, SeekOrigin.Begin); }
/// <summary> /// Write a specified clipboard data from an encrypted file. /// </summary> /// <param name="clipboardWriter">The <see cref="ClipboardWriter"/> used to write the data.</param> /// <param name="identifier">The data identifier.</param> /// <param name="clipboardDataPath">The full path to the clipboard data folder.</param> private void ReadFileToClipboardData(ClipboardWriter clipboardWriter, DataIdentifier identifier, string clipboardDataPath) { Requires.NotNull(clipboardWriter, nameof(clipboardWriter)); Requires.NotNull(identifier, nameof(identifier)); Requires.NotNullOrWhiteSpace(clipboardDataPath, nameof(clipboardDataPath)); var dataFilePath = Path.Combine(clipboardDataPath, $"{identifier.Identifier}.dat"); if (!File.Exists(dataFilePath)) { return; } var dataPassword = SecurityHelper.ToSecureString(SecurityHelper.EncryptString(SecurityHelper.ToSecureString( identifier.Identifier.ToString( )))); Requires.NotNull(dataPassword, nameof(dataPassword)); var fileStream = File.OpenRead(dataFilePath); var aesStream = new AesStream(fileStream, dataPassword, SecurityHelper.GetSaltKeys(dataPassword).GetBytes(16)); clipboardWriter.AddData(identifier.FormatName, aesStream, fileStream); }
private void SetControls(DataIdentifier identifier) { if (this.pictureBoxSignalPreview.InvokeRequired) { SetImageCallBack setImageCallBack = new SetImageCallBack(this.SetControls); this.Invoke(setImageCallBack, identifier); } else { //this.pictureBoxSignalPreview.Image = ((object[])(identifier.RawData))[0] as Bitmap; using (MemoryStream stream = new MemoryStream((((object[])(identifier.RawData))[0]) as byte[])) { this.pictureBoxSignalPreview.Image = System.Drawing.Bitmap.FromStream(stream); } this.pictureBoxSignalPreview.Refresh(); } if (this.listBoxBarCodesExtracted.InvokeRequired) { SetBarCodeListCallBack setBarCodeListCallBack = new SetBarCodeListCallBack(this.SetControls); this.Invoke(setBarCodeListCallBack, identifier); } else { this.listBoxBarCodesExtracted.DataSource = ((object[])(identifier.RawData))[1];//new string[] { Identifier.DataUniqueID}; this.listBoxBarCodesExtracted.Refresh(); } }
public Packet(byte[] dataStream) { // Read the data identifier from the beginning of the stream (4 bytes) this.dataIdentifier = (DataIdentifier)BitConverter.ToInt32(dataStream, 0); // Read the length of the name (4 bytes) int nameLength = BitConverter.ToInt32(dataStream, 4); // Read the length of the message (4 bytes) int msgLength = BitConverter.ToInt32(dataStream, 8); // Read the name field if (nameLength > 0) { this.name = Encoding.UTF8.GetString(dataStream, 12, nameLength); } else { this.name = null; } // Read the message field if (msgLength > 0) { this.message = Encoding.UTF8.GetString(dataStream, 12 + nameLength, msgLength); } else { this.message = null; } }
public void WriteData(BinaryWriter writer) { writer.Write(ammoDataEntries.Count); foreach (var entry in ammoDataEntries) { entry.Write(writer); } writer.Write(segments.Count); foreach (var mod in segments) { mod.Write(writer); Debug.Log($"Saving mod {mod.modid} which is {mod.byteLength} bytes long"); } enumTranslator.Write(writer); writer.Write(partialData.Count); foreach (var pair in partialData) { DataIdentifier.Write(writer, pair.Key); pair.Value.Write(writer); } appearancesData.Write(writer); }
public static GameObject InstantiateActorWithData(long actorId, GameObject prefab, RegionRegistry.RegionSetId id, Vector3 pos, Quaternion rot, CompoundDataPiece data) { preparedData.Add(DataIdentifier.GetActorIdentifier(actorId), new PreparedData() { Data = data, SourceType = PreparedData.PreparationSource.SPAWN }); return(SceneContext.Instance.GameModel.InstantiateActor(actorId, prefab, id, pos, rot, false, false)); }
public Packet(string friendName) { dataIdentifier = DataIdentifier.Null; message = null; senderName = null; recipientName = friendName; seqNumber = 0; }
//Default Constructor public Packet() { dataIdentifier = DataIdentifier.Null; message = null; senderName = null; recipientName = null; seqNumber = 0; }
private DataPair doCorrelation(DataIdentifier identifier, DataItem item) { if (this.correlator == null) { this.correlator = new Correlator(); } return(this.correlator.Correlate(identifier, item)); }
/// <summary> /// Delete a data from the server /// </summary> /// <param name="cloudFolder">The <see cref="CloudFolder"/> that contains informations about the application folder.</param> /// <param name="dataIdentifier">The data identifier used to determines which file will be uploaded.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task DeleteFileAsync(CloudFolder cloudFolder, DataIdentifier dataIdentifier) { var fileName = $"{dataIdentifier.Identifier}.dat"; var cloudDataFilePath = Path.Combine(cloudFolder.FullPath, fileName); if (cloudFolder.Files.Any(file => file.FullPath == cloudDataFilePath)) { await CurrentCloudStorageProvider.DeleteFileAsync(cloudDataFilePath); } }
//private void setDeviceInstance() //{ // object deviceInstance = this.detector.GetDeviceInstance(); // byte[] deviceInstanceBytes = CommonUtility.BinarySerialize(deviceInstance); // string deviceInstanceStateLocation = ConfigurationManager.AppSettings.Get("DeviceInstanceStateLocation"); // deviceInstanceStateLocation = deviceInstanceStateLocation.EndsWith("\\") ? deviceInstanceStateLocation.Substring(0, (deviceInstanceStateLocation.Length - 1)) : deviceInstanceStateLocation; // if (!Directory.Exists(deviceInstanceStateLocation)) // { // Directory.CreateDirectory(deviceInstanceStateLocation); // } // string deviceInstanceStateResourceName = ConfigurationManager.AppSettings.Get("DefaultDeviceInstanceStateResourceName"); // string filePath = String.Format("{0}\\{1}", deviceInstanceStateLocation, deviceInstanceStateResourceName); // using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write)) // { // fileStream.Write(deviceInstanceBytes, 0, deviceInstanceBytes.Length); // } //} void detector_CallBack(DataIdentifier Identifier) { //this.pictureBoxSignalPreview.Image = ((object[])(Identifier.RawData))[0] as Bitmap; //this.pictureBoxSignalPreview.Refresh(); //this.listBoxBarCodesExtracted.DataSource = ((object[])(Identifier.RawData))[1];//new string[] { Identifier.DataUniqueID}; //this.listBoxBarCodesExtracted.Refresh(); Thread thread = new Thread(this.threadProcSafe); thread.Start(Identifier); }
static IEnumerable <KeyValuePair <DataIdentifier, CompoundDataPiece> > GetAllData(GameModel model) { foreach (var v in model.actors) { if (v.Value?.transform == null) { continue; } yield return(new KeyValuePair <DataIdentifier, CompoundDataPiece>(DataIdentifier.GetActorIdentifier(v.Key), ReadDataFromGameObject(v.Value.transform.gameObject))); } }
public static void Prefix(GameModel __instance, long actorId, GameObject gameObj, bool skipNotify) { var potentialTag = PersistentAmmoManager.GetPotentialDataTag(gameObj); if (potentialTag != null) { ExtendedData.preparedData[DataIdentifier.GetActorIdentifier(actorId)] = new ExtendedData.PreparedData() { SourceType = ExtendedData.PreparedData.PreparationSource.AMMO, Data = potentialTag }; } }
private void OnDataIdentifierEntitySelected(DataIdentifier dataIdentifier, string key) { Assert.IsNotNull(dataIdentifier); Assert.IsFalse(string.IsNullOrEmpty(key)); Assert.IsNotNull(dataIdentifier.Links); Assert.IsTrue(dataIdentifier.Links.ContainsKey(key)); this.selectedEntity = null; this.selectedDataIdentifier = dataIdentifier; this.selectedDataIdentifierKey = key; this.wasDataIdentifierSelected = true; }
public override DataIdentifier[] GenerateIdentifiers() { if (DataIdentifier != null || IsFrozen) { throw new InvalidOperationException("GenerateIdentifiers should only be called by FeatureWorld"); } DataIdentifier = new DataIdentifier(this, 0, (int)Math.Ceiling(Math.Log(Count + IdOffset, 2)), WorldType); foreach (var feature in Features) { feature.DataIdentifier = DataIdentifier; } return(new[] { DataIdentifier }); }
public void SetDataIdentifier(DataIdentifier dataIdentifier, string key) { Assert.IsNotNull(dataIdentifier); Assert.IsFalse(string.IsNullOrEmpty(key)); Assert.IsNotNull(dataIdentifier.Links); Assert.IsTrue(dataIdentifier.Links.ContainsKey(key)); this.dataIdentifier = dataIdentifier; this.Entity = dataIdentifier.Links[key].Entity; this.address = this.Entity.Address; this.packagePath = "DATA_IDENTIFIER"; this.archivePath = dataIdentifier.Identifier; this.nameInArchive = key; }
public override DataIdentifier[] GenerateIdentifiers() { if (_identifiers != null || IsFrozen) { throw new InvalidOperationException("GenerateIdentifiers should only be called by FeatureWorld"); } _identifiers = new DataIdentifier[Count]; for (var i = 0; i < Features.Count; i++) { _identifiers[i] = new DataIdentifier(this, Features[i], i, 1, WorldType); Features[i].DataIdentifier = _identifiers[i]; } return(_identifiers); }
//private object getDeviceInstance() //{ // object deviceInstance = null; // byte[] deviceInstanceBytes = null; // string deviceInstanceStateLocation = ConfigurationManager.AppSettings.Get("DeviceInstanceStateLocation"); // deviceInstanceStateLocation = deviceInstanceStateLocation.EndsWith("\\") ? deviceInstanceStateLocation.Substring(0, (deviceInstanceStateLocation.Length - 1)) : deviceInstanceStateLocation; // if (!Directory.Exists(deviceInstanceStateLocation)) // { // Directory.CreateDirectory(deviceInstanceStateLocation); // } // string deviceInstanceStateResourceName = ConfigurationManager.AppSettings.Get("DefaultDeviceInstanceStateResourceName"); // string filePath = String.Format("{0}\\{1}", deviceInstanceStateLocation, deviceInstanceStateResourceName); // using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) // { // deviceInstanceBytes = new byte[fileStream.Length]; // fileStream.Read(deviceInstanceBytes, 0, deviceInstanceBytes.Length); // } // if (deviceInstanceBytes != null) // { // deviceInstance = CommonUtility.BinaryDeserialize(deviceInstanceBytes); // } // return deviceInstance; //} private DataPair doAcquisition(DataIdentifier identifier) { DataItem dataItem = this.xiAcquirer.Acquire(); DataPair pair = new DataPair() { Identifier = identifier, Items = new List <DataItem>() { dataItem } }; return(pair); }
public Packet(byte[] dataStream) { this.dataIdentifier = (DataIdentifier)BitConverter.ToInt32(dataStream, 0); int msgLength = BitConverter.ToInt32(dataStream, 4); if (msgLength > 0) { this.message = Encoding.UTF8.GetString(dataStream, 8, msgLength); } else { this.message = null; } }
protected internal virtual void PopulateDataIdentifiers() { DiOwnerId = new DataIdentifier(this, -1, (int)Math.Ceiling(Math.Log(Register.Max)), WorldTypeBoth); DiCivVision = new DataIdentifier(this, -2, 2, WorldTypeCiv); DiCivLastMapUpdate = new DataIdentifier(this, -3, 15, WorldTypeCiv); DiBaseVision = new DataIdentifier[Register.Max]; Dis = new DataIdentifier[Register.Max + 3]; for (var i = 0; i < Register.Max; i++) { DiBaseVision[i] = new DataIdentifier(this, i, 2, WorldTypeBase); Dis[i] = DiBaseVision[i]; } Dis[Register.Max + DiExtraCount + DiOwnerId.Index] = DiOwnerId; Dis[Register.Max + DiExtraCount + DiCivVision.Index] = DiCivVision; Dis[Register.Max + DiExtraCount + DiCivLastMapUpdate.Index] = DiCivLastMapUpdate; }
public Packet(byte[] dataStream) { // Read the data identifier from the beginning of the stream (4 bytes) this.dataIdentifier = (DataIdentifier)BitConverter.ToInt32(dataStream, 0); // Read the length of the name (4 bytes) int nameLength = BitConverter.ToInt32(dataStream, 4); // Read the length of the message (4 bytes) int msgLength = BitConverter.ToInt32(dataStream, 8); // Read the name field if (nameLength > 0) this.name = Encoding.UTF8.GetString(dataStream, 12, nameLength); else this.name = null; // Read the message field if (msgLength > 0) this.message = Encoding.UTF8.GetString(dataStream, 12 + nameLength, msgLength); else this.message = null; }
// Default Constructor public Packet() { this.dataIdentifier = DataIdentifier.Null; this.message = null; this.name = null; }
public void Register(DataIdentifier id, Func<EndPoint, ChatPacket, ChatPacket> handler) { _packetHandlers.Add(id, handler); }