Example #1
0
            public GDataTypes.GDataUserAliasEntry AppendUserAliasEntry(string _Xml, GDataTypes.GDataUserAliasEntry userAliasEntry)
            {
                var _paresdXml = new GDataTypes.ParseXML(_Xml);
                var _userSingelAliasEntry = new GDataTypes.GDataAliasEntry();
                foreach (var _entry in _paresdXml.ListFormat)
                {
                    var _aliasEntry = new GDataTypes.GDataAliasEntry();
                    foreach (var _attribute in _entry.at)
                    {
                        if (_attribute.Value == "aliasEmail" || _attribute.Value == "userEmail")
                        {
                            if (_attribute.Value == "aliasEmail")
                            {
                                _userSingelAliasEntry.aliasEmail = _attribute.NextAttribute.Value;
                            }
                            if (_attribute.Value == "userEmail")
                            {
                                _userSingelAliasEntry.UserName = _attribute.NextAttribute.Value;
                            }
                            if (_userSingelAliasEntry.UserName != null && _userSingelAliasEntry.aliasEmail != null)
                            {
                                userAliasEntry.Add(_userSingelAliasEntry);
                            }
                        }
                    }
                    foreach (var _subEntry in _entry.sub)
                    {
                        foreach (var _attribute in _subEntry.at)
                        {

                            if (_attribute.Value == "aliasEmail" || _attribute.Value == "userEmail")
                            {
                                if (_attribute.Value == "aliasEmail")
                                {
                                    _aliasEntry.aliasEmail = _attribute.NextAttribute.Value;
                                }
                                if (_attribute.Value == "userEmail")
                                {
                                    _aliasEntry.UserName = _attribute.NextAttribute.Value;
                                }
                                if (_aliasEntry.UserName != null && _aliasEntry.aliasEmail != null)
                                {
                                    userAliasEntry.Add(_aliasEntry);
                                }
                            }
                        }
                    }
                }
                return userAliasEntry;
            }
Example #2
0
            public GDataTypes.GDataContactEntrys AppendContactEntrys(ContactEntry contactEntry, GDataTypes.GDataContactEntrys gDataContactEntrys)
            {
                var _gDataContactEntry = new GDataTypes.GDataContactEntry();

                    _gDataContactEntry.Name = contactEntry.Title.Text;
                    foreach (var _emailEntry in contactEntry.Emails)
                    {
                        if (_emailEntry.Work == true)
                        {
                            _gDataContactEntry.Email = _emailEntry.Address;
                        }
                    }
                    foreach (var _phoneNumberEntry in contactEntry.Phonenumbers)
                    {
                        if (_phoneNumberEntry.Rel == ContactsRelationships.IsWork)
                        {
                            _gDataContactEntry.PhoneNumber = _phoneNumberEntry.Value;
                        }
                        if (_phoneNumberEntry.Rel == ContactsRelationships.IsHome)
                        {
                            _gDataContactEntry.HomePhoneNumber = _phoneNumberEntry.Value;
                        }
                        if (_phoneNumberEntry.Rel == ContactsRelationships.IsMobile)
                        {
                            _gDataContactEntry.MobilePhoneNumber = _phoneNumberEntry.Value;
                        }
                        if (_phoneNumberEntry.Rel == ContactsRelationships.IsOther)
                        {
                            _gDataContactEntry.OtherPhoneNumber = _phoneNumberEntry.Value;
                        }
                    }
                    foreach (var _postaAddressEntry in contactEntry.PostalAddresses)
                    {
                        if (_postaAddressEntry.Rel == ContactsRelationships.IsWork)
                        {
                            _gDataContactEntry.PostalAddress = _postaAddressEntry.FormattedAddress;
                        }
                        if (_postaAddressEntry.Rel == ContactsRelationships.IsHome)
                        {
                            _gDataContactEntry.HomeAddress = _postaAddressEntry.FormattedAddress;
                        }
                    }
                    _gDataContactEntry.SelfUri = contactEntry.SelfUri.ToString();
                    gDataContactEntrys.Add(_gDataContactEntry);

                return gDataContactEntrys;
            }
