Last active
December 21, 2015 15:59
-
-
Save fernandezdavid/6330767 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //-------------------------------------------Views----------------------------------- | |
| // <copyright file="Model.cs" company="Microsoft"> | |
| // Copyright (c) Microsoft Corporation. All rights reserved. | |
| // </copyright> | |
| //------------------------------------------------------------------------------ | |
| namespace Microsoft.Samples.Kinect.BasicInteractions | |
| { | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Collections.ObjectModel; | |
| using System.Linq; | |
| using System.Windows.Media.Imaging; | |
| using System.Xml.Linq; | |
| using Properties; | |
| using HTTPClientLibrary; | |
| /** | |
| * Se implementa la logica de como se recuperan los datos del catalogo del servidor de archivo | |
| * Se define como se va presentar el catalogo mediante un XML | |
| * Se levanta desde la base de dato la informacion util del catalogo | |
| */ | |
| public class Model | |
| { | |
| private readonly List<Category> categories; | |
| private List<Adverts> catalogos; | |
| private String directoryLocalImages = "Content\\Images";// "Content\\Images"; @"\\CALISTO\Users\Public\omkt" | |
| private HTTPClientConnection HTTPDownloader; | |
| private Datos data; | |
| private Adverts catalog; | |
| private String[] paths; | |
| private DateTime _inicio; | |
| private DateTime _fin; | |
| private double _heigthuser; | |
| private Boolean _date = false; | |
| //private AdvertInteractions advertInteractions; | |
| private Dictionary<String, CatalogDetails> masterTable = new Dictionary<String, CatalogDetails>(); | |
| private Dictionary<String, CatalogDetailInteractions> masterViewsTable = new Dictionary<String, CatalogDetailInteractions>(); | |
| private Dictionary<String, bool> flagLikeTable = new Dictionary<String, bool>(); | |
| private Dictionary<String, bool> flagViewTable = new Dictionary<String, bool>(); | |
| private AdvertCampaigns advertCampaigns; | |
| private AdvertCampaignInteractions advertCampaignInteractions; | |
| private AdvertCampaignDetailInteractions advertCampaignDetailInteractions; | |
| private CatalogDetailInteractions catalogDetailsInteraction; | |
| public Model() | |
| { | |
| this.categories = new List<Category>(); | |
| data = new Datos(); | |
| catalogos = new List<Adverts>(); | |
| catalogos= data.GetAdverts(); | |
| paths = GetPath(new DateTime(2012, 09, 17)); | |
| HTTPDownloader = new HTTPClientConnection(); | |
| HTTPDownloader.setBaseAddress("http://www.f1-photo.com/"); | |
| String[] localPathDir = { directoryLocalImages }; | |
| // HTTPDownloader.downloadFile(paths, localPathDir); | |
| this.SetMasterTable(); | |
| advertCampaigns = data.GetAdvertCampaigns(catalogos[0].AdvertId); | |
| this.CreateXml(); | |
| this.LoadStories(); | |
| } | |
| /** | |
| * Inicializo las banderas de las vista y me gusta que va tener cada catalogo | |
| * la masterViewsTable es la tabla de las distintas interacciones del usuario | |
| * @since 22/06/2013 | |
| */ | |
| public void SetLikeTable() | |
| { | |
| masterViewsTable = new Dictionary<String, CatalogDetailInteractions>(); | |
| foreach (var catalogo in catalogos) | |
| { | |
| foreach (var detail in catalogo.CatalogDetails) | |
| { | |
| flagLikeTable[HTTPClientLibrary.HTTPLocalPathConverter.convertToLocalPath(detail.CommercialProducts.ProductImages.Path)] = false; | |
| flagViewTable[HTTPClientLibrary.HTTPLocalPathConverter.convertToLocalPath(detail.CommercialProducts.ProductImages.Path)] = false; | |
| } | |
| } | |
| } | |
| /** | |
| * Asigno la altura de la persona trackeada | |
| * @since 17/02/2013 | |
| * @param heigth double | |
| */ | |
| public void SetHeight(double heigth) | |
| { | |
| _heigthuser = heigth; | |
| } | |
| /** | |
| * Method GetHeightUser | |
| * @since 17/02/2013 | |
| * @return la altura de la persona | |
| */ | |
| public double GetHeightUser() | |
| { | |
| return _heigthuser; | |
| } | |
| /** | |
| * Se Guarda una nueva campaña interaccion buscando al catalogo que pertenece | |
| * y asignando la persona que esta interactuando | |
| * @since 10/06/2013 | |
| */ | |
| public void InsertAdvertCampaignInteractions() | |
| { | |
| advertCampaignInteractions = new AdvertCampaignInteractions(); | |
| advertCampaignInteractions.StartDatetime = DateTime.Now; | |
| advertCampaignInteractions.AdvertCampaigns = advertCampaigns; | |
| advertCampaignInteractions = data.AddAdvertCampaignInteractions(advertCampaignInteractions); | |
| } | |
| /** | |
| * Se Guarda una nueva interaccion buscando al catalogo que pertenece | |
| * y asignando la persona que esta interactuando | |
| * @since 10/06/2013 | |
| * @param advereInteractions AdvertCampaignDetailInteractions | |
| * @param nameAdvert String | |
| */ | |
| public void InsertAdvertCampaignDetailInteractions(AdvertCampaignDetailInteractions pAdvertCampaignDetailInteractions, String nameAdvert) | |
| { | |
| Adverts cat = catalogos.First(c => c.Name == nameAdvert); | |
| advertCampaignDetailInteractions=new AdvertCampaignDetailInteractions(); | |
| advertCampaignDetailInteractions.Adverts = cat; | |
| advertCampaignDetailInteractions.Height =(decimal) _heigthuser; | |
| advertCampaignDetailInteractions.StartDatetime = DateTime.Now; | |
| advertCampaignDetailInteractions.AdvertCampaignInteractions = advertCampaignInteractions; | |
| data.AddAdvertCampaignDetailInteractions(advertCampaignDetailInteractions); | |
| _date = true; | |
| } | |
| /** | |
| * Inicializo las banderas de las vista y me gusta que va tener cada catalogo | |
| * @since 03/07/2012 | |
| */ | |
| public void SetMasterTable() | |
| { | |
| masterViewsTable = new Dictionary<String, CatalogDetailInteractions>(); | |
| foreach (var catalogo in catalogos) | |
| { | |
| foreach (var detail in catalogo.CatalogDetails) | |
| { | |
| masterTable[HTTPClientLibrary.HTTPLocalPathConverter.convertToLocalPath(detail.CommercialProducts.ProductImages.Path)] = detail; | |
| flagLikeTable[HTTPClientLibrary.HTTPLocalPathConverter.convertToLocalPath(detail.CommercialProducts.ProductImages.Path)] = false; | |
| flagViewTable[HTTPClientLibrary.HTTPLocalPathConverter.convertToLocalPath(detail.CommercialProducts.ProductImages.Path)] = false; | |
| } | |
| } | |
| } | |
| /** | |
| * @since 28/05/2012 | |
| * @return Las rutas de las imagenes del catalogo en donde se encuentra en el servidor | |
| */ | |
| private String[] GetPath(DateTime date) | |
| { | |
| var list = new List<string>(); | |
| foreach (var catalogo in catalogos) | |
| { | |
| foreach (var detail in catalogo.CatalogDetails) | |
| { | |
| list.Add(detail.CommercialProducts.ProductImages.Path); | |
| } | |
| } | |
| return list.ToArray(); | |
| } | |
| public Interactions GetInteracion(int id) | |
| { | |
| return data.GetInteraction(id); | |
| } | |
| public AdvertCampaigns GetAdvertCampaigns() | |
| { | |
| return advertCampaigns; | |
| } | |
| public Interactions GetInteracionName(String name) | |
| { | |
| return data.GetInteractionXCampaign(name); | |
| } | |
| /** | |
| * Asigno la fecha de inicio de la interaccion | |
| * @since 22/04/2013 | |
| * @param time Datetime | |
| */ | |
| public void SetDateStart(DateTime time) | |
| { | |
| _inicio = time; | |
| _date = true; | |
| } | |
| /** | |
| * Asigno la fecha fin de la interaccion | |
| * @since 22/04/2013 | |
| * @param time Datetime | |
| */ | |
| public void SetDateEnd(DateTime time) | |
| { | |
| _fin = DateTime.Now ; | |
| _date = false; | |
| if(advertCampaignDetailInteractions.StartDatetime!=null) | |
| { | |
| advertCampaignDetailInteractions.TimeElapsed =(int) _fin.Subtract(advertCampaignDetailInteractions.StartDatetime).TotalSeconds; | |
| advertCampaignDetailInteractions.EndDatetime = _fin; | |
| catalogDetailsInteraction.EndDatetime = _fin; | |
| catalogDetailsInteraction.TimeElapsed = (int)_fin.Subtract(catalogDetailsInteraction.StartDatetime).TotalSeconds; | |
| data.UpdateCatalogDetailInteractions(catalogDetailsInteraction); | |
| data.UpdateAdvertCampaignDetailInteractions(advertCampaignDetailInteractions); | |
| } | |
| } | |
| /** | |
| * @since 30/04/2013 | |
| * @retrurn Obtengo el flag si tiene fecha inicio | |
| */ | |
| public Boolean GetIsDate() | |
| { | |
| return _date; | |
| } | |
| /** | |
| * @since 30/06/2012 | |
| * @return Obtengo el acesso a lo datos | |
| */ | |
| public Datos GetData() | |
| { | |
| return data; | |
| } | |
| public List<Adverts> GetCatalogs()//sin uso | |
| { | |
| return catalogos; | |
| } | |
| /** | |
| * Method GetmasterTable | |
| * @since 11/08/2012 | |
| * @return La tabla con los detalles del catalogo | |
| */ | |
| public Dictionary<String, CatalogDetails> GetmasterTable() | |
| { | |
| return masterTable; | |
| } | |
| /** | |
| * @since 09/09/2012 | |
| * @return la tabla con todos los detalles de de las interaccion | |
| */ | |
| public Dictionary<String, CatalogDetailInteractions> GetMasterViewTable() | |
| { | |
| return masterViewsTable; | |
| } | |
| /** | |
| * @since 17/08/2013 | |
| * @return la tabla con todos flag de me gusta | |
| */ | |
| public Dictionary<String, bool> GetflagLikeTable() | |
| { | |
| return flagLikeTable; | |
| } | |
| /** | |
| * @since 17/08/2013 | |
| * @param pCatalogDetails CatalogDetailInteractions | |
| */ | |
| public void SetCatalogDetailsInteractions(CatalogDetailInteractions pCatalogDetailsInteractions) | |
| { | |
| catalogDetailsInteraction = pCatalogDetailsInteractions; | |
| } | |
| public ReadOnlyCollection<Category> Categories | |
| { | |
| get { return this.categories.AsReadOnly(); } | |
| } | |
| public Dictionary<String, bool> GetflagViewTable() | |
| { | |
| return flagViewTable; | |
| } | |
| public ReadOnlyCollection<string> CreateSpeechGrammar() | |
| { | |
| var speechKeywords = new List<string>(); | |
| int maxNumberOfStories = 0; | |
| foreach (Category cat in this.categories) | |
| { | |
| if (maxNumberOfStories < cat.Content.Count) | |
| { | |
| maxNumberOfStories = cat.Content.Count; | |
| } | |
| // Add each of the categories to the list. | |
| if (!speechKeywords.Contains(cat.Title)) | |
| { | |
| if (cat.Title.Contains("&")) | |
| { | |
| speechKeywords.Add(cat.Title.Replace("&", "and")); | |
| } | |
| speechKeywords.Add(cat.Title); | |
| } | |
| foreach (ContentItem cont in cat.Content) | |
| { | |
| if (cont.Subcategory.Length > 1) | |
| { | |
| if (!speechKeywords.Contains(cont.Subcategory)) | |
| { | |
| if (cont.Subcategory.Contains("&")) | |
| { | |
| speechKeywords.Add(cont.Subcategory.Replace("&", "and")); | |
| } | |
| speechKeywords.Add(cont.Subcategory); | |
| } | |
| } | |
| } | |
| } | |
| speechKeywords.Add(Settings.Default.SubcategoryAll); | |
| // Add the control words for the application. | |
| speechKeywords.Add(Settings.Default.SpeechSelectWord); | |
| speechKeywords.Add(Settings.Default.SpeechBackWord); | |
| speechKeywords.Add(Settings.Default.SpeechHomeWord); | |
| speechKeywords.Add(Settings.Default.SpeechLikeWord); | |
| speechKeywords.Add(Settings.Default.SpeechDislikeWord); | |
| speechKeywords.Add(Settings.Default.SpeechPlayWord); | |
| speechKeywords.Add(Settings.Default.SpeechPauseWord); | |
| speechKeywords.Add(Settings.Default.SpeechStartWord); | |
| // add the story numbers | |
| for (var choice = NumberWords.One; | |
| (int)choice <= maxNumberOfStories | |
| && choice <= NumberWords.Twenty; | |
| choice++) | |
| { | |
| speechKeywords.Add(choice.ToString()); | |
| } | |
| return speechKeywords.AsReadOnly(); | |
| } | |
| /** | |
| * Se Crea un XML para poder mostrar el catalogo, de esta forma cada vista sabe como tiene que mostrar el catalogo | |
| * primero se crean los distintos catalogo que va mostrar luego se lista los distintos productos y por ultimo | |
| * se muestra la imagen del producto a mostrar | |
| * @since 14/05/2012 | |
| */ | |
| private void CreateXml() | |
| { | |
| XDocument miXML = new XDocument( | |
| new XDeclaration("1.0", "utf-8", "yes"), new XElement("Catalogos")); | |
| XElement catalogo = miXML.Element("Catalogos"); | |
| foreach (String im in paths) | |
| { | |
| String title = masterTable[HTTPClientLibrary.HTTPLocalPathConverter.convertToLocalPath(im)].CommercialProducts.ProductName; | |
| int id = masterTable[HTTPClientLibrary.HTTPLocalPathConverter.convertToLocalPath(im)].AdvertId; | |
| catalogo.Add(new XElement("Producto", | |
| new XElement("title", title), | |
| new XElement("category",catalogos.Find(c=> c.AdvertId==id).Name), | |
| new XElement("image", HTTPClientLibrary.HTTPLocalPathConverter.convertToLocalPath(im)))); | |
| } | |
| miXML.Save("Content\\Stories.xml"); | |
| } | |
| private void LoadStories() | |
| { | |
| XDocument doc = XDocument.Load("Content\\Stories.xml"); | |
| foreach (XElement ele in doc.Descendants("Producto")) | |
| { | |
| string categoryTitle = ele.Element("category").Value; | |
| Category category = this.categories.FirstOrDefault(c => c.Title.Equals(categoryTitle)); | |
| if (category == null) | |
| { | |
| category = new Category { Title = categoryTitle }; | |
| this.categories.Add(category); | |
| } | |
| if (category != null) | |
| { | |
| var content = new ContentItem | |
| { | |
| Title = ele.Element("title").Value, | |
| Category = category, | |
| Subcategory = "", | |
| // Subcategory = ele.Element("subcategory").Value, | |
| Content = " ", | |
| // Content = ele.Element("content").Value, | |
| ContentImage = | |
| string.IsNullOrEmpty(ele.Element("image").Value) | |
| ? null : new BitmapImage(new Uri("pack://siteoforigin:,,,/Content/Images/" + ele.Element("image").Value)),//"pack://siteoforigin:,,,/Content/Images/ @"\\CALISTO\Users\Public\omkt\ | |
| }; | |
| category.AddContent(content); | |
| BitmapImage bi = new BitmapImage(); | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment