/// <summary>
        /// Clone this object.
        /// </summary>
        /// <returns>
        /// A cloned object.
        /// </returns>
        public object Clone()
        {
            SoapHeaderBase header = (SoapHeaderBase)Activator.CreateInstance(this.GetType());

            header.Stub = SerializationUtilities.DeserializeFromXmlText(
                SerializationUtilities.SerializeAsXmlText(this.Stub), this.Stub.GetType());
            return(header);
        }
Exemplo n.º 2
0
 public static StoredArgument From(object argument)
 {
     return(new StoredArgument
     {
         TypeName = SerializationUtilities.PersistedTypeName(argument.GetType()),
         Value = JToken.FromObject(argument)
     });
 }
Exemplo n.º 3
0
 public byte[] GetSerializedData()
 {
     if (!string.IsNullOrEmpty(GetSerializedData(out object obj)))
     {
         return(null);
     }
     return(SerializationUtilities.Serialize(obj));
 }
Exemplo n.º 4
0
        private void CheckForComplete(SlicingOptions options, CubeManager manager)
        {
            int expectedResults = options.TextureSliceX * options.TextureSliceY;

            if (StorageUtilities.GetWorkCompletedCount(TableClient, options.CloudResultPath, options.CloudResultContainer) != expectedResults)
            {
                return;
            }

            var workResults = StorageUtilities.GetWorkCompletedMetadata(TableClient, options.CloudResultPath, options.CloudResultContainer);

            // Write metadata

            CubeMetadata metadata = new CubeMetadata(options.CubeGrid)
            {
                WorldBounds        = manager.ObjInstance.Size,
                VirtualWorldBounds = options.ForceCubicalCubes ? manager.ObjInstance.CubicalSize : manager.ObjInstance.Size,
                VertexCount        = manager.ObjInstance.VertexList.Count
            };

            // Configure texture slicing metadata
            if (!string.IsNullOrEmpty(options.Texture) && (options.TextureSliceX + options.TextureSliceY) > 2)
            {
                metadata.TextureSetSize = new Vector2(options.TextureSliceX, options.TextureSliceY);
            }
            else
            {
                metadata.TextureSetSize = new Vector2(1, 1);
            }

            var resultsList = workResults.Select(w =>
                                                 SerializationUtilities.DecodeMetadataFromBase64(
                                                     Texture.GetCubeListFromTextureTile(options.TextureSliceY, options.TextureSliceX, w.TextureTileX, w.TextureTileY, manager.ObjInstance),
                                                     w.MetadataBase64));

            foreach (var result in resultsList)
            {
                foreach (var cube in result.Keys)
                {
                    metadata.CubeExists[cube.X, cube.Y, cube.Z] = result[cube];
                }
            }


            // Write out some json metadata
            string metadataPath = Path.Combine(outputPath, "metadata.json");

            if (File.Exists(metadataPath))
            {
                File.Delete(metadataPath);
            }

            string metadataString = JsonConvert.SerializeObject(metadata);

            File.WriteAllText(metadataPath, metadataString);

            StorageUtilities.UpdateSetCompleted(TableClient, options.SetKey);
        }
