Exemplo n.º 1
0
        /// <summary>
        /// Creates the default config.
        /// </summary>
        /// <param name="defaultLerningModulesPath">The default lerning modules path.</param>
        /// <remarks>Documented by Dev03, 2009-05-07</remarks>
        public static void CreateDefaultConfig(string defaultLerningModulesPath)
        {
            if (Directory.Exists(defaultLerningModulesPath))
            {
                Settings.Default.DicDir = defaultLerningModulesPath;
                Settings.Default.Save();

                string configPath = Setup.UserConfigPath;

                //Get the only connection from
                IConnectionString defaultConnection = ConnectionStringHandler.GetDefaultConnectionString(configPath);
                if (defaultConnection as UncConnectionStringBuilder == null)
                {
                    ConnectionStringHandler.CreateUncConnection(Resources.DEFAULT_CONNECTION_NAME, defaultLerningModulesPath, configPath, Resources.DEFAULT_CONNECTION_FILE, true, Setup.IsPathOnStick(defaultLerningModulesPath));
                }
                else
                {
                    UncConnectionStringBuilder builder = new UncConnectionStringBuilder(defaultLerningModulesPath, true, Setup.IsPathOnStick(defaultLerningModulesPath));
                    builder.Name = defaultConnection.Name;

                    ConnectionStringHandler.CreateUncConnection(builder, Path.GetDirectoryName(defaultConnection.ConfigFileName), Path.GetFileName(defaultConnection.ConfigFileName));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the profile environment.
        /// </summary>
        /// <remarks>Documented by Dev05, 2007-11-15</remarks>
        public static void InitializeProfile(bool copyDemoDictionary, string dictionaryParentPath)
        {
            MLifter.Controls.LoadStatusMessage progress = new MLifter.Controls.LoadStatusMessage(Resources.UNPACK_TLOADMSG, 100, true);

            try
            {
                if (!Directory.Exists(dictionaryParentPath))
                {
                    Directory.CreateDirectory(dictionaryParentPath);
                }

                if (!copyDemoDictionary)
                {
                    return;
                }

                string zipFilePath = Path.Combine(Application.StartupPath, Resources.SETUP_STARTUP_FOLDERS);

                if (!File.Exists(zipFilePath))
                {
                    return;
                }

                progress.SetProgress(0);
                Cursor.Current = Cursors.WaitCursor;
                progress.Show();

                long    zCount = 0;
                ZipFile zFile  = null;
                try
                {
                    zFile  = new ZipFile(zipFilePath);
                    zCount = zFile.Count;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (zFile != null)
                    {
                        zFile.Close();
                    }
                }
                if (zCount == 0)
                {
                    return;
                }

                using (ZipInputStream zipFile = new ZipInputStream(File.OpenRead(zipFilePath)))
                {
                    ZipEntry entry;

                    int zCounter = 1;
                    while ((entry = zipFile.GetNextEntry()) != null)
                    {
                        string directoryName = Path.GetDirectoryName(entry.Name);
                        string fileName      = Path.GetFileName(entry.Name);

                        if (directoryName.Length > 0)
                        {
                            Directory.CreateDirectory(Path.Combine(dictionaryParentPath, directoryName));
                        }

                        if (fileName.Length > 0)
                        {
                            using (FileStream stream = File.Open(Path.Combine(Path.Combine(dictionaryParentPath, directoryName), fileName), FileMode.Create, FileAccess.Write, FileShare.None))
                            {
                                int    bufferSize = 1024;
                                byte[] buffer     = new byte[bufferSize];

                                while (bufferSize > 0)
                                {
                                    bufferSize = zipFile.Read(buffer, 0, buffer.Length);
                                    if (bufferSize > 0)
                                    {
                                        stream.Write(buffer, 0, bufferSize);
                                    }
                                }
                            }
                        }

                        if ((Path.GetExtension(fileName) == MLifter.DAL.Helper.OdxExtension) ||
                            (Path.GetExtension(fileName) == MLifter.DAL.Helper.EmbeddedDbExtension))
                        {
                            string dicPath = Path.Combine(Path.Combine(dictionaryParentPath, directoryName), fileName);
                            LearningModulesIndexEntry indexEntry = new LearningModulesIndexEntry();
                            indexEntry.DisplayName      = "StartUp";
                            indexEntry.ConnectionString = new MLifter.DAL.Interfaces.ConnectionStringStruct(MLifter.DAL.DatabaseType.MsSqlCe, dicPath, false);
                            Setup.AddRecentLearningModule(indexEntry);
                        }

                        progress.SetProgress((int)Math.Floor(100.0 * (zCounter++) / zCount));
                    }
                }
                Settings.Default.Save();
            }
            catch
            {
                MessageBox.Show(Properties.Resources.INITIALIZE_ENVIRONMENT_ERROR_TEXT, Properties.Resources.INITIALIZE_ENVIRONMENT_ERROR_CAPTION,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                progress.Dispose();
                Cursor.Current = Cursors.Default;
            }
        }