Ejemplo n.º 1
0
        /// <summary>
        /// Sets the information on this page from a dictionary.
        /// </summary>
        /// <param name="dictionary">The dictionary.</param>
        /// <remarks>Documented by Dev02, 2008-01-15</remarks>
        public void SetInfo(MLifter.BusinessLayer.Dictionary dictionary)
        {
            if (dictionary.DictionaryDAL.Parent.CurrentUser.ConnectionString.Typ == MLifter.DAL.DatabaseType.PostgreSQL)
                textBoxDictionaryLocation.Text = GenerateDatabaseInformation(dictionary.DictionaryPath);    //dictionary.DictionaryPath;
            else
                textBoxDictionaryLocation.Text = dictionary.DictionaryPath;

            textBoxDictionaryLocation.SelectionStart = textBoxDictionaryLocation.Text.Length - 1;
            labelNumberOfCards.Text = Convert.ToString(dictionary.Cards.Cards.Count);

            // so that "Nan %" can't be displayed ML-1764
            double score = (double.IsNaN(dictionary.Score)) ? 0.0 : dictionary.Score;
            double highScore = (double.IsNaN(dictionary.Highscore)) ? 0.0 : dictionary.Highscore;

            labelScore.Text = Convert.ToString(Math.Round(score, 2)) + " %";
            labelHighscore.Text = Convert.ToString(Math.Round(highScore, 2)) + " %";
            dictionary.UsedDiskSpaceComplete += new MLifter.BusinessLayer.Dictionary.UsedDiskSpaceCompleteHandler(dictionary_UsedDiskSpaceComplete);
            dictionary.UsedDiskSpaceAsync();
        }
 public IList<int> GetCardMedia(int cardid, MLifter.DAL.Interfaces.Side side)
 {
     return GetCardMedia(cardid, side, null);
 }