Example #3
0
 public GDataTypes.GDataCalendarEntrys AppendCalendarEntrys(CalendarEntry calendarEntry, GDataTypes.GDataCalendarEntrys gDataCalendarEntrys)
 {
     var _gDataCalendarEntry = new GDataTypes.GDataCalendarEntry();
     if (calendarEntry.Title.Text != null)
     {
         _gDataCalendarEntry.Name = calendarEntry.Title.Text;
     }
     if (calendarEntry.Color != null)
     {
         _gDataCalendarEntry.Color = calendarEntry.Color;
     }
     if (calendarEntry.Summary != null)
     {
         _gDataCalendarEntry.Description = calendarEntry.Summary.Text;
     }
     if (calendarEntry.Location != null)
     {
         _gDataCalendarEntry.Location = calendarEntry.Location.ValueString;
     }
     _gDataCalendarEntry.Hidden = calendarEntry.Hidden;
     _gDataCalendarEntry.Selected = calendarEntry.Selected;
     if (calendarEntry.TimeZone != null)
     {
         _gDataCalendarEntry.TimeZone = calendarEntry.TimeZone;
     }
     if (calendarEntry.AccessLevel != null)
     {
         _gDataCalendarEntry.AccessLevel = calendarEntry.AccessLevel;
     }
     if (calendarEntry.SelfUri.ToString() != null)
     {
         _gDataCalendarEntry.SelfUri = calendarEntry.SelfUri.ToString();
     }
     gDataCalendarEntrys.Add(_gDataCalendarEntry);
     return gDataCalendarEntrys;
 }
Example #4
0
            public string SetResource(GDataTypes.GDataResourceService resourceService, string resourceID, string resourceDescription, string resourceType)
            {
                var _domain = resourceService.Domain;

                var _uri = new Uri("https://apps-apis.google.com/a/feeds/calendar/resource/2.0/" + _domain + "/" + resourceID);

                WebRequest _webRequest = WebRequest.Create(_uri);
                _webRequest.ContentType = "application/atom+xml; charset=UTF-8";
                _webRequest.Method = "PUT";
                _webRequest.Headers.Add("Authorization: GoogleLogin auth=" + resourceService.Token);
                byte[] _bytes = Encoding.UTF8.GetBytes("<atom:entry xmlns:atom='http://www.w3.org/2005/Atom'><apps:property xmlns:apps='http://schemas.google.com/apps/2006' name='resourceCommonName' value='" + resourceID + "'/><apps:property xmlns:apps='http://schemas.google.com/apps/2006' name='resourceDescription' value='" + resourceDescription + "'/><apps:property xmlns:apps='http://schemas.google.com/apps/2006' name='resourceType' value='" + resourceType + "'/></atom:entry>");
                Stream _OS = null;
                _webRequest.ContentLength = _bytes.Length;
                _OS = _webRequest.GetRequestStream();
                _OS.Write(_bytes, 0, _bytes.Length);

                _OS.Close();

                WebResponse _webResponse = _webRequest.GetResponse();

                if (_webResponse == null)
                {
                    throw new Exception("WebResponse is null");
                }
                StreamReader _SR = new StreamReader(_webResponse.GetResponseStream());

                var _result = _SR.ReadToEnd().Trim();

                return _result;
            }
Example #5
0
            public string RetriveResource(GDataTypes.GDataResourceService ResourceService, string ResourceId)
            {
                var _domain = ResourceService.Domain;
                var _uri = new Uri("https://apps-apis.google.com/a/feeds/calendar/resource/2.0/" + _domain + "/" + ResourceId);

                WebRequest _webRequest = WebRequest.Create(_uri);

                _webRequest.ContentType = "application/atom+xml; charset=UTF-8";
                _webRequest.Method = "GET";
                _webRequest.Headers.Add("Authorization: GoogleLogin auth=" + ResourceService.Token);

                WebResponse _webResponse = _webRequest.GetResponse();

                if (_webResponse == null)
                {
                    throw new Exception("WebResponse is null");
                }
                StreamReader _SR = new StreamReader(_webResponse.GetResponseStream());

                var _result = _SR.ReadToEnd().Trim();

                return _result;
            }
