예제 #1
0
 private async Task CreateLibraryInstanceAsync()
 {
     try
     {
         Library = await DataBaseEngine.FetchAllAsync();
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
     }
 }
예제 #2
0
 private void InitializeDBMS()
 {
     try
     {
         Debug.WriteLine("DBMS Initialize");
         DataBaseEngine.Initialize();
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
     }
 }
예제 #3
0
 private DataSet selectStored(DataBaseEngine database, string StoredProcedureName, Parameter Add, out ArrayList Output)
 {
     if (database.TryConnectiongToServer())
     {
         Output = new ArrayList();
         SqlConnection  con = new SqlConnection();
         SqlCommand     cmd = new SqlCommand();
         SqlDataAdapter adp = new SqlDataAdapter();
         DataSet        ds  = new DataSet();
         con.ConnectionString = database.ConnectionString;
         cmd.Connection       = con;
         cmd.CommandText      = StoredProcedureName;
         cmd.CommandType      = CommandType.StoredProcedure;
         int Total = Add.Total;
         int Out   = Add.Output;
         if (Total != 0)
         {
             for (int i = 0; i < Add.Total; i++)
             {
                 cmd.Parameters.Add((string)Add.Parameters[Total * 4 - 4], (SqlDbType)Add.Parameters[Total * 4 - 3], (int)Add.Parameters[Total * 4 - 2]);
                 cmd.Parameters[(string)Add.Parameters[Total * 4 - 4]].Value = (string)Add.Parameters[Total * 4 - 1];
                 Total--;
             }
         }
         if (Out != 0)
         {
             for (int i = 0; i < Add.Output; i++)
             {
                 cmd.Parameters.Add(new SqlParameter(
                                        (string)Add.Parameters[(Add.Total + Out) * 4 - 4],
                                        (SqlDbType)Add.Parameters[(Add.Total + Out) * 4 - 3],
                                        (int)Add.Parameters[(Add.Total + Out) * 4 - 2])).Direction =
                     (ParameterDirection)Add.Parameters[(Add.Total + Out) * 4 - 1];
                 Out--;
             }
         }
         adp.SelectCommand = cmd;
         adp.Fill(ds);
         Out = Add.Output;
         for (int i = 0; i < Add.Output; i++)
         {
             Output.Add(cmd.Parameters[(string)Add.Parameters[(Add.Total + Out) * 4 - 4]].Value);
             Out--;
         }
         return(ds);
     }
     else
     {
         Output = null;
         return(null);
     }
 }
예제 #4
0
 public bool CreatePlaylist(string playlistName)
 {
     if (!DataBaseEngine.PlaylistNameAvailable(playlistName))
     {
         return(false);
     }
     else
     {
         DataBaseEngine.CreatePlaylist(playlistName);
         RefreshLibrary();
         return(true);
     }
 }
예제 #5
0
 private DataSet select(DataBaseEngine database, string selectStatement, SqlDbType[] Types, int[] size, string[] Values)
 {
     if (database.TryConnectiongToServer())
     {
         DataSet       ds  = new DataSet();
         SqlConnection con = new SqlConnection(database.ConnectionString);
         SqlCommand    cmd = new SqlCommand(selectStatement, con);
         AddParameter(CountChar(selectStatement), selectStatement, cmd, Types, size, Values);
         SqlDataAdapter adp = new SqlDataAdapter(cmd);
         adp.Fill(ds);
         return(ds);
     }
     else
     {
         return(null);
     }
 }
예제 #6
0
 public DataSet insertClass(DataBaseEngine database, string insertStatement, Parameter Add, DataSet Old)
 {
     if (database.TryConnectiongToServer())
     {
         DataSet       ds = new DataSet(); SqlDataAdapter dp;
         SqlConnection con = new SqlConnection(database.ConnectionString);
         SqlCommand    cmd = new SqlCommand(insertStatement, con);
         ds = addParameterClass(CountChar(insertStatement), insertStatement, cmd, Add, Old);
         dp = new SqlDataAdapter();
         dp.InsertCommand = cmd;
         dp.Update(ds.Tables[0]);
         return(ds);
     }
     else
     {
         return(null);
     }
 }
