コード例 #1
0
ファイル: TagsManager.cs プロジェクト: Hartvi/ipalm-sponges
    public static void Save(string path)
    {
        try{
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Create(path);

            var arr         = new SerializableKeyValuePair <string, TagField> [tagfield.Count];
            int start_count = 0;
            foreach (var pair in tagfield)
            {
                arr [start_count]         = new SerializableKeyValuePair <string, TagField> ();
                arr [start_count].Key     = pair.Key;
                arr [start_count++].Value = pair.Value;
            }

            bf.Serialize(file, arr);

            file.Close();
        }
        catch (FileNotFoundException e)
        {
            Debug.LogException(e);
        }
        catch (IOException e)
        {
            Debug.LogException(e);
        }
    }
コード例 #2
0
 private static void Deselect(SerializableKeyValuePair <TBuyType, BuyButtonData>?datum)
 {
     if (datum != null)
     {
         SetTextActive(datum.Value.Value, false);
     }
 }
コード例 #3
0
        public void SendTerminalSettings(long blockId)
        {
            if (NaniteConstructionManager.NaniteBlocks == null)
            {
                return;
            }

            if (!NaniteConstructionManager.NaniteBlocks.ContainsKey(blockId))
            {
                return;
            }

            if (!NaniteConstructionManager.TerminalSettings.ContainsKey(blockId))
            {
                NaniteConstructionManager.TerminalSettings.Add(blockId, new NaniteTerminalSettings());
            }

            SerializableKeyValuePair <long, NaniteTerminalSettings> settings = new SerializableKeyValuePair <long, NaniteTerminalSettings>(blockId, NaniteConstructionManager.TerminalSettings[blockId]);

            if (!Sync.IsServer)
            {
                //Logging.Instance.WriteLine("SendTerminalSettings -> Server");
                MyAPIGateway.Multiplayer.SendMessageToServer(8964, ASCIIEncoding.ASCII.GetBytes(MyAPIGateway.Utilities.SerializeToXML(settings)));
            }
            else
            {
                //Logging.Instance.WriteLine("SendTerminalSettings -> Others");
                MyAPIGateway.Multiplayer.SendMessageToOthers(8960, ASCIIEncoding.ASCII.GetBytes(MyAPIGateway.Utilities.SerializeToXML(settings)));
            }
        }
コード例 #4
0
        public bool Equals(SerializableKeyValuePair <TKey, TValue> other)
        {
            var comparer1 = EqualityComparer <TKey> .Default;
            var comparer2 = EqualityComparer <TValue> .Default;

            return(comparer1.Equals(_key, other._key) &&
                   comparer2.Equals(_value, other._value));
        }
コード例 #5
0
        bool HasConflict(SerializableKeyValuePair pair, List <SerializableKeyValuePair> list)
        {
            if (IsKeyNull(pair))
            {
                return(list.FindAll(e => IsKeyNull(e)).Count > 1);
            }

            return(list.FindAll(e => !IsKeyNull(e) && e.key.Equals(pair.key)).Count > 1);
        }
コード例 #6
0
 // Safe method to check if key is null outside of main thread
 bool IsKeyNull(SerializableKeyValuePair pair)
 {
     try
     {
         return(pair.key.Equals(null));
     }
     catch (Exception)
     {
         return(true);
     }
 }
コード例 #7
0
        public void WriteXml(System.Xml.XmlWriter writer)
        {
            XmlSerializer           serializer = new XmlSerializer(typeof(SerializableKeyValuePair <TKey, TValue>));
            XmlSerializerNamespaces ns         = new XmlSerializerNamespaces();

            ns.Add("", "");
            foreach (TKey key in this.Keys)
            {
                TValue value = this[key];
                var    kvp   = new SerializableKeyValuePair <TKey, TValue>(key, value);
                serializer.Serialize(writer, kvp, ns);
            }
        }
