Mar a chaidh sinn a-steach don chuspair air mar a tha toraidhean 1C ag obair ann an àrainneachd Linux, chaidh aon bhuannachd a lorg - dìth inneal ioma-ùrlar grafaigeach goireasach airson a bhith a’ riaghladh grunn de luchd-frithealaidh 1C. Agus chaidh co-dhùnadh an tarraing air ais seo a cheartachadh le bhith a’ sgrìobhadh GUI airson goireas rac console. Chaidh Tcl/tk a thaghadh mar chànan leasachaidh mar, nam bheachd-sa, an cànan as freagarraiche airson na h-obrach seo. Agus mar sin, bu mhath leam cuid de thaobhan inntinneach den fhuasgladh a thaisbeanadh anns an stuth seo.
Gus obrachadh bidh feum agad air sgaoilidhean tcl/tk agus 1C. Agus bhon a chuir mi romham a’ chuid as fheàrr a dhèanamh de na comasan lìbhrigidh tcl/tk bunaiteach gun a bhith a’ cleachdadh phasganan treas-phàrtaidh, bidh feum agam air dreach 8.6.7, a tha a’ toirt a-steach ttk - pasgan le eileamaidean grafaigeach a bharrachd, agus feumaidh sinn sa mhòr-chuid ttk. :: TreeView, leigidh e le dàta taisbeanaidh an dà chuid ann an cruth structar craoibhe agus ann an cruth clàr (liosta). Cuideachd, anns an dreach ùr, chaidh an obair le eisgeachdan ath-obrachadh (an òrdugh feuch, a tha air a chleachdadh sa phròiseact nuair a bhios tu a’ ruith òrdughan bhon taobh a-muigh).
Tha grunn fhaidhlichean anns a 'phròiseact (ged nach eil dad a' cur bacadh ort bho bhith a 'dèanamh a h-uile càil ann an aon):
rac_gui.cfg - an rèiteachadh bunaiteach
rac_gui.tcl - prìomh sgriobt cur air bhog
Anns an eòlaire lib tha faidhlichean a thèid an luchdachadh gu fèin-ghluasadach aig àm tòiseachaidh:
function.tcl - faidhle le modhan-obrach
gui.tcl - prìomh eadar-aghaidh grafaigeach
images.tcl - leabharlann dhealbhan base64
Bidh am faidhle rac_gui.tcl, gu dearbh, a’ tòiseachadh an eadar-theangair, a’ tòiseachadh caochladairean, a’ luchdachadh mhodalan, configs, agus mar sin air adhart. Susbaint an fhaidhle le beachdan:
rac_gui.tcl
#!/bin/sh
exec wish "$0" -- "$@"
# Устанавливаем текущий каталог
set dir(root) [pwd]
# Устанавливаем рабочий каталог, если его нет то создаём
set dir(work) [file join $env(HOME) .rac_gui]
if {[file exists $dir(work)] == 0 } {
file mkdir $dir(work)
}
# каталог с модулями
set dir(lib) "[file join $dir(root) lib]"
# загружаем пользовательский конфиг, если он отсутствует, то копируем дефолтный
if {[file exists [file join $dir(work) rac_gui.cfg]] ==0} {
file copy [file join [pwd] rac_gui.cfg] [file join $dir(work) rac_gui.cfg]
}
source [file join $dir(work) rac_gui.cfg]
# Код проверки наличия rac и правильности указания пути в конфиге
# если программа не найдена то будет выведен диалог для указания корректного пути
# и этот путь будет записан в пользовательский конфиг
if {[file exists $rac_cmd] == 0} {
set rac_cmd [tk_getOpenFile -initialdir $env(HOME) -parent . -title "Укажите путь до rac" -initialfile rac]
file copy [file join $dir(work) rac_gui.cfg] [file join $dir(work) rac_gui.cfg.bak]
set orig_file [open [file join $dir(work) rac_gui.cfg.bak] "r"]
set file [open [file join $dir(work) rac_gui.cfg] "w"]
while {[gets $orig_file line] >=0 } {
if {[string match "set rac_cmd*" $line]} {
puts $file "set rac_cmd $rac_cmd"
} else {
puts $file $line
}
}
close $file
close $orig_file
#return "$host:$port"
file delete [file join $dir(work) 1c_srv.cfg.bak]
} else {
puts "Found $rac_cmd"
}
set cluster_user ""
set cluster_pwd ""
set agent_user ""
set agent_pwd ""
## LOAD FILE ##
# Загружаем модули кроме gui.tcl так как его надо загрузить последним
foreach modFile [lsort [glob -nocomplain [file join $dir(lib) *.tcl]]] {
if {[file tail $modFile] ne "gui.tcl"} {
source $modFile
puts "Loaded module $modFile"
}
}
source [file join $dir(lib) gui.tcl]
source [file join $dir(work) rac_gui.cfg]
# Читаем файл со списком серверов 1С
# и добавляем в дерево
if [file exists [file join $dir(work) 1c_srv.cfg]] {
set f [open [file join $dir(work) 1c_srv.cfg] "RDONLY"]
while {[gets $f line] >=0} {
.frm_tree.tree insert {} end -id "server::$line" -text "$line" -values "$line"
}
}
Às deidh a h-uile dad a tha a dhìth a luchdachadh sìos agus sgrùdadh a dhèanamh airson làthaireachd an goireas rac, thèid uinneag grafaigeach a chuir air bhog. Tha trì eileamaidean ann an eadar-aghaidh a’ phrògraim:
Crann-inneal, craobh agus liosta
Rinn mi susbaint na “craobh” cho coltach sa ghabhas ris an uidheamachd àbhaisteach Windows bho 1C.
Tha am prìomh chòd a chruthaicheas an uinneag seo anns an fhaidhle
lib/gui.tcl
# установка размера и положения основного окна
# можно установить в переменную topLevelGeometry в конфиг программы
if {[info exists topLevelGeometry]} {
wm geometry . $topLevelGeometry
} else {
wm geometry . 1024x768
}
# Заголовок окна
wm title . "1C Rac GUI"
wm iconname . "1C Rac Gui"
# иконка окна (берется из файла lib/imges.tcl)
wm iconphoto . tcl
wm protocol . WM_DELETE_WINDOW Quit
wm overrideredirect . 0
wm positionfrom . user
ttk::style theme use clam
# Панель инсрументов
set frm_tool [frame .frm_tool]
pack $frm_tool -side left -fill y
ttk::panedwindow .panel -orient horizontal -style TPanedwindow
pack .panel -expand true -fill both
pack propagate .panel false
ttk::button $frm_tool.btn_add -command Add -image add_grey_32
ttk::button $frm_tool.btn_del -command Del -image del_grey_32
ttk::button $frm_tool.btn_edit -command Edit -image edit_grey_32
ttk::button $frm_tool.btn_quit -command Quit -image quit_grey_32
pack $frm_tool.btn_add $frm_tool.btn_del $frm_tool.btn_edit -side top -padx 5 -pady 5
pack $frm_tool.btn_quit -side bottom -padx 5 -pady 5
# Дерево с полосами прокрутки
set frm_tree [frame .frm_tree]
ttk::scrollbar $frm_tree.hsb1 -orient horizontal -command [list $frm_tree.tree xview]
ttk::scrollbar $frm_tree.vsb1 -orient vertical -command [list $frm_tree.tree yview]
set tree [ttk::treeview $frm_tree.tree -show tree
-xscrollcommand [list $frm_tree.hsb1 set] -yscrollcommand [list $frm_tree.vsb1 set]]
grid $tree -row 0 -column 0 -sticky nsew
grid $frm_tree.vsb1 -row 0 -column 1 -sticky nsew
grid $frm_tree.hsb1 -row 1 -column 0 -sticky nsew
grid columnconfigure $frm_tree 0 -weight 1
grid rowconfigure $frm_tree 0 -weight 1
# назначение обработчика нажатия кнопкой мыши
bind $frm_tree.tree <ButtonRelease> "TreePress $frm_tree.tree"
# Список для данных (таблица)
set frm_work [frame .frm_work]
ttk::scrollbar $frm_work.hsb -orient horizontal -command [list $frm_work.tree_work xview]
ttk::scrollbar $frm_work.vsb -orient vertical -command [list $frm_work.tree_work yview]
set tree_work [
ttk::treeview $frm_work.tree_work
-show headings -columns "par val" -displaycolumns "par val"
-xscrollcommand [list $frm_work.hsb set]
-yscrollcommand [list $frm_work.vsb set]
]
# Установка цветов для чередования в таблице
$tree_work tag configure dark -background $color(dark_table_bg)
$tree_work tag configure light -background $color(light_table_bg)
# Размещение элементов на форме
grid $tree_work -row 0 -column 0 -sticky nsew
grid $frm_work.vsb -row 0 -column 1 -sticky nsew
grid $frm_work.hsb -row 1 -column 0 -sticky nsew
grid columnconfigure $frm_work 0 -weight 1
grid rowconfigure $frm_work 0 -weight 1
pack $frm_tree $frm_work -side left -expand true -fill both
#.panel add $frm_tool -weight 1
.panel add $frm_tree -weight 1
.panel add $frm_work -weight 1
Tha an algairim airson a bhith ag obair leis a’ phrògram mar a leanas:
1. An toiseach, feumaidh tu am prìomh fhrithealaiche brabhsair a chuir ris (ie, am frithealaiche riaghlaidh brabhsair (ann an Linux, tha riaghladh air a chuir air bhog leis an àithne “/ opt/1C/v8.3/x86_64/ras cluster —daemon”)).
Gus seo a dhèanamh, cliog air a’ phutan “+” agus san uinneig a tha a’ fosgladh, cuir a-steach seòladh an fhrithealaiche agus port:
Às deidh sin, nochdaidh an frithealaiche againn sa chraoibh le bhith a’ cliogadh air, fosglaidh liosta de chlàran no thèid mearachd ceangail a thaisbeanadh.
2. Ma bhriogas tu air ainm a’ chlàir, fosglaidh e liosta de ghnìomhan a tha rim faighinn air a shon.
3.…
Agus mar sin air adhart, i.e. gus brabhsair ùr a chur ris, tagh fear sam bith a tha ri fhaighinn air an liosta agus brùth air a’ phutan “+” sa bhàr-inneal agus thèid an còmhradh ùr a thaisbeanadh:
Bidh na putanan sa bhàr-inneal a’ coileanadh ghnìomhan a rèir a’ cho-theacsa, i.e. A rèir dè an eileamaid den chraoibh no den liosta a thèid a thaghadh, thèid aon dòigh-obrach no dòigh eile a dhèanamh.
Bheir sinn sùil air an eisimpleir den phutan cuir ris (“+”):
Còd gineadh putan:
ttk::button $frm_tool.btn_add -command Add -image add_grey_32
An seo chì sinn nuair a thèid am putan a bhrùthadh, gun tèid am modh “Cuir ris” a chuir gu bàs, an còd aige:
proc Add {} {
global active_cluster host
# Определяем идентификатор выделенного элемента
set id [.frm_tree.tree selection]
# Определяем значение этого элемента
set values [.frm_tree.tree item [.frm_tree.tree selection] -values]
set key [lindex [split $id "::"] 0]
# в зависимости от того что выделили будет запущена нужная процедура
if {$key eq "" || $key eq "server"} {
set host [ Add::server ]
return
}
Add::$key .frm_tree.tree $host $values
}
Seo aon de na buannachdan a tha an lùib diog: faodaidh tu luach caochladair a thoirt seachad mar ainm modh-obrach:
Add::$key .frm_tree.tree $host $values
Is e sin, mar eisimpleir, ma chomharraicheas sinn am prìomh fhrithealaiche agus ma bhrùthas sinn “+”, an uairsin thèid am modh Add ::server a chuir air bhog, ma tha e aig a’ bhuidheann - Add ::cluster agus mar sin air adhart (sgrìobhaidh mi mu dheidhinn far a bheil an Tha “iuchraichean” riatanach a’ tighinn bho ann am beagan gu h-ìosal), bidh na modhan clàraichte a’ tarraing eileamaidean grafaigeach a tha iomchaidh don cho-theacsa.
Mar is dòcha gu bheil thu air mothachadh mar-thà, tha na foirmean coltach ann an stoidhle - chan eil seo na iongnadh, oir tha iad air an taisbeanadh le aon mhodh, nas mionaidiche prìomh fhrèam an fhoirm (uinneag, putanan, ìomhaigh, bileag), ainm a 'mhodh-obrachaidh Cuir ris an ìre as àirde
proc AddToplevel {lbl img {win_name .add}} {
set cmd "destroy $win_name"
if [winfo exists $win_name] {destroy $win_name}
toplevel $win_name
wm title $win_name $lbl
wm iconphoto $win_name tcl
# метка с иконкой
ttk::label $win_name.lbl -image $img
# фрейм с полями ввода
set frm [ttk::labelframe $win_name.frm -text $lbl -labelanchor nw]
grid columnconfigure $frm 0 -weight 1
grid rowconfigure $frm 0 -weight 1
# фрейм и кнопки
set frm_btn [frame $win_name.frm_btn -border 0]
ttk::button $frm_btn.btn_ok -image ok_grey_24 -command { }
ttk::button $frm_btn.btn_cancel -command $cmd -image quit_grey_24
grid $win_name.lbl -row 0 -column 0 -sticky nw -padx 5 -pady 10
grid $frm -row 0 -column 1 -sticky nw -padx 5 -pady 5
grid $frm_btn -row 1 -column 1 -sticky se -padx 5 -pady 5
pack $frm_btn.btn_cancel -side right
pack $frm_btn.btn_ok -side right -padx 10
return $frm
}
Paramadairean gairm: tiotal, ainm ìomhaigh airson an ìomhaigh bhon leabharlann (lib/images.tcl) agus paramadair ainm uinneag roghainneil (bunaiteach .add). Mar sin, ma ghabhas sinn na h-eisimpleirean gu h-àrd airson am prìomh fhrithealaiche agus brabhsair a chur ris, bidh a’ ghairm a rèir sin:
AddToplevel "Добавление основного сервера" server_grey_64
no
AddToplevel "Добавление кластера" cluster_grey_64
Uill, a’ leantainn leis na h-eisimpleirean seo, seallaidh mi na dòighean-obrach a tha a’ taisbeanadh a’ cuir còmhraidhean ris airson frithealaiche no brabhsair.
Cuir ris::server
proc Add::server {} {
global default
# выводим основную форму
set frm [AddToplevel "Добавление основного сервера" server_grey_64]
# добавляем етки и поля ввода на эту форму
label $frm.lbl_host -text "Адрес сервера"
entry $frm.ent_host
label $frm.lbl_port -text "Порт"
entry $frm.ent_port
$frm.ent_port insert end $default(port)
grid $frm.lbl_host -row 0 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_host -row 0 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_port -row 1 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_port -row 1 -column 1 -sticky nsew -padx 5 -pady 5
grid columnconfigure $frm 0 -weight 1
grid rowconfigure $frm 0 -weight 1
#set frm_btn [frame .add.frm_btn -border 0]
# переопределяем обработчик нажатия кнопки
.add.frm_btn.btn_ok configure -command {
set host [SaveMainServer [.add.frm.ent_host get] [.add.frm.ent_port get]]
.frm_tree.tree insert {} end -id "server::$host" -text "$host" -values "$host"
destroy .add
return $host
}
return $frm
}
Cuir ris::cluster
proc Add::cluster {tree host values} {
global default lifetime_limit expiration_timeout session_fault_tolerance_level
global max_memory_size max_memory_time_limit errors_count_threshold security_level
global load_balancing_mode kill_problem_processes
agent_user agent_pwd cluster_user cluster_pwd auth_agent
if {$agent_user ne "" && $agent_pwd ne ""} {
set auth_agent "--agent-user=$agent_user --agent-pwd=$agent_pwd"
} else {
set auth_agent ""
}
# устанавливаем глобальные переменные ()
set lifetime_limit $default(lifetime_limit)
set expiration_timeout $default(expiration_timeout)
set session_fault_tolerance_level $default(session_fault_tolerance_level)
set max_memory_size $default(max_memory_size)
set max_memory_time_limit $default(max_memory_time_limit)
set errors_count_threshold $default(errors_count_threshold)
set security_level [lindex $default(security_level) 0]
set load_balancing_mode [lindex $default(load_balancing_mode) 0]
set frm [AddToplevel "Добавление кластера" cluster_grey_64]
label $frm.lbl_host -text "Адрес основного сервера"
entry $frm.ent_host
label $frm.lbl_port -text "Порт"
entry $frm.ent_port
$frm.ent_port insert end $default(port)
label $frm.lbl_name -text "Название кластера"
entry $frm.ent_name
label $frm.lbl_secure_connect -text "Защищённое соединение"
ttk::combobox $frm.cb_security_level -textvariable security_level -values $default(security_level)
label $frm.lbl_expiration_timeout -text "Останавливать выключенные процессы через:"
entry $frm.ent_expiration_timeout -textvariable expiration_timeout
label $frm.lbl_session_fault_tolerance_level -text "Уровень отказоустойчивости"
entry $frm.ent_session_fault_tolerance_level -textvariable session_fault_tolerance_level
label $frm.lbl_load_balancing_mode -text "Режим распределения нагрузки"
ttk::combobox $frm.cb_load_balancing_mode -textvariable load_balancing_mode
-values $default(load_balancing_mode)
label $frm.lbl_errors_count_threshold -text "Допустимое отклонение количества ошибок сервера, %"
entry $frm.ent_errors_count_threshold -textvariable errors_count_threshold
label $frm.lbl_processes -text "Рабочие процессы:"
label $frm.lbl_lifetime_limit -text "Период перезапуска, сек."
entry $frm.ent_lifetime_limit -textvariable lifetime_limit
label $frm.lbl_max_memory_size -text "Допустимый объём памяти, КБ"
entry $frm.ent_max_memory_size -textvariable max_memory_size
label $frm.lbl_max_memory_time_limit -text "Интервал превышения допустимого объёма памяти, сек."
entry $frm.ent_max_memory_time_limit -textvariable max_memory_time_limit
label $frm.lbl_kill_problem_processes -justify left -anchor nw -text "Принудительно завершать проблемные процессы"
checkbutton $frm.check_kill_problem_processes -variable kill_problem_processes -onvalue yes -offvalue no
grid $frm.lbl_host -row 0 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_host -row 0 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_port -row 1 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_port -row 1 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_name -row 2 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_name -row 2 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_secure_connect -row 3 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.cb_security_level -row 3 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_expiration_timeout -row 4 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_expiration_timeout -row 4 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_session_fault_tolerance_level -row 5 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_session_fault_tolerance_level -row 5 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_load_balancing_mode -row 6 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.cb_load_balancing_mode -row 6 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_errors_count_threshold -row 7 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_errors_count_threshold -row 7 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_processes -row 8 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.lbl_lifetime_limit -row 9 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_lifetime_limit -row 9 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_max_memory_size -row 10 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_max_memory_size -row 10 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_max_memory_time_limit -row 11 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.ent_max_memory_time_limit -row 11 -column 1 -sticky nsew -padx 5 -pady 5
grid $frm.lbl_kill_problem_processes -row 12 -column 0 -sticky nw -padx 5 -pady 5
grid $frm.check_kill_problem_processes -row 12 -column 1 -sticky nw -padx 5 -pady 5
# переопределяем обработчик
.add.frm_btn.btn_ok configure -command {
RunCommand "" "cluster insert
--host=[.add.frm.ent_host get]
--port=[.add.frm.ent_port get]
--name=[.add.frm.ent_name get]
--expiration-timeout=$expiration_timeout
--lifetime-limit=$lifetime_limit
--max-memory-size=$max_memory_size
--max-memory-time-limit=$max_memory_time_limit
--security-level=$security_level
--session-fault-tolerance-level=$session_fault_tolerance_level
--load-balancing-mode=$load_balancing_mode
--errors-count-threshold=$errors_count_threshold
--kill-problem-processes=$kill_problem_processes
$auth_agent $host"
Run::server $tree $host ""
destroy .add
}
return $frm
}
Nuair a thathar a’ dèanamh coimeas eadar còd nam modhan sin, tha an t-eadar-dhealachadh ri fhaicinn don tsùil rùisgte; cuiridh mi fòcas air an inneal-làimhseachaidh putan “OK”. Ann an Tk, faodar feartan eileamaidean grafaigeach a thoirt thairis nuair a thèid am prògram a chuir an gnìomh a’ cleachdadh an roghainn configures. Mar eisimpleir, an òrdugh tùsail airson am putan a thaisbeanadh:
ttk::button $frm_btn.btn_ok -image ok_grey_24 -command { }
Ach anns na foirmean againn, tha an àithne an urra ris a’ ghnìomhachd a tha a dhìth:
.add.frm_btn.btn_ok configure -command {
RunCommand "" "cluster insert
--host=[.add.frm.ent_host get]
--port=[.add.frm.ent_port get]
--name=[.add.frm.ent_name get]
--expiration-timeout=$expiration_timeout
--lifetime-limit=$lifetime_limit
--max-memory-size=$max_memory_size
--max-memory-time-limit=$max_memory_time_limit
--security-level=$security_level
--session-fault-tolerance-level=$session_fault_tolerance_level
--load-balancing-mode=$load_balancing_mode
--errors-count-threshold=$errors_count_threshold
--kill-problem-processes=$kill_problem_processes
$auth_agent $host"
Run::server $tree $host ""
destroy .add
}
Anns an eisimpleir gu h-àrd, bidh am putan “clogged” a’ tòiseachadh a’ mhodh-obrach airson cruinneachadh a chur ris.
An seo is fhiach e gluasad a dh’ ionnsaigh obrachadh le eileamaidean grafaigeach ann an Tk - airson diofar eileamaidean cuir a-steach dàta (inntrigeadh, bogsa combo, putan seic, msaa) chaidh paramadair a thoirt a-steach mar chaochladair teacsa:
entry $frm.ent_lifetime_limit -textvariable lifetime_limit
Tha an caochladair seo air a mhìneachadh san ainm-àite cruinneil agus tha an luach a chaidh a-steach an-dràsta ann. An fheadhainn sin. gus an teacsa a chaidh a chuir a-steach fhaighinn bhon raon, cha leig thu leas ach an luach a tha co-chosmhail ris a’ chaochladair a leughadh (gu dearbh, fhad ‘s a tha e air a mhìneachadh nuair a chruthaicheas tu an eileamaid).
Is e an dàrna dòigh airson an teacsa a chaidh a chuir a-steach fhaighinn air ais (airson eileamaidean den t-seòrsa inntrigidh) an òrdugh faighinn a chleachdadh:
.add.frm.ent_name get
Chithear an dà dhòigh seo anns a’ chòd gu h-àrd.
Le bhith a’ briogadh air a’ phutan seo, anns a’ chùis seo, cuiridh am modh RunCommand air bhog leis an loidhne-àithne a chaidh a chruthachadh airson cruinneachadh a chur ris a thaobh rac:
/opt/1C/v8.3/x86_64/rac cluster insert --host=localhost --port=1540 --name=dsdsds --expiration-timeout=0 --lifetime-limit=0 --max-memory-size=0 --max-memory-time-limit=0 --security-level=0 --session-fault-tolerance-level=0 --load-balancing-mode=performance --errors-count-threshold=0 --kill-problem-processes=no localhost:1545
A-nis tha sinn a’ tighinn chun phrìomh àithne, a bhios a’ cumail smachd air cur air bhog rac leis na paramadairean a dh’ fheumas sinn, cuideachd a’ parsadh toradh òrdughan gu liostaichean agus tilleadh, ma bhios feum air:
RunCommand
proc RunCommand {root par} {
global dir rac_cmd cluster work_list_row_count agent_user agent_pwd cluster_user cluster_pwd
puts "$rac_cmd $par"
set work_list_row_count 0
# открываем канал в неблокирующем режиме
# $rac - команда с полным путём
# $par - сформированные ключи запуска и опции
set pipe [open "|$rac_cmd $par" "r"]
try {
set lst ""
set l ""
# вывод команды добавляем в список списков
while {[gets $pipe line]>=0} {
#puts $line
if {$line eq ""} {
lappend l $lst
set lst ""
} else {
lappend lst [string trim $line]
}
}
close $pipe
return $l
} on error {result options} {
# Запуск обработчика ошибок
ErrorParcing $result $options
return ""
}
}
Às deidh dhut dàta prìomh fhrithealaiche a chuir a-steach, thèid a chur ris a ’chraobh, airson seo, anns a’ mhodh Add:server gu h-àrd, tha an còd a leanas an urra:
.frm_tree.tree insert {} end -id "server::$host" -text "$host" -values "$host"
A-nis, le bhith a’ cliogadh air ainm an fhrithealaiche sa chraoibh, gheibh sinn liosta de chlàran air an riaghladh leis an t-seirbheisiche sin, agus le bhith a’ cliogadh air brabhsair, gheibh sinn liosta de na h-eileamaidean brabhsair (frithealaichean, infobases, msaa). Tha seo air a bhuileachadh ann am modh TreePress (faidhle lib/function.tcl):
proc TreePress {tree} {
global host server active_cluster infobase
# определяем выделенный элемент
set id [$tree selection]
# устанавливаем нужные глобальные переменные
SetGlobalVarFromTreeItems $tree $id
# Определяем ключ и значение, т.е. именно тип выбранного элемента
set values [$tree item $id -values]
set key [lindex [split $id "::"] 0]
# и в зависимости от того что выбрали будет запущена соответствующая процедура
# в пространстве имён Run
Run::$key $tree $host $values
}
Mar sin, thèid Run :: server a chuir air bhog airson a’ phrìomh fhrithealaiche (airson cruinneachadh - Run :: cluster, airson frithealaiche obrach - Run:: work_server, msaa). An fheadhainn sin. tha luach an caochladair $ key mar phàirt de ainm an eileamaid chraoibh a tha air a shònrachadh leis an roghainn -id.
Bheir sinn aire don mhodh-obrach
Ruith::server
proc Run::server {tree host values} {
# получаем список кластеров требуемого сервера
set lst [RunCommand server::$host "cluster list $host"]
if {$lst eq ""} {return}
set l [lindex $lst 0]
#puts $lst
# удаляем лишнее из списка
.frm_work.tree_work delete [ .frm_work.tree_work children {}]
# читаем список
foreach cluster_list $lst {
# Заполняем список полученными значениями
InsertItemsWorkList $cluster_list
# обрабатываем вывод (список) для добавления данных в дерево
foreach i $cluster_list {
#puts $i
set cluster_list [split $i ":"]
if {[string trim [lindex $cluster_list 0]] eq "cluster"} {
set cluster_id [string trim [lindex $cluster_list 1]]
lappend cluster($cluster_id) $cluster_id
}
if {[string trim [lindex $cluster_list 0]] eq "name"} {
lappend cluster($cluster_id) [string trim [lindex $cluster_list 1]]
}
}
}
# добавляем кластеры в дерево
foreach x [array names cluster] {
set id [lindex $cluster($x) 0]
if { [$tree exists "cluster::$id"] == 0 } {
$tree insert "server::$host" end -id "cluster::$id" -text "[lindex $cluster($x) 1]" -values "$id"
# добавляем элементы в кластер
InsertClusterItems $tree $id
}
}
if { [$tree exists "agent_admins::$id"] == 0 } {
$tree insert "server::$host" end -id "agent_admins::$id" -text "Администраторы" -values "$id"
#InsertClusterItems $tree $id
}
}
Bidh am modh-obrach seo a’ pròiseasadh na fhuaireadh bhon t-seirbheisiche tro àithne RunCommand agus a’ cur a h-uile seòrsa rud ris a’ chraoibh - cruinneachaidhean, diofar eileamaidean freumha (bunait, frithealaichean obrach, seiseanan, is mar sin air adhart). Ma choimheadas tu gu dlùth, chì thu fios gu modh InsertItemsWorkList a-staigh. Tha e air a chleachdadh gus eileamaidean a chur ri liosta grafaigeach le bhith a’ giullachd toradh a’ ghoireas rac console, a chaidh a thilleadh roimhe seo mar liosta don chaochladair $lst. Seo liosta de liostaichean anns a bheil paidhrichean de dh’ eileamaidean air an sgaradh le coloin.
Mar eisimpleir, liosta de cheanglaichean brabhsair:
svk@svk ~]$ /opt/1C/v8.3/x86_64/rac connection list --cluster=783d2170-56c3-11e8-c586-fc75165efbb2 localhost:1545
connection : dcf5991c-7d24-11e8-1690-fc75165efbb2
conn-id : 0
host : svk.home
process : 79de2e16-56c3-11e8-c586-fc75165efbb2
infobase : 00000000-0000-0000-0000-000000000000
application : "JobScheduler"
connected-at : 2018-07-01T14:49:51
session-number : 0
blocked-by-ls : 0
connection : b993293a-7d24-11e8-1690-fc75165efbb2
conn-id : 0
host : svk.home
process : 79de2e16-56c3-11e8-c586-fc75165efbb2
infobase : 00000000-0000-0000-0000-000000000000
application : "JobScheduler"
connected-at : 2018-07-01T14:48:52
session-number : 0
blocked-by-ls : 0
Ann an cruth grafaigeach seallaidh e rudeigin mar seo:
Bidh am modh-obrach gu h-àrd a’ taghadh ainmean nan eileamaidean airson a’ chinn agus an dàta airson an clàr a lìonadh:
InsertItemsWorkList
proc InsertItemsWorkList {lst} {
global work_list_row_count
# установка чередования цвета для строки
if [expr $work_list_row_count % 2] {
set tag dark
} else {
set tag light
}
# разбор строк на пары ключ - значение
foreach i $lst {
if [regexp -nocase -all -- {(D+)(s*?|)(:)(s*?|)(.*)} $i match param v2 v3 v4 value] {
lappend column_list [string trim $param]
lappend value_list [string trim $value]
}
}
# заполнение таблицы
.frm_work.tree_work configure -columns $column_list -displaycolumns $column_list
.frm_work.tree_work insert {} end -values $value_list -tags $tag
.frm_work.tree_work column #0 -stretch
# установка заголовков
foreach j $column_list {
.frm_work.tree_work heading $j -text $j
}
incr work_list_row_count
}
An-seo, an àite àithne shimplidh [split $str ":"], a sgoltadh an t-sreang 'na eileamaidean eadar-dhealaichte le ":" agus a thilleas liosta, thèid abairt àbhaisteach a chleachdadh, leis gu bheil coloin ann an cuid de dh'eileamaidean cuideachd.
Tha modh InsertClusterItems (aon de ghrunnan coltach ris) dìreach a’ cur liosta de eileamaidean cloinne le aithnichearan co-fhreagarrach ri craobh na h-eileamaid cnuasachaidh a tha a dhìth
InsertClusterItems
proc InsertClusterItems {tree id} {
set parent "cluster::$id"
$tree insert $parent end -id "infobases::$id" -text "Информационные базы" -values "$id"
$tree insert $parent end -id "servers::$id" -text "Рабочие серверы" -values "$id"
$tree insert $parent end -id "admins::$id" -text "Администраторы" -values "$id"
$tree insert $parent end -id "managers::$id" -text "Менеджеры кластера" -values $id
$tree insert $parent end -id "processes::$id" -text "Рабочие процессы" -values "workprocess-all"
$tree insert $parent end -id "sessions::$id" -text "Сеансы" -values "sessions-all"
$tree insert $parent end -id "locks::$id" -text "Блокировки" -values "blocks-all"
$tree insert $parent end -id "connections::$id" -text "Соединения" -values "connections-all"
$tree insert $parent end -id "profiles::$id" -text "Профили безопасности" -values $id
}
Faodaidh tu beachdachadh air dà roghainn eile airson modh-obrach coltach ris a chuir an gnìomh, far am bi e follaiseach gu soilleir mar as urrainn dhut òrdughan ath-aithris a bharrachadh agus faighinn cuidhteas:
Anns a 'mhodh-obrachaidh seo, tha cur-ris agus sgrùdadh air am fuasgladh ceann-air:
Cuir a-steach BaseItems
proc InsertBaseItems {tree id} {
set parent "infobase::$id"
if { [$tree exists "sessions::$id"] == 0 } {
$tree insert $parent end -id "sessions::$id" -text "Сеансы" -values "$id"
}
if { [$tree exists "locks::$id"] == 0 } {
$tree insert $parent end -id "locks::$id" -text "Блокировки" -values "$id"
}
if { [$tree exists "connections::$id"] == 0 } {
$tree insert $parent end -id "connections::$id" -text "Соединения" -values "$id"
}
}
Seo dòigh-obrach nas ceart:
InsertProfileItems
proc InsertProfileItems {tree id} {
set parent "profile::$id"
set lst {
{dir "Виртуальные каталоги"}
{com "Разрешённые COM-классы"}
{addin "Внешние компоненты"}
{module "Внешние отчёты и обработки"}
{app "Разрешённые приложения"}
{inet "Ресурсы интернет"}
}
foreach i $lst {
append item [lindex $i 0] "::$id"
if { [$tree exists $item] == 0 } {
$tree insert $parent end -id $item -text [lindex $i 1] -values "$id"
}
unset item
}
}
Is e an eadar-dhealachadh eatarra cleachdadh lùb, anns a bheil na h-òrdughan ath-aithris air an cur an gnìomh. Dè an dòigh cleachdaidh a tha an urra ris an leasaiche.
Tha sinn air dèiligeadh ri cur ri eileamaidean agus a’ faighinn dàta air ais, a-nis tha an t-àm ann fòcas a chuir air deasachadh. Leis, gu bunaiteach, thathas a ’cleachdadh na h-aon pharaimearan airson deasachadh agus cur ris (ach a-mhàin am bunait fiosrachaidh), thathas a’ cleachdadh na h-aon chruthan còmhraidh. Tha an algorithm airson modhan gairm airson cuir ris a’ coimhead mar seo:
Cuir ris::$key-> AddToplevel
Agus airson deasachadh mar seo:
Deasaich::$key-> Cuir ris::$key-> AddTopLevel
Mar eisimpleir, gabhamaid deasachadh brabhsair, i.e. Às deidh dhut briogadh air ainm a’ bhraisle sa chraoibh, brùth air a’ phutan deasachaidh sa bhàr-inneal (peansail) agus thèid am foirm co-fhreagarrach a thaisbeanadh air an sgrion:
Deasaich::cluster
proc Edit::cluster {tree host values} {
global default lifetime_limit expiration_timeout session_fault_tolerance_level
global max_memory_size max_memory_time_limit errors_count_threshold security_level
global load_balancing_mode kill_problem_processes active_cluster
agent_user agent_pwd cluster_user cluster_pwd auth
if {$cluster_user ne "" && $cluster_pwd ne ""} {
set auth "--cluster-user=$cluster_user --cluster-pwd=$cluster_pwd"
} else {
set auth ""
}
# рисуем форму для кластера
set frm [Add::cluster $tree $host $values]
# меняем текст на метке
$frm configure -text "Редактирование кластера"
set active_cluster $values
# получаем данные по выделенному кластеру
set lst [RunCommand cluster::$values "cluster info --cluster=$active_cluster $host"]
# заполняем поля
FormFieldsDataInsert $frm $lst
# выключаем поля, редактирование которых запрещено
$frm.ent_host configure -state disable
$frm.ent_port configure -state disable
# переназначаем обработчик
.add.frm_btn.btn_ok configure -command {
RunCommand "" "cluster update
--cluster=$active_cluster $auth
--name=[.add.frm.ent_name get]
--expiration-timeout=$expiration_timeout
--lifetime-limit=$lifetime_limit
--max-memory-size=$max_memory_size
--max-memory-time-limit=$max_memory_time_limit
--security-level=$security_level
--session-fault-tolerance-level=$session_fault_tolerance_level
--load-balancing-mode=$load_balancing_mode
--errors-count-threshold=$errors_count_threshold
--kill-problem-processes=$kill_problem_processes
$auth $host"
$tree delete "cluster::$active_cluster"
Run::server $tree $host ""
destroy .add
}
}
Stèidhichte air na beachdan anns a’ chòd, ann am prionnsapal, tha a h-uile dad soilleir, ach a-mhàin gu bheil còd làimhseachaidh a’ phutan air a dhol thairis air agus gu bheil modh-obrach FormFieldsDataInsert ann a lìonas na raointean le dàta agus a thòisicheas na caochladairean:
Cuir a-steach FoirmFieldsData
proc FormFieldsDataInsert {frm lst} {
foreach i [lindex $lst 0] {
# получаем список параметров и значений
if [regexp -nocase -all -- {(D+)(s*?|)(:)(s*?|)(.*)} $i match param v2 v3 v4 value] {
# меняем символы
regsub -all -- "-" [string trim $param] "_" entry_name
# заполняем данными
if [winfo exists $frm.ent_$entry_name] {
$frm.ent_$entry_name delete 0 end
$frm.ent_$entry_name insert end [string trim $value """]
}
if [winfo exists $frm.cb_$entry_name] {
global $entry_name
set $entry_name [string trim $value """]
}
# для чекбоксов меняем значения
if [winfo exists $frm.check_$entry_name] {
global $entry_name
if {$value eq "0"} {
set $entry_name no
} elseif {$value eq "1"} {
set $entry_name yes
} else {
set $entry_name $value
}
}
}
}
}
Anns a 'mhodh-obrachaidh seo, nochd buannachd eile de tcl - tha luachan caochladairean eile air an cur an àite ainmean caochlaideach. An fheadhainn sin. gus lìonadh fhoirmean agus tòiseachadh caochladairean gu fèin-ghluasadach, tha ainmean raointean agus caochladairean a’ freagairt ri suidsichean loidhne-àithne a’ ghoireas rac agus ainmean paramadairean toraidh àithne le beagan eisgeachd - thèid fo-sgòr a chuir an àite an dash. E.g obraichean clàraichte - àicheadh a 'freagairt ris an raon ent_scheduled_jobs_deny agus caochlaideach clàraichte_jobs_àicheadh.
Faodaidh foirmean airson cur-ris agus deasachadh a bhith eadar-dhealaichte ann an co-dhèanamh nan raointean, mar eisimpleir, ag obair le bunait fiosrachaidh:
A 'cur ri tèarainteachd fiosrachaidh
A 'deasachadh tèarainteachd fiosrachaidh
Anns a’ mhodh deasachaidh Deasaich :: infobase, tha na raointean riatanach air an cur ris an fhoirm; tha an còd voluminous, mar sin chan eil mi ga thaisbeanadh an seo.
Le samhlachas, tha modhan airson cur-ris, deasachadh, cuir às air an cur an gnìomh airson eileamaidean eile.
Leis gu bheil gnìomhachd a ’ghoireis a’ ciallachadh àireamh neo-chuingealaichte de luchd-frithealaidh, cruinneachaidhean, stòran fiosrachaidh, msaa, gus faighinn a-mach dè am buidheann a bhuineas don t-seirbheisiche no an siostam tèarainteachd fiosrachaidh, chaidh grunn chaochladairean cruinne a thoirt a-steach, agus tha na luachan aca air an suidheachadh gach fear. an uair a phutas tu air eileamaidean na craoibhe. An fheadhainn sin. bidh am modh-obrach a’ ruith tro na h-eileamaidean pàrant gu lèir agus a’ suidheachadh nan caochladairean:
SetGlobalVarFromTreeItems
proc SetGlobalVarFromTreeItems {tree id} {
global host server active_cluster infobase
set parent [$tree parent $id]
set values [$tree item $id -values]
set key [lindex [split $id "::"] 0]
switch -- $key {
server {set host $values}
work_server {set server $values}
cluster {set active_cluster $values}
infobase {set infobase $values}
}
if {$parent eq ""} {
return
} else {
SetGlobalVarFromTreeItems $tree $parent
}
}
Leigidh am brabhsair 1C leat obrachadh le no às aonais cead. Tha dà sheòrsa de luchd-rianachd ann - rianadair àidseant brabhsair agus rianadair brabhsair. Mar sin, airson obrachadh ceart, chaidh 4 caochladairean cruinne eile a thoirt a-steach anns an robh logadh a-steach agus facal-faire an rianaire. An fheadhainn sin. ma tha cunntas rianadair sa bhuidheann, thèid còmhradh a thaisbeanadh gus do logadh a-steach agus facal-faire a chuir a-steach, thèid an dàta a shàbhaladh mar chuimhne agus a chuir a-steach do gach àithne airson a’ bhuidheann fhreagarrach.
Tha seo an urra ris a’ mhodh làimhseachadh mhearachdan.
Mearachd Parcadh
proc ErrorParcing {err opt} {
global cluster_user cluster_pwd agent_user agent_pwd
switch -regexp -- $err {
"Cluster administrator is not authenticated" {
AuthorisationDialog "Администратор кластера"
.auth_win.frm_btn.btn_ok configure -command {
set cluster_user [.auth_win.frm.ent_name get]
set cluster_pwd [.auth_win.frm.ent_pwd get]
destroy .auth_win
}
#RunCommand $root $par
}
"Central server administrator is not authenticated" {
AuthorisationDialog "Администратор агента кластера"
.auth_win.frm_btn.btn_ok configure -command {
set agent_user [.auth_win.frm.ent_name get]
set agent_pwd [.auth_win.frm.ent_pwd get]
destroy .auth_win
}
}
"Администратор кластера не аутентифицирован" {
AuthorisationDialog "Администратор кластера"
.auth_win.frm_btn.btn_ok configure -command {
set cluster_user [.auth_win.frm.ent_name get]
set cluster_pwd [.auth_win.frm.ent_pwd get]
destroy .auth_win
}
#RunCommand $root $par
}
"Администратор центрального сервера не аутентифицирован" {
AuthorisationDialog "Администратор агента кластера"
.auth_win.frm_btn.btn_ok configure -command {
set agent_user [.auth_win.frm.ent_name get]
set agent_pwd [.auth_win.frm.ent_pwd get]
destroy .auth_win
}
}
(.+) {
tk_messageBox -type ok -icon error -message "$err"
}
}
}
An fheadhainn sin. a rèir dè a thilleas an àithne, bidh am freagairt a rèir sin.
Aig an àm seo, chaidh timcheall air 95 sa cheud den ghnìomhachd a chuir an gnìomh, chan eil air fhàgail ach obair le pròifilean tèarainteachd a chuir an gnìomh agus deuchainn a dhèanamh air =). Sin e. Tha mi duilich airson an sgeulachd crùbach.
Tha an còd ri fhaighinn gu traidiseanta
Ùrachadh: Chrìochnaich mi a bhith ag obair le pròifilean tèarainteachd. A-nis tha an comas-gnìomh 100% air a chuir an gnìomh.
Ùrachadh 2: chaidh sgìreachadh gu Beurla is Ruisis a chur ris, chaidh obair ann an win7 a dhearbhadh
Source: www.habr.com