Exemplo n.º 1
0
		public void FromModel(Indiagram indiagram)
		{
			Text = indiagram.Text;
			ImagePath = indiagram.ImagePath;
			SoundPath = indiagram.SoundPath;
			Position = indiagram.Position;
			IsEnabled = indiagram.IsEnabled ? 1 : 0;
			IsCategory = indiagram.IsCategory ? 1 : 0;
			ParentId = indiagram.Parent == null ? ROOT_PARENT : indiagram.Parent.Id;
		}
Exemplo n.º 2
0
		public virtual void CopyFrom(Indiagram other, bool excludeId = false)
		{
			Text = other.Text;
			ImagePath = other.ImagePath;
			SoundPath = other.SoundPath;
			IsEnabled = other.IsEnabled;
			Position = other.Position;
			Parent = other.Parent;
			if (!excludeId)
			{
				Id = other.Id;
			}
		}
 public async void PlayIndiagram(Indiagram indiagram)
 {
     if (indiagram.HasCustomSound)
     {
         var audioFile = await StorageFile.GetFileFromPathAsync(indiagram.SoundPath);
         var stream = await audioFile.OpenAsync(FileAccessMode.Read);
         PlayStream(stream);
     }
     else
     {
         SpeechSynthesisStream stream = await _ttsSpeechSynthesizer.SynthesizeTextToStreamAsync(indiagram.Text);
         PlayStream(stream);
     }
 }
		protected override void IndiagramSelectedAction(Indiagram indiagram)
		{
			base.IndiagramSelectedAction(indiagram);
			
			if (indiagram.IsCategory)
			{
				string dialogKey = indiagram.HasChildren ? Business.Dialogs.ADMIN_COLLECTION_EXPLORECOLLECTION_CATEGORY : Business.Dialogs.ADMIN_COLLECTION_EXPLORECOLLECTION_CATEGORY_WITHOUTCHILDREN;
				MessageDialogService.Show(dialogKey, new Dictionary<string, object>
				{
					{"Indiagram", indiagram},
					{"GoIntoCallback", (Action<Category>)GoIntoAction }
				});
			}
			else
			{
				MessageDialogService.Show(Business.Dialogs.ADMIN_COLLECTION_EXPLORECOLLECTION_INDIAGRAM, new Dictionary<string, object>
				{
					{"Indiagram", indiagram}
				});
			}
		}
		protected override void IndiagramSelectedAction(Indiagram indiagram)
		{
			base.IndiagramSelectedAction(indiagram);

			Category category = indiagram as Category;
			if (category == null)
			{
				return;
			}

			string dialogKey = Business.Dialogs.ADMIN_COLLECTION_SELECTCATEGORY_WITHOUTCHILDREN;
			if (category.Children.Any(x => x.IsCategory))
			{
				dialogKey = Business.Dialogs.ADMIN_COLLECTION_SELECTCATEGORY;
			}
			MessageDialogService.Show(dialogKey, new Dictionary<string, object>
			{
				{"Indiagram", indiagram},
				{"GoIntoCallback", (Action<Category>)GoIntoAction},
				{"SelectedCallback", (Action<Category>)OnCategorySelected}
			});	
		}
		public void Delete(Indiagram indiagram)
		{
			// remove from parent tree or from home root category
			Category parent = indiagram.Parent as Category;
			if (parent != null)
			{
				parent.Children.Remove(indiagram);
				Save(parent);
			}
			else
			{
				_collection.Remove(indiagram);
			}

			// Delete children if have any
			if (indiagram.IsCategory)
			{
				DeleteTree(indiagram as Category);
			}

			// Delete this object
			IndiagramSql sqlObject = SearchById(indiagram.Id);
			_databaseContent.Remove(sqlObject);
			try
			{
				Connection.Delete<IndiagramSql>(indiagram.Id);
			}
			catch (Exception)
			{
				//TODO : log error
			}
		}
		private Indiagram Create(Indiagram indiagram)
		{
			IndiagramSql sqlObject = new IndiagramSql();
			sqlObject.FromModel(indiagram);

			try
			{
				Connection.Insert(sqlObject);
			}
			catch (Exception)
			{
				//TODO : log error
			}
			indiagram.Id = sqlObject.Id;
			_databaseContent.Add(sqlObject);
			return indiagram;
		}