コード例 #8
0
        public void SendAssemblerSettings(long blockId)
        {
            if (!NaniteConstructionManager.AssemblerSettings.ContainsKey(blockId))
            {
                NaniteConstructionManager.AssemblerSettings.Add(blockId, new NaniteAssemblerSettings());
            }

            SerializableKeyValuePair <long, NaniteAssemblerSettings> settings = new SerializableKeyValuePair <long, NaniteAssemblerSettings>(blockId, NaniteConstructionManager.AssemblerSettings[blockId]);

            if (Sync.IsClient)
            {
                MyAPIGateway.Multiplayer.SendMessageToServer(8965, ASCIIEncoding.ASCII.GetBytes(MyAPIGateway.Utilities.SerializeToXML(settings)));
            }
            else if (Sync.IsServer)
            {
                MyAPIGateway.Multiplayer.SendMessageToOthers(8962, ASCIIEncoding.ASCII.GetBytes(MyAPIGateway.Utilities.SerializeToXML(settings)));
            }
        }
コード例 #9
0
        private static CSharpReference PrepareForTransfer(CSharpReference reference, ModuleDefinition original)
        {
            List <SerializableKeyValuePair <string, string> > attribs = reference.internalAttributes;

            for (int i = 0; i < attribs.Count; i++)
            {
                if (attribs[i].Key == "Include")
                {
                    SerializableKeyValuePair <string, string> serializableKeyValuePair = attribs[i];
                    serializableKeyValuePair.Value = Path.GetFullPath(Path.Combine(original.RootDirectory,
                                                                                   reference.internalAttributes[i].Value));
                    attribs[i] = serializableKeyValuePair;
                }
            }

            reference.internalAttributes = attribs;
            return(reference);
        }
コード例 #10
0
        public void Save_Handler()
        {
            List <SerializableKeyValuePair <string, object> > list = new List <SerializableKeyValuePair <string, object> >();

            foreach (DictionaryEntry de in TenantData.tenants)
            {
                object tenant = de.Value;
                SerializableKeyValuePair <string, object> keyValue = new SerializableKeyValuePair <string, object>(de.Key.ToString(), de.Value);
                list.Add(keyValue);
            }

            BinaryFormatter fo = new BinaryFormatter();
            FileStream      f  = new FileStream("savefile.svf",
                                                FileMode.Create, FileAccess.Write);

            fo.Serialize(f, list);
            f.Close();
        }
コード例 #11
0
        protected override void OnPreRender(EventArgs e)
        {
            if (FoldersComboBox.SelectedFolder != null && FoldersComboBox.SelectedFolder.FolderPath.StartsWith("Users/", StringComparison.InvariantCultureIgnoreCase))
            {
                var userFolder = FolderManager.Instance.GetUserFolder(User ?? UserController.Instance.GetCurrentUserInfo());
                if (FoldersComboBox.SelectedFolder.FolderID == userFolder.FolderID)
                {
                    FoldersComboBox.SelectedItem = new ListItem
                    {
                        Text  = FolderManager.Instance.MyFolderName,
                        Value = userFolder.FolderID.ToString(CultureInfo.InvariantCulture)
                    };
                }
                else if (UsePersonalFolder) //if UserPersonalFolder is true, make sure the file is under the user folder.
                {
                    FoldersComboBox.SelectedItem = new ListItem
                    {
                        Text  = FolderManager.Instance.MyFolderName,
                        Value = userFolder.FolderID.ToString(CultureInfo.InvariantCulture)
                    };

                    FilesComboBox.SelectedFile = null;
                }
            }

            FoldersLabel.Text = FolderManager.Instance.MyFolderName;

            FileUploadControl.Options.FolderPicker.Disabled = UsePersonalFolder;
            if (FileUploadControl.Options.FolderPicker.Disabled && FoldersComboBox.SelectedFolder != null)
            {
                var selectedItem = new SerializableKeyValuePair <string, string>(
                    FoldersComboBox.SelectedItem.Value, FoldersComboBox.SelectedItem.Text);

                FileUploadControl.Options.FolderPicker.InitialState = new DnnDropDownListState
                {
                    SelectedItem = selectedItem
                };
                FileUploadControl.Options.FolderPath = FoldersComboBox.SelectedFolder.FolderPath;
            }

            base.OnPreRender(e);
        }