Ejemplo n.º 3
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     WordsHelper.CopyWords(this, target as IWords);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the settings.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="Settings">The settings.</param>
        /// <remarks>Documented by Dev08, 2009-01-09</remarks>
        public void SetSettings(int id, MLifter.DAL.Interfaces.ISettings Settings)
        {
            throw new NotAllowedInDbModeException();

            //using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            //{
            //    cmd.CommandText = "UPDATE \"Cards\" SET settings_id=@value WHERE id=@id";
            //    cmd.Parameters.Add("@id", id);
            //    cmd.Parameters.Add("@value", (Settings as DbSettings).Id);

            //    MSSQLCEConn.ExecuteNonQuery(cmd);
            //}
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Registers the learn logic to this control.
 /// </summary>
 /// <param name="learnlogic">The learnlogic.</param>
 /// <remarks>Documented by Dev02, 2008-04-22</remarks>
 /// <remarks>Documented by Dev02, 2008-04-29</remarks>
 public void RegisterLearnLogic(MLifter.BusinessLayer.LearnLogic learnlogic)
 {
     this.learnlogic = learnlogic;
     this.learnlogic.UserDialog += new LearnLogic.UserDialogEventHandler(learnlogic_UserDialog);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// CopyTo method
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="progressDelegate">The progress delegate.</param>
 /// <remarks>Documented by Dev08, 2009-02-06</remarks>
 public void CopyTo(MLifter.DAL.Tools.ICopy target, MLifter.DAL.Tools.CopyToProgress progressDelegate)
 {
     IStatistics targetStatistics = target as IStatistics;
     if (targetStatistics != null)
         StatisticsHelper.Copy(this as IStatistics, targetStatistics, progressDelegate);
 }
Ejemplo n.º 7
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IGradeTyping), progressDelegate);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the byte array from stream.
        /// </summary>
        /// <param name="media">The media.</param>
        /// <param name="rpu">The rpu.</param>
        /// <param name="caller">The caller.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2009-01-16</remarks>
        private static byte[] GetByteArrayFromStream(System.IO.Stream media, MLifter.DAL.Tools.StatusMessageReportProgress rpu, object caller)
        {
            int buffer_length = 10240;
            byte[] data = new byte[media.Length];
            StatusMessageEventArgs args = new StatusMessageEventArgs(StatusMessageType.CreateMediaProgress, (int)media.Length);

            media.Seek(0, SeekOrigin.Begin);

            int read = 0;
            int pos = 0;
            do
            {
                read = media.Read(data, pos, Math.Min(buffer_length, data.Length - pos));
                pos += read;
                args.Progress = pos;
                if (rpu != null)
                    rpu.Invoke(args, caller);
            }
            while (read == buffer_length);
            return data;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Handles the UsedDiskSpaceComplete event of the dictionary control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="MLifter.BusinessLayer.Dictionary.UsedDiskSpaceCompleteEventArgs"/> instance containing the event data.</param>
 /// <remarks>Documented by Dev02, 2008-01-15</remarks>
 void dictionary_UsedDiskSpaceComplete(object sender, MLifter.BusinessLayer.Dictionary.UsedDiskSpaceCompleteEventArgs e)
 {
     if (!labelUsedDiskSpace.InvokeRequired)
     {
         labelUsedDiskSpace.Text = MLifter.Tools.FileSizeToString(e.space);
         labelUsedDiskFiles.Text = Convert.ToString(e.count);
     }
     else
         labelUsedDiskSpace.Invoke((MethodInvoker)delegate { dictionary_UsedDiskSpaceComplete(sender, e); });
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Shows the specified choices.
 /// </summary>
 /// <param name="choices">The choices.</param>
 /// <remarks>Documented by Dev03, 2008-02-26</remarks>
 public void Show(MLifter.BusinessLayer.MultipleChoice choices)
 {
     flowLayoutPanelMultipleChoice.Font = this.Font;
     m_Choices = choices;
     flowLayoutPanelMultipleChoice.SuspendLayout();
     PrepareList();
     ResizeButtons();
     flowLayoutPanelMultipleChoice.ResumeLayout();
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InfoPage"/> class.
 /// </summary>
 /// <param name="dictionary">The dictionary.</param>
 /// <remarks>Documented by Dev02, 2008-01-15</remarks>
 public InfoPage(MLifter.BusinessLayer.Dictionary dictionary)
 {
     SetInfo(dictionary);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Copies to.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="progressDelegate">The progress delegate.</param>
 /// <remarks>Documented by Dev03, 2009-03-23</remarks>
 public void CopyTo(MLifter.DAL.Tools.ICopy target, MLifter.DAL.Tools.CopyToProgress progressDelegate)
 {
     throw new NotImplementedException();
 }
        public void SetCardMedia(int id, int cardid, MLifter.DAL.Interfaces.Side side, MLifter.DAL.Interfaces.WordType type, bool isDefault, MLifter.DAL.Interfaces.EMedia mediatype)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                SqlCeTransaction tran = cmd.Connection.BeginTransaction();

                ClearCardMedia(cardid, side, type, mediatype);

                cmd.CommandText = "INSERT INTO \"Cards_MediaContent\" (media_id, cards_id, side, type, is_default) " +
                    "VALUES (@mediaid, @cardid, @side, @type, @isdefault);";
                cmd.Parameters.Add("@mediaid", id);
                cmd.Parameters.Add("@cardid", cardid);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@isdefault", isDefault);
                MSSQLCEConn.ExecuteNonQuery(cmd);

                tran.Commit();
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }
 public IList<int> GetCardMedia(int cardid, MLifter.DAL.Interfaces.Side side, MLifter.DAL.Interfaces.WordType type)
 {
     return GetCardMedia(cardid, side, type);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets a single property value for a media object.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="property">The property.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev02, 2008-08-07</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public string GetPropertyValue(int id, MLifter.DAL.Interfaces.MediaProperty property)
        {
            Dictionary<MediaProperty, string> properties = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.MediaProperties, id)] as Dictionary<MediaProperty, string>;
            if (properties != null && properties.ContainsKey(property))
                return properties[property];

            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
            cmd.CommandText = "SELECT property, value FROM MediaProperties WHERE media_id=@id";
            cmd.Parameters.Add("@id", id);
            SqlCeDataReader reader = MSSQLCEConn.ExecuteReader(cmd);

            properties = new Dictionary<MediaProperty, string>();
            while (reader.Read())
                properties[(MediaProperty)Enum.Parse(typeof(MediaProperty), reader["property"].ToString())] = reader["value"].ToString();

            reader.Close();
            Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.MediaProperties, id, new TimeSpan(1, 0, 0))] = properties;

            if (properties.ContainsKey(property))
                return properties[property];
            else
                return null;
        }
