Exemplo n.º 1
0
        private void btChekConnection_Click(object sender, EventArgs e)
        {
            DbTypeItem selitem = (DbTypeItem)cmbDbConectionType.SelectedItem;

            String context = tbConnectionString.Text;

            try
            {
                DomainContext.InitConnection(selitem.ConType, context);
                Dialogs.InformationF(this, "Тест соединения успешен.");
            }
            catch (Exception ex)
            {
                Dialogs.ErrorF(this, ex.Expand());
                errorTracker.SetError(btChekConnection, "Проверка строки соединения неуспешна");
                return;
            }

            errorTracker.SetError(btChekConnection, null);
        }
Exemplo n.º 2
0
        private void CreateSettingUpdater_FormClosing(object sender, FormClosingEventArgs e)
        {
            if ((e.CloseReason != CloseReason.UserClosing & e.CloseReason != CloseReason.None) ||
                this.DialogResult != DialogResult.OK)
            {
                return;
            }

            if (errorTracker.Count != 0)
            {
                Dialogs.ErrorF(this, errorTracker.ToString());
                e.Cancel = true;

                if (editLink != null)
                {
                    ItemsInSets.Add(editLink);
                }
                return;
            }

            DbTypeItem dbItem = (DbTypeItem)cmbDbConectionType.SelectedItem;

            int?taskId = null;
            int tid;

            if (int.TryParse(tbNumberTask.Text, out tid))
            {
                taskId = tid;
            }

            // формируем настройку для получения настроек
            TfsDbLink newLink = editLink ?? new TfsDbLink();

            newLink.Name                 = tbSettingName.Text;
            newLink.ServerUri            = new Uri(tbTfsProject.Text);
            newLink.ServerPathToSettings = tbSetFileServerFolder.Text + "/" + tbFileNameSet.Text;


            // Собираем и пакуем настройки накатки
            var newSet = new UpdateDbSetting();

            newSet.ServerPathScripts                 = tbFolderForScripts.Text;
            newSet.TypeConnectionFullName            = dbItem.ConType.ToString();
            newSet.AssemplyWithImplementDbConnection = dbItem.AssembyRawBytes;
            newSet.ConnectionStringModelDb           = tbConnectionString.Text;
            newSet.ScriptPartBeforeBodyWithTran      = tbPartBeforescript.Text.GetNullIfIsNullOrWhiteSpace();
            newSet.ScriptPartAfterBodyWithTran       = tbPartAfterScript.Text.GetNullIfIsNullOrWhiteSpace();
            newSet.ScriptUpdateVer = tbScriptUpdateVer.Text.GetNullIfIsNullOrWhiteSpace();
            newSet.FormatBinary    = new FormatBinaryData()
            {
                Prefix     = tbFormatBinPrefix.Text,
                FormatByte = tbFormatBinFormat.Text
            };

            var encodedSetting = newSet.SerializeAesEncrypt(newLink.ServerPathToSettings);

            string fileNameSet = tbFileNameSet.Text;

            try
            {
                using (var tfsbl = new TFSRoutineBL())
                {
                    var localFileSetPath = Path.Combine(tfsbl.Tempdir, fileNameSet);

                    tfsbl.VersionControl(new Uri(tbTfsProject.Text));
                    tfsbl.MapTempWorkspace(tbSetFileServerFolder.Text);

                    tfsbl.GetLastFile(fileNameSet);

                    var fileExist = File.Exists(localFileSetPath);

                    if (fileExist && !tfsbl.CheckOut(localFileSetPath))
                    {
                        throw new Exception("Извлечение настроек неуспешно. Повторите позже");
                    }

                    // блокируем от изменений
                    if (fileExist && !tfsbl.LockFile(fileNameSet))
                    {
                        throw new Exception("Производится сохранение настроек другим пользователем.");
                    }

                    // если есть - удаляем
                    if (fileExist)
                    {
                        File.Delete(localFileSetPath);
                    }

                    // записываем новый
                    File.WriteAllBytes(localFileSetPath, encodedSetting);

                    if (!fileExist)
                    {
                        tfsbl.AddFile(localFileSetPath);
                    }

                    List <int> linkedTask = new List <int>();
                    if (taskId.HasValue)
                    {
                        linkedTask.Add(taskId.Value);
                    }
                    tfsbl.CheckIn("Добавленение настроек версионности", linkedTask);
                }

                if (editLink == null)
                {
                    this.ItemsInSets.Add(newLink);
                }
            }
            catch (Exception ex)
            {
                String msg = ex.Expand();
                if (ex.GetType().Name == "TargetInvocationException" && ex.InnerException != null)
                {
                    msg = ex.InnerException.Message;
                }
                Dialogs.ErrorF(this, "Сохранение неуспешно" + Environment.NewLine + msg);
                e.Cancel = true;
            }
        }