Exemplo n.º 8
0
		private void CollectionIndiagramSelectedAction(Indiagram indiagram)
		{
			if (CheckIsReading() && (indiagram.IsCategory || !SettingsService.IsDragAndDropEnabled))
			{
				return;
			}

			Category category = indiagram as Category;
			if (category != null)
			{
				Read(indiagram);
				PushCategory(category);
			}
			else
			{
				if (SentenceCanAddMoreIndiagrams)
				{
					if (!SettingsService.IsDragAndDropEnabled)
					{
						Read(indiagram);
					}
					AddIndiagramToSentence(indiagram);

					if (SettingsService.IsBackHomeAfterSelectionEnabled && !IsCorrectionModeEnabled && PopCategory())
					{
						while (PopCategory())
						{
						}
					}
					else
					{
						RefreshDisplayList();
					}
				}
			}
		}
Exemplo n.º 9
0
		public static bool AreSameIndiagram(Indiagram a, Indiagram b)
		{
			if (a == null && b == null)
			{
				return true;
			}

			if (a == null || b == null)
			{
				return false;
			}

			return a.Id == b.Id;
		}
        public void Copy(Indiagram indiagram, bool isCategory)
        {
            _indiagram = isCategory ? new Category() : new Indiagram();
			_indiagram.CopyFrom(indiagram, true);
            HasBuffer = true;
        }
Exemplo n.º 11
0
		private void OnTopIndiagramSelected(Indiagram indiagram)
		{
			if (!SettingsService.IsDragAndDropEnabled || indiagram.IsCategory)
			{
				var command = TopIndiagramSelectedCommand;
				if (command != null && command.CanExecute(indiagram))
				{
					command.Execute(indiagram);
				}
			}
		}
		private Indiagram Update(Indiagram indiagram)
		{
			IndiagramSql sqlObject = SearchById(indiagram.Id);
			if (sqlObject == null)
			{
				throw new InvalidOperationException(string.Format("Can not update a non created object, id = {0}", indiagram.Id));
			}

			sqlObject.FromModel(indiagram);

			try
			{
				Connection.Update(sqlObject);
			}
			catch (Exception)
			{
				//TODO : log error
			}

			return indiagram;
		}
Exemplo n.º 13
0
		private void Read(Indiagram indiagram)
		{
			bool canRead = true;
			if (indiagram.IsCategory)
			{
				canRead = SettingsService.IsCategoryNameReadingEnabled;
			}

			if (canRead)
			{
				lock (_readingMutex)
				{
					if (_isReading)
					{
						canRead = false;
					}
					else
					{
						_isReading = true;
					}
				}
			}

			if (canRead)
			{
				TextToSpeechService.PlayIndiagram(indiagram);
			}
		}
Exemplo n.º 14
0
		private async Task ReadCollectionFromZip(IArchiveEntry entry, ZipDirectory currentDirectory, string currentPath, Dictionary<string, IArchiveEntry> resourceEntries, Indiagram parent)
		{
			using (Stream entryStream = entry.OpenEntryStream())
			{
				XDocument xmlDocument = XDocument.Load(entryStream);

				XElement rootElement = xmlDocument.Element("indiagram");
				if (rootElement != null)
				{
					// the current element is an indiagram, just read it
					await CreateIndiagramFromXml(rootElement, false, parent, async (key, type) =>
					{
						return await Task.Run(() =>
						{
							if (resourceEntries.ContainsKey(key))
							{
								return resourceEntries[key].OpenEntryStream();
							}
							throw new IndexOutOfRangeException(string.Format("Key {0} is not available in resources", key));
						});
					});
				}
				else
				{
					// the current element is a category, read it + process its children
					rootElement = xmlDocument.Element("category");
					if (rootElement == null)
					{
						return;
					}

					Indiagram category = await CreateIndiagramFromXml(rootElement, true, parent, async (key, type) =>
					{
						return await Task.Run(() =>
						{
							if (resourceEntries.ContainsKey(key))
							{
								return resourceEntries[key].OpenEntryStream();
							}
							throw new IndexOutOfRangeException(string.Format("Key {0} is not available in resources", key));
						});
					});

					XElement indiagramsElement = rootElement.Element("indiagrams");
					if (indiagramsElement == null)
					{
						return;
					}
					foreach (XElement child in indiagramsElement.Elements("indiagram"))
					{
						// look for the entry
						string directoryName = Path.GetDirectoryName(child.Value);
						string fileName = Path.GetFileName(child.Value);

						ZipDirectory directory = GetSubZipDirectory(currentDirectory, currentPath, directoryName);

						if (directory.Files.ContainsKey(fileName))
						{
							await ReadCollectionFromZip(directory.Files[fileName], directory, directoryName, resourceEntries, category);
						}
						else
						{
							throw new IndexOutOfRangeException("file names mismatch");
						}
					}
				}
			}
		}
 public IndiagramContainer(Indiagram indiagram)
 {
     Indiagram = indiagram;
 }