Ejemplo n.º 16
0
		/// <summary>
		/// Handles the QueryRemove event of the driveDetector control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="MLifter.Components.DriveDetectorEventArgs"/> instance containing the event data.</param>
		/// <remarks>Documented by Dev02, 2007-12-11</remarks>
		void driveDetector_QueryRemove(object sender, MLifter.Components.DriveDetectorEventArgs e)
		{
			//prevent drive removal is memory lifter is running from it or if it has a dictionary open from it
			if (e.Drive == Setup.ApplicationRoot)
				e.Cancel = true;

			if (LearnLogic.Dictionary != null && e.Drive == new DirectoryInfo(LearnLogic.Dictionary.DictionaryPath).Root.FullName)
			{
				try
				{
					if (LearnLogic.LearningModuleLoaded && !LearnLogic.CloseLearningModule())
						e.Cancel = true;
					else
						e.Cancel = false;
				}
				catch
				{
					e.Cancel = true;
				}
			}
		}
Ejemplo n.º 17
0
        /// <summary>
        /// Sets a single property value for a media object.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <remarks>Documented by Dev02, 2008-08-07</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public void SetPropertyValue(int id, MLifter.DAL.Interfaces.MediaProperty property, string value)
        {
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
            SqlCeTransaction tran = cmd.Connection.BeginTransaction();

            if (GetPropertyValue(id, property) == null)
                cmd.CommandText = "INSERT INTO MediaProperties (media_id, property, value) VALUES (@media_id, @property, @value);";
            else
                cmd.CommandText = "UPDATE MediaProperties SET value=@value WHERE media_id=@media_id AND property=@property;";

            Dictionary<MediaProperty, string> properties = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.MediaProperties, id)] as Dictionary<MediaProperty, string>;
            if (properties == null)
                properties = new Dictionary<MediaProperty, string>();
            properties[property] = value;
            Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.MediaProperties, id, new TimeSpan(1, 0, 0))] = properties;

            cmd.Parameters.Add("@media_id", id);
            cmd.Parameters.Add("@property", property.ToString());
            cmd.Parameters.Add("@value", value);
            MSSQLCEConn.ExecuteNonQuery(cmd);

            tran.Commit();
        }
