Esempio n. 1
0
        public string GetNewChange(string change_id = "%")
        {
            New_Change newchange   = new New_Change(change_id);
            string     Json_String = "{" + JsonMaker.GetJSON(newchange) + "}";

            Logger.LogAction(((JObject)JsonConvert.DeserializeObject(Json_String)).ToString(), "JSON_Gets");
            return(Json_String);
        }
Esempio n. 2
0
 public void OnChangedTargetTransformValue(Vector3 pos)
 {
     if (_nowPhase == SYNC_PHASE.Syncing)
     {
         string data = JsonMaker.SendStringData(pos);
         _ws.Send(data);
     }
 }
Esempio n. 3
0
        public void TestDeserialize()
        {
            var    text  = new { Token = "tkn" };
            string json  = JsonMaker.Serialize(text);
            string token = JsonMaker.DeserializeToken(json);

            Assert.IsNotNull(token, "token != null");
            Assert.IsTrue(token == "tkn");
        }
    static void Main(string[] args)
    {
        string  data = "{ 'test': 42, 'test2': 'test2\"', 'structure' : { 'field1': 'field1', 'field2': 44 } }";
        dynamic x    = new DynamicJsonObject(JsonMaker.ParseJSON(data));

        Console.WriteLine(x.test2);
        Console.WriteLine(x.structure.field1);
        Console.ReadLine();
    }
Esempio n. 5
0
 public TablesData()
 {
     isJson    = appConfig.IsStoreToJson;
     isDB      = appConfig.IsStoreDataBase;
     jsonMaker = new JsonMaker()
     {
         isWrittenJson = false
     };
 }
Esempio n. 6
0
        public void TestSerialize()
        {
            int[]  x    = new[] { 1, 2, 3 };
            string json = JsonMaker.Serialize(x);

            json = Regex.Escape(json);
            string a = @"\[1,2,3]";

            Assert.IsTrue(json == a);
        }
Esempio n. 7
0
        /// <summary>Get and store token</summary>
        /// <returns>Success of authorization</returns>
        public bool Authorize(string username, string password, out HttpStatusCode statusCode)
        {
            var    loginData = new { username = username, password = password };
            string json      = JsonMaker.Serialize(loginData);
            string tokenJson = Send(AuthorizationUri, json, "application/json", out statusCode);

            if (statusCode == HttpStatusCode.OK)
            {
                Token = JsonMaker.DeserializeToken(tokenJson);
            }
            return(Token != null);
        }
Esempio n. 8
0
 public MainWindow()
 {
     InitializeComponent();
     ParamList = JsonMaker.JsonLoad(@"data\TableParam.json");
     //JsonMaker.JsonSave(ParamList, @"data\TableParam.json");
     ParamObs            = new ObservableCollection <TableParamStruct>(ParamList);
     cbTypes.ItemsSource = ParamObs;
     if (cbTypes.Items.Count > 0)
     {
         cbTypes.SelectedIndex = 0;
     }
     NumericUpDown nm = new NumericUpDown();
 }
Esempio n. 9
0
 public string SendActivities(Report activities, out HttpStatusCode statusCode)
 {
     return(Send(SendDataUri, JsonMaker.Serialize(activities), "application/json", out statusCode));
 }
Esempio n. 10
0
 public JsonMakerCreationEventArgs(Type objectType, JsonMaker maker)
 {
     ObjectType = objectType;
     Maker      = maker;
 }
