Ejemplo n.º 1
0
 public filesView()
 {
     mlibrary = new methodLibrary();
     apiLibrary = new Library_APICall();
     photosCollection = new ObservableCollection<Photos>();
     this.InitializeComponent();
 }
Ejemplo n.º 2
0
        public AddNewTeam()
        {
            this.InitializeComponent();
            //timezone_friendly = new ObservableCollection<string>();
            //tznames = new ObservableCollection<timezone>();
            //ReadOnlyCollection<TimeZoneInfo> tz = TimeZoneInfo.GetSystemTimeZones();
            //foreach (var tzone in tz)
            //{
            //    tznames.Add(new timezone(tzone.DisplayName));
            //}
            //TimeZoneCombo.DisplayMemberPath = tznames;
            rtemplate = new TemplateTeams();
            mlb = new methodLibrary();
            APILibrary = new Library_APICall();

            countries = new string[]
            {"Afghanistan","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica","Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Bouvet Island","Brazil","British Indian Ocean Territory","Brunei Darussalam","Bulgaria","Burkina Faso",
            "Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central African Republic","Chad","Chile","China","Christmas Island","Cocos (Keeling) Islands","Colombia","Comoros","Congo","Congo, the Democratic Republic of the","Cook Islands","Costa Rica","Cote D'Ivoire","Croatia","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia", "Falkland Islands (Malvinas)","Faroe Islands","Fiji","Finland","France","French Guiana","French Polynesia","French Southern Territories","Gabon","Gambia",
            "Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guadeloupe","Guam","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Heard Island and Mcdonald Islands","Holy See (Vatican City State)", "Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran, Islamic Republic of","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Korea, Democratic People's Republic of","Korea, Republic of","Kuwait","Kyrgyzstan","Lao People's Democratic Republic",
            "Latvia","Lebanon","Lesotho","Liberia","Libyan Arab Jamahiriya","Liechtenstein","Lithuania","Luxembourg","Macao","Macedonia, the Former Yugoslav Republic of","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique", "Mauritania","Mauritius","Mayotte","Mexico","Micronesia, Federated States of","Moldova, Republic of","Monaco","Mongolia","Montserrat","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Norfolk Island","Northern Mariana Islands","Norway","Oman","Pakistan","Palau","Palestinian Territory, Occupied","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Pitcairn","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saint Helena","Saint Kitts and Nevis","Saint Lucia","Saint Pierre and Miquelon","Saint Vincent and the Grenadines","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia and Montenegro","Seychelles","Sierra Leone","Singapore","Slovakia",
            "Slovenia","Solomon Islands","Somalia","South Africa","South Georgia and the South Sandwich Islands","Spain","Sri Lanka","Sudan","Suriname","Svalbard and Jan Mayen","Swaziland","Sweden","Switzerland","Syrian Arab Republic","Taiwan, Province of China","Tajikistan","Tanzania, United Republic of", "Thailand","Timor-Leste","Togo","Tokelau","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Tuvalu",
            "Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","United States Minor Outlying Islands","Uruguay","Uzbekistan","Vanuatu","Venezuela","Viet Nam","Virgin Islands, British","Virgin Islands, US","Wallis and Futuna","Western Sahara","Yemen","Zambia","Zimbabwe",};

            sportnames = new string[]
            {
                "Basketball","Soccer","Softball","Baseball","Volleyball","Football","Cricket","Rugby","Lacrosse" ,"Wiffleball" ,"Bowling","Dodgeball","Field Hockey","Ice Hockey","Inline Hockey","Kickball","Paintball","Polo","Rowing","Ultimate" ,"Water Polo" ,"Other Sport" ,"Dragon Boat","Australian Football","Badminton" ,"Bandy" ,"Bocce","Broomball","Cheerleading","Chess","Croquet","Curling",
                "Cycling","Fencing","Foosball","Hurling","Indoor Soccer","Netball","Running","Swimming","Tennis","Floorball","Petanque","Golf","Sailing","Roller Derby","Wrestling","Ki-O-Rahi","Ringette","Non-Sport Group","Outrigger","Cow Tipping" ,"Racquetball" ,"Gymnastics-Men","Gymnastics-Women","Track And Field" ,"Archery","Floor Hockey","Slo-pitch" ,"Street Hockey" ,"Pickleball","Wheelchair Basketball",
                "Sled Hockey","Wheelchair Softball","Quad Rugby","Handcycling","Adaptive Sports","Cross Country" ,"Cross Country Skiing","Alpine Skiing","Wheelchair Hockey","Wheelchair Volleyball","Wheelchair Lacrosse","Horseback Riding" ,"Diving"
            };
            this.NavigationCacheMode = NavigationCacheMode.Required;
        }
 public PhotosDetailComments()
 {
     apiLibrary = new Library_APICall();
     commlist = new ObservableCollection<Comments>();
     this.InitializeComponent();
     comments = new ObservableCollection<Comments>();
 }
Ejemplo n.º 4
0
 public AddNewForumTopic()
 {
     this.InitializeComponent();
     mlibrary = new methodLibrary();
     APILibrary = new Library_APICall();
     this.NavigationCacheMode = NavigationCacheMode.Required;
 }
Ejemplo n.º 5
0
 public static async Task<ObservableCollection<TrackingItemsObj>> getTrackingItems()
 {
     ObservableCollection<TrackingItemsObj> ritem = new ObservableCollection<TrackingItemsObj>();
    
     Library_APICall apiLibrary = new Library_APICall();
     string resp = await apiLibrary.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/tracked_items/search?team_id=" + Constants.CurrentTeamID);
     RootObjectTrackingItemStatus ritemstatus = trackingStatusDataDeserializer(resp);
     if (ritemstatus.collection.items != null)
     {
         Dictionary<string, int> rstatus_items_data_ht = new Dictionary<string, int>();
         for (int i = 0; i < ritemstatus.collection.items[0].data.Count; i++)
         {
             if (!rstatus_items_data_ht.ContainsKey(ritemstatus.collection.items[0].data[i].name))
             {
                 rstatus_items_data_ht.Add(ritemstatus.collection.items[0].data[i].name, i);
             }
         }
         ritem.Clear();
         for (int i = 0; i < ritemstatus.collection.items.Count; i++)
         {
             TrackingItemsObj robj = new TrackingItemsObj();
             robj.itemid = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["id"]].value;
             robj.teamid = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["team_id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["team_id"]].value;
             robj.itemname = String.IsNullOrEmpty((string)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["name"]].value) ? "" : (string)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["name"]].value;
             ritem.Add(robj);
         }
         return ritem;
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 6
0
 public PaymentItemDetails()
 {
     this.InitializeComponent();
     APILibrary = new Library_APICall();
     rteamfee = new TeamFeeItems();
     selectedTeamMember = new Team_Member();
     rteammember_collection = new ObservableCollection<Team_Member>();
     selectedTeamMemberPosInList = 0;
 }
Ejemplo n.º 7
0
 public PhotosView()
 {
     tempfilepath = null;
     mlibrary = new methodLibrary();
     apiLibrary = new Library_APICall();
     photosCollection = new ObservableCollection<Photos>();
     team_media_group_id = null;
     this.InitializeComponent();
 }
Ejemplo n.º 8
0
 public MediaFolders()
 {
     teamid = 0;
     mLibrary = new methodLibrary();
     apiLibrary = new Library_APICall();
     rteamMedia = new RootObjectTeamMedia();
     photoCollectionFolder = new ObservableCollection<PhotoCollectionFolder>();
     //rotatorphoto = new ObservableCollection<RotatorPhotos>();
     this.InitializeComponent();
 }
Ejemplo n.º 9
0
 public PaymentsPage()
 {
     this.InitializeComponent();
     APILibrary = new Library_APICall();
     mlibrary = new methodLibrary();
     rteamFeeAPI = new RootObjectTeamFeeAPI();
     rMemberPaymentAPI = new RootObjectMemberPaymentAPI();
     rpaymentcollection = new ObservableCollection<TeamFeeItems>();
     rpayment = new RootPaymentCollection();
 }
Ejemplo n.º 10
0
 public ForumPostsPage()
 {
     this.InitializeComponent();
     this.NavigationCacheMode = NavigationCacheMode.Required;
     rftopic = new ForumsTopic();
     mlibrary = new methodLibrary();
     APILibrary = new Library_APICall();
     rfpost = new ObservableCollection<ForumsPost>();
     /*ReplyToPostBox.MaxHeight = ReplyToPostBox.Height;
     replybutton.MaxHeight = ReplyToPostBox.MaxHeight;
     replybutton.Height = ReplyToPostBox.Height;*/
     
 }