Ejemplo n.º 18
0
		/// <summary>
		/// Handles the DeviceRemoved event of the driveDetector control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="MLifter.Components.DriveDetectorEventArgs"/> instance containing the event data.</param>
		/// <remarks>Documented by Dev02, 2007-12-11</remarks>
		void driveDetector_DeviceRemoved(object sender, MLifter.Components.DriveDetectorEventArgs e)
		{
			//clean up after removal of the drive
			if (LearnLogic.Dictionary != null && driveRemoved != null && !driveRemoved.Visible)
			{
				if (LearnLogic.CurrentLearningModule.ConnectionString.Typ == DatabaseType.MsSqlCe)
				{
					if (LearnLogic.CurrentLearningModule.ConnectionString.ConnectionString.StartsWith(e.Drive))
					{
						try { LearnLogic.CloseLearningModuleWithoutSaving(); }
						catch (Exception exp) { Trace.WriteLine(exp.ToString()); }
					}
				}
				else
				{
					FileInfo dictionaryFile = new FileInfo(LearnLogic.Dictionary.DictionaryPath);
					dictionaryFile.Refresh();
					if (e.Drive == new DirectoryInfo(LearnLogic.Dictionary.DictionaryPath).Root.FullName && !dictionaryFile.Exists)
					{
						//disable all open forms
						foreach (Form form in Application.OpenForms)
						{
							//[ML-753] - make sure that the driveremoved dialog does not get disabled itself
							if (form != driveRemoved)
								form.Enabled = false;
						}
						Enabled = false;

						if (!this.IsInTray)
						{
							driveRemoved.Enabled = true;
							driveRemoved.Show();

							while (true)
							{
								//check for stick presence
								dictionaryFile.Refresh();
								if (dictionaryFile.Exists)
									break;
								if (driveRemoved.DialogResult != DialogResult.None)
									break;
								System.Threading.Thread.CurrentThread.Join(50);
								Application.DoEvents();
							}
						}

						if (!dictionaryFile.Exists)
						{
							//close dictionary without saving
							LearnLogic.CloseLearningModuleWithoutSaving();
							//close all open forms
							//[ML-754] - The openForms collection must not be modified during the enumeration operation
							System.Collections.Generic.List<Form> openForms = new System.Collections.Generic.List<Form>();
							foreach (Form form in Application.OpenForms)
								openForms.Add(form);
							foreach (Form form in openForms)
							{
								if (form != this && form != driveRemoved)
									form.Close();
							}
						}

						//reenable all open forms
						foreach (Form form in Application.OpenForms)
						{
							form.Enabled = true;
						}
						Enabled = true;
						driveRemoved.DialogResult = DialogResult.None;
						driveRemoved.Hide();
					}
				}
			}

			if ((e.Drive == Setup.ApplicationRoot && !new DirectoryInfo(Setup.ApplicationRoot).Exists) || IsInTray)
			{
				try
				{
					if (IsInTray)
						TrayIcon.Visible = false; //do not use IsInTray=false, since it would try to access the removed device
					if (LearnLogic.LearningModuleLoaded)
						LearnLogic.SaveLearningModule();
				}
				catch { }
				finally
				{
					Environment.Exit(-1);
				}
			}
		}
Ejemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExportHelper"/> class.
 /// </summary>
 /// <param name="dictionary">The dictionary.</param>
 /// <param name="exportPath">The full export path including the export file name.</param>
 /// <remarks>Documented by Dev03, 2008-08-20</remarks>
 public ExportHelper(MLifter.DAL.Interfaces.IDictionary dictionary, string exportPath)
 {
     m_dictionary = dictionary;
     m_exportPath = exportPath;
     m_exportFolder = Path.GetDirectoryName(exportPath);
 }
Ejemplo n.º 20
0
		/// <summary>
		/// Handles the ConvertingFinished event of the converter control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="MLifter.Classes.ConvertingEventArgs"/> instance containing the event data.</param>
		/// <remarks>Documented by Dev05, 2009-03-03</remarks>
		private void converter_ConvertingFinished(object sender, MLifter.Classes.ConvertingEventArgs e)
		{
			(sender as MLifter.Classes.Convert).ConvertingFinished -= converter_ConvertingFinished;

			this.Invoke((MethodInvoker)delegate { OpenLearningModule(e.ConvertedFile); });
		}
Ejemplo n.º 21
0
 /// <summary>
 /// Handles the CreateMediaProgressChanged event of the Dictionary control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="MLifter.DAL.Tools.StatusMessageEventArgs"/> instance containing the event data.</param>
 /// <remarks>Documented by Dev03, 2008-08-22</remarks>
 void Dictionary_CreateMediaProgressChanged(object sender, MLifter.DAL.Tools.StatusMessageEventArgs args)
 {
     if (statusDialog != null)
         statusDialog.SetProgress(args.ProgressPercentage);
 }