Exemplo n.º 5
0
        private static void CustomReadPropertiesFromElements(SerializationContext serializationContext, PersistentTypeHasAssociations element, XmlReader reader)
        {
            Action useAssocAttrUpgradeFunc =
                () =>
            {
                // this is here when converting from older versions than 1.0.5.0 to set 'UseAssociationAttribute' to true
                if (ModelUpgrader.Instance.DeserializingModelVersion <
                    ModelUpgrader.Version_1_0_5_0)
                {
                    ModelUpgrader.Instance.UpdateMakeChangesFlag();
                }
            };

            while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == XmlNodeType.Element)
            {
                switch (reader.LocalName)
                {
                case "end1":
                    if (reader.IsEmptyElement)
                    {                                        // No serialized value, must be default one.
                        SerializationUtilities.Skip(reader); // Skip this tag.
                    }
                    else
                    {
                        OrmAssociationEnd end1 = new OrmAssociationEnd(element, "End1");
                        end1.DeserializeFromXml(reader, "end1");
                        element.End1 = end1;

                        useAssocAttrUpgradeFunc();

                        SerializationUtilities.SkipToNextElement(reader);
                        reader.SkipToNextElementFix();
                    }
                    break;

                case "end2":
                    if (reader.IsEmptyElement)
                    {                                        // No serialized value, must be default one.
                        SerializationUtilities.Skip(reader); // Skip this tag.
                    }
                    else
                    {
                        OrmAssociationEnd end2 = new OrmAssociationEnd(element, "End2");
                        end2.DeserializeFromXml(reader, "end2");
                        element.End2 = end2;

                        useAssocAttrUpgradeFunc();

                        SerializationUtilities.SkipToNextElement(reader);
                        reader.SkipToNextElementFix();
                    }
                    break;

                default:
                    return;      // Don't know this element.
                }
            }
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (RendomMessages == null)
            {
                new ArgumentException();
            }

            SerializationUtilities.SaveData(new BotMessageData(textBoxFirstMessage.Text, RendomMessages.ToArray()));
        }
Exemplo n.º 7
0
 public Team(TeamModel t)
 {
     Id        = t.Id;
     PlayerIDs = new HashSet <int>();
     foreach (int i in SerializationUtilities.DeserializeIntList(t.PlayerIDs))
     {
         PlayerIDs.Add(i);
     }
 }
        /// <summary>
        /// Gets the post body for sending a request.
        /// </summary>
        /// <param name="operations">The list of operations.</param>
        /// <returns>The POST body, for using in the web request.</returns>
        protected string GetPostBody(IEnumerable <Operation> operations)
        {
            BatchJobMutateRequest request = new BatchJobMutateRequest()
            {
                operations = operations.ToArray()
            };

            return(SerializationUtilities.SerializeAsXmlText(request));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a copy of this connection object with a new <see cref="Guid"/> value.
        /// </summary>
        /// <returns>A new copy of this connection object with its <see cref="Guid"/> property initialized to a new value.</returns>
        public virtual object Clone()
        {
            object clonedConnection = SerializationUtilities.Clone(this);

            ((BaseConnection)clonedConnection).ParentFolder = null;
            ((BaseConnection)clonedConnection).Guid         = Guid.NewGuid();

            return(clonedConnection);
        }
Exemplo n.º 10
0
 /// <summary>
 ///Populates a <see cref="System.Runtime.Serialization.SerializationInfo"/> with the data needed to serialize the target object.
 /// </summary>
 /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/> to populate with data. </param>
 /// <param name="context">The destination (see <see cref="System.Runtime.Serialization.StreamingContext"/>) for this serialization. </param>
 public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     lock (_putLock) {
         lock (_takeLock) {
             SerializationUtilities.DefaultWriteObject(info, context, this);
             info.AddValue("Data", ToArray());
         }
     }
 }
Exemplo n.º 11
0
        public virtual IDBObject GetDBObject()
        {
            TeamModel t = new TeamModel();

            t.Id        = Id;
            t.PlayerIDs = SerializationUtilities.SerializeList(new List <int>(PlayerIDs));

            return(t);
        }
        /// <summary>
        /// Gets the post body for sending a request.
        /// </summary>
        /// <param name="operations">The list of operations.</param>
        /// <returns>The POST body, for using in the web request.</returns>
        private string GetPostBody(Operation[] operations)
        {
            BatchJobMutateRequest request = new BatchJobMutateRequest()
            {
                operations = operations.ToArray()
            };

            return(SerializationUtilities.SerializeAsXmlText(request));
        }
