Example #1
0
 Boolean ProcessOneElement(ReplicationService.DataForGet dg, ref Boolean bError)
 {
     if (dg == null)
     {
         return(false);
     }
     ReplicationService.PackageData pd = _client.GetDataForGet(_clientId, _sessionId, dg);
     if (pd == null)
     {
         return(false);
     }
     if (!pd.HasContent)
     {
         return(false);
     }
     if (pd.Tables == null)
     {
         return(false);
     }
     foreach (var t in pd.Tables)
     {
         ProcessSingleTable(t);
     }
     using (var cmd = _cnn.CreateCommand())
     {
         cmd.CommandText = String.Format("a2repl.{0}_from_server_written", dg.TableName);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@id", dg.Id);
         cmd.ExecuteNonQuery();
     }
     _client.SetDataForGetSent(_clientId, _sessionId, dg);
     return(true);
 }
Example #2
0
        Boolean ProcessPackage(Int64 pkgId)
        {
            var pd       = new ReplicationService.PackageData();
            var counters = new Dictionary <String, Int32>();

            using (var cmd = _cnn.CreateCommand())
            {
                cmd.CommandText = "a2repl.package_content_load_client";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue(String.Empty, (Int32)0).Direction = ParameterDirection.ReturnValue;
                cmd.Parameters.AddWithValue("@pkgid", pkgId);
                using (var rdr = cmd.ExecuteReader())
                {
                    do
                    {
                        var di = new ReplicationService.DataTable();
                        ReadDataTable(di, rdr);
                        while (rdr.Read())
                        {
                            ReadData(di, rdr);
                        }
                        if (pd.Tables == null)
                        {
                            pd.Tables = new List <ReplicationService.DataTable>();
                        }
                        if (!String.IsNullOrEmpty(di.TableName))
                        {
                            pd.Tables.Add(di);
                            if (!counters.ContainsKey(di.TableName))
                            {
                                counters.Add(di.TableName, 0);
                            }
                            counters[di.TableName] += di.Rows.Count;
                        }
                    } while (rdr.NextResult());
                }
                pd.HasMoreData = (Int32)cmd.Parameters[0].Value != 0;
                pd.HasContent  = pd.Tables != null;
                Log.Write("   Id={0} ...", pkgId.ToString());
                _client.SendPackageContent(_clientId, _sessionId, pd);
            }
            using (var cmd = _cnn.CreateCommand())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = String.Format("a2repl.set_package_client_sent", pkgId);
                cmd.Parameters.AddWithValue("@pkgid", pkgId);
                cmd.ExecuteNonQuery();
            }
            Log.WriteLine("   успешно");
            foreach (var d in counters)
            {
                Log.WriteLine("   \tЭлементов {0} : {1}", d.Key.ToString(), d.Value.ToString());
            }
            return(true);
        }
 Boolean ProcessItem(Int64 itemId, String itemName)
 {
     if (!_counters.ContainsKey(itemName))
     {
         _counters.Add(itemName, 0);
     }
     ReplicationService.PackageData pd = new ReplicationService.PackageData();
     using (var cmd = _cnn.CreateCommand())
     {
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = String.Format("a2repl.get_{0}_for_send", itemName);
         cmd.Parameters.AddWithValue("@id", itemId);
         using (var rdr = cmd.ExecuteReader())
         {
             do
             {
                 var di = new ReplicationService.DataTable();
                 ReadDataTable(di, rdr);
                 while (rdr.Read())
                 {
                     ReadData(di, rdr);
                 }
                 if (pd.Tables == null)
                 {
                     pd.Tables = new List <ReplicationService.DataTable>();
                 }
                 pd.Tables.Add(di);
             } while (rdr.NextResult());
         }
     }
     pd.HasContent = pd.Tables != null;
     Log.Write("\t{0} Id={1}{2} ...", itemName, itemId.ToString(), SqlExtension.Id2String(itemId));
     pd.ItemName = itemName; // обязательно!
     pd.ItemId   = itemId;
     _client.SendPackage(_clientId, _sessionId, pd);
     using (var cmd = _cnn.CreateCommand())
     {
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = String.Format("a2repl.set_{0}_sent", itemName);
         cmd.Parameters.AddWithValue("@sessionid", _sessionId);
         cmd.Parameters.AddWithValue("@id", itemId);
         cmd.ExecuteNonQuery();
     }
     Log.WriteLine("   успешно");
     _counters[itemName]++;
     return(true);
 }