Ejemplo n.º 1
0
Archivo: Setting.cs Proyecto: LiveFly/X
        /// <summary>加载完成后</summary>
        protected override void OnLoaded()
        {
            if (LogPath.IsNullOrEmpty())
            {
                LogPath = "Log";
            }
            if (DataPath.IsNullOrEmpty())
            {
                DataPath = "Data";
            }
            if (BackupPath.IsNullOrEmpty())
            {
                BackupPath = "Backup";
            }
            if (LogFileFormat.IsNullOrEmpty())
            {
                LogFileFormat = "{0:yyyy_MM_dd}.log";
            }

            if (PluginServer.IsNullOrWhiteSpace())
            {
                PluginServer = "http://x.newlifex.com/";
            }

            base.OnLoaded();
        }
Ejemplo n.º 2
0
Archivo: Setting.cs Proyecto: zeroyou/X
        /// <summary>加载完成后</summary>
        protected override void OnLoaded()
        {
            var web = Runtime.IsWeb;

            if (LogPath.IsNullOrEmpty())
            {
                LogPath = web ? "..\\Log" : "Log";
            }
            if (DataPath.IsNullOrEmpty())
            {
                DataPath = web ? "..\\Data" : "Data";
            }
            if (BackupPath.IsNullOrEmpty())
            {
                BackupPath = web ? "..\\Backup" : "Backup";
            }
            //if (TempPath.IsNullOrEmpty()) TempPath = web ? "..\\Temp" : "Temp";
            if (LogFileFormat.IsNullOrEmpty())
            {
                LogFileFormat = "{0:yyyy_MM_dd}.log";
            }

            if (PluginServer.IsNullOrWhiteSpace())
            {
                PluginServer = "http://x.newlifex.com/";
            }

            base.OnLoaded();
        }
Ejemplo n.º 3
0
        public bool InitBackup()
        {
            ServerUrl = ServerUrl.TrimEnd('/');

            store = new DocumentStore {
                Url = ServerUrl, DefaultDatabase = Database, ApiKey = ApiKey
            };
            store.Initialize();

            var json = @"{ ""BackupLocation"": """ + BackupPath.Replace("\\", "\\\\") + @""" }";

            var url = "/admin/backup";

            if (Incremental)
            {
                url += "?incremental=true";
            }
            var req = CreateRequest(url, "POST");

            req.Write(json);
            try
            {
                Console.WriteLine("Sending json {0} to {1}", json, ServerUrl);

                var response = req.ReadResponseJson();
                Console.WriteLine(response);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public bool InitBackup()
        {
            ServerUrl = ServerUrl.TrimEnd('/');

            var json = @"{ ""BackupLocation"": """ + BackupPath.Replace("\\", "\\\\") + @""" }";

            var uriString = ServerUrl + "/admin/backup";

            if (Incremental)
            {
                uriString += "?incremental=true";
            }
            var req = WebRequest.Create(uriString);

            req.Method = "POST";
            req.UseDefaultCredentials = true;
            req.PreAuthenticate       = true;
            req.Credentials           = CredentialCache.DefaultCredentials;

            using (var streamWriter = new StreamWriter(req.GetRequestStream()))
            {
                streamWriter.WriteLine(json);
                streamWriter.Flush();
            }

            try
            {
                Console.WriteLine("Sending json {0} to {1}", json, ServerUrl);

                using (var resp = req.GetResponse())
                    using (var reader = new StreamReader(resp.GetResponseStream()))
                    {
                        var response = reader.ReadToEnd();
                        Console.WriteLine(response);
                    }
            }
            catch (WebException we)
            {
                var response = we.Response as HttpWebResponse;
                if (response == null)
                {
                    Console.WriteLine(we.Message);
                    return(false);
                }
                Console.WriteLine(response.StatusCode + " " + response.StatusDescription);
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    Console.WriteLine(reader.ReadToEnd());
                    return(false);
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>加载后检查默认值</summary>
        protected override void OnLoaded()
        {
            if (SQLiteDbPath.IsNullOrEmpty())
            {
                SQLiteDbPath = Runtime.IsWeb ? "..\\Data" : "Data";
            }
            if (BackupPath.IsNullOrEmpty())
            {
                BackupPath = Runtime.IsWeb ? "..\\Backup" : "Backup";
            }

            base.OnLoaded();
        }
Ejemplo n.º 6
0
        private String ConvertBackupPath()
        {
            var Desktop  = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            var _Desktop = BackupPath.Replace("{{Desktop}}", Desktop);

            if (!Directory.Exists(_Desktop))
            {
                Directory.CreateDirectory(_Desktop);
            }


            return(_Desktop);
        }
Ejemplo n.º 7
0
        public bool InitBackup()
        {
            ServerUrl = ServerUrl.TrimEnd('/');

            var json = @"{ ""BackupLocation"": """ + BackupPath.Replace("\\", "\\\\") + @""" }";

            var req = WebRequest.Create(ServerUrl + "/admin/backup");

            req.Method = "POST";
            req.UseDefaultCredentials = true;
            req.PreAuthenticate       = true;
            req.Credentials           = CredentialCache.DefaultCredentials;

            using (var streamWriter = new StreamWriter(req.GetRequestStream()))
            {
                streamWriter.WriteLine(json);
                streamWriter.Flush();
            }

            try
            {
                Console.WriteLine(string.Format("Sending json {0} to {1}", json, ServerUrl));

                using (var resp = req.GetResponse())
                    using (var reader = new StreamReader(resp.GetResponseStream()))
                    {
                        var response = reader.ReadToEnd();
                        Console.WriteLine(response);
                    }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        public bool InitBackup()
        {
            ServerUrl = ServerUrl.TrimEnd('/');
            try //precaution - to show error properly just in case
            {
                var serverUri = new Uri(ServerUrl);
                if ((String.IsNullOrWhiteSpace(serverUri.PathAndQuery) || serverUri.PathAndQuery.Equals("/")) &&
                    String.IsNullOrWhiteSpace(Database))
                {
                    Database = Constants.SystemDatabase;
                }

                var serverHostname = serverUri.Scheme + Uri.SchemeDelimiter + serverUri.Host + ":" + serverUri.Port;

                store = new DocumentStore {
                    Url = serverHostname, DefaultDatabase = Database, ApiKey = ApiKey
                };
                store.Initialize();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                try
                {
                    store.Dispose();
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch (Exception) { }
                return(false);
            }


            var backupRequest = new
            {
                BackupLocation   = BackupPath.Replace("\\", "\\\\"),
                DatabaseDocument = new DatabaseDocument {
                    Id = Database
                }
            };

            var json = RavenJObject.FromObject(backupRequest).ToString();

            var url = "/admin/backup";

            if (Incremental)
            {
                url += "?incremental=true";
            }
            try
            {
                var req = CreateRequest(url, "POST");

                req.WriteAsync(json).Wait();

                Console.WriteLine("Sending json {0} to {1}", json, ServerUrl);

                var response = req.ReadResponseJson();
                Console.WriteLine(response);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                return(false);
            }

            return(true);
        }