Exemple #1
0
        public ToolbarSettings GetSettings()
        {
            ToolbarSettings setts;
            var             settsFilePath = Path.Combine(Locations.AppDirectoryPath, Settings.Default.XToolbarSettingsFile);

            if (File.Exists(settsFilePath))
            {
                try
                {
                    setts = m_UserSettsSrv.ReadSettings <ToolbarSettings>(settsFilePath);
                }
                catch (Exception ex)
                {
                    throw new UserException($"Failed to read settings file at {settsFilePath}. Remove file to clear settings", ex);
                }
            }
            else
            {
                setts = new ToolbarSettings()
                {
                    SpecificationFile = ToolbarsDefaultSpecFilePath
                };
            }

            return(setts);
        }
        public void CustomConverterDerivedTypeTest()
        {
            var srv = new UserSettingsService();

            var setts = new SettsMock4()
            {
                Obj = new ObjectType2()
                {
                    Value = "XYZ"
                }
            };

            var res1 = new StringBuilder();

            var ser = new BaseValueSerializer <IObjectType>(x => x.Value, x => new ObjectType2()
            {
                Value = x
            });

            srv.StoreSettings(setts, new StringWriter(res1), ser);
            var res2 = srv.ReadSettings <SettsMock4>(new StringReader("{\"Obj\":\"ABC\"}"), ser);

            Assert.AreEqual("{\"Obj\":\"XYZ\"}", res1.ToString());
            Assert.AreEqual("ABC", res2.Obj.Value);
        }
        public void ReadSettingsTest()
        {
            var srv1 = new UserSettingsService(m_ServHelper.WorkingDir,
                                               new UserSettingsAttribute("SettsStorage", true));

            var srv2 = new UserSettingsService(m_ServHelper.WorkingDir,
                                               new UserSettingsAttribute("SettsStorage", true, typeof(SettsMockTransformer)));

            Directory.CreateDirectory(Path.Combine(m_ServHelper.WorkingDir, "SettsStorage"));

            var settsFile1 = Path.Combine(m_ServHelper.WorkingDir, "SettsStorage", "mock1.setts");
            var settsFile2 = Path.Combine(m_ServHelper.WorkingDir, "SettsStorage", "mock2.setts");

            File.WriteAllBytes(settsFile1, Resources.mock1);
            File.WriteAllBytes(settsFile2, Resources.mock2);

            var setts1 = srv1.ReadSettings <SettsMock1>("mock1");
            var setts2 = srv1.ReadSettings <SettsMock1>("mock2");
            var setts3 = srv1.ReadSettings <SettsMock2>("mock1");
            var setts4 = srv1.ReadSettings <SettsMock2>("mock2");
            var setts5 = srv2.ReadSettings <SettsMock1>("mock1");
            var setts6 = srv2.ReadSettings <SettsMock1>("mock2");
            var setts7 = srv2.ReadSettings <SettsMock2>("mock1");
            var setts8 = srv2.ReadSettings <SettsMock2>("mock2");

            Assert.AreEqual("AAA", setts1.Field1);
            Assert.AreEqual(10, setts1.Field2);
            Assert.AreEqual("BBB", setts2.Field1);
            Assert.AreEqual(default(double), setts2.Field2);
            Assert.AreEqual("AAA", setts3.Field1);
            Assert.AreEqual(default(double), setts3.Field3);
            Assert.AreEqual(default(bool), setts3.Field4);
            Assert.AreEqual("BBB", setts4.Field1);
            Assert.AreEqual(12.5, setts4.Field3);
            Assert.AreEqual(true, setts4.Field4);

            Assert.AreEqual("AAA", setts5.Field1);
            Assert.AreEqual(10, setts5.Field2);
            Assert.AreEqual("BBB", setts6.Field1);
            Assert.AreEqual(default(double), setts6.Field2);
            Assert.AreEqual("AAA", setts7.Field1);
            Assert.AreEqual(10, setts7.Field3);
            Assert.AreEqual(default(bool), setts7.Field4);
            Assert.AreEqual("BBB", setts8.Field1);
            Assert.AreEqual(12.5, setts8.Field3);
            Assert.AreEqual(true, setts8.Field4);
        }
        private ObservableCollection <QrCodeInfo> ReadQrCodeData()
        {
            ObservableCollection <QrCodeInfo> data = null;

            try
            {
                using (var stream = m_Drawing.TryOpenStream(STREAM_NAME, AccessType_e.Read))
                {
                    if (stream != null)
                    {
                        m_Logger.Log("Reading QR code data", LoggerMessageSeverity_e.Debug);

                        using (var reader = new StreamReader(stream))
                        {
                            data = m_Serializer.ReadSettings <ObservableCollection <QrCodeInfo> >(
                                reader, new PictureValueSerializer(m_Logger, m_Drawing));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                m_Logger.Log(ex);
            }

            if (data != null)
            {
                var usedPictures = new List <IXObject>();

                for (int i = data.Count - 1; i >= 0; i--)
                {
                    if (data[i].Picture == null)
                    {
                        data.RemoveAt(i);
                        m_Logger.Log($"Removed dangling QR code data at index {i}", LoggerMessageSeverity_e.Debug);
                    }
                    //As we serialize names of the features (removing and readding QR code may cause duplication in the data which is not recognized as dangling)
                    else if (usedPictures.Find(p => p.Equals(data[i].Picture)) != null)
                    {
                        data.RemoveAt(i);
                        m_Logger.Log($"Removed duplicate QR code data at index {i}", LoggerMessageSeverity_e.Debug);
                    }
                    else
                    {
                        usedPictures.Add(data[i].Picture);
                    }
                }
            }
            else
            {
                data = new ObservableCollection <QrCodeInfo>();
            }

            data.CollectionChanged += OnDataCollectionChanged;

            Init(data);

            return(data);
        }
Exemple #5
0
        internal static BatchJob FromFile(string filePath)
        {
            var svc = new UserSettingsService();

            var batchJob = svc.ReadSettings <BatchJob>(filePath);

            return(batchJob);
        }
        public void ReadSettingsTest()
        {
            var srv = new UserSettingsService();

            var mock1 = "{\"Field1\":\"AAA\",\"Field2\":10.0,\"__version\":\"0.0\"}";
            var mock2 = "{\"Field1\":\"BBB\",\"Field3\":12.5,\"Field4\":true,\"__version\":\"2.1.0\"}";

            var setts1 = srv.ReadSettings <SettsMock1>(new StringReader(mock1));
            var setts2 = srv.ReadSettings <SettsMock1>(new StringReader(mock2));
            var setts3 = srv.ReadSettings <SettsMock2>(new StringReader(mock2));
            var setts4 = srv.ReadSettings <SettsMock1>(new StringReader(mock1));
            var setts5 = srv.ReadSettings <SettsMock1>(new StringReader(mock2));
            var setts6 = srv.ReadSettings <SettsMock2>(new StringReader(mock1));
            var setts7 = srv.ReadSettings <SettsMock2>(new StringReader(mock2));

            Assert.AreEqual("AAA", setts1.Field1);
            Assert.AreEqual(10, setts1.Field2);
            Assert.AreEqual("BBB", setts2.Field1);
            Assert.AreEqual(default(double), setts2.Field2);
            Assert.AreEqual("BBB", setts3.Field1);
            Assert.AreEqual(12.5, setts3.Field3);
            Assert.AreEqual(true, setts3.Field4);

            Assert.AreEqual("AAA", setts4.Field1);
            Assert.AreEqual(10, setts4.Field2);
            Assert.AreEqual("BBB", setts5.Field1);
            Assert.AreEqual(default(double), setts5.Field2);
            Assert.AreEqual("AAA", setts6.Field1);
            Assert.AreEqual(10, setts6.Field3);
            Assert.AreEqual(default(bool), setts6.Field4);
            Assert.AreEqual("BBB", setts7.Field1);
            Assert.AreEqual(12.5, setts7.Field3);
            Assert.AreEqual(true, setts7.Field4);
        }
Exemple #7
0
        public static void ReadSettings()
        {
            //--- read
            var svc = new UserSettingsService();

            var userSetts = svc.ReadSettings <UserSettings>(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                             "my-app-settings.json"));
            //---
        }
Exemple #8
0
 public CustomToolbarInfo GetToolbar(string toolbarSpecFilePath)
 {
     if (File.Exists(toolbarSpecFilePath))
     {
         return(m_UserSettsSrv.ReadSettings <CustomToolbarInfo>(toolbarSpecFilePath));
     }
     else
     {
         return(new CustomToolbarInfo());
     }
 }
 public CustomToolbarInfo GetToolbar(out bool isReadOnly, string toolbarSpecFilePath)
 {
     if (File.Exists(toolbarSpecFilePath))
     {
         isReadOnly = !IsEditable(toolbarSpecFilePath);
         return(m_UserSettsSrv.ReadSettings <CustomToolbarInfo>(toolbarSpecFilePath));
     }
     else
     {
         isReadOnly = false;
         return(new CustomToolbarInfo());
     }
 }
        public void CustomConverterAndVersionTest()
        {
            var srv = new UserSettingsService();

            var setts = new SettsMock2()
            {
                Field1 = ""
            };

            var res1 = new StringBuilder();

            var ser = new BaseValueSerializer <string>(x => "ABC", x => "XYZ");

            srv.StoreSettings(setts, new StringWriter(res1), ser);
            var res2 = srv.ReadSettings <SettsMock2>(new StringReader("{\"Field1\":\"ABC\",\"Field3\":0.0,\"Field4\":false,\"__version\":\"2.1.0\"}"), ser);

            Assert.AreEqual("{\"Field1\":\"ABC\",\"Field3\":0.0,\"Field4\":false,\"__version\":\"2.1.0\"}", res1.ToString());
            Assert.AreEqual("XYZ", res2.Field1);
        }