Example #1
0
        private void btAdd_Click(object sender, EventArgs e)
        {
            var nl = new TfsDbLink();

            do
            {
                nl.Name = Dialogs.InputBox(this, "Наименование связки TFS-DB.", "Наименование связки", "Новая связка");

                if (nl.Name.IsNullOrWhiteSpace())
                {
                    MessageBox.Show(this, "Не указано наименование связки");
                    return;
                }

                if (link.Any(x => x.Name == nl.Name))
                {
                    MessageBox.Show(this, "Наименование должно быть уникальным");
                }
            } while (link.Any(x => x.Name == nl.Name));

            WrapTfs wrapTfs = new WrapTfs();

            nl.ServerUri = wrapTfs.ShowTeamProjectPicker(this);

            SelFileOnServer(nl);

            link.Add(nl);

            dgvTFSDB.Update();
        }
Example #2
0
        private void SelFileOnServer(TfsDbLink link)
        {
            if (link.ServerUri != null)
            {
                WrapTfs wrapTfs = new WrapTfs();
                var     vc      = wrapTfs.VersionControlServerGet(link.ServerUri);

                var selItem = wrapTfs.ShowDialogChooseItem(this, vc);

                if (selItem == null)
                {
                    return;
                }

                if (selItem.ItemType != ItemType.File)
                {
                    Dialogs.ErrorF(this, "Необходимо выбрать файл настроек");
                    return;
                }

                var tempFile = Path.Combine(DomainContext.TempPath, Guid.NewGuid().ToString());

                wrapTfs.VersionControlServerDownloadFile(vc, selItem.Path, tempFile);

                UpdateDbSetting sets = null;
                String          msg  = "Файл настроек не расшифрован. Либо выбран не файл настроек, либо еще чо. Exception: {0}";
                try
                {
                    sets = File.ReadAllBytes(tempFile).DeserializeAesDecrypt <UpdateDbSetting>(selItem.Path);
                }
                catch (Exception ex)
                {
                    msg = String.Format(msg, ex.Expand());
                }

                if (sets == null || sets.ServerPathScripts.IsNullOrWhiteSpace())
                {
                    Dialogs.InformationF(this, msg);
                }
                else
                {
                    link.ServerPathToSettings = selItem.Path;
                }
            }
        }
Example #3
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;
            }
        }
Example #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);
                }
            }
        }