// Warning - will not work - see comment above ProblemFour method invokation in Main()
        public static void Main()
        {
            var mongoHandler = new MongoDbHandler();
            var sqlHandler = new SqlServerHandler();
            var mySqlHandler = new MySqlHandler();
            var pdfHandler = new PdfHandler();
            var xmlToSql = new XmlToSqlServerLoader();
            var excellHandler = new ExcellHandler();
            var mongoToSql = new MongoToSqlServerLoader();
            var zipExtractor = new ZipExtractor();
            var jsonHandler = new JsonHandler();
            var sqliteHandler = new SqliteHandler();
            var xmlHandler = new XmlHandler();

            if (!Directory.Exists(OutputDirectory))
            {
                Directory.CreateDirectory(OutputDirectory);
            }

            //// Mongolab.com credentials - Username: TeamXenon , Passsword: xenon123

            ProblemOne(mongoHandler, mongoToSql, zipExtractor, excellHandler);

            ProblemTwo(pdfHandler);

            ProblemThree(xmlHandler);

            //// NOTE!!! - you need to go to CarParts.Data.MySql project and in its App.config file
            //// you should change the password in the connectionString tag with which you connect to your localhost instance of the MySQL Workbench server.
            ProblemFour(sqlHandler, mySqlHandler, jsonHandler);

            ProblemFive(mongoHandler, xmlToSql);

            ProblemSix(excellHandler, sqlHandler, sqliteHandler, mySqlHandler);
        }
Пример #2
0
        private static void ExtractDic(string dictionaryFolder, ZipExtractor zip, List<ZipExtractor.ZipFileEntry> dir, ref bool found)
        {
            foreach (ZipExtractor.ZipFileEntry entry in dir)
            {
                if (entry.FilenameInZip.EndsWith(".dic", StringComparison.OrdinalIgnoreCase) || entry.FilenameInZip.EndsWith(".aff", StringComparison.OrdinalIgnoreCase))
                {
                    string fileName = Path.GetFileName(entry.FilenameInZip);

                    // French fix
                    if (fileName.StartsWith("fr-moderne"))
                        fileName = fileName.Replace("fr-moderne", "fr_FR");

                    // German fix
                    if (fileName.StartsWith("de_DE_frami"))
                        fileName = fileName.Replace("de_DE_frami", "de_DE");

                    // Russian fix
                    if (fileName.StartsWith("russian-aot"))
                        fileName = fileName.Replace("russian-aot", "ru_RU");

                    string path = Path.Combine(dictionaryFolder, fileName);
                    zip.ExtractFile(entry, path);

                    found = true;
                }
            }
        }
Пример #3
0
        private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            Cursor = Cursors.Default;
            if (e.Error != null && _xmlName == "Nikse.SubtitleEdit.Resources.HunspellDictionaries.xml.gz")
            {
                MessageBox.Show("Unable to download " + _downloadLink + Environment.NewLine +
                                "Switching host - please re-try!");
                LoadDictionaryList("Nikse.SubtitleEdit.Resources.HunspellBackupDictionaries.xml.gz");
                labelPleaseWait.Text         = string.Empty;
                buttonOK.Enabled             = true;
                buttonDownload.Enabled       = true;
                buttonDownloadAll.Enabled    = true;
                comboBoxDictionaries.Enabled = true;
                Cursor = Cursors.Default;
                return;
            }

            if (e.Error != null)
            {
                MessageBox.Show(LanguageSettings.Current.GetTesseractDictionaries.DownloadFailed + Environment.NewLine +
                                Environment.NewLine +
                                e.Error.Message);
                DialogResult = DialogResult.Cancel;
                return;
            }

            string dictionaryFolder = Utilities.DictionaryFolder;

            if (!Directory.Exists(dictionaryFolder))
            {
                Directory.CreateDirectory(dictionaryFolder);
            }

            int index = comboBoxDictionaries.SelectedIndex;

            using (var ms = new MemoryStream(e.Result))
                using (ZipExtractor zip = ZipExtractor.Open(ms))
                {
                    List <ZipExtractor.ZipFileEntry> dir = zip.ReadCentralDir();
                    // Extract dic/aff files in dictionary folder
                    bool found = false;
                    ExtractDic(dictionaryFolder, zip, dir, ref found);

                    if (!found) // check zip inside zip
                    {
                        foreach (ZipExtractor.ZipFileEntry entry in dir)
                        {
                            if (entry.FilenameInZip.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
                            {
                                using (var innerMs = new MemoryStream())
                                {
                                    zip.ExtractFile(entry, innerMs);
                                    ZipExtractor innerZip = ZipExtractor.Open(innerMs);
                                    List <ZipExtractor.ZipFileEntry> innerDir = innerZip.ReadCentralDir();
                                    ExtractDic(dictionaryFolder, innerZip, innerDir, ref found);
                                }
                            }
                        }
                    }
                }

            Cursor = Cursors.Default;
            labelPleaseWait.Text         = string.Empty;
            buttonOK.Enabled             = true;
            buttonDownload.Enabled       = true;
            buttonDownloadAll.Enabled    = true;
            comboBoxDictionaries.Enabled = true;
            if (_testAllIndex >= 0)
            {
                DownloadNext();
                return;
            }
            MessageBox.Show(string.Format(LanguageSettings.Current.GetDictionaries.XDownloaded, comboBoxDictionaries.Items[index]));
        }