Ejemplo n.º 11
0
 public signin()
 {
     this.InitializeComponent();
     LibraryAuth = new Library_TokenAuth();
     LibraryAPI = new Library_APICall();
     lib = new methodLibrary();
     rme = new RootObjectMe();
     rmembers = new RootObjectMembers();
     rteams = new RootObjectTeams();
     rusers = new RootObjectUsers();
     meAPI = "https://api.teamsnap.com/v3/me";
    // CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
 }
Ejemplo n.º 12
0
 public AddEvent()
 {
     this.InitializeComponent();
     this.NavigationCacheMode = NavigationCacheMode.Required;
     ruserteam = new CollectionUsersTeam();
     rtemplate = new TemplateEvents();
     mlibrary = new methodLibrary();
     APILibrary = new Library_APICall();
     opponent_id_map = new Hashtable();
     location_id_map = new Hashtable();
     game_type_code = 0;
     opponentAvailable = false;
     locationAvailable = false;
     //opponents = new List<string>();
 }
Ejemplo n.º 13
0
 public AddNewEmail()
 {
     mlb = new methodLibrary();
     APILibrary = new Library_APICall();
     mselectrecipient = new ObservableCollection<CollectionUsersTeamMembers>();
     ruser = new RootObjectUsers();
     teamid_temp = 0;
     memberid = 0;
     parameterPresent = false;
     recipient_ids = null;
     recipient_names = null;
     rcem = new CollectionEventAvailabilityMembers();
     this.Loaded += AddNewEmail_Loaded;
     this.InitializeComponent();
 }
Ejemplo n.º 14
0
 public AddNewOpponent()
 {
     this.InitializeComponent();
     mlibrary = new methodLibrary();
     APILibrary = new Library_APICall();
     teamid = 0;
     Frame rootFrame = Window.Current.Content as Frame;
     if (rootFrame.CanGoBack)
     {
         // If we have pages in our in-app backstack and have opted in to showing back, do so
         SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
     }
     else
     {
         // Remove the UI from the title bar if there are no pages in our in-app back stack
         SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
     }
 }
Ejemplo n.º 15
0
        public Forums()
        {
            this.InitializeComponent();
            APILibrary = new Library_APICall();
            mlibrary = new methodLibrary();
            rforumposts = new RootObjectForumPosts();
            rforumtopics = new RootObjectForumTopics();
            rforumdata = new RootObjectForumsData();
            remails = new RootObjectEmails();
            remaildata = new RootEmailData();
            ftopic = new ObservableCollection<ForumsTopic>();
            etopic = new ObservableCollection<EmailTopics>();
            DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
            this.NavigationCacheMode = NavigationCacheMode.Required;
            //rforumdatatopic = new ForumsTopic();
            //this.NavigationCacheMode = NavigationCacheMode.Required;
            teamid = 0;

        }
Ejemplo n.º 16
0
        public static async Task<ObservableCollection<MemberItemTrackingStatus>> getTrackingItemStatus(long trackingitemid)
        {
            ObservableCollection<MemberItemTrackingStatus> ritemstatuscollection = new ObservableCollection<MemberItemTrackingStatus>();
            methodLibrary mlb = new methodLibrary();
            string userclass = await mlb.readSerializedUserClass();
            RootObjectUsers rusers = new RootObjectUsers();
            rusers = Users.usersDataDeserializer(userclass);

            Library_APICall apiLibrary = new Library_APICall();
            string resp = await apiLibrary.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/tracked_item_statuses/search?tracked_item_id=" + trackingitemid);
            RootObjectTrackingItemStatus ritemstatus = trackingStatusDataDeserializer(resp);

            Dictionary<string, int> rstatus_items_data_ht = new Dictionary<string, int>();
            for (int i = 0; i < ritemstatus.collection.items[0].data.Count; i++)
            {
                if (!rstatus_items_data_ht.ContainsKey(ritemstatus.collection.items[0].data[i].name))
                {
                    rstatus_items_data_ht.Add(ritemstatus.collection.items[0].data[i].name, i);
                }
            }
            ritemstatuscollection.Clear();
            for (int i = 0; i < ritemstatus.collection.items.Count; i++)
            {
                MemberItemTrackingStatus robj = new MemberItemTrackingStatus();
                robj.object_id = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["id"]].value;
                robj.trackingitemid = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["tracked_item_id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["tracked_item_id"]].value;
                robj.status = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status"]].value == null ? "" : (string)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status"]].value;
                robj.member_id = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["member_id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["member_id"]].value;
                robj.status_code = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status_code"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status_code"]].value;
                CollectionUsersTeamMembers rmember = new CollectionUsersTeamMembers();
                rmember = mlb.getMemberInfoFromFile(rusers, robj.member_id);
                robj.member_name = rmember.fullname;
                ritemstatuscollection.Add(robj);
            }
            
            return ritemstatuscollection;
        }
Ejemplo n.º 17
0
 public RosterDetail()
 {
     this.InitializeComponent();
     LibraryAPI = new Library_APICall();
     rfammemcontacts = new ObservableCollection<FamilyMemberContacts>();
 }
