public ShopRoomCrawler() { Uri uri = new Uri("http://m.yofang.cn/server/shop/search"); ShopRoomCriteria criteria = new ShopRoomCriteria(); criteria.city = "北京"; criteria.from = 0; criteria.PageNo = 1; criteria.perPageCount = 10; var webResponse = new WebAgent().Request(uri, criteria); var stream = webResponse.GetResponseStream(); string strResponse = ZipWrapper.GetResponseContent(stream); _htmlContent = strResponse; }
public void LoadWorld(string argFileName) { //Create Temp directory DirectoryInfo localDirectory = Directory.CreateDirectory("ScWorldEdit"); string newFileName = localDirectory.FullName + "\\Temp.zip"; File.Copy(argFileName, newFileName, true); //Open the zip file. //Save the three files to the Temp dir ZipWrapper.ExtractZipFile(newFileName, localDirectory.FullName); //Open the files. World.Load(localDirectory.FullName); //return localWorld; }
private void createDocumentButton_Click() { try { TabItem selectedItem = ((TabItem)openedProjectTabControl.SelectedItem); Dictionary <string, TextBox> markValueRefs; Dictionary <string, FrameworkElement> auxiliaryRefs; openedProjectMarkStorage.TryGetValue(selectedItem.Uid, out markValueRefs); openedProjectAuxiliaryStorage.TryGetValue(selectedItem.Uid, out auxiliaryRefs); FrameworkElement outputDocPath; auxiliaryRefs.TryGetValue("outputDocPath", out outputDocPath); FrameworkElement projectFilePath; auxiliaryRefs.TryGetValue("projectFilePath", out projectFilePath); if (((TextBox)outputDocPath).Text.Length == 0) { InformDialogUtil.ShowError("Не указан путь сохранения."); return; } List <string> outputFilePaths = ZipWrapper.ExtractTemplateAndGetResultFilePaths(((TextBox)projectFilePath).Text, ((TextBox)outputDocPath).Text, selectedItem.Header.ToString()); MicrosoftOfficeWrapper.UpdateBookmarkValuesAndSaveDocument(outputFilePaths, markValueRefs); // Clear TextBox Elements. foreach (var mvr in markValueRefs) { bool?isChecked = ((CheckBox)auxiliaryRefs[mvr.Key]).IsChecked; if (isChecked.Value == false) { mvr.Value.Text = string.Empty; } } InformDialogUtil.ShowInfoWithEntries("Создание документа(ов) выполнено успешно:", outputFilePaths); } catch (Exception ex) { InformDialogUtil.ShowError("Ошибка на этапе создания документа: \r\n" + ex.ToString()); } }
private void SaveProjectMethod(object sender, RoutedEventArgs e) { TabItem selectedItem = (TabItem)openedProjectTabControl.SelectedItem; if (selectedItem == null) { InformDialogUtil.ShowWarning("Нет открытого проекта."); return; } Dictionary <string, ObservableCollection <string> > dictWord; openedProjectDictWordStorage.TryGetValue(selectedItem.Uid, out dictWord); if (dictWord != null) { ZipWrapper.UpdateDictWordInProjectFileArchive(selectedItem.Uid, dictWord); InformDialogUtil.ShowInfo("Cловари для закладок успешно сохранены в файле проекта: " + selectedItem.Uid); } }
private void createProjectButton_Click(object sender, RoutedEventArgs e) { var fbd = new System.Windows.Forms.FolderBrowserDialog(); System.Windows.Forms.DialogResult result = fbd.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { string projectArchiveName = ZipWrapper.CreateProjectFileArchiveAndGetResultFilePath(projectModel, fbd.SelectedPath); InformDialogUtil.ShowInfo("Файл проекта создан: \r\n" + projectArchiveName); Close(); Owner.Close(); Owner.Owner.Close(); projectModel.openProjectDelegate(projectArchiveName); } else { InformDialogUtil.ShowWarning("Не указана директория для сохранения файла проекта."); } }
private void openProjectFunction(string projectFilePath) { ProjectModel currentProjectModel = ZipWrapper.ReadProjectModelFromArchive(projectFilePath); fillTabControlForSelectedProject(currentProjectModel, projectFilePath); }
private void fillTabControlForSelectedProject(ProjectModel currentProjectModel, string projectFilePath) { Thickness defaultThickness = new Thickness(5, 5, 5, 0); Thickness checkBoxThickness = new Thickness(5, 0, 5, 5); Dictionary <string, TextBox> markValueRefs = new Dictionary <string, TextBox>(); Dictionary <string, FrameworkElement> auxiliaryRefs = new Dictionary <string, FrameworkElement>(); auxiliaryRefs.Add("projectFilePath", new TextBox() { Text = projectFilePath }); // Fill UI with elements. Grid infoGrid = new Grid(); int rowNumber = 0; foreach (string groupName in currentProjectModel.templateGroups) { bool checkElementExistence = false; infoGrid.RowDefinitions.Add(new RowDefinition()); TextBlock groupBlock = new TextBlock() { Text = groupName, MinWidth = 25, HorizontalAlignment = HorizontalAlignment.Center, }; groupBlock.Padding = defaultThickness; infoGrid.Children.Add(groupBlock); Grid.SetRow(groupBlock, rowNumber++); foreach (KeyValuePair <string, string> pair in currentProjectModel.templateMarks) { if (!currentProjectModel.templateMarkSpecGroup[pair.Key].Equals(groupName)) { continue; } checkElementExistence = true; infoGrid.RowDefinitions.Add(new RowDefinition()); TextBlock textBlock = new TextBlock() { Text = pair.Value, MinWidth = 25, HorizontalAlignment = HorizontalAlignment.Left, FontWeight = FontWeights.DemiBold }; textBlock.Padding = defaultThickness; infoGrid.Children.Add(textBlock); Grid.SetRow(textBlock, rowNumber++); infoGrid.RowDefinitions.Add(new RowDefinition()); TextBox textBox = new TextBox() { MinWidth = 200, FontWeight = FontWeights.Regular }; markValueRefs.Add(pair.Key, textBox); textBox.Margin = defaultThickness; infoGrid.Children.Add(textBox); Grid.SetRow(textBox, rowNumber++); infoGrid.RowDefinitions.Add(new RowDefinition()); Button button = new Button() { Content = "...", Height = 20, Width = 20, HorizontalAlignment = HorizontalAlignment.Center, Command = new Command(arg => openDictWordButton_Click(pair.Key, pair.Value)) }; infoGrid.Children.Add(button); button.Margin = checkBoxThickness; Grid.SetRow(button, rowNumber); infoGrid.RowDefinitions.Add(new RowDefinition()); CheckBox checkBox = new CheckBox() { IsChecked = false, Height = 20, Width = 20, HorizontalAlignment = HorizontalAlignment.Right }; infoGrid.Children.Add(checkBox); checkBox.Margin = checkBoxThickness; Grid.SetRow(checkBox, rowNumber++); auxiliaryRefs.Add(pair.Key, checkBox); } if (checkElementExistence) { infoGrid.RowDefinitions.Add(new RowDefinition()); Separator groupSeparator = new Separator(); infoGrid.Children.Add(groupSeparator); groupSeparator.Margin = new Thickness(5, 10, 5, 10); Grid.SetRow(groupSeparator, rowNumber++); } else { infoGrid.Children.Remove(groupBlock); } } infoGrid.RowDefinitions.Add(new RowDefinition()); TextBlock infoTextBlock = new TextBlock() { Text = "Путь сохранения документа(ов) после вставки закладок" }; infoTextBlock.Padding = defaultThickness; infoGrid.Children.Add(infoTextBlock); Grid.SetRow(infoTextBlock, rowNumber++); infoGrid.RowDefinitions.Add(new RowDefinition()); TextBox outputDocPath = new TextBox() { MinWidth = 200, HorizontalAlignment = HorizontalAlignment.Stretch, FontWeight = FontWeights.Regular }; auxiliaryRefs.Add("outputDocPath", outputDocPath); infoGrid.Children.Add(outputDocPath); outputDocPath.Margin = defaultThickness; Grid.SetRow(outputDocPath, rowNumber++); infoGrid.RowDefinitions.Add(new RowDefinition()); Button outputDocButton = new Button() { Content = "Обзор", Width = 60, HorizontalAlignment = HorizontalAlignment.Right, Command = new Command(arg => documentPathBrowseButton_Click()) }; infoGrid.Children.Add(outputDocButton); outputDocButton.Margin = new Thickness(0, 0, 5, 0); Grid.SetRow(outputDocButton, rowNumber++); infoGrid.RowDefinitions.Add(new RowDefinition()); Separator separator2 = new Separator(); infoGrid.Children.Add(separator2); separator2.Margin = defaultThickness; Grid.SetRow(separator2, rowNumber++); infoGrid.RowDefinitions.Add(new RowDefinition()); Button createFinalDocButton = new Button() { Content = "Cоздать", Width = 120, HorizontalAlignment = HorizontalAlignment.Center, Command = new Command(arg => createDocumentButton_Click()) }; infoGrid.Children.Add(createFinalDocButton); createFinalDocButton.Margin = defaultThickness; Grid.SetRow(createFinalDocButton, rowNumber++); // Organize storage units. openedProjectMarkStorage.Add(projectFilePath, markValueRefs); openedProjectAuxiliaryStorage.Add(projectFilePath, auxiliaryRefs); Dictionary <string, ObservableCollection <string> > dictWord = (Dictionary <string, ObservableCollection <string> >)ZipWrapper.ReadDictWordFromArchive(projectFilePath); if (dictWord != null) { openedProjectDictWordStorage.Add(projectFilePath, dictWord); } openedProjectTabControl.Items.Add(new TabItem() { Header = currentProjectModel.name, Content = infoGrid, Uid = projectFilePath, FontWeight = FontWeights.SemiBold }); openedProjectTabControl.SelectedIndex = openedProjectTabControl.Items.Count - 1; openedProjectTabControl.Visibility = Visibility.Visible; }