Exemple #1
0
        public string GenerateJson()
        {
            string json = "";

            try{
                System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
                    new System.Web.Script.Serialization.JavaScriptSerializer();

                oSerializer.RegisterConverters
                    (new System.Web.Script.Serialization.JavaScriptConverter[]
                {
                    new DeviceJavaScriptConverter(),
                    new PublishPropertyJavaScriptConverter(),
                    new IncludesJavaScriptConverter(),
                    new SkinJavaScriptConverter(),
                    new ConditionJavaScriptConverter()
                });
                string sJSON = oSerializer.Serialize(this);
                json = sJSON;
            }catch (Exception ex) {
                Logger.Error(ex.Message);
                return("");
            }

            DeviceJSonFormatter djf = new DeviceJSonFormatter();

            json = djf.Format(json);

            return(json);
        }
Exemple #2
0
    public void getObject()
    {
        valid = true;
        try
        {
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            JsonObject = serializer.Deserialize(json, typeof(object));
            IDictionary <string, long> keyValue = new Dictionary <string, long>();
            DynamicQuery objDynamicQuery        = new DynamicQuery(objDataBaseManager);

            string strPrimaryColumn = objDataBaseManager.GetPrimaryColumn(tableName);
            if (strPrimaryColumn == string.Empty)
            {
                ErrorMessage = "[" + tableName + "]  is Primary Column not Found ";
                return;
            }
            else
            {
                keyValue.Add(strPrimaryColumn, Convert.ToInt64(JsonObject[strPrimaryColumn]));
            }

            //          objDynamicQuery.getObject(JsonObject, tableName, keyValue);


            JsonObject = objDynamicQuery.GetObject(tableName, Convert.ToInt64(JsonObject[strPrimaryColumn]));
        }
        catch (Exception e)
        {
            throw;
        }
    }
Exemple #3
0
    public dynamic SaveMaster()
    {
        var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

        serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
        JsonObject = serializer.Deserialize(json, typeof(object));
        IDictionary <string, long> keyValue = new Dictionary <string, long>();

        try
        {
            DynamicQuery objDynamicQuery = new DynamicQuery(objDataBaseManager);

            objDataBaseManager.BeginTransaction();
            objDynamicQuery.saveObject(JsonObject, tableName, keyValue);
            //tran.Commit();
            objDataBaseManager.commit();
        }
        catch (Exception e)
        {
            // tran.Rollback();
            objDataBaseManager.Rollback();
        }
        finally
        {
            //cn.Close();
            objDataBaseManager.closeConnection();
        }
        return(JsonObject);
    }
Exemple #4
0
        /// <summary>
        /// Output the replay as json with minimal post processing.
        /// No removal of duplicate data, no joining of new and updated data.
        /// </summary>
        /// <param name="replay"></param>
        /// <returns></returns>
        public string SerializeRaw(Replay replay)
        {
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            serializer.RegisterConverters(new List <JavaScriptConverter>()
            {
            });

            //Dictionary<int, ActorStateJson> actorStates = new Dictionary<int, ActorStateJson>();
            var frameJson = new List <string>();

            foreach (var f in replay.Frames.Where(x => x.ActorStates.Count > 0))
            {
                List <UInt32>         deletedActorStateIds = new List <UInt32>();
                List <ActorStateJson> newActorStates       = new List <ActorStateJson>();
                List <ActorStateJson> updatedActorStates   = new List <ActorStateJson>();

                Dictionary <int, ActorStateJson> actor = new Dictionary <int, ActorStateJson>();

                foreach (var a in f.ActorStates.Where(x => x.State == ActorStateState.Deleted))
                {
                    deletedActorStateIds.Add(a.Id);
                }

                foreach (var a in f.ActorStates.Where(x => x.State == ActorStateState.New))
                {
                    var actorState = new ActorStateJson();
                    actorState.Id              = a.Id;
                    actorState.UnknownBit      = a.Unknown1;
                    actorState.TypeName        = a.TypeName;
                    actorState.ClassName       = a.ClassName;
                    actorState.InitialPosition = a.Position;
                    actorState.Properties      = new List <ActorStateProperty>();
                    newActorStates.Add(actorState);
                }

                foreach (var a in f.ActorStates.Where(x => x.State == ActorStateState.Existing))
                {
                    var actorState = new ActorStateJson();
                    actorState.Id         = a.Id;
                    actorState.Properties = new List <ActorStateProperty>();

                    actorState.Properties = a.Properties.Select(p => new ActorStateProperty {
                        Name = p.PropertyName, Data = p.Data
                    }).ToList();

                    updatedActorStates.Add(actorState);
                }

                // Serializing at each frame to make sure we capture the state at each step.
                // Otherwise, since we're not cloning objects at each step, we'd serialize only the most recent set of data
                frameJson.Add(serializer.Serialize(new { Time = f.Time, DeletedActorIds = deletedActorStateIds, NewActors = newActorStates, UpdatedActors = updatedActorStates }));
            }
            return("[" + string.Join(",", frameJson) + "]");
        }