Ejemplo n.º 18
0
        private async void UpdateTrackingStatus(long statuscode, long tracked_item_id, long member_id, long object_id)
        {
            Library_APICall apiLibrary = new Library_APICall();
            string res = null;
            try
            {
                ShowStatusMessage(statuscode);
            }
            catch (Exception ex)
            {

            }
            try
            {
                res = "{ \"template\":{ \"data\":[{\"name\":\"status_code\",\"value\":" + statuscode + "}";
                res += ",{\"name\":\"tracked_item_id\",\"value\":" + tracked_item_id + "}";
                res += ",{\"name\":\"member_id\",\"value\":" + member_id + "}";
                res += ",{\"name\":\"type\",\"value\":\"tracked_item_status\"}";
                res += "]}}";
                bool r = await apiLibrary.apiPUT((string)ApplicationData.Current.LocalSettings.Values["Tokens"], res, "https://api.teamsnap.com/v3/tracked_item_statuses/" + object_id);

                if (r == true)
                {
                    memberobj.Clear();
                    memberobj = await TrackingItemStatus.getTrackingItemStatus(tracked_item_id);
                    membertracking.Clear();
                    foreach (var item in memberobj)
                    {
                        membertracking.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 19
0
        public static async Task<RootPaymentCollection> createPaymentCollection(RootObjectTeamFeeAPI rteamFee, RootObjectMemberPaymentAPI rteamMemberPayment)
        {
            Library_APICall APILibrary = new Library_APICall();
            RootPaymentCollection rpayment = new RootPaymentCollection();
            methodLibrary mlb = new methodLibrary();
            List<CollectionUsersTeamMembers> ctrmList = new List<CollectionUsersTeamMembers>();
            Hashtable teamfeeId_ListPos = new Hashtable();  // Keeps track of position of each team id in the team_fees list.
            /*Extracting the list of members for the current team from FileUserClass.txt*/
            Hashtable memberid_ListPos = new Hashtable();  //Keeps track of the position in list based on the member id. Will be useful later.            
            string fileuserclass = await mlb.readSerializedUserClass();
            RootObjectUsers ruser = Users.usersDataDeserializer(fileuserclass);
            for (int i = 0; i < ruser.teams.Count; i++)
            {
                if (ruser.teams[i].id == (long)ApplicationData.Current.LocalSettings.Values["currentTeamID"])
                {
                    for (int j = 0; j < ruser.teams[i].members.Count; j++)
                    {
                        CollectionUsersTeamMembers ctm = new CollectionUsersTeamMembers();
                        ctm = ruser.teams[i].members[j];
                        ctrmList.Add(ctm);                                                                  // Keep in mind that all this stuff is being done for just one team. A single team will have all unique member_ids
                        if (ctrmList.Count > 0)
                        {
                            memberid_ListPos.Add(ruser.teams[i].members[j].member_id, ctrmList.Count - 1);
                        }
                    }
                }
            }
            /****************************/

            /*Working on the TeamFee */
            rpayment.team_fees = new List<TeamFeeItems>();
            Hashtable rteamfee_ht = new Hashtable();    // Adding the data items to a hashtable so that I can compare and add stuff to the right place
            for (int i = 0; i < rteamFee.collection.items[0].data.Count; i++)
            {
                rteamfee_ht.Add(rteamFee.collection.items[0].data[i].name, i);
            }

            // Run through array of items and add it to and object of type TeamFeeItems
            for (int i = 0; i < rteamFee.collection.items.Count; i++)
            {
                TeamFeeItems rtfitems = new TeamFeeItems();
                rtfitems.team_fee_id = rteamFee.collection.items[i].data[(int)rteamfee_ht["id"]].value == null ? 0 : (long)rteamFee.collection.items[i].data[(int)rteamfee_ht["id"]].value;   
                if (!teamfeeId_ListPos.Contains(rtfitems.team_fee_id))
                {
                    teamfeeId_ListPos.Add(rtfitems.team_fee_id, i);
                }     
                rtfitems.team_fee_description = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["description"]].value;
                rtfitems.team_fee_amount = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["amount"]].value;
                rtfitems.team_fee_notes = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["notes"]].value;
                rtfitems.team_fee_balance = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["balance"]].value;
                rtfitems.team_member = new List<Team_Member>();
                rpayment.team_fees.Add(rtfitems);                
            }


            /*************************/
            /*Working on member payments now*/
            //Run through memberPayments and for each matching team_fee_id, add the data to rpayment.team_fees[i].team_member

            Hashtable rteamMemberPayment_ht = new Hashtable();
            for (int i = 0; i < rteamMemberPayment.collection.items[0].data.Count; i++)
            {
                rteamMemberPayment_ht.Add(rteamMemberPayment.collection.items[0].data[i].name, i);
            }
            
            for (int i = 0; i < rteamMemberPayment.collection.items.Count; i++)
            {
                // read the team_fee_id
                long member_team_fee_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["team_fee_id"]].value;
                // check if it matches an existing team_fee_id in teamfeeId_ListPos
                if(teamfeeId_ListPos.ContainsKey(member_team_fee_id))
                {
                    TeamFeeItems rtfitems = new TeamFeeItems();
                    rtfitems = rpayment.team_fees[(int)teamfeeId_ListPos[member_team_fee_id]];
                    Team_Member rteammember = new Team_Member();
                    rteammember.tickmark = new TeamMemberTickMarkVisibility();
                    rteammember.team_fee_id = member_team_fee_id;
                    rteammember.member_payment_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["id"]].value;
                    rteammember.team_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["team_id"]].value;
                    rteammember.amount_paid = (string)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["amount_paid"]].value;
                    
                    rteammember.amount_due = (string)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["amount_due"]].value;
                    rteammember.is_applicable = rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["is_applicable"]].value == null ? false : (bool)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["is_applicable"]].value;
                    rteammember.member_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["member_id"]].value;
                    rteammember.tickmark.is_applicable = rteammember.is_applicable;
                    rteammember.tickmark.amount_due = rteammember.amount_due;
                    //Check if memberid_ListPos contains this team_fee_member_id. If it does, fetch member info from there
                    long team_fee_member_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["member_id"]].value;
                    if (memberid_ListPos.ContainsKey(team_fee_member_id))
                    {
                        int pos = (int)memberid_ListPos[team_fee_member_id];
                        rteammember.member_name = ctrmList[pos].first_name + (String.IsNullOrEmpty(ctrmList[pos].last_name) ? "" : " " + ctrmList[pos].last_name);
                        rteammember.member_photo = ctrmList[pos].member_photo;
                        rteammember.member_photo = ctrmList[pos].member_photo_notscaled;
                        rteammember.email_address = ctrmList[pos].email_address;
                        rteammember.is_non_player = ctrmList[pos].is_non_player;
                    }
                    rpayment.team_fees[(int)teamfeeId_ListPos[member_team_fee_id]].team_member.Add(rteammember);  // Adding rteammember under the right TeamFeeItems
                }
            }
            return rpayment;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// update User Information.
        /// </summary>
        /// <returns></returns>
        public static async Task<RootObjectUsers> updateUser()
        {
            //await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
            //    () =>
            //    {
            //        // UI stuff here
                     
            //    });
            mlb = new methodLibrary();
            //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": in updateUser method");
            string meAPIResponse = await mlb.readFile("meAPIResponse");
            RootObjectMe rme = new RootObjectMe();
            rme = Me.MeDataDeserializer(meAPIResponse);
            string teamAPIResponse = await mlb.readFile("teamAPIResponse");
            RootObjectTeams rteams = new RootObjectTeams();
            //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Deserializing teams response");
            rteams = Teams.teamDataDeserializer(teamAPIResponse);
            // start with rme and store data about the user
            itemCollection = new CollectionUsersItem();
            LibraryAPI = new Library_APICall();
            //teamsCollection = new CollectionUsersTeam();
            rusers = new RootObjectUsers();
            rusers.items = new List<CollectionUsersItem>();
            rusers.teams = new List<CollectionUsersTeam>();
            rsports = new RootObjectSports();
            
            RootObjectMembers rmembers = new RootObjectMembers();
            
            Hashtable rme_ht = new Hashtable();
            Hashtable rteam_ht = new Hashtable();
            Hashtable rteamlinks_ht = new Hashtable();
            string memberAPIResponse = null;
            int id = 0;

            /** Populate a hashtable to get sportname quickly. Also write results of sportsAPI call to a file.**/
            string sportres = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/sports");
            rsports = Sports.usersDataDeserializer(sportres);
            Hashtable rsports_ht = new Hashtable();
            for (int i = 0; i < rsports.collection.items.Count; i++)
            {
                if (!rsports_ht.Contains(rsports.collection.items[i].data[0].value))
                {
                    rsports_ht.Add(rsports.collection.items[i].data[0].value, i);
                }
            }
            mlb.makeAPICallandWriteToFile("sportsName", "https://api.teamsnap.com/v3/sports");

            /************/
            while(id < rme.collection.items[0].data.Count)
            {
                if (!rme_ht.Contains(rme.collection.items[0].data[id].name))
                {
                    rme_ht.Add(rme.collection.items[0].data[id].name, id);
                    
                }
                id++;
            }
            await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Updating itemcollections", false);
            itemCollection.id = rme.collection.items[0].data[(int)rme_ht["id"]].value == null ? 0:(long)rme.collection.items[0].data[(int)rme_ht["id"]].value;
            itemCollection.type = rme.collection.items[0].data[(int)rme_ht["type"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["type"]].value;
            itemCollection.address_country = rme.collection.items[0].data[(int)rme_ht["address_country"]].value == null ? "" : (string)rme.collection.items[0].data[(int)rme_ht["address_country"]].value;
            itemCollection.address_state = rme.collection.items[0].data[(int)rme_ht["address_state"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["address_state"]].value;
            itemCollection.birthday = rme.collection.items[0].data[(int)rme_ht["birthday"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["birthday"]].value;
            itemCollection.email = rme.collection.items[0].data[(int)rme_ht["email"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["email"]].value;
            updatePlanInfo(itemCollection.email);
            itemCollection.first_name = rme.collection.items[0].data[(int)rme_ht["first_name"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["first_name"]].value;
            itemCollection.last_name = rme.collection.items[0].data[(int)rme_ht["last_name"]].value == null ? "":(string)rme.collection.items[0].data[(int)rme_ht["last_name"]].value;
            //itemCollection.teams_count = rme.collection.items[0].data[(int)rme_ht["teams_count"]].value == null ? 0:(long)rme.collection.items[0].data[(int)rme_ht["teams_count"]].value;
            try
            {
                itemCollection.teams_count = (int)rteams.collection.items.Count;
            }
            catch (Exception ex)
            {
                await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Exception in setting team count", true);
            }
            await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": itemcollection has been updated", false);
            rusers.items.Add(itemCollection);
            Debug.WriteLine("MethodLibrary : End rME. Start rTeam.");
            // now use rteams to store data about the teams the user is a member of.
            for(int i=0; i < rusers.items[0].teams_count; i++)
            {
                id = 0;
                try
                {
                    while (id < rteams.collection.items[i].data.Count)
                    {
                        if (!rteam_ht.Contains(rteams.collection.items[i].data[id].name))
                        {
                            rteam_ht.Add(rteams.collection.items[i].data[id].name, id);
                            
                        }
                        id++;
                    }
                    id = 0;
                    while (id < rteams.collection.items[i].links.Count)
                    {
                        if (!rteamlinks_ht.Contains(rteams.collection.items[i].links[id].rel))
                        {
                            rteamlinks_ht.Add(rteams.collection.items[i].links[id].rel, id);
                            
                        }
                        id++;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception in setting rteam_ht and rteamlinks_ht :" + ex);
                    await mlb.writeToLogFile((DateTime.UtcNow).ToString() + "Exception in setting rteam_ht and rteamlinks_ht: " + ex, true);
                }
                teamsCollection = new CollectionUsersTeam();
                teamsCollection.members = new List<CollectionUsersTeamMembers>();
                
                teamsCollection.id = rteams.collection.items[i].data[(int)rteam_ht["id"]].value == null ? 0:(long)rteams.collection.items[i].data[(int)rteam_ht["id"]].value;
               
                teamsCollection.eventsLink = rteams.collection.items[i].links[(int)rteamlinks_ht["events"]].href == null ? "":(string)rteams.collection.items[i].links[(int)rteamlinks_ht["events"]].href;
                /** Writing API call results of Opponents, Events and Locations to file. Speed up stuff ahead**/
                string flname = "events_" + (teamsCollection.id).ToString();
                
                await mlb.makeAPICallandWriteToFile(flname, teamsCollection.eventsLink);
             
                flname = "opponents_" + (teamsCollection.id).ToString();
                mlb.makeAPICallandWriteToFile(flname, (string)rteams.collection.items[i].links[(int)rteamlinks_ht["opponents"]].href);
                
                flname = "locations_" + (teamsCollection.id).ToString();
                mlb.makeAPICallandWriteToFile(flname, (string)rteams.collection.items[i].links[(int)rteamlinks_ht["locations"]].href);

                ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Updating Team";
                /**Done**/
                //string tempres = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], teamsCollection.eventsLink);
                teamsCollection.locationsLink = rteams.collection.items[i].links[(int)rteamlinks_ht["locations"]].href == null ? "":(string)rteams.collection.items[i].links[(int)rteamlinks_ht["locations"]].href;
                string memberslink = rteams.collection.items[i].links[(int)rteamlinks_ht["members"]].href == null ? "":(string)rteams.collection.items[i].links[(int)rteamlinks_ht["members"]].href;
                teamsCollection.type = rteams.collection.items[i].data[(int)rteam_ht["type"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["type"]].value;
                teamsCollection.division_name = rteams.collection.items[i].data[(int)rteam_ht["division_name"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["division_name"]].value;
                teamsCollection.is_archived_season = rteams.collection.items[i].data[(int)rteam_ht["is_archived_season"]].value == null ? false : (bool)rteams.collection.items[i].data[(int)rteam_ht["is_archived_season"]].value;
                teamsCollection.is_retired = rteams.collection.items[i].data[(int)rteam_ht["is_retired"]].value == null ? false : (bool)rteams.collection.items[i].data[(int)rteam_ht["is_retired"]].value;
                teamsCollection.league_name = rteams.collection.items[i].data[(int)rteam_ht["league_name"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["league_name"]].value;
                teamsCollection.league_url = rteams.collection.items[i].data[(int)rteam_ht["league_url"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["league_url"]].value;
                teamsCollection.is_in_league = rteams.collection.items[i].data[(int)rteam_ht["is_in_league"]].value == null ? false : (bool)rteams.collection.items[i].data[(int)rteam_ht["is_in_league"]].value;
                teamsCollection.location_country = rteams.collection.items[i].data[(int)rteam_ht["location_country"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["location_country"]].value;
                teamsCollection.location_postal_code = rteams.collection.items[i].data[(int)rteam_ht["location_postal_code"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["location_postal_code"]].value;
                teamsCollection.location_latitude = rteams.collection.items[i].data[(int)rteam_ht["location_latitude"]].value == null ? "38.8951100" :(string)rteams.collection.items[i].data[(int)rteam_ht["location_latitude"]].value;
                ApplicationData.Current.LocalSettings.Values["team_latitude_" + teamsCollection.id] = (string)teamsCollection.location_latitude;
                teamsCollection.location_longitude = rteams.collection.items[i].data[(int)rteam_ht["location_longitude"]].value == null ? "-77.0363700" : (string)rteams.collection.items[i].data[(int)rteam_ht["location_longitude"]].value;
                ApplicationData.Current.LocalSettings.Values["team_longitude_" + teamsCollection.id] = (string)teamsCollection.location_longitude;
                teamsCollection.name = rteams.collection.items[i].data[(int)rteam_ht["name"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["name"]].value;
                teamsCollection.plan_id = rteams.collection.items[i].data[(int)rteam_ht["plan_id"]].value == null ? 0:(long)rteams.collection.items[i].data[(int)rteam_ht["plan_id"]].value;
                teamsCollection.season_name = rteams.collection.items[i].data[(int)rteam_ht["season_name"]].value == null ? "":(string)rteams.collection.items[i].data[(int)rteam_ht["season_name"]].value;
                teamsCollection.sport_id = rteams.collection.items[i].data[(int)rteam_ht["sport_id"]].value == null ? 0:(long)rteams.collection.items[i].data[(int)rteam_ht["sport_id"]].value;
                teamsCollection.sport_name = getSportName(teamsCollection.sport_id, rsports_ht);                
                teamsCollection.pathToSportLogo = "images/" + teamsCollection.sport_id + ".png";
                ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Updating Team " + teamsCollection.name;
                //teamsCollection.teamOwner = itemCollection.first_name + " " + itemCollection.last_name;

                mlb.writeToLogFile("Calling TeamAvailability API", false);
                mlb.makeAPICallandWriteToFile("teamAvailabilityAPI" + teamsCollection.id, (string)rteams.collection.items[i].links[(int)rteamlinks_ht["availabilities"]].href);

                mlb.writeToLogFile("Done calling TeamAvailability API and updating the availabilityfile", false);
                // make API call to fetch members for that particular team

                memberAPIResponse = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], memberslink);  
                if (memberAPIResponse != "fail")
                {
                    //deserialize the response
                    rmembers = Members.membersDataDeserializer(memberAPIResponse);
                    Hashtable rmember_ht = new Hashtable();
                    // use rmembers to store data about the members the team has
                    for (int j = 0; j < rmembers.collection.items.Count; j++)
                    {
                        int idm = 0;
                       // Debug.WriteLine("Adding values to rmember_ht");
                        while (idm < rmembers.collection.items[j].data.Count)
                        {
                            //Debug.WriteLine("Inside the while loop that adds values to rmember_ht");
                            try
                            {
                                if (!rmember_ht.Contains(rmembers.collection.items[j].data[idm].name))
                                {
                                    rmember_ht.Add(rmembers.collection.items[j].data[idm].name, idm);                                   
                                }
                                idm++;
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex);
                                var tc = new TelemetryClient();
                                await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": rmember_ht exception", true);
                                tc.TrackEvent("rmember_ht exception : " + ex);
                            }
                        }
                        ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Updating Team Members";
                        teammembers = new CollectionUsersTeamMembers();
                        await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Updating teammember", false);
                        teammembers.address_city = rmembers.collection.items[j].data[(int)rmember_ht["address_city"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_city"]].value;
                        teammembers.address_state = rmembers.collection.items[j].data[(int)rmember_ht["address_state"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_state"]].value;
                        teammembers.address_street1 = rmembers.collection.items[j].data[(int)rmember_ht["address_street1"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_street1"]].value;
                        teammembers.address_street2 = rmembers.collection.items[j].data[(int)rmember_ht["address_street2"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_street2"]].value;
                        teammembers.address_zip = rmembers.collection.items[j].data[(int)rmember_ht["address_zip"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["address_zip"]].value;
                        teammembers.birthday = rmembers.collection.items[j].data[(int)rmember_ht["birthday"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["birthday"]].value;
                        teammembers.member_id = rmembers.collection.items[j].data[(int)rmember_ht["id"]].value == null ? 0 : (long)rmembers.collection.items[j].data[(int)rmember_ht["id"]].value;
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": member id " + teammembers.member_id);
                        teammembers.first_name = rmembers.collection.items[j].data[(int)rmember_ht["first_name"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["first_name"]].value;
                        ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Updating " + teammembers.first_name + " information";
                        teammembers.gender = rmembers.collection.items[j].data[(int)rmember_ht["gender"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["gender"]].value;
                        teammembers.is_address_hidden = rmembers.collection.items[j].data[(int)rmember_ht["is_address_hidden"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["hide_address"]].value;
                        teammembers.is_age_hidden = rmembers.collection.items[j].data[(int)rmember_ht["is_age_hidden"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["hide_age"]].value;
                        teammembers.is_manager = rmembers.collection.items[j].data[(int)rmember_ht["is_manager"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["is_manager"]].value;
                        teammembers.is_non_player = rmembers.collection.items[j].data[(int)rmember_ht["is_non_player"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["is_non_player"]].value;
                        teammembers.jersey_number = rmembers.collection.items[j].data[(int)rmember_ht["jersey_number"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["jersey_number"]].value;
                        //Debug.WriteLine("Jersey Number : " + ((bool)string.IsNullOrEmpty((string)rmembers.collection.items[j].data[24].value)) ? true : false );
                        teammembers.last_name = rmembers.collection.items[j].data[(int)rmember_ht["last_name"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["last_name"]].value;
                        teammembers.position = rmembers.collection.items[j].data[(int)rmember_ht["position"]].value == null ? "":(string)rmembers.collection.items[j].data[(int)rmember_ht["position"]].value;
                        teammembers.team_id = rmembers.collection.items[j].data[(int)rmember_ht["team_id"]].value == null ? 0:(long)rmembers.collection.items[j].data[(int)rmember_ht["team_id"]].value;
                        teammembers.user_id = rmembers.collection.items[j].data[(int)rmember_ht["user_id"]].value == null ? 0 : (long)rmembers.collection.items[j].data[(int)rmember_ht["user_id"]].value;
                        bool is_owner = rmembers.collection.items[j].data[(int)rmember_ht["is_owner"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["is_owner"]].value;
                        
                        /// if the current member is also the logged-in user, store that id in a separate object
                        if (teammembers.user_id == rusers.items[0].id)
                        {
                            teamsCollection.loggedInUsersmemberID = teammembers.member_id;
                        }
                        if (is_owner == true)
                        {
                            teamsCollection.teamOwner = teammembers.first_name + " " + teammembers.last_name;
                            teamsCollection.teamOwnerMemberId = teammembers.member_id;
                        }
                        bool is_manager = rmembers.collection.items[j].data[(int)rmember_ht["is_owner"]].value == null ? false : (bool)rmembers.collection.items[j].data[(int)rmember_ht["is_manager"]].value;
                        if (is_manager == true)
                        {
                            teamsCollection.teamManagerName = teammembers.first_name + " " + teammembers.last_name;
                            teamsCollection.teamManagerMemberId = teammembers.member_id;
                        }
                        //teammembers.updated_at = rmembers.collection.items[j].data[(int)rmember_ht["updated_at"]].value == null ? DateTime.MinValue : (DateTime)rmembers.collection.items[j].data[(int)rmember_ht["updated_at"]].value;



                        /*
                         
                         Fetching Family Member Information
                         */
                        ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Looking for " + teammembers.first_name + "'s family information";
                        await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": ****Calling Contacts, Contacts Phone and Contacts Email API for member : " + teammembers.member_id +  "****", false);
                      
                        teammembers.fullname = teammembers.first_name + (teammembers.last_name == null ? "" : (" " + teammembers.last_name));
                        Debug.WriteLine("Member ID : " + teammembers.member_id);
                        await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Updating member_photos", false);
                        //teammembers.member_photo = "images/member_photo.jpg";
                        bool memberPhotofound = false;
                        Debug.WriteLine("Running through all the links to find rel member_photo");
                        for (int m = 0; m < rmembers.collection.items[j].links.Count; m++)
                        {
                            //Debug.WriteLine("rel : " + rmembers.collection.items[j].links[m].rel);
                            //Debug.WriteLine("m : " + m);
                            if (rmembers.collection.items[j].links[m].rel == "member_thumbnail")
                            {
                                teammembers.member_thumbnail_uri = (string)rmembers.collection.items[j].links[m].href;
                            }
                            if (rmembers.collection.items[j].links[m].rel == "member_photo")
                            {
                                memberPhotofound = true;
                                //Debug.WriteLine("Member Photo Exists");
                                Debug.WriteLine(rmembers.collection.items[j].links[m].href);
                                string teammembers_member_photo = (string)rmembers.collection.items[j].links[m].href;
                                
                                try
                                {
                                    ApplicationData.Current.LocalSettings.Values["CurrentStep"] = "Looking for changes to " + teammembers.first_name + "'s profile photo.";
                                    Debug.WriteLine("teammembers_member_photo : " + teammembers_member_photo);
                                    // await downloadImage(teammembers_member_photo, "member" + (teammembers.member_id).ToString());
                                    //teammembers.member_photo = "ms-appdata:///local/member" + (teammembers.member_id).ToString() + "_scaled.png";
                                    teammembers.member_photo_notscaled = "ms-appdata:///local/member" + (teammembers.member_id).ToString() + ".png";
                                    if (String.IsNullOrEmpty(teammembers_member_photo))
                                    {
                                        teammembers.member_photo_imagex_path = "images/member_photo.jpg";
                                        teammembers.member_photo_imagex_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                                    }
                                    else
                                    {
                                        //teammembers.member_photo_imagex_path = "ms-appdata:///temp/ImageCache/" + methodLibrary.BuildFileName(new Uri(teammembers_member_photo));
                                        teammembers.member_photo_imagex_uri = teammembers_member_photo;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine("Failed to download image");
                                    teammembers.member_photo = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                                    teammembers.member_photo_imagex_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                                    teammembers.member_thumbnail_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                                    teammembers.member_photo_notscaled = "images/member_photo.jpg";
                                    teammembers.member_photo_imagex_path = "images/member_photo.jpg";
                                    await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Failed to download image", false);
                                }
                                //}
                            }

                        }
                        Debug.WriteLine("Photo Found : " + memberPhotofound);
                        if(memberPhotofound == false)
                        {
                            Debug.WriteLine("Adding default photos to the teammembers link");
                            teammembers.member_photo = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                            teammembers.member_photo_imagex_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                            teammembers.member_thumbnail_uri = "http://all4ed.org/wp-content/themes/all4ed/assets/images/avatar-placeholder-generic.png";
                            Debug.WriteLine("Finished adding default photos to the teammembers link");
                        }
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": All member photos have been updated");
                        Debug.WriteLine("Adding members to teamcollection");
                        teamsCollection.members.Add(teammembers);
                        rmember_ht.Clear();
                    }
                }
                Debug.WriteLine("Adding teamCollection to rusers");
                rusers.teams.Add(teamsCollection);
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": teamCollection added to userClass");
                rteam_ht.Clear();
                rteamlinks_ht.Clear();
                Debug.WriteLine("Done adding teamcollection to rusers");
                //rsports_ht.Clear();
            }
            await updateAvailability(rusers);
            Debug.WriteLine("MethodLibrary : End rTeam.");
            rsports_ht.Clear();
            Debug.WriteLine("returning users");
            return rusers;
        }
Ejemplo n.º 21
0
        public async Task<bool> doWhatSignInDoes()
        {
            string access_token = null;
            string meAPIResponse = null;
            string teamAPIResponse = null;
            bool writeserializeduserclass = false;
            //string memberAPIResponse = null;
            LibraryAuth = new Library_TokenAuth();
            methodLibrary mlb = new methodLibrary();
            Library_APICall LibraryAPI = new Library_APICall();
            RootObjectMe rme = new RootObjectMe();
            //RootObjectMembers rmembers = new RootObjectMembers();
            RootObjectTeams rteams = new RootObjectTeams();
            RootObjectUsers ru = new RootObjectUsers();
            Debug.WriteLine("doWhatSignInDoes : Checking if token is valid");
            string meAPI = (string)ApplicationData.Current.LocalSettings.Values["meAPI"];
            if (await LibraryAuth.tokenIsValid())
            {
                access_token = (string)ApplicationData.Current.LocalSettings.Values["Tokens"];
                //call Me API
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Token is valid.");
                //meAPIResponse = await LibraryAPI.apiCall(access_token, meAPI);
                string refreshclicked = (string)ApplicationData.Current.LocalSettings.Values["RefreshClicked"];
                // if (await checkIfFileExists(("family_contacts_phone_res" + teammembers.member_id)) && (String.IsNullOrEmpty(refreshclicked) || refreshclicked.Equals("false")))
                if (await checkIfFileExists("meAPIResponse") && (String.IsNullOrEmpty(refreshclicked) || refreshclicked.Equals("false")))
                {
                    meAPIResponse = await readFile("meAPIResponse");
                    if (String.IsNullOrEmpty(meAPIResponse))
                    {
                        meAPIResponse = await LibraryAPI.apiCall(access_token, meAPI);
                    }
                }
                else
                {
                    meAPIResponse = await LibraryAPI.apiCall(access_token, meAPI);
                }
                if (meAPIResponse == "fail")
                {
                    //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Call to Me API failed");
                    return false;
                }
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Call to Me API succeeded.");
                Debug.WriteLine(meAPIResponse);

                // deserialize meAPIResponse
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Deserializaing Me API response.");
                rme = Me.MeDataDeserializer(meAPIResponse);
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": me API response deserialization complete.");
                Hashtable links_ht = new Hashtable();
                int id = 0;
                while (id < rme.collection.items[0].links.Count)
                {
                    if (!links_ht.Contains(rme.collection.items[0].links[id].rel))
                    {
                        links_ht.Add(rme.collection.items[0].links[id].rel, id);
                        
                    }
                    id++;
                }
                
                ApplicationData.Current.LocalSettings.Values["TeamsAPI"] = rme.collection.items[0].links[(int)links_ht["active_teams"]].href;
                string teamAPI = (string)ApplicationData.Current.LocalSettings.Values["TeamsAPI"];
                
                Debug.WriteLine(rme.collection.items[0].data[0].value);
              
                teamAPIResponse = await LibraryAPI.apiCall(access_token, teamAPI);
                if (teamAPIResponse == "fail")
                {
                    //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Call to Teams API failed.");
                    return false;
                }
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Call to Teams API succeded.");
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Deserializing Teams API Response.");
                rteams = Teams.teamDataDeserializer(teamAPIResponse);
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Deserialization of Teams API Response completed successfully.");
                ////await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Writing Me Response to file.");
                await writeFile("meAPIResponse", meAPIResponse);
                await writeFile("teamAPIResponse", teamAPIResponse);
                var rtemplate = rteams.collection.template;
                writeFile("teamTemplate", Teams.teamTemplateSerializer(rtemplate));

                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Updating the User Class.");
                rusers = await methodLibrary.updateUser();
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": User class updated");
                string resp = Users.usersDataSerializer(rusers);
                Debug.WriteLine(resp);
                writeserializeduserclass = await writeSerializedUserClass(resp);
               
                resp = await readSerializedUserClass();
                //return true;
            }
            else 
            {                
                Debug.WriteLine("Network problems");
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Network connectivity problems.");
                return false;
            }
            return writeserializeduserclass;
        }
Ejemplo n.º 22
0
        private async void saveAvailability_Click(object sender, RoutedEventArgs e)
        {
            string res = null;
            try
            {
                //res = "{ \"template\":{ \"data\":[{\"name\":\"status_code\",\"value\":" + status_code + "},{\"name\":\"notes\",\"value\":\"" + availabilityNoteTextBox.Text + "\"},{\"name\":\"event_id\",\"value\":" + eventid + "},{\"name\":\"member_id\",\"value\":" + ((long)ApplicationData.Current.LocalSettings.Values["currentMemberIDforLoggedInUser"]).ToString() + "},{\"name\":\"notes_member_id\",\"value\":" + ((long)ApplicationData.Current.LocalSettings.Values["currentMemberIDforLoggedInUser"]).ToString() + "},{\"name\":\"type\",\"value\":\"availability\"}]}}";
                availabilityNoteTextBox.Visibility = Visibility.Collapsed;
                addAvailabilityNoteButton.Visibility = Visibility.Collapsed;
                availabilityNoteTextBlockGrid.Visibility = Visibility.Visible;
                availabilityNoteTextBlock.Text = availabilityNoteTextBox.Text;
               
                res = "{ \"template\":{ \"data\":[{\"name\":\"status_code\",\"value\":" + status_code + "}";
                res += ",{\"name\":\"notes\",\"value\":\"" + availabilityNoteTextBox.Text + "\"}";
                res += ",{\"name\":\"event_id\",\"value\":" + eventid + "}";
                res += ",{\"name\":\"member_id\",\"value\":" + ((long)ApplicationData.Current.LocalSettings.Values["currentMemberIDforLoggedInUser"]).ToString() + "}";
                res += ",{\"name\":\"author_member_id\",\"value\":" + ((long)ApplicationData.Current.LocalSettings.Values["currentMemberIDforLoggedInUser"]).ToString() + "}";
                res += ",{\"name\":\"notes_author_member_id\",\"value\":" + ((long)ApplicationData.Current.LocalSettings.Values["currentMemberIDforLoggedInUser"]).ToString() + "}";
                res += ",{\"name\":\"type\",\"value\":\"availability\"}]}}";
                Debug.WriteLine(res);
            }
            catch (Exception ex)
            {
                await mlibrary.writeToLogFile("Exception  in creating res for Availability PUT : " + ex, false);
            }

            try
            {
                reventavail.eventMemberAvailability[eventMemberAvailability_pos].memberAvailable[memberAvailable_pos].status_code = status_code;
                reventavail.eventMemberAvailability[eventMemberAvailability_pos].memberAvailable[memberAvailable_pos].notes = availabilityNoteTextBlock.Text;
                //res = AvailabilityAPI.eventAvailabilityDataSerializer(reventavail);
                Debug.WriteLine("Availability res : " + res);
            }
            catch (Exception ex)
            {
                await mlibrary.writeToLogFile("Exception in writing setting status code for reventavail and serializing reventavail : " + ex, true);
            }
            /// Updating collections 
            try
            {
                var rmemberstatus = reventavail.eventMemberAvailability[eventMemberAvailability_pos].memberAvailable;
                teamid = reventavail.eventMemberAvailability[eventMemberAvailability_pos].team_id;
                eventid = reventavail.eventMemberAvailability[eventMemberAvailability_pos].eventid;
                if (String.IsNullOrEmpty(availabilityNoteTextBox.Text))
                {
                    availabilityNoteTextBox.Visibility = Visibility.Collapsed;
                    //addAvailabilityNoteButton.Visibility = Visibility.Visible;
                    addAvailabilityNoteButton.Visibility = Visibility.Collapsed;
                    addAvailabilityNoteButton.Content = "+ Add availability note";
                    availabilityNoteTextBlockGrid.Visibility = Visibility.Collapsed;
                }
                if (rmemberstatus != null)
                {
                    rmemGoing.Clear();
                    rmemMaybe.Clear();
                    rmemNotGoing.Clear();
                    rmemUnknown.Clear();
                    foreach (var rmemstat in rmemberstatus)
                    {
                        if (rmemstat.status_code == 1)
                        {
                            rmemGoing.Add(rmemstat);
                        }
                        else if (rmemstat.status_code == 2)
                        {
                            rmemMaybe.Add(rmemstat);
                        }
                        else if (rmemstat.status_code == 0)
                        {
                            rmemNotGoing.Add(rmemstat);
                        }
                        else
                        {
                            rmemUnknown.Add(rmemstat);
                        }
                    }

                    if (rmemGoing != null)
                    {
                        if (rmemGoing.Count > 0)
                        {
                            NumGoing.Text = (rmemGoing.Count).ToString();
                            goingEmailButton.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            NumGoing.Text = "0";
                        }
                    }
                    if (rmemMaybe != null)
                    {
                        if (rmemMaybe.Count > 0)
                        {
                            NumMaybeGoing.Text = (rmemMaybe.Count).ToString();
                            maybeGoingEmailButton.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            NumMaybeGoing.Text = "0";
                        }
                    }
                    if (rmemNotGoing != null)
                    {
                        if (rmemNotGoing.Count > 0)
                        {
                            NumNotGoing.Text = (rmemNotGoing.Count).ToString();
                            notGoingEmailButton.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            NumNotGoing.Text = "0";
                        }
                    }
                    if (rmemUnknown != null)
                    {
                        if (rmemUnknown.Count > 0)
                        {
                            unknown.Text = (rmemUnknown.Count).ToString();
                            unknownGoingEmailButton.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            unknown.Text = "0";
                        }
                    }
                }
                else
                {
                    availabilityData.Visibility = Visibility.Collapsed;
                    noAvailabilityData.Visibility = Visibility.Visible;
                    availabilityGrid.Visibility = Visibility.Collapsed;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception in updating availability collection : " + ex);
                await mlibrary.writeToLogFile("Exception in updating availability collection : " + ex, true);
            }
            /// Done updating collections.
            try
            {
                saveAvailability.Visibility = Visibility.Collapsed;

                mlibrary.writeFile("EventsMemberAvailability" + Constants.CurrentTeamID, res);
            }
            catch (Exception ex)
            {
                await mlibrary.writeToLogFile("Setting saveAvailability button to collapse + writing reventavail to file", true);
            }
            Library_APICall apiLibrary = new Library_APICall();
            try
            {
                if (!String.IsNullOrEmpty(hrefForAvailabilityRequest))
                {
                    Debug.WriteLine("href: " + hrefForAvailabilityRequest);
                    bool postRes = await apiLibrary.apiPUT((string)ApplicationData.Current.LocalSettings.Values["Tokens"], res, hrefForAvailabilityRequest);
                }
            }
            catch (Exception ex)
            {
                await mlibrary.writeToLogFile("Exception in making a PUT request : " + ex, false);
            }
            //Debug.WriteLine(postRes);
        }
Ejemplo n.º 23
0
        private async void SubmitTrackedItem_Click(object sender, RoutedEventArgs e)
        {
            Library_APICall apiLibrary = new Library_APICall();
            string res = null;
            if (String.IsNullOrEmpty(NewTrackedItemName.Text) || String.IsNullOrWhiteSpace(NewTrackedItemName.Text))
            {
                // Show popup
            }
            else
            {
                try
                {
                    res = "{ \"template\":{ \"data\":[{\"name\":\"name\",\"value\":\"" + NewTrackedItemName.Text + "\"}";
                    res += ",{\"name\":\"team_id\",\"value\":" + Constants.CurrentTeamID + "}";                   
                    res += ",{\"name\":\"type\",\"value\":\"tracked_item\"}";
                    res += "]}}";
                    bool r = await apiLibrary.apiPOST((string)ApplicationData.Current.LocalSettings.Values["Tokens"], res, "https://api.teamsnap.com/v3/tracked_items");
                    if (r == true)
                    {
                       
                        tempobj = await TrackingItemStatus.getTrackingItems();
                        if (tempobj == null)
                        {
                            NoItemsGrid.Visibility = Visibility.Visible;
                            MobileGrid.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            //tempobj.Clear();
                            rtrackingitems.Clear();
                            foreach (var item in tempobj)
                            {
                                rtrackingitems.Add(item);
                            }
                            NoItemsGrid.Visibility = Visibility.Collapsed;
                            MobileGrid.Visibility = Visibility.Visible;
                        }
                    }
                   
                }
                catch (Exception ex)
                {

                }
                NewTrackedItemGrid.Visibility = Visibility.Collapsed;
                TrackedItemsListView.Opacity = 1;
                TrackedItemsListView.IsEnabled = true;
                AddNewItemButton.IsEnabled = true;
            }
        }
Ejemplo n.º 24
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame.CanGoBack)
            {
                // If we have pages in our in-app backstack and have opted in to showing back, do so
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            }
            else
            {
                // Remove the UI from the title bar if there are no pages in our in-app back stack
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
            }

            cal.Clear();
            calAllEvents.Clear();

            CollectionUsersTeam ruserteam = new CollectionUsersTeam();
            if (e.Parameter != null)
            {
                ruserteam = (CollectionUsersTeam)e.Parameter;
                string response = Users.collectionUsersTeamDataSerializer(ruserteam);
                await mlibrary.writeFile("CollectionUsersTeam", response);
            }
            else
            {
                string response = await mlibrary.readFile("CollectionUsersTeam");
                ruserteam = Users.collectionUsersTeamDataDeserializer(response);
            }
            //updateAvailability();
            teamid = ruserteam.id;
            ruserteam.calendar = new List<Calendar>();

            string eventsLink = (string)ruserteam.eventsLink;
            myProgressRing.IsActive = true;
            Library_APICall apic = new Library_APICall();
            Debug.WriteLine(eventsLink);
            
            string flname = "events_" + ruserteam.id;
            //string flname = "events_1870124";
            Debug.WriteLine(flname);
            string res = await mlibrary.readFile(flname);
            try
            {
                if (res == "fail")
                {
                    Debug.WriteLine("Network Problems");
                    networkproblems = true;
                }
                else
                {
                    methodLibrary ml = new methodLibrary();
                    RootObjectEvents revents = Events.eventsDataDeserializer(res);
                    // Go through and add events to ObservableCollection
                    if (revents.collection.items != null)
                    {
                        YesCalendarPage.Visibility = Visibility.Visible;
                        //AddNewEvent.Visibility = Visibility.Visible;
                        NoCalendarPage.Visibility = Visibility.Collapsed;
                        calendarfound = true;
                        Hashtable revent_ht = new Hashtable();
                        for (int i = 0; i < revents.collection.items.Count; i++)
                        {
                            Hashtable location_ht = new Hashtable();
                            for (int j = 0; j < revents.collection.items[i].data.Count; j++)
                            {
                                revent_ht.Add(revents.collection.items[i].data[j].name, j);
                            }
                            Calendar revent_item = new Calendar();
                            if (revents.collection.items[i].data[(int)revent_ht["location_id"]].value == null)
                            {

                            }
                            else
                            {
                                long locationid = (long)revents.collection.items[i].data[(int)revent_ht["location_id"]].value;
                                string locationAPI = "https://api.teamsnap.com/v3/locations/" + locationid.ToString();
                                //string locationres = await apic.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], locationAPI);
                                string locationres = await mlibrary.readFile("locations_" + ruserteam.id);
                                RootObjectLocation rlocation = locations.locationDataDeserializer(locationres);
                                int pos = 0;
                                for (int m = 0; m < rlocation.collection.items.Count; m++)
                                {
                                    if (rlocation.collection.items[m].href == locationAPI)
                                    {
                                        pos = m;
                                        break;
                                    }
                                }

                                for (int l = 0; l < rlocation.collection.items[pos].data.Count; l++)
                                {
                                    location_ht.Add(rlocation.collection.items[pos].data[l].name, l);
                                }
                                revent_item.locationAddress = (string)rlocation.collection.items[pos].data[(int)location_ht["address"]].value;
                                revent_item.locationName = (string)rlocation.collection.items[pos].data[(int)location_ht["name"]].value;
                                revent_item.locationNotes = (string)rlocation.collection.items[pos].data[(int)location_ht["notes"]].value;
                                revent_item.locationPhone = (string)rlocation.collection.items[pos].data[(int)location_ht["phone"]].value;
                                revent_item.name = (string)revents.collection.items[i].data[(int)revent_ht["name"]].value;
                            }
                            revent_item.team_id = teamid;
                            if (String.IsNullOrEmpty(revent_item.locationAddress))
                            {
                                revent_item.eventLatitude = Convert.ToDouble((string)ApplicationData.Current.LocalSettings.Values["team_latitude_" + revent_item.team_id]);
                                revent_item.eventLongitude = Convert.ToDouble((string)ApplicationData.Current.LocalSettings.Values["team_longitude_" + revent_item.team_id]);
                                //revent_item.eventLatitude = 47.23;
                                //revent_item.eventLongitude = -131.45;
                            }
                            else
                            {
                                //address.Text = cald.locationAddress;
                                // mapIconAddress = cald.locationAddress;
                                MapLocationFinderResult resLocation = await convertAddressToCoordinates(revent_item.locationAddress, double.Parse((string)ApplicationData.Current.LocalSettings.Values["team_latitude_" + revent_item.team_id], System.Globalization.CultureInfo.InvariantCulture), double.Parse((string)ApplicationData.Current.LocalSettings.Values["team_longitude_" + revent_item.team_id], System.Globalization.CultureInfo.InvariantCulture));
                                if (resLocation.Status == MapLocationFinderStatus.Success)
                                {
                                    try
                                    {
                                        double lat = Math.Round(resLocation.Locations[0].Point.Position.Latitude, 6);
                                        revent_item.eventLatitude = lat;
                                        double lon = Math.Round(resLocation.Locations[0].Point.Position.Longitude, 6);
                                        revent_item.eventLongitude = lon;
                                    }
                                    catch (Exception ex)
                                    {
                                        revent_item.eventLatitude = 40.939586;
                                        revent_item.eventLongitude = -11.938656;
                                    }
                                    //setMapControlCenter(lat, lon);
                                }
                                else
                                {
                                    //setMapControlCenter(double.Parse((string)ApplicationData.Current.LocalSettings.Values["team_latitude_" + revent_item.team_id], System.Globalization.CultureInfo.InvariantCulture), double.Parse((string)ApplicationData.Current.LocalSettings.Values["team_longitude_" + revent_item.team_id], System.Globalization.CultureInfo.InvariantCulture));
                                    revent_item.eventLatitude = Convert.ToDouble((string)ApplicationData.Current.LocalSettings.Values["team_latitude_" + revent_item.team_id]);
                                    revent_item.eventLongitude = Convert.ToDouble((string)ApplicationData.Current.LocalSettings.Values["team_longitude_" + revent_item.team_id]);
                                    //revent_item.eventLatitude = 47.23;
                                    //revent_item.eventLongitude = -131.45;

                                }
                            }
                            revent_item.game_type = revents.collection.items[i].data[(int)revent_ht["game_type"]].value == null ? null : (string)revents.collection.items[i].data[(int)revent_ht["game_type"]].value;
                            revent_item.uniform = revents.collection.items[i].data[(int)revent_ht["uniform"]].value == null ? null : (string)revents.collection.items[i].data[(int)revent_ht["uniform"]].value;
                            if (revents.collection.items[i].data[(int)revent_ht["opponent_id"]].value == null)
                            {
                                revent_item.opponent_id = null;
                            }
                            else
                            {
                                revent_item.opponent_id = (revents.collection.items[i].data[(int)revent_ht["opponent_id"]].value).ToString();
                                //string opponentres = await apic.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/opponents/" + revent_item.opponent_id);
                                string opponentres = await mlibrary.readFile("opponents_" + ruserteam.id);
                                RootObjectOpponent ropponent = Opponent.opponentDataDeserializer(opponentres);

                                // Use opponent ID to  find opponent name
                                int pos = 0;
                                for (int m = 0; m < ropponent.collection.items.Count; m++)
                                {
                                    if (ropponent.collection.items[m].href == ("https://api.teamsnap.com/v3/opponents/" + revent_item.opponent_id))
                                    {
                                        pos = m;
                                        break;
                                    }
                                }
                                Debug.WriteLine(pos);
                                for (int len = 0; len < ropponent.collection.items[pos].data.Count; len++)
                                {
                                    if (ropponent.collection.items[pos].data[len].name == "name")
                                    {
                                        revent_item.game_title = "vs " + (string)ropponent.collection.items[pos].data[len].value;
                                        break;
                                    }

                                }
                            }
                            // done
                            //revent_item.opponent_id = (string)(revents.collection.items[i].data[(int)revent_ht["opponent_id"]].value).ToString();
                            revent_item.id = (long)revents.collection.items[i].data[(int)revent_ht["id"]].value;
                            if (revent_item.id == 58213232)
                            {
                                Debug.WriteLine("here");
                            }
                            revent_item.additional_location_details = (string)revents.collection.items[i].data[(int)revent_ht["additional_location_details"]].value;
                            revent_item.arrival_date = revents.collection.items[i].data[(int)revent_ht["arrival_date"]].value == null ? DateTime.MinValue : ((DateTime)revents.collection.items[i].data[(int)revent_ht["arrival_date"]].value).ToLocalTime();
                            revent_item.arrival_time = revent_item.arrival_date.ToString("hh:mm tt");
                            revent_item.division_location_id = revents.collection.items[i].data[(int)revent_ht["division_location_id"]].value == null ? 0 : (long)revents.collection.items[i].data[(int)revent_ht["division_location_id"]].value;
                            revent_item.duration_in_minutes = revents.collection.items[i].data[(int)revent_ht["duration_in_minutes"]].value == null ? 0 : (long)revents.collection.items[i].data[(int)revent_ht["duration_in_minutes"]].value;
                            //revent_item.end_Date = (DateTime)revents.collection.items[i].data[(int)revent_ht["end_date"]].value;
                            if (revents.collection.items[i].data[(int)revent_ht["end_date"]].value != null)
                            {
                                revent_item.end_Date = ((DateTime)revents.collection.items[i].data[(int)revent_ht["end_date"]].value).ToLocalTime();
                            }
                            else
                            {
                                revent_item.end_Date = DateTime.MinValue;
                            }
                            
                            revent_item.formatted_results = (string)revents.collection.items[i].data[(int)revent_ht["formatted_results"]].value;
                            revent_item.game_type = (string)revents.collection.items[i].data[(int)revent_ht["game_type"]].value;
                            revent_item.is_game = revents.collection.items[i].data[(int)revent_ht["is_game"]].value == null ? false : (bool)revents.collection.items[i].data[(int)revent_ht["is_game"]].value;
                            revent_item.is_tbd = revents.collection.items[i].data[(int)revent_ht["is_tbd"]].value == null ? false : (bool)revents.collection.items[i].data[(int)revent_ht["is_tbd"]].value;
                            revent_item.label = (string)revents.collection.items[i].data[(int)revent_ht["label"]].value;
                            revent_item.location_id = revents.collection.items[i].data[(int)revent_ht["location_id"]].value == null ? 0 : (long)revents.collection.items[i].data[(int)revent_ht["location_id"]].value;
                            revent_item.minutes_to_arrive_early = revents.collection.items[i].data[(int)revent_ht["minutes_to_arrive_early"]].value == null ? 0 : (long)revents.collection.items[i].data[(int)revent_ht["minutes_to_arrive_early"]].value;
                            revent_item.name = (string)revents.collection.items[i].data[(int)revent_ht["name"]].value;
                            revent_item.notes = (string)revents.collection.items[i].data[(int)revent_ht["notes"]].value;
                            revent_item.start_date = revents.collection.items[i].data[(int)revent_ht["start_date"]].value == null ? DateTime.MinValue : ((DateTime)revents.collection.items[i].data[(int)revent_ht["start_date"]].value).ToLocalTime();
                            revent_item.time_zone = (string)revents.collection.items[i].data[(int)revent_ht["time_zone"]].value;
                            revent_item.updated_at = revents.collection.items[i].data[(int)revent_ht["updated_at"]].value == null ? DateTime.MinValue : (DateTime)revents.collection.items[i].data[(int)revent_ht["updated_at"]].value;
                            revent_item.eventDay = revent_item.start_date.ToString("dd");
                            revent_item.eventMonth = revent_item.start_date.ToString("MMMM");
                            revent_item.dddFormat = (revent_item.start_date.ToString("ddd")).ToUpper();
                            revent_item.eventTime = revent_item.start_date.ToString("hh:mm tt");//revent_item.start_date.Hour.ToString() + ":" + revent_item.start_date.Minute.ToString() + " " + revent_item.start_date.ToString("tt");
                            revent_ht.Clear();
                            location_ht.Clear();
                            if (DateTime.Compare(revent_item.start_date, (DateTime.Now).AddDays(-1)) > 0)  // if there is a start date and no end date
                            {
                                cal.Add(revent_item);
                            }
                            calAllEvents.Add(revent_item);
                        }
                        if (cal.Count < 1)
                        {
                            YesCalendarPage.Visibility = Visibility.Collapsed;
                            NoCalendarPage.Visibility = Visibility.Visible;
                            noCalendarFlipViewButtons.Visibility = Visibility.Visible;
                            MyCalendarListViewAllEventsNoCalendar.Visibility = Visibility.Visible;
                        }
                    }
                    else
                    {
                        YesCalendarPage.Visibility = Visibility.Collapsed;
                        //AddNewEvent.Visibility = Visibility.Collapsed;
                        NoCalendarPage.Visibility = Visibility.Visible;
                        noCalendarFlipViewButtons.Visibility = Visibility.Collapsed;
                        MyCalendarListViewAllEventsNoCalendar.Visibility = Visibility.Collapsed;
                        calendarfound = false;
                    }
                    ApplicationData.Current.LocalSettings.Values["eventTemplateFile"] = "eventTemplate.txt";
                    await mlibrary.writeFile((string)ApplicationData.Current.LocalSettings.Values["eventTemplateFile"], res);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            myProgressRing.IsActive = false;

            if (calendarfound == false)
            {
                YesCalendarPage.Visibility = Visibility.Collapsed;
                NoCalendarPage.Visibility = Visibility.Visible;
                noCalendarFlipViewButtons.Visibility = Visibility.Collapsed;
                MyCalendarListViewAllEventsNoCalendar.Visibility = Visibility.Collapsed;
            }
        }