Exemplo n.º 3
0
        private void cmbDbConectionType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbDbConectionType.SelectedIndex < 0)
            {
                return;
            }

            DbTypeItem selItem = (DbTypeItem)cmbDbConectionType.SelectedItem;

            if (selItem.ConType != null)
            {
                tbConnectionString_Validating(null, null);
                return;
            }

            var filePathAssembly = Dialogs.FileBrowser(
                Owner: this,
                Title: "Выбор сборки с реализацией DbConnection",
                DefaultExt: ".ddl",
                Filter: "Assemblys dll|*.dll",
                AddExtension: false).FirstOrDefault();

            if (filePathAssembly.IsNullOrWhiteSpace())
            {
                cmbDbConectionType.SelectedIndex = 0;
                return;
            }

            Assembly fileAssembly = null;

            byte[] fileAssemblyRaw = null;

            try
            {
                var assName = AssemblyName.GetAssemblyName(filePathAssembly);

                fileAssembly    = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName == assName.FullName);
                fileAssemblyRaw = File.ReadAllBytes(filePathAssembly);

                if (fileAssembly == null)
                {
                    fileAssembly = Assembly.LoadFile(filePathAssembly);
                }
                else
                {
                    var setItem = cmbDbConectionType.Items.Cast <DbTypeItem>().FirstOrDefault(x => x.AssembyNameFile != null && x.AssembyNameFile.FullName == assName.FullName);
                    if (setItem != null)
                    {
                        cmbDbConectionType.SelectedItem = setItem;
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                Dialogs.ErrorF(this, ex.Expand());
                cmbDbConectionType.SelectedIndex = 0;
                return;
            }

            foreach (var asType in fileAssembly.ExportedTypes.Where(x => x.IsSubclassOf(typeof(DbConnection))))
            {
                var item = new DbTypeItem();
                item.ConType         = asType;
                item.AssembyRawBytes = fileAssemblyRaw;
                item.AssembyNameFile = fileAssembly.GetName();
                cmbDbConectionType.Items.Insert(cmbDbConectionType.Items.Count - 1, item);
                cmbDbConectionType.SelectedItem = item;
            }

            if (cmbDbConectionType.SelectedItem == selItem)
            {
                cmbDbConectionType.SelectedIndex = 0;
            }
        }
