private void SortChildren(BNode parent) { SerializedObject serializedParent = new SerializedObject(parent); BNode[] children = parent.Children; SerializedProperty array = serializedParent.FindProperty("children"); for (int i = 0; i < children.Length - 1; i++) { int toChangeIndex = i; float lowestNumber = children[i].boundsInEditor.x; for (int j = i + 1; j < children.Length; j++) { if (children[j].boundsInEditor.x < lowestNumber) { toChangeIndex = j; lowestNumber = children[j].boundsInEditor.x; } } if (toChangeIndex != i) { SerializableUtil.ArraySwapElement(array, i, toChangeIndex, false); BNode temp = children[i]; children[i] = children[toChangeIndex]; children[toChangeIndex] = temp; } } serializedParent.ApplyModifiedProperties(); }
static void Main(string[] args) { string queueName = "07"; var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { //定义队列(hello为队列名) channel.QueueDeclare(queueName, false, false, false, null); //发送到队列的消息 var model = new TestModel { Id = 20, Name = "James", Brith = DateTime.Now, Money = 1000 }; var body = SerializableUtil.Serialize(model); channel.BasicPublish("", queueName, null, body); Console.WriteLine("Sentd"); } } }
static void Main(string[] args) { string queueName = "07"; var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { //定义队列(hello为队列名) channel.QueueDeclare(queueName, false, false, false, null); var consumer = new QueueingBasicConsumer(channel); bool noAck = true; channel.BasicConsume(queueName, noAck, consumer); Console.WriteLine(DateTime.Now + " [*] Waiting for messages."); while (true) { //接受客户端发送的消息并打印出来 var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue(); var message = (TestModel)SerializableUtil.Deserialize(ea.Body); Console.WriteLine(" [x] Received {0}", message); } } } }
private Pair GetUserData(HttpContext context) { if (context.Request.Cookies[FormsAuthentication.FormsCookieName + "UserInfo"] == null) { return(null); } return(SerializableUtil.ConvertZipedBase64StringToObject <Pair>(context.Request.Cookies[FormsAuthentication.FormsCookieName + "UserInfo"].Value)); }
public void ShallowCopyTestMethod() { object clone; SerializableUtil.ShallowCopy(_yongquan, out clone); _nobody = (Person)clone; Assert.AreEqual(_yongquan, _nobody); Assert.AreSame(_yongquan, _nobody); }
public void DeepCopyTestMethod() { object clone; SerializableUtil.DeepCopy(_xiaoyun, out clone); _nobody = (Person)clone; Assert.AreNotSame(_xiaoyun, _nobody); Assert.AreEqual(_xiaoyun, _nobody); }
private void OnUpdateValueList(SerializedProperty treeProperty, SerializedProperty valuesToOverwrite, SerializedObject serializedObject) { if (treeProperty.objectReferenceValue == null) { return; // skip the button } UnityEngine.Object[] allObjects = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(treeProperty.objectReferenceValue)); List <Value> values = new List <Value>(); for (int i = 0; i < allObjects.Length; i++) { if (allObjects[i] is Value) { values.Add(allObjects[i] as Value); } } for (int i = valuesToOverwrite.arraySize - 1; i > -1; i--) { // Get the element "valuesToOverwrite.toOverwrite" SerializedProperty element = valuesToOverwrite.GetArrayElementAtIndex(i).FindPropertyRelative("toOverwrite"); // Go through both lists and remove all matching elements and remove elements which are not in allnames from the // serialized array bool found = false; for (int j = 0; j < values.Count; j++) { if (values[j] == element.objectReferenceValue) { values.RemoveAt(j); found = true; break; } } if (found == false) { SerializableUtil.ArrayRemoveAtIndex(valuesToOverwrite, i); } } // save the index and grow the array int index = valuesToOverwrite.arraySize; valuesToOverwrite.arraySize += values.Count; for (int i = 0; i < values.Count; i++) { valuesToOverwrite.GetArrayElementAtIndex(index++).FindPropertyRelative("toOverwrite").objectReferenceValue = values[i]; } serializedObject.ApplyModifiedProperties(); }
private void RemoveConnection(BNode node) { if (GetParentNode(node, out BNode parent)) { if (!GetChildIndex(parent, node, out int index)) { Debug.LogError("Parent does not contain child. Something seems wrong!"); } else { SerializableUtil.ArrayRemoveAtIndex(new SerializedObject(parent).FindProperty("children"), index); } } }
public string WebUserLoginIn(SystemUser systemUser, bool persistentUser, HttpContext context) { List <SystemRole> listRole = this.systemUserRoleRelationDaoInstance.GetUserAssignRole(systemUser); Pair pair = new Pair(systemUser, listRole); string userInfo = SerializableUtil.ConvertObjectToZipedBase64String <Pair>(pair); HttpCookie userC = new HttpCookie(FormsAuthentication.FormsCookieName + "UserInfo", userInfo); context.Response.Cookies.Add(userC); FormsAuthenticationTicket tk = new FormsAuthenticationTicket(1, systemUser.UserLoginID.ToString(), DateTime.Now, DateTime.Now.AddMinutes(30.0), persistentUser, "", FormsAuthentication.FormsCookiePath); string key = FormsAuthentication.Encrypt(tk); HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, key); context.Response.Cookies.Add(ck); return(FormsAuthentication.GetRedirectUrl(systemUser.UserLoginID.ToString(), persistentUser)); }
public static SRMSerializer Deserialize() { return(SerializableUtil.Deserialize <SRMSerializer>(@"d:\SRM.sl")); }
public void Serialize() { SerializableUtil.Serialize(@"d:\SRM.sl", this); }
public override void DrawInspector(SerializedObject serializedObject) { SubTreeNode objectReference = serializedObject.targetObject as SubTreeNode; SerializedProperty valuesToOverwrite = serializedObject.FindProperty("valuesToOverwrite"); SerializedProperty treeProperty = serializedObject.FindProperty("behaviourTree"); EditorGUILayout.PropertyField(treeProperty); if (GUILayout.Button("Open Tree")) { BTreeEditor editor = ScriptableObject.CreateInstance <BTreeEditor>(); editor.OpenSubTree(treeProperty.objectReferenceValue as BTree, objectReference.ClonedTree); editor.Show(); } if (GUILayout.Button("Update ValueList")) { if (treeProperty.objectReferenceValue == null) { goto DrawArrayValues; // skip the button } UnityEngine.Object[] allObjects = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(treeProperty.objectReferenceValue)); List <Value> values = new List <Value>(); for (int i = 0; i < allObjects.Length; i++) { if (allObjects[i] is Value) { values.Add(allObjects[i] as Value); } } for (int i = valuesToOverwrite.arraySize - 1; i > -1; i--) { // Get the element "valuesToOverwrite.toOverwrite" SerializedProperty element = valuesToOverwrite.GetArrayElementAtIndex(i).FindPropertyRelative("toOverwrite"); // Go through both lists and remove all matching elements and remove elements which are not in allnames from the // serialized array bool found = false; for (int j = 0; j < values.Count; j++) { if (values[j] == element.objectReferenceValue) { values.RemoveAt(j); found = true; break; } } if (found == false) { SerializableUtil.ArrayRemoveAtIndex(valuesToOverwrite, i); } } // save the index and grow the array int index = valuesToOverwrite.arraySize; valuesToOverwrite.arraySize += values.Count; for (int i = 0; i < values.Count; i++) { valuesToOverwrite.GetArrayElementAtIndex(index++).FindPropertyRelative("toOverwrite").objectReferenceValue = values[i]; } serializedObject.ApplyModifiedProperties(); } DrawArrayValues: // Draw the array for (int i = 0; i < valuesToOverwrite.arraySize; i++) { SerializedProperty element = valuesToOverwrite.GetArrayElementAtIndex(i); SerializedProperty toOverwrite = element.FindPropertyRelative("toOverwrite"); SerializedProperty newValue = element.FindPropertyRelative("newValue"); newValue.objectReferenceValue = EditorGUILayout.ObjectField(toOverwrite.objectReferenceValue.name, newValue.objectReferenceValue, typeof(Value), false); } }