コード例 #12
0
        public void SendHammerTerminalSettings(long blockId)
        {
            if (!NaniteConstructionManager.HammerTerminalSettings.ContainsKey(blockId))
            {
                NaniteConstructionManager.HammerTerminalSettings.Add(blockId, new NaniteHammerTerminalSettings());
            }

            SerializableKeyValuePair <long, NaniteHammerTerminalSettings> settings = new SerializableKeyValuePair <long, NaniteHammerTerminalSettings>(blockId, NaniteConstructionManager.HammerTerminalSettings[blockId]);

            if (!Sync.IsServer)
            {
                Logging.Instance.WriteLine($"SendHammerTerminalSettings -> Server: {blockId}");
                MyAPIGateway.Multiplayer.SendMessageToServer(8967, ASCIIEncoding.ASCII.GetBytes(MyAPIGateway.Utilities.SerializeToXML(settings)));
            }
            else
            {
                Logging.Instance.WriteLine($"SendHammerTerminalSettings -> Others: {blockId}");
                MyAPIGateway.Multiplayer.SendMessageToOthers(8966, ASCIIEncoding.ASCII.GetBytes(MyAPIGateway.Utilities.SerializeToXML(settings)));
            }
        }
コード例 #13
0
        private void Select(AbstractBuildingTile tile, SerializableKeyValuePair <TBuyType, BuyButtonData> pair, AbstractMarketManager manager)
        {
            // if we select the selected button, don't do anything
            if (selectedButtonDatum != null && selectedButtonDatum.Value.Equals(pair))
            {
                return;
            }

            BuyButtonData buyButtondatum = pair.Value;

            SetTextActive(buyButtondatum, true);
            btnBuy.transform.position = buyButtondatum.Button.transform.position;

            OnSelectBuyButton(tile, pair.Key);

            Deselect(selectedButtonDatum);
            selectedButtonDatum = pair;

            SetupBuyButton(tile, manager);
        }
コード例 #14
0
        public void SendBeaconTerminalSettings(long blockId)
        {
            if (!NaniteConstructionManager.BeaconTerminalSettings.ContainsKey(blockId))
            {
                NaniteConstructionManager.BeaconTerminalSettings.Add(blockId, new NaniteBeaconTerminalSettings());
            }

            SerializableKeyValuePair <long, NaniteBeaconTerminalSettings> settings = new SerializableKeyValuePair <long, NaniteBeaconTerminalSettings>(blockId, NaniteConstructionManager.BeaconTerminalSettings[blockId]);

            if (!Sync.IsServer)
            {
                //Logging.Instance.WriteLine("SendAssemblerSettings -> Server");
                Logging.Instance.WriteLine("SendBeaconTerminalSettings -> Server: {blockId}");
                MyAPIGateway.Multiplayer.SendMessageToServer(8972, ASCIIEncoding.ASCII.GetBytes(MyAPIGateway.Utilities.SerializeToXML(settings)));
            }
            else
            {
                //Logging.Instance.WriteLine("SendAssemblerSettings -> Others");
                Logging.Instance.WriteLine("SendBeaconTerminalSettings -> Client: {blockId}");
                MyAPIGateway.Multiplayer.SendMessageToOthers(8971, ASCIIEncoding.ASCII.GetBytes(MyAPIGateway.Utilities.SerializeToXML(settings)));
            }
        }
コード例 #15
0
        /// <inheritdoc />
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            using (writeLock.LockRead())
            {
                if (InnerDictionary is ISerializable)
                {
                    info.AddValue(nameof(InnerDictionary), InnerDictionary);
                }
                else
                {
                    SerializableKeyValuePair <TKey, TValue>[] elements = new SerializableKeyValuePair <TKey, TValue> [Count];
                    int index = 0;

                    foreach (var element in this)
                    {
                        elements[index++] = element;
                    }

                    info.AddValue(nameof(elements), elements);
                }
            }
        }
コード例 #16
0
        /// <inheritdoc />
        public void WriteXml(XmlWriter writer)
        {
            if (InnerDictionary is IXmlSerializable)
            {
                (InnerDictionary as IXmlSerializable).WriteXml(writer);
            }
            else
            {
                writer.WriteStartElement("SynchronizedDictionary");

                SerializableKeyValuePair <TKey, TValue>[] elements = new SerializableKeyValuePair <TKey, TValue> [Count];
                int index = 0;

                foreach (var element in this)
                {
                    elements[index++] = element;
                }

                writer.WriteElement("Elements", elements);
                writer.WriteEndElement();
            }
        }