Пример #4
0
        private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            labelPleaseWait.Text = string.Empty;
            if (e.Error != null)
            {
                MessageBox.Show(Configuration.Settings.Language.GetTesseractDictionaries.DownloadFailed);
                ChangeControlsState(true);
                Cursor       = Cursors.Default;
                DialogResult = DialogResult.Cancel;
                return;
            }

            string pluginsFolder = Configuration.PluginsDirectory;

            if (!Directory.Exists(pluginsFolder))
            {
                try
                {
                    Directory.CreateDirectory(pluginsFolder);
                }
                catch (Exception exception)
                {
                    MessageBox.Show($"Unable to create plugin folder {pluginsFolder}: {exception.Message}");
                    ChangeControlsState(true);
                    Cursor = Cursors.Default;
                    return;
                }
            }

            var ms = new MemoryStream(e.Result);

            using (ZipExtractor zip = ZipExtractor.Open(ms))
            {
                List <ZipExtractor.ZipFileEntry> dir = zip.ReadCentralDir();

                // Extract dic/aff files in dictionary folder
                foreach (ZipExtractor.ZipFileEntry entry in dir)
                {
                    string fileName = Path.GetFileName(entry.FilenameInZip);
                    string fullPath = Path.Combine(pluginsFolder, fileName);
                    if (File.Exists(fullPath))
                    {
                        try
                        {
                            File.Delete(fullPath);
                        }
                        catch
                        {
                            MessageBox.Show($"{fullPath} already exists - unable to overwrite it");
                            Cursor = Cursors.Default;
                            ChangeControlsState(true);
                            return;
                        }
                    }
                    zip.ExtractFile(entry, fullPath);
                }
            }
            Cursor = Cursors.Default;
            ChangeControlsState(true);
            if (_updatingAllPlugins)
            {
                _updatingAllPluginsCount++;
                if (_updatingAllPluginsCount == _updateAllListUrls.Count)
                {
                    MessageBox.Show(string.Format(_language.XPluginsUpdated, _updatingAllPluginsCount));
                }
            }
            else
            {
                MessageBox.Show(string.Format(_language.PluginXDownloaded, _downloadedPluginName));
            }
            ShowInstalledPlugins();
        }
        public static void LaunchUpdate(object paramObj)
        {
            Task.Run(async() =>
            {
                var param = (UpdateOrchestraMasterParams)paramObj;

                var modPathList = GetModPathList(param.GameDataPath);
                //var modPathList = new List<string>();
                //modPathList.Add("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Kerbal Space Program\\GameData\\AirplanePlus");     // Forum KSP URL
                //modPathList.Add("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Kerbal Space Program\\GameData\\B9PartSwitch");     // Github URL
                //modPathList.Add("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Kerbal Space Program\\GameData\\EasyVesselSwitch"); // Curseforge URL
                //modPathList.Add("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Kerbal Space Program\\GameData\\FuelTanksPlus");    // Spacedock URL

                //Todo : Parallel.ForEach()
                foreach (var modpath in modPathList)
                {
                    var toLog = new List <UpdateDetails>();
                    try
                    {
                        var modName        = new DirectoryInfo(modpath).Name;
                        var dotVersionFile = new DotVersion(modpath);

                        if (string.IsNullOrEmpty(dotVersionFile.DownloadLink))
                        {
                            toLog.Add(new UpdateDetails()
                            {
                                ModName = modName,
                                Status  = UpdateStatus.FailedToUpdate,
                                Tooltip = "! No Download link inside " + modName + " mod"
                            });
                            continue;
                        }

                        IDownloadLink hostLink = DownloadLinkHelper.GetHostType(dotVersionFile.DownloadLink,
                                                                                dotVersionFile.ModName, param.Webview);
                        var zipExtractor = new ZipExtractor(hostLink.ZipLink);
                        zipExtractor.DownloadAndExtract();

                        var updateMod = new PushUpdatedMod(zipExtractor.UnzippedDirectory, param.GameDataPath, modName);

                        toLog.AddRange(await updateMod.AutomaticPush());
                    }
                    catch (Exception e)
                    {
                        toLog.Add(new UpdateDetails()
                        {
                            ModName = new DirectoryInfo(modpath).Name,
                            Status  = UpdateStatus.FailedToUpdate,
                            Tooltip = "! " + e.Message,
                        });
                    }
                    finally
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            foreach (UpdateDetails log in toLog)
                            {
                                if (param.Logs.ContainsKey(log.ModName))
                                {
                                    // ModAdded < SuccessfullyUpdated < AlreadyUpdated < FailedToUpdate
                                    // So if my log is inferior has the saved one, it should be updated. Else, it shouldn't
                                    if (log.Status < param.Logs[log.ModName].Status)
                                    {
                                        param.Logs[log.ModName] = log;
                                    }
                                }
                                else
                                {
                                    param.Logs.Add(log.ModName, log);
                                }

                                Trace.WriteLine(log.Tooltip);
                            }
                        });
                    }
                }
            }).Wait();
        }