Ejemplo n.º 22
0
		/// <summary>
		/// Handles the FileDropped event of the learningWindow control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="MLifter.Controls.LearningWindow.FileDroppedEventArgs"/> instance containing the event data.</param>
		/// <remarks>Documented by Dev02, 2008-05-08</remarks>
		private void learningWindow_FileDropped(object sender, MLifter.Controls.LearningWindow.FileDroppedEventArgs e)
		{
			ActivateFileDropTimer(e.filename);
		}
Ejemplo n.º 23
0
 /// <summary>
 /// Sets the stack card back colors.
 /// </summary>
 /// <param name="styleHandler">The style handler.</param>
 /// <remarks>Documented by Dev02, 2008-05-09</remarks>
 public void SetStackCardBackColors(MLifter.Components.StyleHandler styleHandler)
 {
     Dictionary<AnswerResult, Color> stackColors = new Dictionary<AnswerResult, Color>();
     foreach (AnswerResult result in Enum.GetValues(typeof(AnswerResult)))
     {
         string stylename = string.Format("{0}_{1}", this.Name, result.ToString());
         if (styleHandler.CurrentStyle.StyledControls.ContainsKey(stylename) && styleHandler.CurrentStyle.StyledControls[stylename].BackColor != Color.Empty)
         {
             Color color = styleHandler.CurrentStyle.StyledControls[stylename].BackColor;
             stackColors.Add(result, color);
         }
     }
     this.StackCardBackColors = stackColors;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Sets the stack card back colors.
 /// </summary>
 /// <param name="styleHandler">The style handler.</param>
 /// <remarks>Documented by Dev02, 2008-05-09</remarks>
 public void SetStackCardBackColors(MLifter.Components.StyleHandler styleHandler)
 {
     stackFlow.SetStackCardBackColors(styleHandler);
 }
Ejemplo n.º 25
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     SettingsHelper.Copy(this, target as ISettings, progressDelegate);
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Copies this instance to the specified target.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
        {
            IChapter targetChapter = target as IChapter;
            if (targetChapter != null && targetChapter.Settings == null && this.Settings != null)
                targetChapter.Settings = targetChapter.Parent.GetParentDictionary().CreateSettings();

            CopyBase.Copy(this, target, typeof(IChapter), progressDelegate);
        }
Ejemplo n.º 27
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IQueryDirections), progressDelegate);
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Creates a new media object.
        /// </summary>
        /// <param name="media">The memory stream containing the media.</param>
        /// <param name="type">The media type.</param>
        /// <param name="rpu">A delegate of type <see cref="StatusMessageReportProgress"/> used to send messages back to the calling object.</param>
        /// <param name="caller">The calling object.</param>
        /// <returns>The id for the new media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public int CreateMedia(System.IO.Stream media, MLifter.DAL.Interfaces.EMedia type, MLifter.DAL.Tools.StatusMessageReportProgress rpu, object caller)
        {
            int newId;
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
            cmd.CommandText = "INSERT INTO MediaContent (data, media_type) VALUES (@data, @type); SELECT @@IDENTITY;";
            cmd.Parameters.Add("@data", SqlDbType.Image);
            cmd.Parameters.Add("@type", SqlDbType.NVarChar, 100);
            cmd.Parameters["@data"].Value = GetByteArrayFromStream(media, rpu, caller);
            cmd.Parameters["@type"].Value = type.ToString();
            newId = Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd));

            return newId;
        }
Ejemplo n.º 29
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, MLifter.DAL.Tools.CopyToProgress progressDelegate)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Ejemplo n.º 30
0
 void Helper_SaveCopyToProgressChanged(object sender, MLifter.DAL.Tools.StatusMessageEventArgs args)
 {
     loadStatusMessage.SetProgress(args.ProgressPercentage);
 }