예제 #1
0
        public async Task LoadData()
        {
            //string sentby="";
            //bool found = false;
            //chatsTable = App.MobileService.GetTable<SendData>();
            //MobileServiceCollection<SendData, SendData> store;
            //store = await chatsTable
            //        .Where(x => x.Read == false)
            //        .ToCollectionAsync();
            //foreach(var msg in store)
            //{

            //    foreach(var item in Items )
            //    {
            //        if(item.PhoneNumber.ToString() == msg.Sender)
            //        {
            //            found = true;
            //            ChatPage.index = Convert.ToInt16(item.ID);
            //            sentby = item.ContactName;
            //        }
            //    }
            //    if (found == false)
            //        sentby = msg.Sender;
            //    Message message = new Message()
            //    {
            //        Sender = sentby,
            //        Text = msg.Message,
            //        SendingTime = Convert.ToDateTime(msg.Time)
            //    };
            //    Binder.Instance.Messages.Add(message);
            //    App.ViewModel.Items[ChatPage.index].FirstLine = msg.Message;
            //}

            bool error = false;

            //this.Items = new ObservableCollection<ChatData>();
            StorageFolder appStorageFolder = IORecipes.GetAppStorageFolder();
            StorageFile   dataFile         = await IORecipes.GetFileInFolder(appStorageFolder, dataFileName);

            if (dataFile != null)
            {
                if (!IsDataLoaded)
                {
                    string itemsAsXML = await IORecipes.ReadStringFromFile(dataFile);

                    this.Items = IORecipes.SerializeFromString <ObservableCollection <ChatData> >(itemsAsXML);
                }
            }
            // Sample data; replace with real data
            else
            {
                if (!IsDataLoaded)
                {
                    Items = CreateSampleItems();
                }
            }
            //await ConnectToWindowsAzure();
            if (AzureConnected)
            {
                createfav();

                //Sync();
                TableQuery <SendData>        query        = new TableQuery <SendData>().Where("PartitionKey eq 'default' and Read eq 'false'");
                TableQuerySegment <SendData> querySegment = null;
                var resultlist = new List <SendData>();

                try
                {
                    while (querySegment == null || querySegment.ContinuationToken != null)
                    {
                        querySegment = await table.ExecuteQuerySegmentedAsync(query, querySegment != null?querySegment.ContinuationToken : null);

                        resultlist.AddRange(querySegment);
                    }
                }
                catch
                {
                    error = true;
                }
                if (error)
                {
                }
                foreach (SendData s in resultlist)
                {
                    bool    found = false;
                    Message temp  = new Message();
                    temp.Id = s.RowKey;

                    temp.Text        = s.Message;
                    temp.SendingTime = s.Time;
                    foreach (ChatData i in Items)
                    {
                        if (i.PhoneNumber.Equals(s.From))
                        {
                            found          = true;
                            ChatPage.index = Convert.ToInt16(i.ID);
                        }
                    }
                    if (!found)
                    {
                        string[] separators = { "(", " " };
                        string[] ph_num     = new string[2];
                        int      num;

                        foreach (Contact c in PhoneContacts)
                        {
                            foreach (ContactPhoneNumber ph in c.PhoneNumbers)
                            {
                                ph_num = ph.ToString().Split(separators, StringSplitOptions.RemoveEmptyEntries);
                                if (ph_num[0].Length >= 10)
                                {
                                    num       = ph_num[0].Length - 10;
                                    ph_num[0] = ph_num[0].Substring(num);

                                    if (ph_num[0] == s.From)
                                    {
                                        AddressBook add = new AddressBook(c.DisplayName, ph_num[0]);
                                        CreateNewChat(add, 0);
                                        temp.Sender    = c.DisplayName;
                                        ChatPage.index = Items.Count - 1;
                                        found          = true;
                                        break;
                                    }
                                }
                            }
                            if (found == true)
                            {
                                break;
                            }
                        }
                        if (!found)
                        {
                            ChatData result =
                                new ChatData()
                            {
                                ID          = (Items.Count).ToString(),
                                ContactName = s.From,
                                PhoneNumber = s.From
                            };
                            this.Items.Add(result);
                            ChatPage.index = Items.Count - 1;
                        }
                    }

                    Binder.Instance.Messages.Add(temp);
                    App.ViewModel.Items[ChatPage.index].FirstLine = s.Message;
                    s.Read = true;
                    await UpdateChat(s);
                }
                if (resultlist.Count > 0)
                {
                    await App.ViewModel.UpdateChats();
                }
            }

            NotifyPropertyChanged("Items");
            this.IsDataLoaded = true;
        }