Esempio n. 11
0
        private JsonMaker MakeJsonMaker(Type objectType)
        {
            // Specific custom deserialization
            JsonMaker customMaker = _TranslatorExtensions?.MakeJsonMaker(objectType);

            if (customMaker != null)
            {
                return(customMaker);
            }

            // String
            if (objectType == typeof(string))
            {
                return(obj =>
                {
                    if (obj == null)
                    {
                        return JsonObject.Null;
                    }
                    else
                    {
                        return new JsonObject(obj as string);
                    }
                });
            }

            // Nullable types
            if (objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                JsonMaker subObjectMaker = MakeJsonMaker(objectType.GetGenericArguments()[0]);
                return(obj =>
                {
                    if (obj == null)
                    {
                        return JsonObject.Null;
                    }
                    else
                    {
                        return subObjectMaker(obj);
                    }
                });
            }

            // Enums
            if (objectType.IsEnum)
            {
                return(obj => new JsonObject(obj.ToString()));
            }

            // Simple types
            foreach (var kvp in SIMPLE_TYPES)
            {
                if (objectType == kvp.Key)
                {
                    ConstructorInfo jtc = typeof(JsonObject).GetConstructor(new Type[] { kvp.Key });
                    return(obj => (JsonObject)jtc.Invoke(new object[] { obj }));
                }
            }

            // Parseable from string
            Func <string, object> parser = JsonReflection.GetParser(objectType);

            if (parser != null)
            {
                Func <object, string> toString = JsonReflection.GetToString(objectType);
                return(obj => new JsonObject(toString(obj)));
            }

            // Explicit Dictionary
            JsonReflection.DictionaryInfo dinfo = JsonReflection.IsDictionary(objectType);
            if (dinfo != null)
            {
                if (JsonReflection.GetParser(dinfo.KeyType) == null)
                {
                    throw new InvalidOperationException("Cannot create JsonMaker for type " + objectType.FullName + " because key type " + dinfo.KeyType.FullName + " cannot be parsed from a string");
                }
                JsonMaker    valueMaker    = GetJsonMaker(dinfo.ValueType);
                Type         kvpType       = typeof(KeyValuePair <,>).MakeGenericType(new Type[] { dinfo.KeyType, dinfo.ValueType });
                PropertyInfo keyProperty   = kvpType.GetProperty("Key");
                PropertyInfo valueProperty = kvpType.GetProperty("Value");

                return(obj =>
                {
                    if (obj == null)
                    {
                        return JsonObject.Null;
                    }
                    var result = JsonObject.EmptyDictionary;
                    foreach (var kvp in obj as IEnumerable)
                    {
                        result[keyProperty.GetValue(kvp).ToString()] = valueMaker(valueProperty.GetValue(kvp));
                    }
                    return result;
                });
            }

            // Array
            Type contentType = JsonReflection.GetEnumerableType(objectType);

            if (contentType != null)
            {
                return(obj =>
                {
                    if (obj == null)
                    {
                        return JsonObject.Null;
                    }
                    JsonMaker itemMaker = GetJsonMaker(contentType);
                    var items = new List <JsonObject>();
                    foreach (object item in (IEnumerable)obj)
                    {
                        items.Add(itemMaker(item));
                    }
                    return new JsonObject(items);
                });
            }

            // Object-as-Dictionary (choice of last resort)
            object defaultObj = JsonReflection.GetDefaultMaker(objectType)();

            var getters    = new Dictionary <string, MemberGetter>();
            var types      = new Dictionary <string, Type>();
            var equalities = new Dictionary <string, MethodInfo>();

            FieldInfo[] fields = objectType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (FieldInfo fi in fields)
            {
                if (fi.GetCustomAttribute <JsonIgnoreAttribute>() != null)
                {
                    continue;
                }

                string name = AdjustedFieldName(fi.Name);

                getters[name]    = obj => fi.GetValue(obj);
                types[name]      = fi.FieldType;
                equalities[name] = fi.FieldType.GetMethod("Equals", new Type[] { typeof(object) });
            }

            return(obj =>
            {
                var jfields = new Dictionary <string, JsonObject>();

                foreach (var kvp in getters)
                {
                    object objVal = kvp.Value(obj);
                    object defVal = kvp.Value(defaultObj);
                    MethodInfo equality = equalities[kvp.Key];
                    bool equal = defVal == null ? objVal == null : (bool)equality.Invoke(defVal, new object[] { objVal });
                    if (!equal)
                    {
                        jfields[kvp.Key] = GetJsonMaker(types[kvp.Key])(objVal);
                    }
                }

                return new JsonObject(jfields);
            });
        }