Exemplo n.º 13
0
 static string SerializeExceptionFilters(IEnumerable <ExceptionFilter> exceptionFilters)
 {
     return(JsonConvert.SerializeObject(
                exceptionFilters.Select(f => new StoredExceptionFilter
     {
         TypeName = SerializationUtilities.PersistedTypeName(f.Type),
         Method = f.Method,
         Arguments = f.Arguments.Select(StoredArgument.From).ToArray()
     })));
 }
Exemplo n.º 14
0
 public TokenCache GetTokenCache()
 {
     if (this.TokenCache != null && this.TokenCache.Length > 0)
     {
         return(SerializationUtilities.ByteArrayToObject <TokenCache>(this.TokenCache));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// Appends the HTTP headers to SOAP xml.
 /// </summary>
 /// <param name="soapRequest">The SOAP request.</param>
 /// <param name="headers">The HTTP headers.</param>
 /// <returns>The modified SOAP xml for appending to the logs.</returns>
 protected string AppendHeadersToSoapXml(string soapRequest, string headers)
 {
     try {
         XmlDocument xDoc    = SerializationUtilities.LoadXml(soapRequest);
         XmlComment  comment = xDoc.CreateComment(headers);
         xDoc.DocumentElement.InsertBefore(comment, xDoc.DocumentElement.FirstChild);
         return(xDoc.OuterXml);
     } catch {
         return(string.Format("{0}\r\n{1}\r\n", headers, soapRequest));
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// Protected constructor. Used by serialization frameworks while
 /// deserializing an exception object.
 /// </summary>
 /// <param name="info">Info about the serialization context.</param>
 /// <param name="context">A streaming context that represents the
 /// serialization stream.</param>
 protected DfpApiException(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     apiException = SerializationUtilities.DeserializeFromXmlText(
         GetValue <string>(info, "apiException"),
         GetValue <Type>(info, "apiExceptionType"));
 }
            public async Task SerializesNullSemVerLevel()
            {
                var package = Data.PackageEntity;

                package.SemVerLevelKey = SemVerLevelKey.Unknown;

                var document = _target.FullFromDb(Data.PackageId, Data.HijackDocumentChanges, package);

                var json = await SerializationUtilities.SerializeToJsonAsync(document);

                Assert.Contains("\"semVerLevel\": null,", json);
            }
Exemplo n.º 18
0
        public void SerializationUtility_ReadWrite_Int32()
        {
            var data = new byte[100];

            for (int i = 0; i < 1000; i++)
            {
                var val = Random.Range(int.MinValue, int.MaxValue);
                var off = Random.Range(0, data.Length - sizeof(int));
                Assert.AreEqual(off + sizeof(int), SerializationUtilities.WriteInt32ToByteArray(data, val, off));
                Assert.AreEqual(val, SerializationUtilities.ReadInt32FromByteArray(data, off));
            }
        }
Exemplo n.º 19
0
 public int CountSuspended(Type type)
 {
     return
         (_connection.ExecuteScalar <int>(
              "select count(*) from DependableJobs " +
              "where Type = COALESCE(@Type, Type) and suspended = 1 and InstanceName = @InstanceName",
              new
     {
         Type = type != null ? SerializationUtilities.PersistedTypeName(type) : null,
         InstanceName = _instanceName
     }));
 }
 /// <summary>
 /// Customize Model and Diagram Loading.
 /// </summary>
 /// <param name="serializationResult">Stores serialization result from the load operation.</param>
 /// <param name="modelPartition">Partition in which the new DslLibrary instance will be created.</param>
 /// <param name="modelFileName">Name of the file from which the DslLibrary instance will be deserialized.</param>
 /// <param name="diagramPartition">Partition in which the new DslDesignerDiagram instance will be created.</param>
 /// <param name="diagramFileName">Name of the file from which the DslDesignerDiagram instance will be deserialized.</param>
 /// <param name="modelRoot">The root of the file that was loaded.</param>
 /// <param name="diagram">The diagram matching the modelRoot.</param>
 protected void OnPostLoadModelAndDiagram(SerializationResult serializationResult, Partition modelPartition, string modelFileName, Partition diagramPartition, string diagramFileName, TModel modelRoot, TDiagram diagram)
 {
     foreach (SerializationMessage message in serializationResult)
     {
         if (message.Kind == SerializationMessageKind.Warning &&
             message.Message.StartsWith(Properties.Resources.MissingIdKey, StringComparison.OrdinalIgnoreCase))
         {
             SerializationUtilities.AddMessage(serializationResult, modelFileName, SerializationMessageKind.Info, Properties.Resources.MissingIdWarnings, 0, 0);
             return;
         }
     }
 }
Exemplo n.º 21
0
        /// <summary> Reconstitute this queue instance from a stream (that is,
        /// deserialize it).
        /// </summary>
        /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/> to populate with data. </param>
        /// <param name="context">The destination (see <see cref="System.Runtime.Serialization.StreamingContext"/>) for this serialization. </param>
        protected LinkedBlockingQueue(SerializationInfo info, StreamingContext context)
        {
            SerializationUtilities.DefaultReadObject(info, context, this);
            _last = _head = new Node(default(T));

            T[] items = (T[])info.GetValue("Data", typeof(T[]));
            foreach (var item in items)
            {
                Insert(item);
            }
            _activeCount = items.Length;
        }
Exemplo n.º 22
0
        string GetSerializedData(out object obj)
        {
            obj = null;
            var error = LoadType(out var type);

            if (!string.IsNullOrEmpty(error))
            {
                return(error);
            }

            return(SerializationUtilities.CreateObjectFromString(type, StringValue, out obj));
        }
Exemplo n.º 23
0
 public override void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     base.GetObjectData(info, context);
     if (apiException != null)
     {
         info.AddValue("apiException", SerializationUtilities.SerializeAsXmlText(apiException));
         info.AddValue("apiExceptionType", apiException.GetType());
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// Converts the report definition to XML format.
        /// </summary>
        /// <param name="definition">The report definition.</param>
        /// <returns>The report definition serialized as an XML string.</returns>
        private string ConvertDefinitionToXml(IReportDefinition definition)
        {
            string xml = SerializationUtilities.SerializeAsXmlText(definition).Replace(
                "ReportDefinition", "reportDefinition");
            XmlDocument doc      = XmlUtilities.CreateDocument(xml);
            XmlNodeList xmlNodes = doc.SelectNodes("descendant::*");

            foreach (XmlElement node in xmlNodes)
            {
                node.RemoveAllAttributes();
            }
            return(doc.OuterXml);
        }
        public SequenceCollectionTypeInfo(Type collectionType)
        {
            collectionType.ThrowIfNull(nameof(collectionType));
            if (!typeof(IList).IsAssignableFrom(collectionType))
            {
                throw new ArgumentException(string.Format("{0} is not a {1}.", collectionType.Name, typeof(IList).Name));
            }

            genericType       = SerializationUtilities.GetGenericType(collectionType, typeof(IList <>));
            elementType       = (genericType != null) ? genericType.GetGenericArguments()[0] : typeof(object);
            isTypeConstrained = elementType != typeof(object);
            isArray           = collectionType.IsArray;
        }
        /// <summary>
        /// Save the state of the instance to a stream (that
        /// is, serialize it).
        /// </summary>
        /// <serialData> The length of the array backing the instance is
        /// emitted (int), followed by all of its elements (each an
        /// <see cref="System.Object"/>) in the proper order.
        /// </serialData>
        /// <param name="serializationInfo">the stream</param>
        /// <param name="context">the context</param>
        public virtual void GetObjectData(SerializationInfo serializationInfo, StreamingContext context)
        {
            SerializationUtilities.DefaultWriteObject(serializationInfo, context, this);

            // Write out array length
            serializationInfo.AddValue("Length", _queue.Length);

            // Write out all elements in the proper order.
            serializationInfo.AddValue("Data", ToArray());

            // Writer out the comparer if not the _defaultComparer.
            serializationInfo.AddValue("Comparer", Comparer);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Parses the XML response from the server into a type object.
        /// </summary>
        /// <typeparam name="T">The type of the object.</typeparam>
        /// <param name="contents">The XML contents.</param>
        /// <returns>The parsed object</returns>
        protected T ParseResponse <T>(string contents)
        {
            XmlDocument xDoc = XmlUtilities.CreateDocument(contents);

            string wrappedXml = string.Format(@"
          <?xml version='1.0' encoding='UTF-8'?>
          <root xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
            {0}
          </root>", xDoc.DocumentElement.OuterXml).Trim();

            return((T)SerializationUtilities.DeserializeFromXmlText(wrappedXml, typeof(T)));
        }
        private static bool HasBaseClassWithDeserializationConstructor(IClassLikeDeclaration classLikeDeclaration)
        {
            if (classLikeDeclaration.DeclaredElement is IClass declaredClass)
            {
                var superClass = declaredClass.GetSuperClass().NotNull("It's unexpected that the highlighting is displayed on System.Object");

                // NOTE: Yes, this will also return true if the base deserialization constructor is private/internal (which means that
                // there is probably an issue). But it may be better to leave non-compilable code than having the missing base call.
                return(SerializationUtilities.HasDeserializationConstructor(superClass));
            }

            return(false);
        }
        public void Draw(SerializedProperty property, ControlRect layout)
        {
            if (m_ImporterReferenceSerializedProperty == null || m_PropertiesArraySerializedProperty == null)
            {
                List <string> propertyNames = new List <string> {
                    "m_ImporterReference", "m_ConstrainProperties"
                };
                List <SerializedProperty> properties = SerializationUtilities.FindPropertiesInClass(property, propertyNames);
                m_ImporterReferenceSerializedProperty = properties[0];
                m_PropertiesArraySerializedProperty   = properties[1];
                if (m_ImporterReferenceSerializedProperty == null || m_PropertiesArraySerializedProperty == null)
                {
                    Debug.LogError("Invalid properties for ImporterPropertiesModule");
                    return;
                }
            }

            if (m_Module == null)
            {
                AuditProfile profile = property.serializedObject.targetObject as AuditProfile;
                if (profile == null)
                {
                    Debug.LogError("ImporterPropertiesModule must be apart of a profile Object");
                    return;
                }
                m_Module = profile.m_ImporterModule;
            }

            if (m_ImporterReferenceSerializedProperty != null)
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    EditorGUI.PropertyField(layout.Get(), m_ImporterReferenceSerializedProperty, new GUIContent("Importer Template"));
                    if (check.changed)
                    {
                        m_Module.m_AssetImporter = null;
                        m_Module.GatherProperties();
                    }
                }
            }

            if (m_ImporterReferenceSerializedProperty.objectReferenceValue != null)
            {
                ConstrainToPropertiesArea(layout);
            }
            else
            {
                Rect r = layout.Get(25);
                EditorGUI.HelpBox(r, "No template Object to constrain properties on.", MessageType.Warning);
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Registers a callback to the specified channel. callback argument is guaranteed to be a byte[] encoded MessagePackSerializableObject object
 /// Use SerializationUtilities to deserialize to the correct message, which should be paired to the channel
 /// </summary>
 public void Subscribe(MessageTypes channel, EventHandler <NetworkMessageContainer> callback)
 {
     _sub.Subscribe(channel.ToString(), (rc, rv) => {
         try
         {
             callback(this, SerializationUtilities.DeserializeMsgPack <NetworkMessageContainer>(rv));
         }
         catch (Exception e)
         {
             ConsoleManager.WriteLine("Redis exception! " + e.Message, ConsoleMessageType.Error);
             ConsoleManager.WriteLine(e.StackTrace, ConsoleMessageType.Error);
         }
     });
 }