Exemplo n.º 16
0
		private async Task<Indiagram> CreateIndiagramFromXml(XElement rootElement, bool isCategory, Indiagram parent, Func<string, StorageType, Task<Stream>> resourceStreamOpener)
		{
			XElement textElement = rootElement.Element("text");
			XElement imagePathElement = rootElement.Element("picture");
			XElement soundPathElement = rootElement.Element("sound");

			if (textElement == null || imagePathElement == null || soundPathElement == null)
			{
				return null;
			}

			string text = textElement.Value;
			string imagePath = imagePathElement.Value;
			string soundPath = soundPathElement.Value;

			if (string.IsNullOrWhiteSpace(imagePath))
			{
				imagePath = null;
			}

			if (string.IsNullOrWhiteSpace(soundPath))
			{
				soundPath = null;
			}

			//copy sound and imagePath if needed
			if (imagePath != null)
			{
				string localImagePath = StorageService.GenerateFilename(StorageType.Image, Path.GetExtension(imagePath));
				await CopyFileAsync(resourceStreamOpener(imagePath, StorageType.Image), localImagePath);

				imagePath = localImagePath;
			}

			if (soundPath != null)
			{
				string localSoundPath = StorageService.GenerateFilename(StorageType.Sound, Path.GetExtension(soundPath));
				await CopyFileAsync(resourceStreamOpener(soundPath, StorageType.Sound), localSoundPath);

				soundPath = localSoundPath;
			}

			Indiagram result = isCategory ? new Category() : new Indiagram();
			result.Text = text;
			result.ImagePath = imagePath;
			result.SoundPath = soundPath;
			result.Parent = parent;
			result.Position = _position++;
			result.IsEnabled = true;

			CollectionStorageService.Save(result);

			if (parent != null)
			{
				Category category = parent as Category;
				if (category != null)
				{
					category.Children.Add(result);
				}
			}
			else
			{
				CollectionStorageService.Collection.Add(result);
			}

			return result;
		}
Exemplo n.º 17
0
		private async Task ReadCollectionFromOldFormat(Stream inputStream, IFolder currentFolder, string currentDirectoryPath, IFolder imageFolder, IFolder soundFolder, Indiagram parent)
		{
			XDocument xmlDocument = XDocument.Load(inputStream);

			XElement rootElement = xmlDocument.Element("indiagram");
			if (rootElement != null)
			{
				// the current element is an indiagram, just read it
				await CreateIndiagramFromXml(rootElement, false, parent, ((key, type) => GetResourceStream(key, (type == StorageType.Image) ? imageFolder : soundFolder)));
			}
			else
			{
				// the current element is a category, read it + process its children
				rootElement = xmlDocument.Element("category");
				if (rootElement == null)
				{
					return;
				}

				Indiagram category = await CreateIndiagramFromXml(rootElement, true, parent, ((key, type) => GetResourceStream(key, (type == StorageType.Image) ? imageFolder : soundFolder)));

				XElement indiagramsElement = rootElement.Element("indiagrams");
				if (indiagramsElement == null)
				{
					return;
				}
				
				foreach (XElement child in indiagramsElement.Elements("indiagram"))
				{
					// look for the entry
					try
					{
						string directoryName = Path.GetDirectoryName(child.Value);
						string fileName = Path.GetFileName(child.Value);

						IFolder folder = await GetSubFolderAsync(currentFolder, currentDirectoryPath, directoryName);

						if (await folder.CheckExistsAsync(fileName) == ExistenceCheckResult.FileExists)
						{
							IFile file = await folder.GetFileAsync(fileName);
							Stream fileStream = await file.OpenAsync(FileAccess.Read);

							using (fileStream)
							{
								await ReadCollectionFromOldFormat(fileStream, folder, directoryName, imageFolder, soundFolder, category);
							}
						}
					}
					catch (Exception)
					{
						//TODO : log error
					}
				}
			}

		}