Пример #6
0
        /// <summary>
        /// Method to open an existing storage from stream
        /// </summary>
        /// <param name="stream">Already opened stream with zip contents</param>
        /// <returns>A valid ZipStorer object</returns>
        public static ZipExtractor Open(Stream stream)
        {
            ZipExtractor zip = new ZipExtractor();
            zip.ZipFileStream = stream;

            if (zip.ReadFileInfo())
                return zip;

            throw new System.IO.InvalidDataException();
        }
Пример #7
0
        public bool ProcessRequestAsync(IRequest request,
                                        ISchemeHandlerResponse response,
                                        OnRequestCompletedHandler requestCompletedCallback)
        {
            Uri u = new Uri(request.Url);

            string inZipUri = "index.html";
            string zipPath  = u.AbsolutePath;

            int idx = zipPath.IndexOf("::");

            if (idx > 0)
            {
                inZipUri = zipPath.Substring(idx + 3);

                zipPath = zipPath.Substring(0, idx);
                zipPath = zipPath.Replace("%20", " ");
            }

            // String file = u.Authority; // + u.AbsolutePath;

            if (File.Exists(zipPath))
            {
                try
                {
                    response.ResponseStream = ZipExtractor.ExtractToMemoryStream(zipPath, inZipUri);
                }
                catch (Exception exp)
                {
                    byte[] byteArray = Encoding.ASCII.GetBytes(EncodeHTML(
                                                                   string.Format("Error reading:\n File:'{0}'\n Url:'{1}'\n Message:{2}",
                                                                                 zipPath, inZipUri, exp.Message)));

                    MemoryStream stream = new MemoryStream(byteArray);

                    response.ResponseStream = stream;
                }

                switch (Path.GetExtension(inZipUri))
                {
                case ".htm":
                case ".html":
                    response.MimeType = "text/html";
                    break;

                case ".js":
                    response.MimeType = "text/javascript";
                    break;

                case ".png":
                    response.MimeType = "image/png";
                    break;

                case ".appcache":
                case ".manifest":
                    response.MimeType = "text/cache-manifest";
                    break;

                case ".css":
                    response.MimeType = "text/css";
                    break;

                default:
                    response.MimeType = "application/octet-stream";
                    break;
                }

                requestCompletedCallback();
                return(true);
            }

            return(false);
        }
Пример #8
0
        private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (e.Error != null && _xmlName == "Nikse.SubtitleEdit.Resources.OpenOfficeDictionaries.xml.zip")
            {
                MessageBox.Show("Unable to connect to extensions.services.openoffice.org... Switching host - please re-try!");
                LoadDictionaryList("Nikse.SubtitleEdit.Resources.HunspellDictionaries.xml.gz");
                labelPleaseWait.Text         = string.Empty;
                buttonOK.Enabled             = true;
                buttonDownload.Enabled       = true;
                comboBoxDictionaries.Enabled = true;
                Cursor = Cursors.Default;
                return;
            }
            else if (e.Error != null)
            {
                MessageBox.Show(Configuration.Settings.Language.GetTesseractDictionaries.DownloadFailed + Environment.NewLine +
                                Environment.NewLine +
                                e.Error.Message);
                DialogResult = DialogResult.Cancel;
                return;
            }

            string dictionaryFolder = Utilities.DictionaryFolder;

            if (!Directory.Exists(dictionaryFolder))
            {
                Directory.CreateDirectory(dictionaryFolder);
            }

            int index = comboBoxDictionaries.SelectedIndex;

            var ms = new MemoryStream(e.Result);

            ZipExtractor zip = ZipExtractor.Open(ms);
            List <ZipExtractor.ZipFileEntry> dir = zip.ReadCentralDir();

            // Extract dic/aff files in dictionary folder
            bool found = false;

            ExtractDic(dictionaryFolder, zip, dir, ref found);

            if (!found) // check zip inside zip
            {
                foreach (ZipExtractor.ZipFileEntry entry in dir)
                {
                    if (entry.FilenameInZip.ToLower().EndsWith(".zip", StringComparison.Ordinal))
                    {
                        var innerMs = new MemoryStream();
                        zip.ExtractFile(entry, innerMs);
                        ZipExtractor innerZip = ZipExtractor.Open(innerMs);
                        List <ZipExtractor.ZipFileEntry> innerDir = innerZip.ReadCentralDir();
                        ExtractDic(dictionaryFolder, innerZip, innerDir, ref found);
                        innerZip.Close();
                    }
                }
            }

            zip.Close();
            Cursor = Cursors.Default;
            labelPleaseWait.Text         = string.Empty;
            buttonOK.Enabled             = true;
            buttonDownload.Enabled       = true;
            comboBoxDictionaries.Enabled = true;
            MessageBox.Show(string.Format(Configuration.Settings.Language.GetDictionaries.XDownloaded, comboBoxDictionaries.Items[index]));
        }