Exemple #5
0
        public string Serialize(Replay replay)
        {
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            serializer.RegisterConverters(new List <JavaScriptConverter>()
            {
                new ReplayJsonConverter(), new FrameJsonConverter(false), new MetadataPropertyConverter(), new ActorStateJsonConverter()
            });
            serializer.MaxJsonLength = 20 * 1024 * 1024;


            return(serializer.Serialize(replay));
        }
Exemple #6
0
 /* Misc Support */
 private static JavaScriptSerializer _getSerializer()
 {
     System.Web.Script.Serialization.JavaScriptSerializer serializer =
         new System.Web.Script.Serialization.JavaScriptSerializer(
             new FlorineTypeResolver()
             );
     serializer.RegisterConverters(
         new List <System.Web.Script.Serialization.JavaScriptConverter>
     {
         new NutrientSetConverter(),
         new IPageConverter()
     }
         );
     return(serializer);
 }
Exemple #7
0
        public string Serialize(Replay replay)
        {
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            serializer.RegisterConverters(new List <JavaScriptConverter>()
            {
                new ReplayJsonConverter(false, includeKeyFrames: false),
                new FrameJsonConverter(false),
                new MetadataPropertyConverter(false, (f) => replay.Frames[(int)f].Time),
                new MetadataPropertyDictionaryConverter(false, (f) => replay.Frames[(int)f].Time),
                new ActorStateJsonConverter(),
                new ClassNetCacheJsonConverter()
            });
            serializer.MaxJsonLength = 40 * 1024 * 1024;


            return(serializer.Serialize(replay));
        }
Exemple #8
0
    public string getJson()
    {
        string jsonData = string.Empty;

        try
        {
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            DynamicJsonConverter.DynamicJsonObject DynamicJsonObject = JsonObject;
            if (DynamicJsonObject != null)
            {
                jsonData = DynamicJsonObject.ToString();
            }
        }
        catch (Exception e)
        {
            throw;
        }
        return(jsonData);
    }
Exemple #9
0
    public dynamic getJsonObject(string json_str)
    {
        dynamic obj = null;

        try
        {
            if (json_str == null)
            {
                return(obj);
            }
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer()
            {
                MaxJsonLength = Int32.MaxValue // specify length as per your business requirement
            };
            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            obj = serializer.Deserialize(json_str, typeof(object));
        }
        catch (Exception exp)
        {
            Log("getJsonObject", exp.Message, true, exp);
        }
        return(obj);
    }
        /**/
        /// <summary>
        /// json 序列化
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <param name="propertys"></param>
        /// <returns></returns>
        public string Serialize <T>(T obj, List <string> propertys)
        {
            _serializer.RegisterConverters(new[] { new PropertyVariableConveter(typeof(T), propertys) });

            return(_serializer.Serialize(obj));
        }
Exemple #11
0
 static Updater()
 {
     jss.RegisterConverters(new JavaScriptConverter[] { new DateTimeConvert() });
 }