Exemplo n.º 18
0
		private void AddIndiagramToSentence(Indiagram indiagram)
		{
			if (SettingsService.IsMultipleIndiagramSelectionEnabled && !IsCorrectionModeEnabled)
			{
				// need to create a copy of the indiagram
				Indiagram copy = new Indiagram();
				copy.CopyFrom(indiagram);
				indiagram = copy;
				indiagram.Id = _sentenceIndiagramId--;
			}

			SentenceIndiagrams.Add(new IndiagramUIModel(indiagram));
		}
		public void PlayIndiagram(Indiagram indiagram)
		{
			if (indiagram.HasCustomSound)
			{
				string word;
				if (_registeredSounds.ContainsKey(indiagram.SoundPath))
				{
					word = _registeredSounds[indiagram.SoundPath];
				}
				else
				{
					if (_speakerSpeech != null)
					{
						word = Guid.NewGuid().ToString();
						_registeredSounds.Add(indiagram.SoundPath, word);
						_speakerSpeech.AddSpeech(word, indiagram.SoundPath);
					}
					else
					{
						//TODO : log issue
						word = "e";
					}
				}
				PlayText(word);
			}
			else
			{
				PlayText(indiagram.Text);
			}
		}
        protected void RefreshBrothers()
        {
            Category parent = CurrentIndiagram.Parent as Category;
            List<Indiagram> children;
            Indiagram defaultLastOne = new Indiagram
            {
                Id = -73,
                Text = LocalizationService.GetString("Collection_EndPosition", "Text")
            };
            if (parent == null)
            {
                children = CollectionStorageService.Collection.OrderBy(x => x.Position).ToList();
            }
            else
            {
                children = parent.Children.OrderBy(x => x.Position).ToList();
            }
            defaultLastOne.Position = children.Any() ? children.Last().Position + 1 : 1;
            children.Add(defaultLastOne);

            Indiagram selectedIndiagram = defaultLastOne;

            // remove current from the list and put the selected one at its place
            Indiagram current = children.FirstOrDefault(x => x.Id == CurrentIndiagram.Id);
            if (current != null)
            {
                int currentIndex = children.IndexOf(current);
                if (currentIndex + 1 < children.Count)
                {
                    selectedIndiagram = children[currentIndex + 1];
                }

                children.RemoveAt(currentIndex);
            }

            Brothers = children;
            BeforeIndiagram = selectedIndiagram;
        }
		/// <summary>
		/// Override this function to receive callback when an indiagram is selected in the browser
		/// </summary>
		/// <param name="indiagram"></param>
		protected virtual void IndiagramSelectedAction(Indiagram indiagram)
		{
		    // Do something with this indiagram
		}
Exemplo n.º 22
0
		private void CollectionIndiagramDragStartAction(Indiagram indiagram)
		{
			if (CheckIsReading())
			{
				return;
			}

			Read(indiagram);
		}
        public AddIndiagramViewModel()
        {
            ImageChoiceCommand = new DelegateCommand(ImageChoiceAction);
            SoundChoiceCommand = new DelegateCommand(SoundChoiceAction);
            RootCommand = new DelegateCommand(RootAction);
            ResetSoundCommand = new DelegateCommand(ResetSoundAction);
            ListenCommand = new DelegateCommand(ListenAction);
            ActivateCommand = new DelegateCommand(ActivateAction);
            DesactivateCommand = new DelegateCommand(DesactivateAction);
            CopyCommand = new DelegateCommand(CopyAction);
            PasteCommand = new DelegateCommand(PasteAction);
            SelectCategoryCommand = new DelegateCommand(SelectCategoryAction);
            SaveCommand = new DelegateCommand(SaveAction);

            CurrentIndiagram = new Indiagram();
            RefreshBrothers();
        }
		public Indiagram Save(Indiagram indiagram)
		{
			if (indiagram == null)
			{
				throw new ArgumentNullException("indiagram");
			}

			if (indiagram.Id > 0)
			{
				return Update(indiagram);
			}
			return Create(indiagram);
		}