예제 #7
0
        private async Task LoadLibraryDiskAsync()
        {
            try
            {
                Debug.WriteLine("Library Initialize");
                var result = await LibraryEngine.Initialize(IsFirstUse);

                foreach (var i in result)
                {
                    if (i.Value.GetType().Name == "StorageFile") //Add/Update DataBase
                    {
                        //Debug.WriteLine("StorageFile");
                        if (i.Key == StorageLibraryChangeType.ContentsChanged)
                        {
                            //Debug.WriteLine("ContentChanged");
                            await DataBaseEngine.Update(i.Value as StorageFile);
                        }
                        else if (i.Key == StorageLibraryChangeType.MovedIntoLibrary)
                        {
                            //Debug.WriteLine("MovedIntoLibrary");
                            await DataBaseEngine.Add((StorageFile)i.Value);
                        }
                    }
                    else if (i.Value.GetType().Name == "String") //Moved Out
                    {
                        //Debug.WriteLine("Move out");
                        DataBaseEngine.Delete(i.Value.ToString());
                    }
                    else if (i.Value.GetType().Name == "KeyValuePair`2") //Moved or Renamed
                    {
                        //Debug.WriteLine("Moved or Renamed");
                        DataBaseEngine.Update((KeyValuePair <string, string>)i.Value);
                    }
                }
                //InitializeFinished?.Invoke(null, EventArgs.Empty);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
예제 #8
0
 private DataSet selectClass(DataBaseEngine database, string selectStatement, Parameter Add)
 {
     if (database.TryConnectiongToServer())
     {
         DataSet       ds  = new DataSet();
         SqlConnection con = new SqlConnection(database.ConnectionString);
         SqlCommand    cmd = new SqlCommand(selectStatement, con);
         int           num = CountChar(selectStatement);
         if (num != 0)
         {
             AddParameterClass(num, selectStatement, cmd, Add);
         }
         SqlDataAdapter adp = new SqlDataAdapter(cmd);
         adp.Fill(ds);
         return(ds);
     }
     else
     {
         return(null);
     }
 }
예제 #9
0
파일: xml.cs 프로젝트: ahmedfahim/PMMS
 public void WriteXml(DataBaseEngine DataBase, string TableName, string XmlName, string SchemaName)
 {
     if (DataBase.TryConnectiongToServer())
     {
         DataSet        ds  = new DataSet();
         SqlConnection  con = new SqlConnection(DataBase.ConnectionString);
         SqlCommand     cmd = new SqlCommand("select " + TableName + ".* from " + TableName, con);
         SqlDataAdapter dep = new SqlDataAdapter(cmd);
         dep.Fill(ds);
         if (SchemaName == null)
         {
             ds.WriteXml(XmlName);
         }
         else if (XmlName == null)
         {
             ds.WriteXmlSchema(SchemaName);
         }
         else
         {
             ds.WriteXml(XmlName);
             ds.WriteXmlSchema(SchemaName);
         }
     }
 }
예제 #10
0
 public void AddSongsToPlaylist(string v, List <MLMusicModel> musics)
 {
     DataBaseEngine.AddSongsToPlaylist(v, musics);
     RefreshLibrary();
 }
예제 #11
0
 public void Clean()
 {
     DataBaseEngine.Reset();
 }
예제 #12
0
 private void RefreshLibrary()
 {
     Library.MInP      = new ObservableCollection <MLMusicInPlaylistModel>(DataBaseEngine.FetchSongPlaylistRelationship().Select(m => new MLMusicInPlaylistModel(m)).ToList());
     Library.Playlists = new ObservableCollection <MLPlayListModel>(DataBaseEngine.FetchPlaylist().Select(p => new MLPlayListModel(p)).ToList());
 }
예제 #13
0
 public void RemoveSongsFromPlaylist(string playlistName, List <MLMusicModel> musics)
 {
     DataBaseEngine.RemoveSongsFromPlaylist(playlistName, musics);
     RefreshLibrary();
 }
예제 #14
0
 public void DeletePlaylist(string name)
 {
     DataBaseEngine.DeletePlaylist(name);
     RefreshLibrary();
 }
예제 #15
0
 public void EditPlaylistName(string oldName, string newName)
 {
     DataBaseEngine.EditPlaylistName(oldName, newName);
     RefreshLibrary();
 }
예제 #16
0
        //[DBTable("t")]
        //class qwer
        //{
        //    [DbColumn("id")]
        //    [DataType(SqlDbType.NChar)]
        //    public string id { set; get; }

        //    [DbColumn("a")]
        //    [DataType(SqlDbType.NChar)]
        //    public string a { set; get; }

        //    [DbColumn("b")]
        //    [DataType(SqlDbType.NChar)]
        //    public string b { set; get; }

        //    [DbColumn("c")]
        //    [DataType(SqlDbType.NChar)]
        //    public string c { set; get; }

        //    [DbColumn("d")]
        //    [DataType(SqlDbType.NChar)]
        //    public string d { set; get; }

        //    [DbColumn("e")]
        //    [DataType(SqlDbType.NChar)]
        //    public string e { set; get; }

        //    [DbColumn("f")]
        //    [DataType(SqlDbType.NChar)]
        //    public string f { set; get; }

        //    [DbColumn("g")]
        //    [DataType(SqlDbType.NChar)]
        //    public string g { set; get; }

        //    [DbColumn("h")]
        //    [DataType(SqlDbType.NChar)]
        //    public string h { set; get; }

        //    [DbColumn("i")]
        //    [DataType(SqlDbType.NChar)]
        //    public string i { set; get; }

        //    [DbColumn("j")]
        //    [DataType(SqlDbType.NChar)]
        //    public string j { set; get; }

        //    [DbColumn("k")]
        //    [DataType(SqlDbType.NChar)]
        //    public string k { set; get; }

        //    [DbColumn("l")]
        //    [DataType(SqlDbType.NChar)]
        //    public string l { set; get; }

        //    [DbColumn("m")]
        //    [DataType(SqlDbType.NChar)]
        //    public string m { set; get; }

        //    [DbColumn("n")]
        //    [DataType(SqlDbType.NChar)]
        //    public string n { set; get; }
        //}

        static void Main(string[] args)
        {
            DataBaseInfo dbinfo = new DataBaseInfo()
            {
                ServerName    = @"DESKTOP-4BDM3A8\SQLEXPRESS",
                DataBase      = "HWSMST",
                Athentication = AthenticationType.WindowsAthentication
            };

            DataBaseEngine.DataBaseInfo = dbinfo;

            PhoneBook p = new PhoneBook()
            {
                ID          = 1009,
                Name        = "asd",
                PhoneNumber = "345678",
                Occupation  = "b'bb",
                Description = "''''''''''''''''",
                Active      = 1
            };

            PhoneBook p2 = new PhoneBook()
            {
            };

            Type t = p2.GetType();

            PropertyInfo[] pi = t.GetProperties();
            foreach (PropertyInfo pp in pi)
            {
                System.Console.WriteLine(pp.Name + "    " + pp.GetValue(p2, new object[] { }));
            }

            DataBaseEngine.Insert(p2);

            //DataBaseEngine.Update(p,p2, (x) => x.ID == 1014);

            //DataBaseEngine.Delete(new PhoneBook(), (x) => x.ID == 1014);

            //DataBaseEngine.Count(p.ID);
            //List<PhoneBook> l = DataBaseEngine.Select(new PhoneBook(), x => x.ID == 2);

            //l.ForEach(i =>
            //{
            //    Type t = i.GetType();
            //    PropertyInfo[] pi = t.GetProperties();
            //    foreach (PropertyInfo pp in pi)
            //    {
            //        System.Console.WriteLine(pp.Name + "    " + pp.GetValue(i, new object[] { }));
            //    }
            //});

            //qwer a = new qwer()
            //{
            //    id = "bbb",
            //    a = "aaa",
            //    b = "aaa",
            //    c = "aaa",
            //    d = "aaa",
            //    e = "aaa",
            //    f = "aaa",
            //    g = "aaa",
            //    h = "aaa",
            //    i = "aaa",
            //    j = "aaa",
            //    k = "aaa",
            //    l = "aaa",
            //    n = "aaa",
            //    m = "aaa",
            //};

            // DataBaseEngine.Insert(a);


            //List<qwer> l = DataBaseEngine.Select(new qwer(), x => x.id == "bbb       ");

            //l.ForEach(i =>
            //{
            //    Type t = i.GetType();
            //    PropertyInfo[] pi = t.GetProperties();
            //    foreach (PropertyInfo pp in pi)
            //    {
            //        System.Console.WriteLine(pp.Name + "    " + pp.GetValue(i, new object[] { }));
            //    }
            //});

            Console.Write("Press Any Key To Exit..");
            Console.ReadKey();
        }
예제 #17
0
 public DatabaseHandling(DataBaseEngine DataBaseInformation)
 {
     this.DataBaseInformation = DataBaseInformation;
 }
예제 #18
0
        public void Start(ClusterConfiguration clusterConf)
        {
            if (!_initialized)
            {
                throw new Exception("Shard host is not initialized. ");
            }
            try
            {
                //IDatabaseEngine engine =_databaseEngineFactory.GetDatabaseEngine();
                DataBaseEngine engine = _databaseEngineFactory.GetDatabaseEngine() as DataBaseEngine;
                if (engine != null)
                {
                    engine.Start(clusterConf);
                }
                else
                {
                    throw new Exception("Database Engine not initialized. ");
                }

                _nodeContext.ShardServer.Start();

                _clientSessionManager.RegisterClientDisconnectListerner(_nodeContext.SecurityManager);
                _nodeContext.ShardServer.RegisterSessionListener(SessionTypes.Client, _clientSessionManager);
                _nodeContext.ShardServer.RegisterSessionListener(SessionTypes.Monitoring, _monitorSessionListener);

                try
                {
                    if (_nodeContext.ShardStatsCollector == null)
                    {
                        _nodeContext.ShardStatsCollector = new ShardStatsCollector();
                    }
                    _nodeContext.ShardStatsCollector.Initialize(_nodeContext.LocalShardName);
                    _nodeContext.ShardStatsCollector.SetStatsValue(StatisticsType.PendingReplicatedOperation, 0);
                }
                catch (Exception ex)
                {
                    if (LoggerManager.Instance.ServerLogger != null && LoggerManager.Instance.ServerLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ServerLogger.Error(
                            _nodeContext.LocalShardName + " Perfmon Counters Initialization ", ex.Message);
                    }
                }

                if (LoggerManager.Instance.ServerLogger != null && LoggerManager.Instance.ServerLogger.IsInfoEnabled)
                {
                    LoggerManager.Instance.ServerLogger.Info("ShardHost.Start()", "Shard Host started successfully.");
                }

                string logMessage = string.Format("Node {0}:{1} for shard \"{2}\" has successfully started.",
                                                  _nodeContext.ShardServer.BindingIp, _nodeContext.ShardServer.Port, _nodeContext.LocalShardName);
                AppUtil.LogEvent(logMessage, System.Diagnostics.EventLogEntryType.Information);

                _running = true;
            }
            catch (Exception ex)
            {
                _running = false;
                if (LoggerManager.Instance.ServerLogger != null && LoggerManager.Instance.ServerLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.ServerLogger.Error("ShardHost.Start()", "Error:", ex);
                }
                string logMessage = string.Format("Node {0}:{1} for shard \"{2}\" cannot be started. \n {3}",
                                                  _nodeContext.ShardServer.BindingIp, _nodeContext.ShardServer.Port, _nodeContext.LocalShardName, ex.ToString());
                AppUtil.LogEvent(AppUtil.EventLogSource, logMessage, EventLogEntryType.Error, EventCategories.Error, EventID.ShardStartError);
                throw;
            }
        }