コード例 #17
0
        private static void HandleDiagnostics(HttpListenerContext httpCtx)
        {
            SerializableKeyValuePair[] serializeableKvps;
            if (!kvps.IsEmpty)
            {
                serializeableKvps = kvps.Select(kvp => new SerializableKeyValuePair { Key = kvp.Key, Value = kvp.Value }).ToArray();
            }
            else
            {
                serializeableKvps = new SerializableKeyValuePair[0];
            }

            var serializer = new XmlSerializer(serializeableKvps.GetType(), new XmlRootAttribute { ElementName = "KeyValuePairs" });
            httpCtx.Response.StatusCode = (int)HttpStatusCode.OK;
            httpCtx.Response.ContentType = MediaTypeNames.Text.Xml;
            using (var targetStream = new MemoryStream())
            {
                serializer.Serialize(targetStream, serializeableKvps);
                targetStream.Flush();

                httpCtx.Response.ContentLength64 = targetStream.Length;
                httpCtx.Response.Close(targetStream.ToArray(), willBlock: false);
            }
        }
コード例 #18
0
        protected override void OnPreRender(EventArgs e)
        {
            if (FoldersComboBox.SelectedFolder != null && FoldersComboBox.SelectedFolder.FolderPath.StartsWith("Users/", StringComparison.InvariantCultureIgnoreCase))
            {
                var userFolder = FolderManager.Instance.GetUserFolder(User ?? UserController.Instance.GetCurrentUserInfo());
                if (FoldersComboBox.SelectedFolder.FolderID == userFolder.FolderID)
                {
                    FoldersComboBox.SelectedItem = new ListItem
                                                   {
                                                       Text = FolderManager.Instance.MyFolderName, 
                                                       Value = userFolder.FolderID.ToString(CultureInfo.InvariantCulture)
                                                   };
                }
                else if (UsePersonalFolder) //if UserPersonalFolder is true, make sure the file is under the user folder.
                {
                    FoldersComboBox.SelectedItem = new ListItem
                                                    {
                                                        Text = FolderManager.Instance.MyFolderName,
                                                        Value = userFolder.FolderID.ToString(CultureInfo.InvariantCulture)
                                                    };

                    FilesComboBox.SelectedFile = null;
                }
            }

            FoldersLabel.Text = FolderManager.Instance.MyFolderName;

            FileUploadControl.Options.FolderPicker.Disabled = UsePersonalFolder;
            if (FileUploadControl.Options.FolderPicker.Disabled && FoldersComboBox.SelectedFolder != null)
            {
                var selectedItem = new SerializableKeyValuePair<string, string>(
                    FoldersComboBox.SelectedItem.Value, FoldersComboBox.SelectedItem.Text);

                FileUploadControl.Options.FolderPicker.InitialState = new DnnDropDownListState
                                                                          {
                                                                              SelectedItem = selectedItem
                                                                                  
                                                                          };
                FileUploadControl.Options.FolderPath = FoldersComboBox.SelectedFolder.FolderPath;
            }

            base.OnPreRender(e);
        }
コード例 #19
0
 protected KeyValuePair <int, TValue> ToKvp(SerializableKeyValuePair serializable)
 {
     return(new KeyValuePair <int, TValue>(ParseInt(serializable.Key), ParseValue(serializable.Value)));
 }
コード例 #20
0
 /// <summary>
 /// Elimina un elemento del diccionario.
 /// </summary>
 /// <param name="item">Elemento a eliminar.</param>
 public void Remove(SerializableKeyValuePair item)
 {
     this.Dictionary.Remove(item.ToKeyValuePair());
 }
コード例 #21
0
 protected override void SetupScreen(AbstractBuildingTile tile, AbstractMarketManager manager)
 {
     selectedButtonDatum = null;
     SetupTypeButtons(tile, manager);
 }
コード例 #22
0
 public void Add(SerializableKeyValuePair <TKey, TValue> kvp)
 {
     this._elements.Add(kvp);
 }
コード例 #23
0
 /// <summary>
 /// Añade un elemento al diccionario.
 /// </summary>
 /// <param name="item">Elemento a añadir.</param>
 public void Add(SerializableKeyValuePair item)
 {
     this.Dictionary.Add(item.ToKeyValuePair());
 }
コード例 #24
0
 public StudentMaterialPartViewModel(SerializableKeyValuePair <EducationMaterialPart, bool> part, SolidColorBrush trueColor, SolidColorBrush falseColor)
 {
     _part       = part;
     _trueColor  = trueColor;
     _falseColor = falseColor;
 }