Example #6
0
            public GDataTypes.GDataResourceEntrys CreateResourceEntrys(string xml, GDataTypes.GDataResourceService resourceService)
            {
                var _paresdXml = new GDataTypes.ParseXML(xml);

                var _gDataResourceEntrys = new GDataTypes.GDataResourceEntrys();
                var _gdataSingelResourceEntry = new GDataTypes.GDataResourceEntry();
                foreach (var _sEntry in _paresdXml.ListFormat)
                {
                    foreach (var _attribute in _sEntry.at)
                    {

                        if (_attribute.Value == "resourceId" || _attribute.Value == "resourceCommonName" || _attribute.Value == "resourceEmail" || _attribute.Value == "resourceDescription" || _attribute.Value == "resourceType")
                        {

                            if (_attribute.Value == "resourceId")
                            {
                                if (_attribute.NextAttribute.Value != null)
                                {
                                    _gdataSingelResourceEntry.ResourceId = _attribute.NextAttribute.Value;
                                }
                                else
                                {
                                    _gdataSingelResourceEntry.ResourceId = "_EMPTY_";
                                }
                            }
                            if (_attribute.Value == "resourceCommonName")
                            {
                                if (_attribute.NextAttribute.Value != null)
                                {
                                    _gdataSingelResourceEntry.CommonName = _attribute.NextAttribute.Value;
                                }
                                else
                                {
                                    _gdataSingelResourceEntry.CommonName = "_EMPTY_";
                                }
                            }
                            if (_attribute.Value == "resourceEmail")
                            {
                                if (_attribute.NextAttribute.Value != null)
                                {
                                    _gdataSingelResourceEntry.Email = _attribute.NextAttribute.Value;
                                }
                                else
                                {
                                    _gdataSingelResourceEntry.Email = "_EMPTY_";
                                }
                            }
                            if (_attribute.Value == "resourceDescription")
                            {
                                if (_attribute.NextAttribute.Value != null)
                                {
                                    _gdataSingelResourceEntry.Description = _attribute.NextAttribute.Value;
                                }
                                else
                                {
                                    _gdataSingelResourceEntry.Description = "_EMPTY_";
                                }
                            }
                            if (_attribute.Value == "resourceType")
                            {
                                if (_attribute.NextAttribute.Value != null)
                                {
                                    _gdataSingelResourceEntry.Type = _attribute.NextAttribute.Value;
                                }
                                else
                                {
                                    _gdataSingelResourceEntry.Type = "_EMPTY_";
                                }
                            }
                        }

                    }

                    var _gdataResourceEntry = new GDataTypes.GDataResourceEntry();
                    foreach (var _subEntry in _sEntry.sub)
                    {
                        foreach (var _attribute in _subEntry.at)
                        {

                            if (_attribute.Value == "resourceId" || _attribute.Value == "resourceCommonName" || _attribute.Value == "resourceEmail" || _attribute.Value == "resourceDescription" || _attribute.Value == "resourceType")
                            {

                                if (_attribute.Value == "resourceId")
                                {

                                    _gdataResourceEntry.ResourceId = _attribute.NextAttribute.Value;
                                }
                                if (_attribute.Value == "resourceCommonName")
                                {

                                    _gdataResourceEntry.CommonName = _attribute.NextAttribute.Value;
                                }
                                if (_attribute.Value == "resourceEmail")
                                {

                                    _gdataResourceEntry.Email = _attribute.NextAttribute.Value;
                                }
                                if (_attribute.Value == "resourceDescription")
                                {

                                    _gdataResourceEntry.Description = _attribute.NextAttribute.Value;
                                }
                                if (_attribute.Value == "resourceType")
                                {

                                    _gdataResourceEntry.Type = _attribute.NextAttribute.Value;
                                }

                            }

                        }
                    }
                    if (_gdataResourceEntry.ResourceId != null)
                    {
                        _gDataResourceEntrys.Add(_gdataResourceEntry);
                    }
                }
                if (_gdataSingelResourceEntry.ResourceId != null)
                {
                    _gDataResourceEntrys.Add(_gdataSingelResourceEntry);
                }
                return _gDataResourceEntrys;
            }