Пример #9
0
        void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            labelPleaseWait.Text = string.Empty;
            if (e.Error != null)
            {
                MessageBox.Show("Download failed!");
                DialogResult = DialogResult.Cancel;
                return;
            }

            string pluginsFolder = Configuration.PluginsDirectory;

            if (!Directory.Exists(pluginsFolder))
            {
                try
                {
                    Directory.CreateDirectory(pluginsFolder);
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Unable to create plugin folder " + pluginsFolder + ": " + exception.Message);
                    return;
                }
            }
            var ms = new MemoryStream(e.Result);

            ZipExtractor zip = ZipExtractor.Open(ms);
            List <ZipExtractor.ZipFileEntry> dir = zip.ReadCentralDir();

            // Extract dic/aff files in dictionary folder
            foreach (ZipExtractor.ZipFileEntry entry in dir)
            {
                string fileName = Path.GetFileName(entry.FilenameInZip);
                string fullPath = Path.Combine(pluginsFolder, fileName);
                if (File.Exists(fullPath))
                {
                    try
                    {
                        File.Delete(fullPath);
                    }
                    catch
                    {
                        MessageBox.Show(string.Format("{0} already exists - unable to overwrite it", fullPath));
                        Cursor = Cursors.Default;
                        labelPleaseWait.Text       = string.Empty;
                        buttonOK.Enabled           = true;
                        buttonDownload.Enabled     = true;
                        listViewGetPlugins.Enabled = true;
                        return;
                    }
                }
                zip.ExtractFile(entry, fullPath);
            }
            zip.Close();
            ms.Close();
            Cursor = Cursors.Default;
            labelPleaseWait.Text       = string.Empty;
            buttonOK.Enabled           = true;
            buttonDownload.Enabled     = true;
            listViewGetPlugins.Enabled = true;
            MessageBox.Show(string.Format(_language.PluginXDownloaded, _downloadedPluginName));
            ShowInstalledPlugins();
        }
        private static void ProblemOne(MongoDbHandler mongoHandler, MongoToSqlServerLoader mongoToSql, ZipExtractor extractor, ExcellHandler excellHandler)
        {
            /*// populating database in mongolab with some useless testing data
            try
            {
                new mongodataseeder().seed(mongohandler);
            }
            catch (exception ex)
            {
                console.writeline("just in case you uncomment and try to populate the cloud database with existing id's and it throws :)");
            }*/

            mongoToSql.Load(mongoHandler);
            Console.WriteLine("successsfully added all in a sql database");

            extractor.Extract();
            Console.WriteLine("Files extracted successfully.");

            excellHandler.MigrateFromExcellToSqlServer();
            Console.WriteLine("successfully added sales table from excell files.");
        }
Пример #11
0
 public ZipExtractorProxy(IDirectory directory)
 {
     extractor = directory as ZipExtractor;
 }
Пример #12
0
        private static void ImportSalesFromExcel()
        {
            var db = new ChemicalsDbContext();

            IZipExtractor zipExtractor = new ZipExtractor();
            ExcelImporter<Sale> k = new ExcelImporter<Sale>(zipExtractor);
            ICollection<Sale> sales = k.ImportModelsDataFromZipFile("../../../Files/Sales.zip", "./tests2");

            foreach (var item in sales)
            {
                db.Sales.Add(item);
            }

            db.SaveChanges();

            Console.WriteLine("The data was successfully imported to SQL Server.");
        }
Пример #13
0
        private static void ImportProducesFromExcel()
        {
            var db = new ChemicalsDbContext();

            IZipExtractor zipExtractor = new ZipExtractor();
            ExcelImporter<Produce> k = new ExcelImporter<Produce>(zipExtractor);
            ICollection<Produce> produces = k.ImportModelsDataFromZipFile("../../../Files/Produces.zip", "./tests1");

            foreach (var item in produces)
            {
                db.Produces.Add(item);
            }

            db.SaveChanges();
        }