Exemple #12
0
        public string GenerateJson()
        {
            string json ="";

            try{

                System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
                     new System.Web.Script.Serialization.JavaScriptSerializer();

                oSerializer.RegisterConverters
                    (new System.Web.Script.Serialization.JavaScriptConverter[]
                     {
                        new DeviceJavaScriptConverter(),
                     	new PublishPropertyJavaScriptConverter(),
                        new IncludesJavaScriptConverter(),
                        new SkinJavaScriptConverter(),
                        new ConditionJavaScriptConverter()
                     });
                string sJSON = oSerializer.Serialize(this);
                json =  sJSON;

            }catch(Exception ex){
                Logger.Error(ex.Message);
                return "";
            }

            DeviceJSonFormatter djf= new DeviceJSonFormatter();
            json = djf.Format(json);

            return json;
        }
    protected override void Render(HtmlTextWriter writer)
    {
        writer.AddAttribute(HtmlTextWriterAttribute.Id, ContainerClientID);
        writer.RenderBeginTag(HtmlTextWriterTag.Div);
        writer.AddAttribute(HtmlTextWriterAttribute.Id, DataElementClientID);
        writer.AddAttribute(HtmlTextWriterAttribute.Name, DataElementUniqueID);
        writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
        IList<BXWeekScheduleHourSpanControl> hourControls = HourSpans;
        if (hourControls.Count > 0)
        {
            BXWeekScheduleHourSpan[] hours = new BXWeekScheduleHourSpan[hourControls.Count];
            for (int i = 0; i < hourControls.Count; i++)
                hours[i] = hourControls[i].Item;

            BXWeekScheduleHourSpanJSONConverter hourConverter = new BXWeekScheduleHourSpanJSONConverter(CultureInfo.InvariantCulture.DateTimeFormat);
            System.Web.Script.Serialization.JavaScriptSerializer jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            jsSerializer.RegisterConverters(new JavaScriptConverter[] { hourConverter });
            StringBuilder hoursJavascript = new StringBuilder();
            jsSerializer.Serialize(hours, hoursJavascript);

            writer.AddAttribute(HtmlTextWriterAttribute.Value, hoursJavascript.ToString(), true);
        }
        writer.RenderBeginTag(HtmlTextWriterTag.Input);
        writer.RenderEndTag();
        writer.RenderEndTag();
    }
Exemple #14
0
 static ConfigForm()
 {
     jss.RegisterConverters(new JavaScriptConverter[] { new DateTimeConvert() });
 }