Example #7
0
            public string SetProfile(GDataTypes.GDataProfileService profileService, string id, string postalAddress, string phoneNumber, string mobilePhoneNumber, string otherPhoneNumber, string homePostalAddress, string homePhoneNumber)
            {
                var _domain = profileService.Domain;

                var _uri = new Uri("http://www.google.com/m8/feeds/profiles/domain/" + _domain + "/full/" + id);

                var _googleProfileService = new GoogleProfileService();
                res = _googleProfileService.GetProfile(profileService, id);

                elem = XElement.Parse(res.ToString().Trim());

                ns = "http://schemas.google.com/g/2005";

                string _formatedRes = res.Replace("\"", "'");

                if (postalAddress != null)
                {
                    if (_formatedRes.Contains("gd:structuredPostalAddress rel='http://schemas.google.com/g/2005#work'"))
                    {

                        foreach (var _element in elem.Elements(ns + "structuredPostalAddress"))
                        {
                            if (_element.FirstAttribute.Value == "http://schemas.google.com/g/2005#work")
                            {

                                _element.SetElementValue(ns + "formattedAddress", postalAddress);
                            }

                        }
                        newXml = elem.ToString();
                    }
                    else
                    {
                        newXml = elem.ToString().Replace("</entry>", "<gd:structuredPostalAddress rel='http://schemas.google.com/g/2005#work'><gd:formattedAddress>" + postalAddress + "</gd:formattedAddress></gd:structuredPostalAddress></entry>");
                        elem = XElement.Parse(newXml.ToString().Trim());
                    }
                }

                if (homePostalAddress != null)
                {
                    if (_formatedRes.Contains("gd:structuredPostalAddress rel='http://schemas.google.com/g/2005#home'"))
                    {

                        foreach (var _element in elem.Elements(ns + "structuredPostalAddress"))
                        {

                            if (_element.FirstAttribute.Value == "http://schemas.google.com/g/2005#home")
                            {
                                _element.SetElementValue(ns + "formattedAddress", homePostalAddress);
                            }

                        }
                        newXml = elem.ToString();
                    }
                    else
                    {
                        newXml = elem.ToString().Replace("</entry>", "<gd:structuredPostalAddress rel='http://schemas.google.com/g/2005#home'><gd:formattedAddress>" + homePostalAddress + "</gd:formattedAddress></gd:structuredPostalAddress></entry>");
                        elem = XElement.Parse(newXml.ToString().Trim());
                    }
                }

                if (phoneNumber != null)
                {
                    if (res.Contains("phoneNumber rel='http://schemas.google.com/g/2005#work'"))
                    {

                        foreach (var _element in elem.Elements(ns + "phoneNumber"))
                        {

                            if (_element.FirstAttribute.Value == "http://schemas.google.com/g/2005#work")
                            {
                                _element.SetValue(phoneNumber);
                            }
                            newXml = elem.ToString();
                        }
                    }
                    else
                    {
                        newXml = elem.ToString().Replace("</entry>", "<gd:phoneNumber rel='http://schemas.google.com/g/2005#work' primary='true'>" + phoneNumber + "</gd:phoneNumber></entry>");
                        elem = XElement.Parse(newXml.ToString().Trim());
                    }
                }

                if (mobilePhoneNumber != null)
                {
                    if (res.Contains("phoneNumber rel='http://schemas.google.com/g/2005#mobile'"))
                    {
                        foreach (var _element in elem.Elements(ns + "phoneNumber"))
                        {
                            if (_element.FirstAttribute.Value == "http://schemas.google.com/g/2005#mobile")
                            {
                                _element.SetValue(mobilePhoneNumber);
                            }
                        }
                        newXml = elem.ToString();
                    }
                    else
                    {
                        newXml = elem.ToString().Replace("</entry>", "<gd:phoneNumber rel='http://schemas.google.com/g/2005#mobile'>" + mobilePhoneNumber + "</gd:phoneNumber></entry>");
                        elem = XElement.Parse(newXml.ToString().Trim());
                    }
                }

                if (otherPhoneNumber != null)
                {
                    if (res.Contains("phoneNumber rel='http://schemas.google.com/g/2005#other'"))
                    {
                        foreach (var _element in elem.Elements(ns + "phoneNumber"))
                        {
                            if (_element.FirstAttribute.Value == "http://schemas.google.com/g/2005#other")
                            {
                                _element.SetValue(otherPhoneNumber);
                            }
                            newXml = elem.ToString();
                        }
                    }
                    else
                    {
                        newXml = elem.ToString().Replace("</entry>", "<gd:phoneNumber rel='http://schemas.google.com/g/2005#other'>" + mobilePhoneNumber + "</gd:phoneNumber></entry>");
                        elem = XElement.Parse(newXml.ToString().Trim());
                    }
                }

                if (homePhoneNumber != null)
                {
                    if (res.Contains("phoneNumber rel='http://schemas.google.com/g/2005#home'"))
                    {
                        foreach (var _element in elem.Elements(ns + "phoneNumber"))
                        {
                            if (_element.FirstAttribute.Value == "http://schemas.google.com/g/2005#home")
                            {
                                _element.SetValue(homePhoneNumber);
                            }
                            newXml = elem.ToString();
                        }
                    }
                    else
                    {
                        newXml = elem.ToString().Replace("</entry>", "<gd:phoneNumber rel='http://schemas.google.com/g/2005#home'>" + homePhoneNumber + "</gd:phoneNumber></entry>");
                        elem = XElement.Parse(newXml.ToString().Trim());
                    }
                }

                WebRequest _webRequest = WebRequest.Create(_uri);
                _webRequest.ContentType = "application/atom+xml; charset=UTF-8";
                _webRequest.Method = "PUT";
                _webRequest.Headers.Add("Authorization: GoogleLogin auth=" + profileService.Token);
                _webRequest.Headers.Add("GData-Version: 3.0");

                var _post = newXml;

                byte[] _bytes = Encoding.UTF8.GetBytes(_post);
                Stream _OS = null;
                _webRequest.ContentLength = _bytes.Length;
                _OS = _webRequest.GetRequestStream();
                _OS.Write(_bytes, 0, _bytes.Length);

                _OS.Close();

                WebResponse _webResponse = _webRequest.GetResponse();

                if (_webResponse == null)
                {
                    throw new Exception("WebResponse is null");
                }
                StreamReader _SR = new StreamReader(_webResponse.GetResponseStream());

                var _result = _SR.ReadToEnd().Trim();

                return _result;
            }
