private void HandleEncoderProbed(object sender, VideoEncoder.VideoProfileInfo profileInfo) { var dict = new VarDictionary(); dict.Set("name", "supportedProfiles"); VarArray js_profiles = new VarArray(); dict.Set("profiles", js_profiles); if (profileInfo.Result < 0) { LogError(profileInfo.Result, "Cannot get supported profiles"); PostMessage(dict); } if (profileInfo.VideoProfileDescriptions.Count > 0) { var idx = 0u; foreach (var profile in profileInfo.VideoProfileDescriptions) { js_profiles.Set(idx++, VideoProfileToString(profile.Profile)); } } PostMessage(dict); }
private void CreateArray() { if (!string.IsNullOrWhiteSpace(txtName.Text)) { if (MainViewModel.MainViewModelStatic.Variables.Where(a => a.Name == txtName.Text).Count() == 0) { VarArray array = new VarArray { IsNumber = true, Name = txtName.Text, Id = Guid.NewGuid() }; MainViewModel.MainViewModelStatic.Arrays.Add(array); array.Group = "Default"; var wv = new WindowView { TabName = "Array - " + array.Name, Content = (UserControl) new ArrayEditor { DataContext = array } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); MainViewModel.MainViewModelStatic.SelectedTab = MainViewModel.MainViewModelStatic.OpenWindows.IndexOf(wv); this.Close(); } else { MessageBox.Show("A variable with this name already exists. Please choose another name."); } } else { MessageBox.Show("Name must contain text."); } }
/// <summary> /// Serialize the argument object into the stream provided. /// </summary> /// <param name="data">Xml stream to serialize the argument object into</param> public void Serialize(IXMLSerializeData data) { #region Prepare PropertySet object names = null, values = null; myProperties.GetAllProperties(out names, out values); IStringArray myNames = new StrArray(); string[] nameArray = (string[])names; IVariantArray myValues = new VarArray(); object[] valArray = (object[])values; for (int i = 0; i < nameArray.GetLength(0); ++i) { myNames.Add(nameArray[i]); if (valArray[i] is IDataset) { IName myDatasetName = ((IDataset)valArray[i]).FullName; myValues.Add(myDatasetName); } else { myValues.Add(valArray[i]); } } #endregion data.TypeName = "WatermarkFunctionArguments"; data.TypeNamespaceURI = @"http://www.esri.com/schemas/ArcGIS/10.2"; data.AddObject("Names", myNames); data.AddObject("Values", myValues); }
public InvPayload(InventoryVector[] inventory) { Contract.Requires<ArgumentNullException>(inventory != null, "inventory"); Inventory = new VarArray<InventoryVector>(inventory); ByteSize = Inventory.ByteSize; }
public AddrPayload(TimestampedNetworkAddress[] addressList) { Contract.Requires<ArgumentNullException>(addressList != null); AddressList = new VarArray<TimestampedNetworkAddress>(addressList); ByteSize = AddressList.ByteSize; }
/// <summary> /// Handler for messages coming in from the browser via postMessage(). The /// @a var_message can contain anything: a JSON string; a string that encodes /// method names and arguments; etc. /// /// Here we use messages to communicate with the user interface /// /// </summary> /// <param name="vmessage">The message posted by the browser.</param> private void OnHandleMessage(object sender, Var varMessage) { if (!varMessage.IsArray) { return; } // Message should be an array with the following elements: // [command, path, extra args] var message = new VarArray(varMessage); var command = message[0].AsString(); var fileName = message[1].AsString(); if (fileName.Length == 0 || fileName[0] != '/') { ShowStatusMessage("File name must begin with /"); return; } Console.WriteLine($"command: {command} File Name: {fileName}"); if (command == "load") { Load(fileName); } else if (command == "save") { var fileText = message[2].AsString(); Save(fileName, fileText); } else if (command == "delete") { Delete(fileName); } else if (command == "list") { var dirName = fileName; messageLoop.PostWork <string>(List2, dirName); } else if (command == "makedir") { var dirName = fileName; MakeDir(dirName); } else if (command == "rename") { var newName = message[2].AsString(); Rename(fileName, newName); } else if (command == "query") { var dirName = fileName; messageLoop.PostWork <string>(Query2, dirName); //Query2(PPError.Ok, dirName); } }
public HeadersPayload(Block[] headers, bool autoConvertBlocksToHeaders) { if (autoConvertBlocksToHeaders) { headers = (from b in headers select b.ConvertToBlockHeader()).ToArray(); } Headers = new VarArray<Block>(headers); ByteSize = Headers.ByteSize; }
public InvPayload(byte[] buffer, int offset) : base(buffer, offset) { Contract.Requires<ArgumentNullException>(buffer != null, "buffer"); Contract.Requires<ArgumentException>(buffer.Length >= InvPayload.MinimumByteSize, "buffer"); Contract.Requires<ArgumentOutOfRangeException>(offset >= 0, "offset"); Contract.Requires<ArgumentOutOfRangeException>(offset <= buffer.Length - InvPayload.MinimumByteSize, "offset"); Inventory = new VarArray<InventoryVector>(buffer, offset); ByteSize = Inventory.ByteSize; }
public Tx(uint version, TxIn[] txIn, TxOut[] txOut, uint lockTime) { Contract.Requires<ArgumentNullException>(txIn != null, "txIn"); Contract.Requires<ArgumentNullException>(txOut != null, "txOut"); Version = version; TxIns = new VarArray<TxIn>(txIn); TxOuts = new VarArray<TxOut>(txOut); LockTime = lockTime; ByteSize = Version.ByteSize() + TxIns.ByteSize + TxOuts.ByteSize + LockTime.ByteSize(); }
public HeadersPayload(byte[] buffer, int offset) : base(buffer, offset) { Contract.Requires<ArgumentNullException>(buffer != null, "buffer"); Contract.Requires<ArgumentException>(buffer.Length >= HeadersPayload.MinimumByteSize, "buffer"); Contract.Requires<ArgumentOutOfRangeException>(offset >= 0, "offset"); Contract.Requires<ArgumentOutOfRangeException>(offset <= buffer.Length - HeadersPayload.MinimumByteSize, "offset"); Headers = new VarArray<Block>(buffer, offset); ByteSize = Headers.ByteSize; }
public GetHeadersPayload(uint version, Hash[] hashStart, Hash hashStop) { Contract.Requires<ArgumentNullException>(hashStart != null, "hashStart"); Contract.Requires<ArgumentNullException>(hashStop != null, "hashStop"); Version = version; HashStart = new VarArray<Hash>(hashStart); StartCount = new VarInt((uint)hashStart.Length); HashStop = hashStop; ByteSize = Version.ByteSize() + StartCount.ByteSize + HashStart.ByteSize + HashStop.ByteSize; }
public Block(uint version, Hash previousBlock, Hash merkleRoot, uint timestamp, uint bits, uint nonce, VarArray<Tx> transactions) { Contract.Requires<ArgumentNullException>(previousBlock != null); Contract.Requires<ArgumentNullException>(merkleRoot != null); Version = version; PreviousBlock = previousBlock; MerkleRoot = merkleRoot; Timestamp = Timestamp; Bits = bits; Nonce = nonce; Transactions = transactions; }
void PostArrayMessage(string command, params string[] strings) { using (var message = new VarArray()) { message[0] = new Var(command); for (uint i = 0; i < strings.Length; ++i) { message[i + 1] = new Var(strings[i]); } PostMessage(message); } }
public GetHeadersPayload(byte[] buffer, int offset) : base(buffer, offset) { Contract.Requires<ArgumentNullException>(buffer != null, "buffer"); Contract.Requires<ArgumentException>(buffer.Length >= GetHeadersPayload.MinimumByteSize, "buffer"); Contract.Requires<ArgumentOutOfRangeException>(offset >= 0, "offset"); Contract.Requires<ArgumentOutOfRangeException>(offset <= buffer.Length - GetHeadersPayload.MinimumByteSize, "offset"); Version = buffer.ReadUInt32(offset); StartCount = new VarInt(buffer, StartCount_Offset(ref offset)); HashStart = new VarArray<Hash>(buffer, HashStart_Offset(ref offset)); HashStop = new Hash(buffer, HashStop_Offset(ref offset)); ByteSize = Version.ByteSize() + StartCount.ByteSize + HashStart.ByteSize + HashStop.ByteSize; }
public Tx(byte[] buffer, int offset) : base(buffer, offset) { Contract.Requires<ArgumentNullException>(buffer != null, "buffer"); Contract.Requires<ArgumentException>(buffer.Length >= Tx.MinimumByteSize, "buffer"); Contract.Requires<ArgumentOutOfRangeException>(offset >= 0, "offset"); Contract.Requires<ArgumentOutOfRangeException>(offset <= buffer.Length - Tx.MinimumByteSize, "offset"); Version = buffer.ReadUInt32(offset); TxIns = new VarArray<TxIn>(buffer, TxIns_Offset(ref offset)); TxOuts = new VarArray<TxOut>(buffer, TxOuts_Offset(ref offset)); LockTime = buffer.ReadUInt32(LockTime_Offset(ref offset)); ByteSize = Version.ByteSize() + TxIns.ByteSize + TxOuts.ByteSize + LockTime.ByteSize(); }
public Block(byte[] buffer, int offset) : base(buffer, offset) { Contract.Requires<ArgumentNullException>(buffer != null, "buffer"); Contract.Requires<ArgumentException>(buffer.Length > Block.MinimumByteSize, "buffer"); Contract.Requires<ArgumentOutOfRangeException>(offset >= 0, "offset"); Contract.Requires<ArgumentOutOfRangeException>(offset < buffer.Length - Block.MinimumByteSize, "offset"); Version = buffer.ReadUInt32(offset); PreviousBlock = new Hash(buffer, PreviousBlock_Offset(ref offset)); MerkleRoot = new Hash(buffer, MerkleRoot_Offset(ref offset)); Timestamp = buffer.ReadUInt32(Timestamp_Offset(ref offset)); Bits = buffer.ReadUInt32(Bits_Offset(ref offset)); Nonce = buffer.ReadUInt32(Nonce_Offset(ref offset)); Transactions = new VarArray<Tx>(buffer, Transactions_Offset(ref offset)); }
async Task UpdateNetworkList() { using (var networkMonitor = new PepperSharp.NetworkMonitor(this)) { var networkListInfo = await networkMonitor.UpdateNetworkListAsync(); if (networkListInfo.Result != PPError.Ok) { PostMessage($"UpdateNetworkList failed: {networkListInfo.Result}"); return; } using (var networkList = networkListInfo.NetworkList) { // Send the new network list to JavaScript. using (var varNetworkList = new VarArray()) { uint infoIndex = 0; foreach (var nic in networkList.NetworkInterfaces) { using (VarDictionary varNetwork = new VarDictionary()) { varNetwork.Set("displayName", nic.DisplayName); varNetwork.Set("name", nic.Name); varNetwork.Set("state", GetEnumAsString(typeof(NetworkInterfaceState), nic.State)); varNetwork.Set("type", GetEnumAsString(typeof(NetworkInterfaceType), nic.NetworkType)); varNetwork.Set("MTU", nic.MTU); using (var varIPAddresses = new VarArray()) { uint j = 0; foreach (var address in nic.NetAddresses) { varIPAddresses.Set(j++, address.DescriptionWithPort); } varNetwork.Set("ipAddresses", varIPAddresses); varNetworkList.Set(infoIndex++, varNetwork); } } } PostMessage(varNetworkList); } } } }
static void Main(string[] args) { string Str = "Arrays are very common in programming, they look something like: [1,2,3,4,5]"; string VarArray; int indexOfString = Str.IndexOf("["); VarArray = Str.Remove(0, indexOfString); VarArray = VarArray.Remove(3, 4); indexOfString = VarArray.IndexOf("]"); VarArray = VarArray.Insert(indexOfString, ",6,7,8,9,10"); /*VarArray = VarArray.Replace("4","9"); * indexOfString = VarArray.IndexOf("5"); * VarArray = VarArray.Remove(indexOfString, 1); * VarArray = VarArray.Insert(indexOfString,"10");*/ Console.WriteLine(VarArray); }
private void mainTree_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (mainTree.SelectedItem == null) { return; } WindowView wv = null; if (mainTree.SelectedItem.GetType() == typeof(Zone)) { Zone z = mainTree.SelectedItem as Zone; var existingWindows = (from a in MainViewModel.MainViewModelStatic.OpenWindows let b = a.Content as ZoneEditor where b != null && b.DataContext == z select a); if (existingWindows.Count() == 0) { wv = new WindowView { TabName = "Zone - " + z.ZoneName, Content = (UserControl) new ZoneEditor { DataContext = z } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); } else { wv = existingWindows.First(); } } if (mainTree.SelectedItem.GetType() == typeof(InteractableGroup)) { InteractableGroup g = mainTree.SelectedItem as InteractableGroup; var existingWindows = (from a in MainViewModel.MainViewModelStatic.OpenWindows let b = a.Content as InteractableGroupViewer where b != null && b.DataContext == g select a); if (existingWindows.Count() == 0) { wv = new WindowView { TabName = "Interactable Group - " + g.Name, Content = (UserControl) new InteractableGroupViewer { DataContext = g } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); } else { wv = existingWindows.First(); } } if (mainTree.SelectedItem.GetType() == typeof(Variable)) { Variable g = mainTree.SelectedItem as Variable; var existingWindows = (from a in MainViewModel.MainViewModelStatic.OpenWindows let b = a.Content as VariableEditor where b != null && b.DataContext == g select a); if (existingWindows.Count() == 0) { wv = new WindowView { TabName = "Variable - " + g.Name, Content = (UserControl) new VariableEditor { DataContext = g } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); } else { wv = existingWindows.First(); } } if (mainTree.SelectedItem.GetType() == typeof(VarArray)) { VarArray g = mainTree.SelectedItem as VarArray; var existingWindows = (from a in MainViewModel.MainViewModelStatic.OpenWindows let b = a.Content as ArrayEditor where b != null && b.DataContext == g select a); if (existingWindows.Count() == 0) { wv = new WindowView { TabName = "Array - " + g.Name, Content = (UserControl) new ArrayEditor { DataContext = g } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); } else { wv = existingWindows.First(); } } if (mainTree.SelectedItem.GetType() == typeof(ItemClass)) { ItemClass g = mainTree.SelectedItem as ItemClass; var existingWindows = (from a in MainViewModel.MainViewModelStatic.OpenWindows let b = a.Content as ItemClassEditor where b != null && b.DataContext == g select a); if (existingWindows.Count() == 0) { wv = new WindowView { TabName = "Item Class - " + g.Name, Content = (UserControl) new ItemClassEditor { DataContext = g } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); } else { wv = existingWindows.First(); } } if (mainTree.SelectedItem.GetType() == typeof(Item)) { Item g = mainTree.SelectedItem as Item; var existingWindows = (from a in MainViewModel.MainViewModelStatic.OpenWindows let b = a.Content as ItemEditor where b != null && b.DataContext == g select a); if (existingWindows.Count() == 0) { wv = new WindowView { TabName = "Item - " + g.ItemName, Content = (UserControl) new ItemEditor { DataContext = g } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); } else { wv = existingWindows.First(); } } if (mainTree.SelectedItem.GetType() == typeof(Conversation)) { Conversation g = mainTree.SelectedItem as Conversation; var existingWindows = (from a in MainViewModel.MainViewModelStatic.OpenWindows let b = a.Content as ConversationEditor where b != null && b.DataContext == g select a); if (existingWindows.Count() == 0) { wv = new WindowView { TabName = "Conversation - " + g.Name, Content = (UserControl) new ConversationEditor { DataContext = g } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); } else { wv = existingWindows.First(); } } if (mainTree.SelectedItem.GetType() == typeof(CommonEvent)) { CommonEvent g = mainTree.SelectedItem as CommonEvent; var existingWindows = (from a in MainViewModel.MainViewModelStatic.OpenWindows let b = a.Content as CommonEventEditor where b != null && b.DataContext == g select a); if (existingWindows.Count() == 0) { wv = new WindowView { TabName = "Common Event - " + g.Name, Content = (UserControl) new CommonEventEditor { DataContext = g } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); } else { wv = existingWindows.First(); } } if (mainTree.SelectedItem.GetType() == typeof(StatusEffect)) { StatusEffect g = mainTree.SelectedItem as StatusEffect; var existingWindows = (from a in MainViewModel.MainViewModelStatic.OpenWindows let b = a.Content as StatusEffectEditor where b != null && b.DataContext == g select a); if (existingWindows.Count() == 0) { wv = new WindowView { TabName = "Status Effect - " + g.Name, Content = (UserControl) new StatusEffectEditor { DataContext = g } }; MainViewModel.MainViewModelStatic.OpenWindows.Add(wv); } else { wv = existingWindows.First(); } } if (wv != null) { MainViewModel.MainViewModelStatic.SelectedTab = MainViewModel.MainViewModelStatic.OpenWindows.IndexOf(wv); } }
public static MainViewModel FromXML(XElement xml) { MainViewModel mvm = new MainViewModel(); XElement statusEffects = xml.Element("StatusEffects"); if (statusEffects != null) { foreach (var a in statusEffects.Elements("StatusEffect")) { mvm.StatusEffects.Add(StatusEffect.FromXML(a)); } } XElement zones = xml.Element("Zones"); if (zones != null) { mvm.Zones = new ObservableCollection <Zone>(from a in zones.Elements("Zone") select Zone.FromXML(a)); } //Link the exits. foreach (var sourceZone in mvm.Zones) { foreach (var sourceRoom in sourceZone.Rooms) { foreach (var exit in sourceRoom.Exits) { foreach (var destZone in mvm.Zones) { if (exit.ZoneID == destZone.ZoneId) { foreach (var destRoom in destZone.Rooms) { if (exit.RoomID == destRoom.RoomID) { exit.ZoneLink = destZone; exit.RoomLink = destRoom; } } } } } } } XElement interactables = xml.Element("Interactables"); if (interactables != null) { mvm.Interactables = new ObservableCollection <Interactable>(from a in interactables.Elements("Interactable") select Interactable.FromXML(a)); } XElement variables = xml.Element("Variables"); if (variables != null) { mvm.Variables = new ObservableCollection <Variable>(from a in variables.Elements("Variable") select Variable.FromXML(a)); } XElement arrays = xml.Element("Arrays"); if (arrays != null) { mvm.Arrays = new ObservableCollection <VarArray>(); mvm.Arrays = new ObservableCollection <VarArray>(from a in arrays.Elements("Array") select VarArray.FromXML(a)); } else { mvm.Arrays = new ObservableCollection <VarArray>(); } mvm.InteractableGroups.Clear(); mvm.RecalculateInteractableGroups(); XElement itemClasses = xml.Element("ItemClasses"); mvm.ItemClasses = new ObservableCollection <ItemClass>(); if (itemClasses != null) { foreach (var a in itemClasses.Elements("ItemClass")) { mvm.ItemClasses.Add(ItemClass.FromXML(a)); } } XElement settings = xml.Element("PlayerSettings"); if (settings != null) { mvm.Settings = PlayerSettings.FromXML(settings); } XElement items = xml.Element("Items"); mvm.Items = new ObservableCollection <Item>(); if (items != null) { foreach (var a in items.Elements("Item")) { mvm.Items.Add(Item.FromXml(a)); } } XElement commonEvents = xml.Element("CommonEvents"); if (commonEvents != null) { foreach (var a in commonEvents.Elements("CommonEvent")) { mvm.CommonEvents.Add(CommonEvent.FromXML(a)); } } XElement conversations = xml.Element("Conversations"); if (conversations != null) { foreach (var a in conversations.Elements("Conversation")) { mvm.Conversations.Add(Conversation.FromXML(a)); } } //Resolve all interactable references //foreach (var a in mvm.InteractableRefStack) //{ // var guid = a.Value; // var list = a.Key; // var interactable = mvm.Interactables.Where(i => i.InteractableID == guid).FirstOrDefault(); //} return(mvm); }
public AddrPayload(byte[] buffer, int offset) { AddressList = new VarArray<TimestampedNetworkAddress>(buffer, offset); ByteSize = AddressList.ByteSize; }
/// <summary> /// Serialize the argument object into the stream provided. /// </summary> /// <param name="data">Xml stream to serialize the argument object into</param> public void Serialize(IXMLSerializeData data) { #region Prepare PropertySet object names = null, values = null; myProperties.GetAllProperties(out names, out values); IStringArray myNames = new StrArray(); string[] nameArray = (string[])names; IVariantArray myValues = new VarArray(); object[] valArray = (object[])values; for (int i = 0; i < nameArray.GetLength(0); ++i) { myNames.Add(nameArray[i]); if (valArray[i] is IDataset) { IName myDatasetName = ((IDataset)valArray[i]).FullName; myValues.Add(myDatasetName); } else myValues.Add(valArray[i]); } #endregion data.TypeName = "NDVICustomFunctionArguments"; data.TypeNamespaceURI = @"http://www.esri.com/schemas/ArcGIS/10.2"; data.AddObject("Names", myNames); data.AddObject("Values", myValues); }