Exemple #15
0
        private string serializeResponse(object data, Dictionary <String, Object> table)
        {
            String result = "";

            // table may contain a "serialisation" block with serialisation parameters from the
            // body of a post, or it may contain indeividual serialisation parameters which were provided
            // in the query string. Either way we need a one-off serialiser instance to process it.
            if (table != null &&
                (table.ContainsKey("serialization") ||
                 table.ContainsKey("gotodepth") ||
                 table.ContainsKey("listsatdepth") ||
                 table.ContainsKey("liststodepth")))   // These keys have already been forced to lower case...
            {
                var bespokeSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();

                RestSerializer bespokeConverter = new RestSerializer();
                if (table.ContainsKey("serialization"))
                {
                    Dictionary <String, Object> serializationParams = table["serialization"] as Dictionary <String, Object>;
                    if (serializationParams != null)
                    {
                        // ...but these keys haven't
                        string key = serializationParams.Keys.FirstOrDefault(k => k.Equals("listsatdepth", StringComparison.InvariantCultureIgnoreCase));
                        if (!string.IsNullOrEmpty(key))
                        {
                            string sListsToDepth = serializationParams[key].ToString();
                            RestSerializationDepth eListsToDepth;
                            if (Enum.TryParse <RestSerializationDepth>(sListsToDepth, out eListsToDepth))
                            {
                                bespokeConverter.ListsAtDepth = eListsToDepth;
                            }
                        }

                        key = serializationParams.Keys.FirstOrDefault(k => k.Equals("gotodepth", StringComparison.InvariantCultureIgnoreCase));
                        if (!string.IsNullOrEmpty(key))
                        {
                            string sGoToDepth = serializationParams[key].ToString();
                            RestSerializationDepth eGoToDepth;
                            if (Enum.TryParse <RestSerializationDepth>(sGoToDepth, out eGoToDepth))
                            {
                                bespokeConverter.GoToDepth = eGoToDepth;
                            }
                        }

                        key = serializationParams.Keys.FirstOrDefault(k => k.Equals("liststodepth", StringComparison.InvariantCultureIgnoreCase));
                        if (!string.IsNullOrEmpty(key))
                        {
                            string sListsToDepth = serializationParams[key].ToString();
                            bespokeConverter.ListsToDepth = resolveDepthSetting(sListsToDepth, bespokeConverter.ListsToDepth);
                            //RestSerializationDepth eListsToDepth;
                            //if (Enum.TryParse<RestSerializationDepth>(sListsToDepth, out eListsToDepth))
                            //{
                            //    bespokeConverter.ListsToDepth = eListsToDepth;
                            //}
                        }

                        key = serializationParams.Keys.FirstOrDefault(k => k.Equals("ignore", StringComparison.InvariantCultureIgnoreCase));
                        if (!string.IsNullOrEmpty(key))
                        {
                            foreach (object oIgnoreType in serializationParams[key] as Dictionary <String, Object> )
                            {
                                KeyValuePair <string, object> ignoreType = (KeyValuePair <string, object>)oIgnoreType;
                                Type      onType   = Type.GetType("Consensus." + ignoreType.Key + ", Consensus.Client");
                                ArrayList toIgnore = ignoreType.Value as ArrayList;

                                if (onType != null && toIgnore != null && toIgnore.Count > 0)
                                {
                                    bespokeConverter.Ignore.Add(onType, toIgnore.ToArray().ToList().ConvertAll <string>(i => i.ToString()));
                                }
                            }
                        }

                        key = serializationParams.Keys.FirstOrDefault(k => k.Equals("include", StringComparison.InvariantCultureIgnoreCase));
                        if (!string.IsNullOrEmpty(key))
                        {
                            foreach (object oIncludeType in serializationParams[key] as Dictionary <String, Object> )
                            {
                                KeyValuePair <string, object> includeType = (KeyValuePair <string, object>)oIncludeType;
                                Type      onType    = Type.GetType("Consensus." + includeType.Key + ", Consensus.Client");
                                ArrayList toInclude = includeType.Value as ArrayList;

                                if (onType != null && toInclude != null && toInclude.Count > 0)
                                {
                                    bespokeConverter.Include.Add(onType, toInclude.ToArray().ToList().ConvertAll <string>(i => i.ToString()));
                                }
                            }
                        }

                        key = serializationParams.Keys.FirstOrDefault(k => k.Equals("namedlistsresolvetodepth", StringComparison.InvariantCultureIgnoreCase));
                        if (!string.IsNullOrEmpty(key))
                        {
                            foreach (object oContainingType in serializationParams[key] as Dictionary <String, Object> )
                            {
                                KeyValuePair <string, object> containingType = (KeyValuePair <string, object>)oContainingType;
                                Type onType = Type.GetType("Consensus." + containingType.Key + ", Consensus.Client");
                                Dictionary <String, Object> lists = containingType.Value as Dictionary <String, Object>;
                                if (onType != null && lists != null)
                                {
                                    Dictionary <string, RestSerializationDepth> typeListSettings = new Dictionary <string, RestSerializationDepth>();
                                    foreach (KeyValuePair <string, object> list in lists)
                                    {
                                        RestSerializationDepth eListToDepth;
                                        if (Enum.TryParse <RestSerializationDepth>(list.Value.ToString(), out eListToDepth))
                                        {
                                            typeListSettings.Add(list.Key, eListToDepth);
                                        }
                                    }
                                    if (typeListSettings.Count > 0)
                                    {
                                        bespokeConverter.NamedListsResolveToDepth.Add(onType, typeListSettings);
                                    }
                                }
                            }
                        }
                    }
                }
                if (table.ContainsKey("gotodepth"))
                {
                    string sGoToDepth = table["gotodepth"].ToString();
                    RestSerializationDepth eGoToDepth;
                    if (Enum.TryParse <RestSerializationDepth>(sGoToDepth, out eGoToDepth))
                    {
                        bespokeConverter.GoToDepth = eGoToDepth;
                    }
                }
                if (table.ContainsKey("listsatdepth"))
                {
                    string sListsAtDepth = table["listsatdepth"].ToString();
                    RestSerializationDepth eListsAtDepth;
                    if (Enum.TryParse <RestSerializationDepth>(sListsAtDepth, out eListsAtDepth))
                    {
                        bespokeConverter.ListsAtDepth = eListsAtDepth;
                    }
                }
                if (table.ContainsKey("liststodepth"))
                {
                    string sListsToDepth = table["liststodepth"].ToString();
                    bespokeConverter.ListsToDepth = resolveDepthSetting(sListsToDepth, bespokeConverter.ListsToDepth);
                    //RestSerializationDepth eListsToDepth;
                    //if (Enum.TryParse<RestSerializationDepth>(sListsToDepth, out eListsToDepth))
                    //{
                    //    bespokeConverter.ListsToDepth = eListsToDepth;
                    //}
                }

                bespokeSerializer.RegisterConverters(new System.Web.Script.Serialization.JavaScriptConverter[] { bespokeConverter });
                return(bespokeSerializer.Serialize(data));
            }
            else
            {
                result = RestHandler.Serializer.Serialize(data);
            }

            return(result);
        }