예제 #2
0
        public async void createfav()
        {
            int num;

            string[] separators = { "(", " " };
            string[] ph_num     = new string[2];

            bool          contactavailable;
            StorageFolder appStorageFolder = IORecipes.GetAppStorageFolder();
            StorageFile   dataFile         = await IORecipes.GetFileInFolder(appStorageFolder, FavContactFileName);

            if (dataFile != null)
            {
                if (!IsFavLoaded)
                {
                    string itemsAsXML = await IORecipes.ReadStringFromFile(dataFile);

                    this.Favcontacts = IORecipes.SerializeFromString <ObservableCollection <Favourites> >(itemsAsXML);
                }
            }
            // Sample data; replace with real data
            else
            {
                this.Favcontacts = new ObservableCollection <Favourites>();
                foreach (Contact c in PhoneContacts)
                {
                    foreach (ContactPhoneNumber ph in c.PhoneNumbers)
                    {
                        ph_num = ph.ToString().Split(separators, StringSplitOptions.RemoveEmptyEntries);

                        if (ph_num[0].Length >= 10)
                        {
                            num       = ph_num[0].Length - 10;
                            ph_num[0] = ph_num[0].Substring(num);


                            contactavailable = await ConnectToWindowsAzure(ph_num[0]);

                            if (contactavailable)
                            {
                                Favourites fav = new Favourites()
                                {
                                    Name            = c.DisplayName,
                                    Favouritenumber = ph_num[0]
                                };
                                this.Favcontacts.Add(fav);
                                //favSource.Add(new AddressBook(c.DisplayName, ph_num[0]));
                            }
                        }
                    }
                }

                string itemsAsXML = IORecipes.SerializeToString(this.Favcontacts);
                dataFile = await IORecipes.CreateFileInFolder(appStorageFolder, FavContactFileName);

                await IORecipes.WriteStringToFile(dataFile, itemsAsXML);
            }
            //favDataSource = AlphaKeyGroup<AddressBook>.CreateGroups(favSource,
            //        System.Threading.Thread.CurrentThread.CurrentUICulture,
            //        (AddressBook s) => { return s.Name; }, true);
            IsFavLoaded = true;
        }
예제 #3
0
        public async Task LoadData()
        {
            //move this to constructor!!!
            this.Items_1 = new ObservableCollection <ToDoItemModel>();
            this.Items_2 = new ObservableCollection <ToDoItemModel>();
            this.Items_3 = new ObservableCollection <ToDoItemModel>();
            this.Items_4 = new ObservableCollection <ToDoItemModel>();

            StorageFolder appFolder = IORecipes.GetAppStorageFolder();
            StorageFile   dataFile  = await IORecipes.GetFileInFolder(appFolder, DATA_FILE_NAME);

            if (dataFile != null)
            {
                if (!isDataLoaded)
                {
                    string itemsAsXml = await IORecipes.ReadStringFromFile(dataFile);

                    this.Items = IORecipes.SerializeFromString <ObservableCollection <ToDoItemModel> >(itemsAsXml);
                }
            }
            else
            {
                if (!isDataLoaded)
                {
                    this.Items = new ObservableCollection <ToDoItemModel>();
                    this.Items.Add(
                        new ToDoItemModel()
                    {
                        ID     = DateTime.Now.Ticks.ToString(),
                        Note   = "This is the First ToDo Description This is the First ToDo Description This is the First ToDo Description This is the First ToDo Description",
                        Title  = "First Thing",
                        tdDate = DateTime.Now.AddDays(1),
                        Type   = 1
                    });
                    this.Items.Add(
                        new ToDoItemModel()
                    {
                        ID     = (DateTime.Now.Ticks + 1).ToString(),
                        Note   = "This is the Second ToDo Description",
                        Title  = "Second Thing",
                        tdDate = DateTime.Now.AddDays(2),
                        Type   = 3
                    });
                    this.Items.Add(
                        new ToDoItemModel()
                    {
                        ID     = (DateTime.Now.Ticks + 2).ToString(),
                        Note   = "This is the Third ToDo Description",
                        Title  = "Third Thing",
                        tdDate = DateTime.Now.AddDays(3),
                        Type   = 1
                    });
                    this.Items.Add(
                        new ToDoItemModel()
                    {
                        ID     = (DateTime.Now.Ticks + 2).ToString(),
                        Note   = "This is the Third ToDo Description",
                        Title  = "Third Thing",
                        tdDate = DateTime.Now.AddDays(4),
                        Type   = 3
                    });
                } // end if (!isDataLoaded)
            }     //end if (dataFile != null)
            this.isDataLoaded = true;
            NotifyPropertyChanged("Items");
            checkSortItemsForCategory();
        }// end LoadData()