Esempio n. 12
0
        /// <summary>
        /// Reads data from CSV and XML files and store to Json format file or database depends on parameters.
        /// </summary>
        public void StoreDataFromFile()
        {
            try
            {
                DataSet dataSet = TablesCreation();

                if (isDB)
                {
                    foreach (var currentDataModel in storeData.Read())
                    {
                        dataSet.Tables["Team"].Rows.Add(currentDataModel.TeamID, currentDataModel.TeamName);
                        dataSet.Tables["Member"].Rows.Add(currentDataModel.MemberID, currentDataModel.TeamID, currentDataModel.PassportNumber, currentDataModel.MemberName, currentDataModel.MemberSurname);

                        for (int i = 0; i < currentDataModel.Projects.Length; i++)
                        {
                            DataRow[] foundProjects = dataSet.Tables["Project"].Select("ProjectID = '" + currentDataModel.Projects[i].ProjectID.ToString() + "'");
                            if (foundProjects.Length == 0)
                            {
                                dataSet.Tables["Project"].Rows.Add(currentDataModel.Projects[i].ProjectID, currentDataModel.Projects[i].ProjectName, currentDataModel.Projects[i].ProjectCreatedDate,
                                                                   currentDataModel.Projects[i].ProjectDueDate, currentDataModel.Projects[i].ProjectDescription);
                            }
                            dataSet.Tables["MemberProject"].Rows.Add(currentDataModel.MemberID, currentDataModel.Projects[i].ProjectID);
                        }
                    }
                    count = InsertBy(dataSet);

                    //If there is a trouble with storing data in database then switch to Json.
                    if (count == -1 && isJson == false)
                    {
                        isJson = true;
                    }
                }

                if (isJson)
                {
                    foreach (var currentDataModel in storeData.Read())
                    {
                        jsonMaker = new JsonMaker(currentDataModel, path, jsonPath);
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.DoLogging(LogType.Error, ex, "Error in process to storing/updating data.");
                MessageBox.Show(ex.Message);
                isWrittenDB = true;
            }

            if (isJson && !jsonMaker.isWrittenJson)
            {
                LogManager.DoLogging(LogType.Success, null, "Data succesfuly stored in json format.");
                jsonMaker.isWrittenJson = true;
            }

            if (isDB && !isWrittenDB && count != -1)
            {
                LogManager.DoLogging(LogType.Success, null, "Data succesfuly stored in Data Base.");
                isWrittenDB = true;
            }
            try
            {
                if (AppConfiguration.GetInstance.IsStoreToJson || AppConfiguration.GetInstance.IsStoreDataBase)
                {
                    File.Delete(path);
                }
            }
            catch (Exception ex)
            {
                LogManager.DoLogging(LogType.Error, ex);
            }
        }
Esempio n. 13
0
        public string GetPCR(string pcr_id = "%")
        {
            Utilities.UseRequiredFields = true;
            StringBuilder Pcr_Json = new StringBuilder();

            Pcr pcr = new Pcr(pcr_id);

            Pcr_Json.Append(JsonMaker.GetJSON(pcr) + System.Environment.NewLine);

            Dispatch Dispatch = new Dispatch(pcr.pcr_dispatch_id);

            Pcr_Json.Append("," + JsonMaker.GetJSON(Dispatch) + System.Environment.NewLine);

            List <Members> MembersList = Utilities.GetClassList <Members>("pcr_members", pcr_id, "pcr_id");

            Pcr_Json.Append("," + JsonMaker.GetJSONFromList(MembersList, Prefix: "pcr_members") + System.Environment.NewLine);

            Demographic Demographic = new Demographic(pcr.pcr_demographic_id);

            Pcr_Json.Append("," + JsonMaker.GetJSON(Demographic) + System.Environment.NewLine);

            Assessment Assessment = new Assessment(pcr.pcr_assessment_id);

            Pcr_Json.Append("," + JsonMaker.GetJSON(Assessment) + System.Environment.NewLine);

            Narrative_Notes Narrative_Notes = new Narrative_Notes(pcr.pcr_narrative_notes_id);

            Pcr_Json.Append("," + JsonMaker.GetJSON(Narrative_Notes) + System.Environment.NewLine);

            Rma Rma = new Rma(pcr.pcr_rma_id);

            Pcr_Json.Append("," + JsonMaker.GetJSON(Rma) + System.Environment.NewLine);

            Apcf Apcf = new Apcf(pcr.pcr_apcf_id);

            Pcr_Json.Append("," + JsonMaker.GetJSON(Apcf) + System.Environment.NewLine);

            Disposition Disposition = new Disposition(pcr.pcr_disposition_id);

            Pcr_Json.Append("," + JsonMaker.GetJSON(Disposition) + System.Environment.NewLine);

            Ems_run Ems_Run = new Ems_run(pcr.ems_run);

            Pcr_Json.Append("," + JsonMaker.GetJSON(Ems_Run) + System.Environment.NewLine);

            Narcotic Narcotic = new Narcotic(pcr.pcr_narcotics_id);

            Pcr_Json.Append("," + JsonMaker.GetJSON(Narcotic) + System.Environment.NewLine);

            PCR.Authorization Authorization = new PCR.Authorization(pcr.pcr_authorization_id);
            Pcr_Json.Append("," + JsonMaker.GetJSON(Authorization));

            string         SelectQuery = "(SELECT a.* FROM pcr_buttons a inner join all_buttons b on a.button_id = b.id inner join sections c on b.section_id = c.id) buttons";
            List <Buttons> ButtonsList = Utilities.GetClassList <Buttons>(SelectQuery, pcr_id, "pcr_id");

            Pcr_Json.Append("," + JsonMaker.GetJSONFromList(ButtonsList, Prefix: "pcr_buttons") + System.Environment.NewLine);

            SelectQuery = "(SELECT a.* FROM pcr_inputs a inner join all_buttons b on a.input_id = b.id inner join sections c on b.section_id = c.id) inputs";
            List <Inputs> InputsList = Utilities.GetClassList <Inputs>(SelectQuery, pcr_id, "pcr_id");

            Pcr_Json.Append("," + JsonMaker.GetJSONFromList(InputsList, Prefix: "pcr_inputs") + System.Environment.NewLine);

            Pcr_Json.Insert(0, "{");
            Pcr_Json.Append("}");
            Logger.LogAction(((JObject)JsonConvert.DeserializeObject(Pcr_Json.ToString())).ToString(), "JSON_Gets");
            return(Pcr_Json.ToString());
        }
        public void StoreActivitiesListInDbAsJson(List <Activity> activities)
        {
            string json = JsonMaker.Serialize(activities);

            DbHelper.StoreJsonInActivitiesRegistry(_connectionString, json);
        }