Пример #1
0
        public static Result Export(string filepath, ImportedObject obj)
        {
            using (var ms = new MemoryStream())
            {
                using (var sr = new StreamReader(ms))
                {
                    var serializer = new DataContractJsonSerializer(typeof(ImportedObject));
                    serializer.WriteObject(ms, obj);
                    ms.Position = 0;

                    var json = sr.ReadToEnd();

                    Console.WriteLine(json);
                }
            }

            return(Result.Failed);
        }
Пример #2
0
        public static Result Export(string filepath, ImportedObject obj, bool encrypt)
        {
            if (string.IsNullOrWhiteSpace(filepath))
            {
                return(Result.InvalidPath);
            }

            string json = null;

            try
            {
                json = Util.SerializeJson(obj);
            }
            catch
            {
                return(Result.InvalidData);
            }

            if (encrypt)
            {
                var setting = Resources.SettingsPath;
                init(setting, 0, 0, -1);

                var pass = new string('\0', 32);
                getpass(setting, pass);

                json = Encrypter.Encrypt(json, pass);
            }

            try
            {
                File.WriteAllText(filepath, json);
            }
            catch
            {
                return(Result.InvalidPath);
            }

            return(Result.Success);
        }