Example #8
0
            public string GetProfiles(GDataTypes.GDataProfileService profileService, string nextPage)
            {
                var _domain = profileService.Domain;

                if (nextPage == "")
                {
                    nextPage = "https://www.google.com/m8/feeds/profiles/domain/" + _domain + "/full";
                }

                var _uri = new Uri(nextPage);

                WebRequest _webRequest = WebRequest.Create(_uri);
                _webRequest.ContentType = "application/atom+xml; charset=UTF-8";
                _webRequest.Method = "Get";
                _webRequest.Headers.Add("Authorization: GoogleLogin auth=" + profileService.Token);
                _webRequest.Headers.Add("GData-Version: 3.0");

                WebResponse _webResponse = _webRequest.GetResponse();

                if (_webResponse == null)
                {
                    throw new Exception("WebResponse is null");
                }
                StreamReader _SR = new StreamReader(_webResponse.GetResponseStream());

                var _result = _SR.ReadToEnd().Trim();

                return _result;
            }
Example #9
0
            public GDataTypes.GDataProfileEntrys CreateProfileEntrys(string xml, GDataTypes.GDataProfileService profileService)
            {
                var _paresdXml = new GDataTypes.ParseXML(xml);

                var _profileEntrys = new GDataTypes.GDataProfileEntrys();

                string _profileLink = "http://www.google.com/m8/feeds/profiles/domain/" + profileService.Domain + "/full/";

                foreach (var _sEntry in _paresdXml.ListFormat)
                {
                    if (_sEntry.name == "{http://www.w3.org/2005/Atom}entry")
                    {
                        var _profileEntry = new GDataTypes.GDataProfileEntry();
                        _profileEntry.Domain = profileService.Domain;
                        foreach (var _entry in _sEntry.sub)
                        {
                            if (_entry.name == "{http://www.w3.org/2005/Atom}id")
                            {
                                _profileEntry.UserName = _entry.value.Replace(_profileLink,"");
                            }
                            if (_entry.name == "{http://schemas.google.com/g/2005}structuredPostalAddress")
                            {
                                foreach (var _attribute in _entry.at)
                                {
                                    if (_attribute.Value == "http://schemas.google.com/g/2005#home")
                                    {
                                        _profileEntry.HomePostalAddress = _entry.value;
                                    }
                                    if (_attribute.Value == "http://schemas.google.com/g/2005#work")
                                    {
                                        _profileEntry.PostalAddress = _entry.value;
                                    }
                                }
                            }
                            if (_entry.name == "{http://schemas.google.com/g/2005}phoneNumber")
                            {
                                foreach (var _attribute in _entry.at)
                                {
                                    if (_attribute.Value == "http://schemas.google.com/g/2005#other")
                                    {
                                        _profileEntry.OtherPhoneNumber = _entry.value;
                                    }
                                    if (_attribute.Value == "http://schemas.google.com/g/2005#work")
                                    {
                                        _profileEntry.PhoneNumber = _entry.value;
                                    }
                                    if (_attribute.Value == "http://schemas.google.com/g/2005#mobile")
                                    {
                                        _profileEntry.MobilePhoneNumber = _entry.value;
                                    }
                                    if (_attribute.Value == "http://schemas.google.com/g/2005#home")
                                    {
                                        _profileEntry.HomePhoneNumber = _entry.value;
                                    }
                                }
                            }
                        }
                        _profileEntrys.Add(_profileEntry);
                    }
                }

                return _profileEntrys;
            }