Example #1
0
        public void Load(string path, Enum @enum)
        {
            switch (@enum)
            {
            case CurrentDocType.Json:
            {
                var json = new JsonTranslator(CurrentDocumentType, FutureDocumentType, FilePath);
                json.Translate(FutureDocumentType);
                break;
            }

            case CurrentDocType.Xml:
            {
                var          serializer = new XmlSerializer(typeof(root));
                StreamReader reader     = new StreamReader(FilePath);
                XmlRoot = (root)serializer.Deserialize(reader);
                reader.Close();
                break;
            }

            case CurrentDocType.Html:
            {
                var html = new HtmlTranslator(CurrentDocumentType, FutureDocumentType, FilePath);
                html.Translate(FutureDocumentType);
                break;
            }
            }
        }
 /// <summary>
 /// Saves the information from a list into a data source, in this case - a file.
 /// </summary>
 public void SaveToDataSource()
 {
     using (StreamWriter writer = new StreamWriter(PathToDataSource))
     {
         string output = JsonTranslator.ObjToJson(Storage.Values);
         writer.Write(output);
     }
 }
        public void MakeObjectTest_Basic()
        {
            var    bc1        = new Classes.BasicClass("foo", 123, 456.789);
            var    translator = new JsonTranslator();
            string json       = translator.MakeJson(bc1).ToString();

            Classes.BasicClass bc2 = translator.MakeObject <Classes.BasicClass>(JsonObject.Parse(json));
            Assert.IsTrue(Classes.BasicClass.AreEqual(bc1, bc2));
        }
        public static JObject GetDevice(long referenceId)
        {
            var device = Device.AllDevices.Find(x => x.ReferenceId == referenceId);

            if (device == null)
            {
                return(null);
            }
            return(JsonTranslator.ObjectToJson(device));
        }
        /// <summary>
        /// Fills the a list with the info from a data source, in this case - a file.
        /// </summary>
        /// <returns></returns>
        public List <TEntity> GetFromDataSource()
        {
            using (StreamReader reader = new StreamReader(PathToDataSource))
            {
                string jsonFileInput = reader.ReadToEnd();
                Data = JsonTranslator.JsonToList <TEntity>(jsonFileInput);

                return(Data);
            }
        }
        public static JObject GetThing(long referenceId)
        {
            Thing thing;

            if (!XmlSaveLoad.Referencables.TryGetValue(referenceId, out thing))
            {
                return(null);
            }
            return(JsonTranslator.ObjectToJson(thing));
        }
        public static IList <JObject> GetItems()
        {
            // AllDevices has duplicates, so filtering this to be safe.
            var set = new HashSet <Item>();

            foreach (var item in Item.AllItems)
            {
                set.Add(item);
            }
            return(set.Select(x => JsonTranslator.ObjectToJson(x)).ToList());
        }
        public static IList <JObject> GetDevices()
        {
            // Devices can have duplicates in this list.
            var set = new HashSet <Device>();

            foreach (var device in Device.AllDevices)
            {
                set.Add(device);
            }
            return(set.Select(x => JsonTranslator.ObjectToJson(x)).ToList());
        }
Example #9
0
        static async Task Main(string[] args)
        {
            string lang = "fr";
            // Prompts you for text to translate. If you'd prefer, you can
            // provide a string as textToTranslate.

            JsonTranslator translator = new JsonTranslator();

            await translator.TranslateFile(lang,
                                           @"C:\VS2019\FAC\Scor.Facultative.Web.Angular\ClientApp\src\assets\i18n\en.json",
                                           $@"C:\VS2019\FAC\Scor.Facultative.Web.Angular\ClientApp\src\assets\i18n\{lang}.json");
        }