Exemplo n.º 4
0
        public void EditedSet(TfsDbLink tfsDbLinckSet)
        {
            editLink = tfsDbLinckSet;
            if (
                editLink == null ||
                editLink.Name.IsNullOrWhiteSpace() ||
                editLink.ServerUri == null ||
                editLink.ServerUri.AbsolutePath.IsNullOrWhiteSpace() ||
                editLink.ServerPathToSettings.IsNullOrWhiteSpace()
                )
            {
                return;
            }

            String tempfile = null;

            try
            {
                UpdateDbSetting upsets = null;
                using (TFSRoutineBL tfsbl = new TFSRoutineBL())
                {
                    tfsbl.VersionControl(editLink.ServerUri);

                    tempfile = Path.Combine(DomainContext.TempPath, Guid.NewGuid().ToString());
                    tfsbl.DownloadFile(editLink.ServerPathToSettings, tempfile);
                }

                try
                {
                    upsets = File.ReadAllBytes(tempfile).DeserializeAesDecrypt <UpdateDbSetting>(editLink.ServerPathToSettings);
                }
                catch (Exception ex)
                {
                    String msg = ex.Expand();
                    if (ex.GetType().Name == "TargetInvocationException" && ex.InnerException != null)
                    {
                        msg = ex.InnerException.Message;
                    }
                    throw new Exception("Получение файла настроек неуспешно. Exception: " + msg);
                }

                if (upsets == null || upsets.ServerPathScripts.IsNullOrWhiteSpace())
                {
                    throw new Exception("Получение файла настроек неуспешно");
                }

                Type    conn             = typeof(SqlConnection);
                Boolean useSqlConnection = true;

                if (upsets.TypeConnectionFullName != conn.ToString())
                {
                    if (upsets.AssemplyWithImplementDbConnection == null)
                    {
                        throw new Exception($"В настроках указан тип DbConnection '{upsets.TypeConnectionFullName}', но отсутствует бинарное представление сборки реализации");
                    }

                    conn = null;
                    Assembly conAss = null;

                    foreach (var asmly in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        conn = asmly.GetType(upsets.TypeConnectionFullName, false);

                        if (conn != null)
                        {
                            conAss = asmly;
                            break;
                        }
                    }

                    if (conn == null)
                    {
                        conAss = AppDomain.CurrentDomain.Load(upsets.AssemplyWithImplementDbConnection);
                    }

                    conn = conAss.ExportedTypes.FirstOrDefault(x => x.FullName == upsets.TypeConnectionFullName);

                    if (conn == null)
                    {
                        throw new Exception($"Не удалось найти тип DbConnection '{upsets.TypeConnectionFullName}'");
                    }
                    useSqlConnection = false;
                }

                tbFolderForScripts.Text = upsets.ServerPathScripts;
                tbConnectionString.Text = upsets.ConnectionStringModelDb;
                tbPartBeforescript.Text = upsets.ScriptPartBeforeBodyWithTran;
                tbPartAfterScript.Text  = upsets.ScriptPartAfterBodyWithTran;
                tbScriptUpdateVer.Text  = upsets.ScriptUpdateVer;
                tbTfsProject.Text       = editLink.ServerUri.OriginalString;
                var revStr      = new String(editLink.ServerPathToSettings.Reverse().ToArray());
                var revFileName = revStr.SubString(0, revStr.IndexOf("/"));
                var revServPath = revStr.SubString(revStr.IndexOf("/") + 1);
                tbSetFileServerFolder.Text = new String(revServPath.Reverse().ToArray());
                tbFileNameSet.Text         = new String(revFileName.Reverse().ToArray());

                var formatBin = upsets.FormatBinary ?? new FormatBinaryData();
                tbFormatBinPrefix.Text = formatBin.Prefix;
                tbFormatBinFormat.Text = formatBin.FormatByte;

                if (!useSqlConnection)
                {
                    var item = new DbTypeItem();
                    item.AssembyRawBytes = upsets.AssemplyWithImplementDbConnection;
                    item.ConType         = conn;
                    item.AssembyNameFile = conn.Assembly.GetName();

                    cmbDbConectionType.Items.Insert(cmbDbConectionType.Items.Count - 1, item);
                    cmbDbConectionType.SelectedItem = item;
                }

                tbSettingName.Text = editLink.Name;

                ValidateAll();
                tbFileNameSet.ReadOnly        = true;
                btPathFoldertoFileSet.Enabled = false;
                btSelectProjectTFS.Enabled    = false;
            }
            catch
            {
                throw;
            }
            finally
            {
                if (!tempfile.IsNullOrWhiteSpace() || File.Exists(tempfile))
                {
                    File.Delete(tempfile);
                }
            }
        }