コード例 #1
0
        /* TODO add support for other databases.*/

        public Database()
        {
            var setting = SettingObj.Read();

            if (!setting.DataBase.Equals("mysql", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new InvalidOperationException("DB setting is wrone!");
            }
            this.serverAddr = setting.DataBase_Addr;
            this.uid        = setting.DataBase_User;
            this.pwd        = setting.DataBase_Pw;
            this.port       = setting.DataBase_Port ?? 3306;
            baseConnection  = new MySqlConnection($"Server={serverAddr};Uid={uid};Pwd={pwd};Database={DATABASENAME};Port={port};SslMode=Preferred;");

            if (ValidDatabase())
            {
                if (!ValidTable())
                {
                    throw new EntryPointNotFoundException("Invalid DataBase has been used on this session.");
                }
                else
                {
                    baseConnection.Open();
                }
            }
            else if (!CreateDatabase())
            {
                throw new EntryPointNotFoundException("Invalid DataBase has been used on this session.");
            }
            else
            {
                baseConnection.Open();
            }
        }
コード例 #2
0
        public IEnumerable <RmtFile> LoadData(bool loadAll = false)
        {
            var mCon = new MySqlConnection($"Server={serverAddr};Uid={uid};Pwd={pwd};Port={port};Database={DATABASENAME};SslMode=Preferred;");
            var cmd  = new MySqlCommand($"SELECT `id`,  `time`,  `name`,  `path`,  `isuploaded`,  `showonuploader`, `uploadid`, `upprogress`, `initialfoldername` " +
                                        $"FROM `{TABLE_RECORDED}` " +
                                        (loadAll ? "" : "WHERE `showonuploader` = '1' AND `isuploaded` = '0'") +
                                        $"ORDER BY `time` ASC LIMIT 1000", mCon);
            MySqlDataReader result = null;

            try
            {
                mCon.Open();
                result = cmd.ExecuteReader();
            }
            catch (MySqlException e)
            {
                "Database Error:{0}".ErrorLognConsole(e.Message);
                yield break;
            }
            catch (Exception e)
            {
                "Unknow error occured when reading database : {0}".ErrorLognConsole(e.Message);
                yield break;
            }
            string root = SettingObj.Read().StorageFolder;

            while (result.Read())
            {
                var tmp  = result["initialfoldername"];
                var item = new RmtFile(System.IO.Path.Combine(root, (string)result["path"]), !(tmp == DBNull.Value), (tmp == DBNull.Value ? string.Empty:tmp.ToString()), true);
                item.ID = (string)result["id"];
                yield return(item);
            }
            cmd.Dispose();
            mCon.Close();
        }
コード例 #3
0
        public static bool SortFile(string[] margs)
        {
            "App started.".InfoLognConsole();
            SettingObj mySetting = null;
            bool       a         = false;

            while (!a)
            {
                Console.WriteLine("Reading settings.");

                try
                {
                    mySetting = SettingObj.Read();
                    //mySetting = ((dynamic)Activator.CreateInstance(SettingObj)).Read();
                    a = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error : {0}", ex.Message);
                    "Fail to read settings [{0}]".InfoLognConsole(ex.Message);
                    Console.WriteLine("Sleep 10 sec...");
                    System.Threading.Tasks.Task.Delay(10000);
                }
            }
            EPGAccess  mAccess = null;
            StreamFile mpars   = null;

            if (margs.Any(x => x.Equals("-main", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.MasterViewControl();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-mirakurun", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MirakurunWarpper.MirakurunViewer();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-setup", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.Setting();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-rcdbview", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.RecordedListView();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-cloud", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.CloudViewer();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-upload", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.Uploader();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-epgstation", StringComparison.OrdinalIgnoreCase)))
            {
                Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=EPGstation=-=-=-=-=-=-=-=-=-=-=-");
                // Start process the parameters, group them to their own entries.
                List <string> clPara = new List <string>();
                if (margs.Count() <= 1)
                {
                    return(false);/* TODO Change to default(_) if this is not a reference type */
                }
                System.Text.StringBuilder sbb = new System.Text.StringBuilder();
                foreach (var p in margs)
                {
                    if (p.StartsWith("-"))
                    {
                        var tmp = sbb.ToString();
                        if (tmp.Length > 1 && tmp.StartsWith("-"))
                        {
                            clPara.Add(tmp);
                        }
                        sbb.Clear(); // Clear the stringbuilder every time it hits the char "-"
                        sbb.Append(p);
                    }
                    else
                    {
                        sbb.AppendFormat(" {0}", p);
                    }
                }
                "App start with parameter\"{0}\"".InfoLognConsole(sbb.ToString());
                clPara.Add(sbb.ToString()); // Lack of the last run in the loop, so add the last parameter manuly.
                int  id      = -1;
                bool t_check = false;
                try
                {//first see para -id
                    t_check = int.TryParse(clPara.First(x => x.StartsWith("-id")).Substring(4), out id);
                }
                catch
                {
                    t_check = false;
                }
                if (!t_check)
                {//if -id is not working, try get enviroment variable. maybe not working.
                    "parameter -id not found or not a number.".ErrorLognConsole();
                    var e_id = Environment.GetEnvironmentVariable("RECORDEDID");
                    if (!e_id.IsNullOrEmptyOrWhiltSpace() && !int.TryParse(e_id, out id))
                    {
                        "Failed to find \"RECORDEDID\" from Enviorment variable".ErrorLognConsole();
                        "App catch error. exiting...".InfoLognConsole();
                        return(false);
                    }
                    "Environment Variable \"RECORDEDID={0}\"".InfoLognConsole(id.ToString());
                }
                Console.WriteLine("Preparing for access Epgstation server.");
                mAccess = new EPGAccess(mySetting);
                mpars   = mAccess.GetStreamFileObj(id);
                if (mpars == null)
                {
                    "Remote file is missing or \"ID:{0}\" does not exsits.".ErrorLognConsole(id.ToString());
                    "App catch error. exiting...".InfoLognConsole();
                    return(false);
                }
                if (mpars.ChannelName.IsNullOrEmptyOrWhiltSpace())
                {
                    string channel = "";
                    try
                    {
                        channel = clPara.First(x => x.StartsWith("-cn")).Substring(4);
                    }
                    catch
                    {
                        channel = "UNKNOW";
                    }
                    finally
                    {
                        mpars.ChannelName = channel;
                    }
                }
            }
            else
            {
                mpars = GetPara(margs);
            }
            if (mpars == null)
            {
                return(false);
            }
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (var p in margs)
            {
                sb.Append(p + " ");
            }
            PrintInfomation(mpars);
            if (!MoveFile(mpars, mySetting, mAccess))
            {
                "Local file is missing : \"File:{0}\" does not exsit.".ErrorLognConsole(System.IO.Path.GetFileName(mpars.FilePath));
                "App catch error. exiting...".InfoLognConsole();
                return(false);
            }
            ;
            "App has completed job. exiting...".InfoLognConsole();
            return(true);
        }
コード例 #4
0
 private void Settings_Load(object sender, EventArgs e)
 {
     mySetting = SettingObj.Read();
     SettingToForm();
 }