Example #10
0
        private void ListBoxItem_ViewCurrentDocumentType_OnSelected(object p_sender, RoutedEventArgs p_e)
        {
            FilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                    @"Components\DefaultLisaResume.json");
            JsonTranslator json = new JsonTranslator(Translator.CurrentDocType.Json,
                                                     Translator.FutureDocType.Json, FilePath);

            json.Translate(Translator.FutureDocType.Json);

            Clipboard.SetText(FilePath);

            //SampleCodePages.Content = new SampleCodePage(FilePath);
        }
        public void ConvertJson()
        {
            // Arrange
             const string json = "{ \"Name\": \"Test\", \"Valid\": true }";

             // Act
             var translator = new JsonTranslator(typeof (ComplexType));
             var result = translator.Translate(json);

             // Assert
             Assert.IsNotNull(result);
             Assert.IsInstanceOf<ComplexType>(result);
        }
        public void MakeObjectTest_Complex()
        {
            Classes.ComplexClass cc1 = Classes.ComplexClass.MakeExample1();
            cc1.IgnoredDouble = 123;
            var    translator = new JsonTranslator();
            string json       = translator.MakeJson <Classes.ComplexClass>(cc1).ToMultilineString();

            cc1.IgnoredDouble = 321;
            Classes.ComplexClass cc2 = translator.MakeObject <Classes.ComplexClass>(JsonObject.Parse(json));
            string notEqualBecause   = Classes.ComplexClass.NotEqualBecause(cc1, cc2);

            Assert.IsNull(notEqualBecause, notEqualBecause);
        }
        public void ConvertJsonWithValidProperties()
        {
            // Arrange
             const string json = "{ \"Name\": \"Test\", \"Valid\": true }";

             // Act
             var translator = new JsonTranslator(typeof(ComplexType));
             dynamic result = translator.Translate(json);

             // Assert
             Assert.IsNotNull(result);
             Assert.AreEqual("Test", result.Name);
             Assert.AreEqual(true, result.Valid);
        }
 public static IList <JObject> GetThings()
 {
     // This seems to have prefabs in it.  Not sure how to filter those out apart from checking ReferenceId 0
     return(OcclusionManager.AllThings.Keys.Where(x => x.ReferenceId != 0).Select(thing =>
     {
         try
         {
             return JsonTranslator.ObjectToJson(thing);
         }
         catch (Exception ex)
         {
             Logging.Log("GetThings: Exception deserializing thing id {0}: {1}\n{2}", thing.ReferenceId, ex.Message, ex.StackTrace);
             return null;
         }
     }).Where(x => x != null).ToList());
 }
        public static JObject UpdateDevice(long referenceId, JObject updates)
        {
            var device = Device.AllDevices.Find(x => x.ReferenceId == referenceId);

            if (device == null)
            {
                return(null);
            }

            try
            {
                JsonTranslator.UpdateObjectFromJson(updates, device);
            }
            catch (JsonTranslationException e)
            {
                throw new BadRequestException(e.Message);
            }
            return(JsonTranslator.ObjectToJson(device));
        }
        public static JObject UpdateThing(long referenceId, JObject updates)
        {
            Thing thing;

            if (!XmlSaveLoad.Referencables.TryGetValue(referenceId, out thing))
            {
                return(null);
            }

            try
            {
                JsonTranslator.UpdateObjectFromJson(updates, thing);
            }
            catch (JsonTranslationException e)
            {
                throw new BadRequestException(e.Message);
            }
            return(JsonTranslator.ObjectToJson(thing));
        }
        public void MakeObjectTest_CustomConversion()
        {
            var translator = new JsonTranslator();

            translator.JsonMakerCreated += (sender, e) =>
            {
                JsonTranslator.JsonMaker originalMaker = e.Maker;
                e.Maker = obj =>
                {
                    JsonObject baseJson = originalMaker(obj);
                    return(new JsonObject(new Dictionary <string, JsonObject>()
                    {
                        { "Type", new JsonObject(e.ObjectType.Name) },
                        { "Version", new JsonObject(new int[] { 1, 0, 0 }.Select(i => new JsonObject(i))) },
                        { "Value", baseJson }
                    }));
                };
            };
            translator.ObjectMakerCreated += (sender, e) =>
            {
                JsonTranslator.ObjectMaker originalMaker = e.Maker;
                e.Maker = json =>
                {
                    return(originalMaker(json.Dictionary["Value"]));
                };
            };

            var    bc1        = new Classes.BasicClass("foo", 123, 456.789);
            string jsonString = translator.MakeJson(bc1).ToString();

            Classes.BasicClass bc2 = translator.MakeObject <Classes.BasicClass>(JsonObject.Parse(jsonString));
            Assert.IsTrue(Classes.BasicClass.AreEqual(bc1, bc2));

            Classes.ComplexClass cc1 = Classes.ComplexClass.MakeExample1();
            cc1.IgnoredDouble = 123;
            jsonString        = translator.MakeJson <Classes.ComplexClass>(cc1).ToMultilineString();
            cc1.IgnoredDouble = 321;
            Classes.ComplexClass cc2 = translator.MakeObject <Classes.ComplexClass>(JsonObject.Parse(jsonString));
            string notEqualBecause   = Classes.ComplexClass.NotEqualBecause(cc1, cc2);

            Assert.IsNull(notEqualBecause, notEqualBecause);
        }
        void Awake()
        {
            WebAPIPlugin.Instance = this;

            WebAPI.Config.LoadConfig();
            Dispatcher.Initialize();

            if (WebAPI.Config.Instance.Enabled)
            {
                this.ApplyPatches();

                var ownAssembly = typeof(WebAPIPlugin).Assembly;
                this.RegisterControllers(ownAssembly);
                JsonTranslator.LoadJsonTranslatorStrategies(ownAssembly);
            }
            else
            {
                Logging.Log("WebAPI is disabled.");
            }
        }
Example #19
0
        public SampleCodePage(string path)
        {
            InitializeComponent();

            object o = SampleCodePages.Content;

            if (path == "")
            {
                FilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                        @"Components\DefaultLisaResume.json");
                path = FilePath;
                JsonTranslator json = new JsonTranslator(Translator.CurrentDocType.Json,
                                                         Translator.FutureDocType.Json, FilePath);
                json.Translate(Translator.FutureDocType.Json);

                Clipboard.SetText(FilePath);
            }

            panel      = new System.Windows.Forms.Panel();
            host.Child = panel;
            dockIt("notepad.exe", path);
        }
 public DictToJsonConversionTests()
 {
     _translator = new JsonTranslator();
 }
 public JsonToDictConversionTests()
 {
     _translator = new JsonTranslator();
 }