Ejemplo n.º 1
0
        private SelectResponse ProcessSimpleSelectRecursive(SelectRequest pRequest, SelectResponse pResponse)
        {
            if (pResponse.SelectResult.IsSetNextToken())
            {
                pRequest.NextToken = pResponse.SelectResult.NextToken;

                SelectResponse mNewResponse;
                try
                {
                    mNewResponse = this.aSimpleDBClient.Select(pRequest);
                }
                catch (System.OutOfMemoryException)
                {
                    this.SetSimpleDBClient();

                    mNewResponse = this.aSimpleDBClient.Select(pRequest);
                }

                mNewResponse.SelectResult.Item.AddRange(pResponse.SelectResult.Item);

                return(this.ProcessSimpleSelectRecursive(pRequest, mNewResponse));
            }
            else
            {
                return(pResponse);
            }
        }
Ejemplo n.º 2
0
        public string Request(Domain.Delete pDelete)
        {
            #region Delete conditions validation

            if (pDelete.Conditions.Count == 0)
            {
                throw new Exception("SimpleSQL: unparameterized delete is not supported.");
            }

            #endregion

            string mDomainName = this.GetDomainName(pDelete.Table);

            SelectResponse mSelectResponse = this.ProcessSimpleSelect(mDomainName, null, pDelete.Conditions, pDelete.Table);

            int mTotalDeleteItems = 0;

            if (mSelectResponse.IsSetSelectResult())
            {
                DeleteAttributesRequest mDeleteAction;

                foreach (Item mCurrentItem in mSelectResponse.SelectResult.Item)
                {
                    if (mCurrentItem.IsSetName())
                    {
                        mDeleteAction = new DeleteAttributesRequest().WithDomainName(mDomainName).WithItemName(mCurrentItem.Name);
                        this.aSimpleDBClient.DeleteAttributes(mDeleteAction);

                        mTotalDeleteItems++;
                    }
                }
            }

            return(mTotalDeleteItems.ToString());
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            SelectResponse response = new SelectResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("SelectResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, SelectResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Item", targetDepth))
                    {
                        var unmarshaller = ItemUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Items.Add(item);
                        continue;
                    }
                    if (context.TestExpression("NextToken", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.NextToken = unmarshaller.Unmarshall(context);
                        continue;
                    }
                }
            }

            return;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles when a key is being pressed while the <see cref="Control"/> has focus.
        /// This is called immediately before <see cref="Control.KeyPressed"/>.
        /// Override this method instead of using an event hook on <see cref="Control.KeyPressed"/> when possible.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnKeyPressed(KeyEventArgs e)
        {
            base.OnKeyPressed(e);

            if (e.Code == KeyCode.Escape)
            {
                if (RequestEndDialog != null)
                {
                    RequestEndDialog.Raise(this, EventArgs.Empty);
                }
            }
            else
            {
                var asNumeric = e.Code.GetNumericKeyAsValue();
                if (!asNumeric.HasValue)
                {
                    return;
                }

                var value = asNumeric.Value - 1;
                if (value < 0)
                {
                    value = 10;
                }

                if (value < _responses.Length)
                {
                    if (SelectResponse != null)
                    {
                        SelectResponse.Raise(this, EventArgsHelper.Create(_responses[value]));
                    }
                }
            }
        }
        public override string GetUserNameByEmail(string email)
        {
            this.VerifyKeys();

            if (!String.IsNullOrEmpty(email))
            {
                DomainHelper.CheckForDomain(Settings.Default.AWSMembershipDomain, _simpleDBClient);
                SelectRequest request = new SelectRequest();
                request.SelectExpression = String.Concat(
                    "Select * from `",
                    Settings.Default.AWSMembershipDomain,
                    "` where Email='",
                    email,
                    "'"
                    );
                SelectResponse response = this._simpleDBClient.Select(request);
                if (response.Items.Count == 0)
                {
                    return(String.Empty);
                }
                else
                {
                    return(response.Items[0].Name);
                }
            }

            throw new ArgumentNullException("email", "The email passed in is null");
        }
Ejemplo n.º 7
0
        public Routes GetAllRoutes()
        {
            Routes routes = new Routes();

            using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey))
            {
                SelectRequest request =
                    new SelectRequest().WithSelectExpression(
                        string.Format("SELECT * FROM Routes "));
                SelectResponse response = client.Select(request);
                foreach (Item item in response.SelectResult.Item)
                {
                    string value = item.Attribute.GetValueByName("Id");
                    Route  route = new Route
                    {
                        Id             = Guid.Parse(item.Attribute.GetValueByName("Id")),
                        Distance       = item.Attribute.GetDoubleValueByName("Distance"),
                        LastTimeRidden = item.Attribute.GetDateTimeValueByName("LastTimeRidden"),
                        Name           = item.Attribute.GetValueByName("Name"),
                        Location       = item.Attribute.GetValueByName("Location"),
                    };
                    routes.Add(route);
                }
            }
            return(routes);
        }
Ejemplo n.º 8
0
 public override T Get(Guid id)
 {
     try
     {
         SelectRequest request = new SelectRequest();
         request.SelectExpression = "select * from " + m_objectMapper.TableName + " where itemName() = '" + id + "'";
         SelectResponse response = m_simpleDBClient.Select(request);
         if (response.IsSetSelectResult() && response.SelectResult.Item.Count == 1)
         {
             SimpleDBObjectReader <T> objectReader = new SimpleDBObjectReader <T>(response.SelectResult, m_objectMapper.SetValue);
             return(objectReader.First());
         }
         else if (response.IsSetSelectResult() && response.SelectResult.Item.Count == 1)
         {
             throw new ApplicationException("Multiple rows were returned for Get with id=" + id + ".");
         }
         else
         {
             return(default(T));
         }
     }
     catch (Exception excp)
     {
         logger.Error("Exception SimpleDBAssetPersistor Get(for " + typeof(T).Name + "). " + excp.Message);
         throw;
     }
 }
Ejemplo n.º 9
0
        public Profiles GetProfileList()
        {
            Profiles profiles = new Profiles();

            using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey))
            {
                SelectRequest request = new SelectRequest {
                    SelectExpression = "SELECT * FROM Profiles"
                };

                SelectResponse response = client.Select(request);

                var list = from item in response.SelectResult.Item
                           select new Profile()
                {
                    Id          = Guid.Parse(item.Attribute.GetValueByName("Id")),
                    Description = item.Attribute.GetValueByName("Description"),
                    Location    = item.Attribute.GetValueByName("Location"),
                    Name        = item.Attribute.GetValueByName("Name")
                };
                foreach (Profile profile in list)
                {
                    profiles.Add(profile);
                }
            }

            return(profiles);
        }
Ejemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this._domainName = String.Format(Settings.Default.SimpleDbDomainNameFormat, this.Context.User.Identity.Name);

            if (!this.Page.IsPostBack)
            {
                using (AmazonSimpleDBClient sdbClient = new AmazonSimpleDBClient(Amazon.RegionEndpoint.USWest2))
                {
                    DomainHelper.CheckForDomain(this._domainName, sdbClient);
                    SelectRequest selectRequest = new SelectRequest()
                    {
                        SelectExpression = String.Format("select * from `{0}`", this._domainName)
                    };
                    SelectResponse selectResponse = sdbClient.Select(selectRequest);
                    List <Item>    items          = selectResponse.Items;
                    List <Pet>     pets           = items.Select(l => new Pet
                    {
                        Id            = l.Name,
                        PhotoThumbUrl = l.Attributes.First(a => a.Name == "PhotoThumbUrl").Value,
                        Name          = l.Attributes.First(a => a.Name == "Name").Value,
                        Birthdate     = l.Attributes.First(a => a.Name == "Birthdate").Value,
                        Sex           = l.Attributes.First(a => a.Name == "Sex").Value,
                        Type          = l.Attributes.First(a => a.Name == "Type").Value,
                        Breed         = l.Attributes.First(a => a.Name == "Breed").Value
                    }).ToList();
                    this.PetRepeater.DataSource = pets;
                    this.PetRepeater.DataBind();
                }
            }
        }
Ejemplo n.º 11
0
        public async Task <List <Member> > GetMembers()
        {
            _logger.LogWarning($"Getting members at : {DateTime.Now.ToString("HH:mm:ss.000")}");

            var members = new List <Member>();

            var client = GetClient();

            SelectRequest request = new SelectRequest();

            request.SelectExpression = $"SELECT * FROM {Domain} WHERE ItemName() LIKE '{IdPrefix}:%' AND Name > '' ORDER BY Name";

            SelectResponse response = await client.SelectAsync(request);

            foreach (var item in response.Items)
            {
                var member = new Member();

                member.DbKey = item.Name;

                foreach (var attribute in item.Attributes)
                {
                    switch (attribute.Name)
                    {
                    case "Name":
                        member.Name = attribute.Value;
                        break;

                    case "MembershipNumber":
                        member.MembershipNumber = Convert.ToInt32(attribute.Value);
                        break;

                    case "Admin":
                        member.Admin = attribute.Value == "0" ? false : true;
                        break;

                    case "LastPaid":
                        member.LastPaid = DateTime.Parse(attribute.Value);
                        break;

                    case "Enabled":
                        member.Enabled = attribute.Value == "0" ? false : true;
                        break;

                    case "Pin":
                        member.Pin = Convert.ToInt32(attribute.Value);
                        break;

                    default:
                        break;
                    }
                }

                members.Add(member);
            }

            return(members);
        }
Ejemplo n.º 12
0
        public async Task <List <MatchResult> > GetAllMatchResults()
        {
            _logger.LogWarning($"Getting all match results");

            var results = new List <MatchResult>();

            var client = GetClient();

            SelectRequest request = new SelectRequest();

            request.SelectExpression = $"SELECT * FROM {Domain} WHERE ItemName() LIKE '{IdPrefix}:%' AND WeightDecimal > '' ORDER BY WeightDecimal DESC";

            SelectResponse response = await client.SelectAsync(request);

            foreach (var item in response.Items)
            {
                var result = new MatchResult();

                result.DbKey = item.Name;

                foreach (var attribute in item.Attributes)
                {
                    switch (attribute.Name)
                    {
                    case "MatchId":
                        result.MatchId = attribute.Value;
                        break;

                    case "MembershipNumber":
                        result.MembershipNumber = Convert.ToInt32(attribute.Value);
                        break;

                    case "Peg":
                        result.Peg = attribute.Value;
                        break;

                    case "WeightDecimal":
                        result.WeightDecimal = float.Parse(attribute.Value);
                        break;

                    case "Points":
                        result.Points = float.Parse(attribute.Value);
                        break;

                    default:
                        break;
                    }
                }

                results.Add(result);
            }

            return(results);
        }
Ejemplo n.º 13
0
        //
        // MembershipProvider.GetAllUsers
        //

        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            MembershipUserCollection users = new MembershipUserCollection();

            try
            {
                SelectRequest  request  = new SelectRequest().WithSelectExpression("Select * from " + domain);
                SelectResponse response = client.Select(request);
                totalRecords = response.SelectResult.Item.Count;
                string username         = "";
                string email            = "";
                string passwordQuestion = "";
                bool   isApproved       = false;
                foreach (Item item in response.SelectResult.Item)
                {
                    List <Attribute> attributes = item.Attribute;
                    foreach (Attribute att in attributes)
                    {
                        switch (att.Name)
                        {
                        case "Email": email = att.Value; break;

                        case "PasswordQuestion": passwordQuestion = att.Value; break;

                        case "IsApproved": isApproved = bool.Parse(att.Value); break;

                        default: break;
                        }
                    }
                    username = item.Name;

                    MembershipUser user = new MembershipUser(this.Name, username,
                                                             "", email, passwordQuestion, "", isApproved, false,
                                                             DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today);
                    users.Add(user);
                }
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "GetAllUsers ");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }

            return(users);
        }
Ejemplo n.º 14
0
        //
        // RoleProvider.GetRolesForUser
        //

        public override string[] GetRolesForUser(string username)
        {
            SelectRequest request = new SelectRequest().WithSelectExpression("Select * from " + domain + " where Username='******'");
            //QueryRequest request = new QueryRequest().WithDomainName(domain).WithQueryExpression("['Username' = '" + username + "']");
            SelectResponse response = client.Select(request);
            List <string>  roles    = new List <string> ();

            foreach (Item key in response.SelectResult.Item)
            {
                roles.Add(key.Name.Replace(username + "-", ""));
            }
            return(roles.ToArray());
        }
Ejemplo n.º 15
0
        void ResponseText_Clicked(object sender, MouseButtonEventArgs e)
        {
            var src      = (ResponseText)sender;
            var response = src.Response;

            if (response != null)
            {
                if (SelectResponse != null)
                {
                    SelectResponse.Raise(this, EventArgsHelper.Create(response));
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Get the query result data for the current expression.
        /// </summary>
        /// <param name="model">Expression tree model containing the expression inspector data.</param>
        /// <returns>The collection of message data.</returns>
        private T[] GetQueryData(Nequeo.Model.ExpressionTreeModel model)
        {
            List <T> items        = new List <T>();
            bool     foundEnought = false;
            string   token        = null;
            int      take         = Int32.MaxValue;

            // Create the query string.
            string query = GetQuery(model, out take);

            // If a query has been created.
            if (!String.IsNullOrEmpty(query))
            {
                do
                {
                    // Get the set of data.
                    SelectRequest request = new SelectRequest(query);
                    if (token != null)
                    {
                        request.NextToken = token;
                    }

                    // Get the response.
                    SelectResponse response = _client.Select(request);

                    // Get the items.
                    List <Item> segment = response.Items;
                    token = response.NextToken;
                    foreach (Item entity in segment)
                    {
                        // Add the item found.
                        items.Add(GetType(entity));

                        // If we have enought.
                        if (items.Count >= take)
                        {
                            break;
                        }
                    }

                    // If we have enought.
                    if (items.Count >= take)
                    {
                        foundEnought = true;
                    }
                }while (token != null && !foundEnought);
            }

            // Return the collection of data.
            return(items.ToArray());
        }
Ejemplo n.º 17
0
        static void ReadFromSimpleDb(AWSCredentials credentials)
        {
            AmazonSimpleDBClient client = new AmazonSimpleDBClient(credentials, RegionEndpoint.USEast1);

            // attribute names are case sensitive
            // comparisons are lexicographical. no numeric comparisons exist
            SelectRequest  request  = new SelectRequest("select * from `aws-talk` WHERE `Price` > '01'");
            SelectResponse response = client.Select(request);

            foreach (Item item in response.Items)
            {
                Console.WriteLine("Item {0} has attributes: {1}",
                                  item.Name, String.Join(" ; ", item.Attributes.Select(a => string.Format("{0}={1}", a.Name, a.Value))));
            }
        }
        public async Task <List <NewsItem> > GetNewsItems()
        {
            _logger.LogWarning($"Getting news items at : {DateTime.Now.ToString("HH:mm:ss.000")}");

            var newsItems = new List <NewsItem>();

            var client = GetClient();

            SelectRequest request = new SelectRequest();

            request.SelectExpression = $"SELECT * FROM {Domain} WHERE ItemName() LIKE '{IdPrefix}:%' AND Date > '' ORDER BY Date DESC";

            SelectResponse response = await client.SelectAsync(request);

            foreach (var item in response.Items)
            {
                var newsItem = new NewsItem();

                newsItem.DbKey = item.Name;

                foreach (var attribute in item.Attributes)
                {
                    switch (attribute.Name)
                    {
                    case "Date":
                        newsItem.Date = DateTime.Parse(attribute.Value);
                        break;


                    case "Title":
                        newsItem.Title = attribute.Value;
                        break;

                    case "Body":
                        newsItem.Body = attribute.Value;
                        break;


                    default:
                        break;
                    }
                }

                newsItems.Add(newsItem);
            }

            return(newsItems);
        }
Ejemplo n.º 19
0
        public string Request(Domain.Update pUpdate)
        {
            #region Update conditions validation

            if (pUpdate.Conditions.Count == 0)
            {
                throw new Exception("SimpleSQL: unparameterized update is not supported.");
            }

            #endregion

            string mDomainName = this.GetDomainName(pUpdate.Table);

            SelectResponse mSelectResponse = this.ProcessSimpleSelect(mDomainName, null, pUpdate.Conditions, pUpdate.Table);

            int mTotalUpdatedItems = 0;

            if (mSelectResponse.IsSetSelectResult())
            {
                foreach (Item mCurrentItem in mSelectResponse.SelectResult.Item)
                {
                    if (mCurrentItem.IsSetName())
                    {
                        List <ReplaceableAttribute> mUpdateTargets = new List <ReplaceableAttribute>();

                        foreach (Condition mTarget in pUpdate.Targets)
                        {
                            mUpdateTargets.Add(new ReplaceableAttribute()
                            {
                                Name    = mTarget.Attribute,
                                Value   = mTarget.Values[0].ToString(),
                                Replace = true
                            }
                                               );
                        }

                        PutAttributesRequest mReplaceAction = new PutAttributesRequest().WithDomainName(mDomainName).WithItemName(mCurrentItem.Name).WithAttribute(mUpdateTargets.ToArray());

                        this.aSimpleDBClient.PutAttributes(mReplaceAction);

                        mTotalUpdatedItems++;
                    }
                }
            }

            return(mTotalUpdatedItems.ToString());
        }
Ejemplo n.º 20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                List <Item> items = null;
                DomainHelper.CheckForDomain(Settings.Default.PetBoardPublicDomainName, _simpleDBClient);
                SelectRequest selectRequest = new SelectRequest()
                {
                    SelectExpression = String.Format("select * from `{0}`", Settings.Default.PetBoardPublicDomainName)
                };

                SelectResponse selectResponse = _simpleDBClient.Select(selectRequest);
                items = selectResponse.Items;

                bool noSampledData = (this.Request.Cookies["UseSampleData"] != null &&
                                      "false".Equals(this.Request.Cookies["UseSampleData"].Value));
                if (items.Count == 0 &&
                    noSampledData == false)
                {
                    this.SampleDataPromptPanel.Visible = true;

                    if (User.Identity.IsAuthenticated)
                    {
                        PostSignInMessage.Visible = true;
                    }
                    else
                    {
                        PreSignInMessage.Visible = true;
                    }
                }
                else
                {
                    List <Pet> pets = items.Select(l => new Pet
                    {
                        Id            = l.Name,
                        PhotoThumbUrl = l.Attributes.First(a => a.Name == "PhotoThumbUrl").Value,
                        Name          = l.Attributes.First(a => a.Name == "Name").Value,
                        Birthdate     = l.Attributes.First(a => a.Name == "Birthdate").Value,
                        Sex           = l.Attributes.First(a => a.Name == "Sex").Value,
                        Type          = l.Attributes.First(a => a.Name == "Type").Value,
                        Breed         = l.Attributes.First(a => a.Name == "Breed").Value
                    }).ToList();
                    this.PetRepeater.DataSource = pets;
                    this.PetRepeater.DataBind();
                }
            }
        }
Ejemplo n.º 21
0
        public override List <MCItem> Select(string Query, string Domain)
        {
            string         sdbDomain = SetDomain(Domain);
            SelectRequest  request   = new SelectRequest().WithSelectExpression(Query);
            SelectResponse response  = client.Select(request);
            List <MCItem>  items     = new List <MCItem>();

            foreach (Item sdb in response.SelectResult.Item)
            {
                MCItem newItem = new MCItem(sdb.Name, Domain);
                foreach (Attribute attribute in sdb.Attribute)
                {
                    newItem.Attributes.Add(attribute.Name, attribute.Value);
                }
                items.Add(newItem);
            }
            return(items);
        }
Ejemplo n.º 22
0
 public override object GetProperty(Guid id, string propertyName)
 {
     try
     {
         SelectRequest request = new SelectRequest();
         request.SelectExpression = "select " + propertyName.ToLower() + " from " + m_objectMapper.TableName + " where itemName() = '" + id.ToString() + "'";
         SelectResponse response = m_simpleDBClient.Select(request);
         if (response.IsSetSelectResult())
         {
             return(response.SelectResult.Item[0].Attribute[0].Value);
         }
         return(null);
     }
     catch (Exception excp)
     {
         logger.Error("Exception SimpleDBAssetPersistor GetProperty (for " + typeof(T).Name + "). " + excp.Message);
         throw;
     }
 }
Ejemplo n.º 23
0
        public bool CheckAuthentication(string userName, string password)
        {
            bool success = false;

            using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey))
            {
                SelectRequest request =
                    new SelectRequest().WithSelectExpression(string.Format("SELECT Id FROM Profiles where Username = '******' and Password='******'", userName, password));

                SelectResponse response = client.Select(request);
                if (response.SelectResult.Item.Count > 0)
                {
                    success           = true;
                    AuthenticatedUser = Guid.Parse(response.SelectResult.Item.First().Name);
                }
            }

            return(success);
        }
Ejemplo n.º 24
0
        public Route GetRouteById(Guid routeId)
        {
            Route route = new Route();

            using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey))
            {
                SelectRequest request =
                    new SelectRequest().WithSelectExpression(
                        string.Format("SELECT * FROM Routes where Id = '{0}'", routeId));
                SelectResponse response = client.Select(request);

                if (response.SelectResult.Item.Count > 0)
                {
                    route.Id             = Guid.Parse(response.SelectResult.Item[0].Attribute.GetValueByName("Id"));
                    route.Distance       = response.SelectResult.Item[0].Attribute.GetDoubleValueByName("Distance");
                    route.LastTimeRidden = response.SelectResult.Item[0].Attribute.GetDateTimeValueByName("LastTimeRidden");
                }
            }
            return(route);
        }
Ejemplo n.º 25
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this._petIdString = this.Request.QueryString["petid"];

            if (!String.IsNullOrEmpty(this._petIdString))
            {
                this._itemName   = this._petIdString ?? Guid.NewGuid().ToString();
                this._domainName = String.Format(Settings.Default.SimpleDbDomainNameFormat, this.Context.User.Identity.Name);

                UpdatePageWithPetInformation(RetrievePetFromPrivateDomain());

                DomainHelper.CheckForDomain(Properties.Settings.Default.PetBoardFriendsDomain, _simpleDBClient);
                SelectRequest selectRequest = new SelectRequest()
                {
                    SelectExpression = String.Format("select * from `{0}` where `Pet` = '{1}'", Properties.Settings.Default.PetBoardFriendsDomain, this._petIdString)
                };
                SelectResponse selectResponse = _simpleDBClient.Select(selectRequest);
                LikesCount.Text = selectResponse.Items.Count().ToString();
            }
        }
Ejemplo n.º 26
0
        public List <Route> GetUsersRoutes(Guid userId)
        {
            List <Route> list = new List <Route>();

            using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey))
            {
                SelectRequest request =
                    new SelectRequest().WithSelectExpression(
                        string.Format("SELECT RouteId FROM ProfileRoutes where ProfileId = '{0}'", userId));
                SelectResponse response = client.Select(request);
                foreach (Item routeItem in response.SelectResult.Item)
                {
                    list.Add(new Route()
                    {
                        Id = Guid.Parse(routeItem.Attribute.GetValueByName("RouteId"))
                    });
                }
            }

            return(list);
        }
Ejemplo n.º 27
0
        public Profile GetProfileById(Guid id)
        {
            Profile profile;

            using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey))
            {
                SelectRequest request =
                    new SelectRequest().WithSelectExpression(string.Format("SELECT * FROM Profiles where Id = '{0}'", id));

                SelectResponse response = client.Select(request);
                profile = (from item in response.SelectResult.Item
                           select new Profile()
                {
                    Id = Guid.Parse(item.Attribute.GetValueByName("Id")),
                    Description = item.Attribute.GetValueByName("Description"),
                    Location = item.Attribute.GetValueByName("Location"),
                    Name = item.Attribute.GetValueByName("Name")
                }).First();
            }
            return(profile);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Populates the list of items for the specified domain name.
        /// </summary>
        /// <param name="domainName">The domain name.</param>
        private void PopulateItemsNamesList(string domainName)
        {
            SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                //Unhook from event.
                SimpleDB.Client.OnSimpleDBResponse -= handler;
                SelectResponse response = args.Response as SelectResponse;

                if (null != response)
                {
                    SelectResult selectResult = response.SelectResult;
                    if (null != selectResult)
                    {
                        this.Dispatcher.BeginInvoke(() =>
                        {
                            this.ItemsNameList.Clear();
                            if (selectResult.Item.Count > 0)
                            {
                                selectResult.Item.ForEach(i => this.ItemsNameList.Add(i.Name));
                                this.ItemsNameMessage = "No of Item: " + selectResult.Item.Count;
                            }
                            else
                            {
                                this.ItemsNameMessage = "No Item";
                                this.ItemsNameList.Clear();
                            }
                        });
                    }
                }
            };
            this.ItemsNameMessage = "Updating Item names...";
            this.ItemsNameList.Clear();
            SimpleDB.Client.OnSimpleDBResponse += handler;
            SimpleDB.Client.Select(new SelectRequest {
                SelectExpression = "SELECT * FROM " + domainName, ConsistentRead = true
            });
        }
Ejemplo n.º 29
0
        public Contacts GetContactsByName(string contactName)
        {
            Contacts myContacts = new Contacts();

            SelectRequest request = new SelectRequest
            {
                SelectExpression = string.Format("SELECT * FROM {0} where Name='{1}' ", DomainName, contactName)
            };
            SelectResponse response = SimpleDBProxy.Service.Select(request);

            var contacts = from item in response.SelectResult.Item
                           select new Contact()
            {
                Email = item.Attribute.GetValueByName("Email"),
                Name  = item.Attribute.GetValueByName("Name"),
                Phone = item.Attribute.GetValueByName("Phone"),
                ID    = item.Name
            };

            myContacts.AddRange(contacts);
            return(myContacts);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Executes a simple select, that is: SELECT * FROM [domain] [conditions]
        /// </summary>
        /// <param name="pDomainName">The target domain name</param>
        /// <param name="pConditions">The conditions list, if any (null is supported)</param>
        /// <returns></returns>
        private SelectResponse ProcessSimpleSelect(string pDomainName, List <string> pAttributes, List <Condition> pConditions, string pTableName)
        {
            DateTime mStart = DateTime.Now;

            StringBuilder mSelectExpression = new StringBuilder();

            mSelectExpression.AppendFormat(
                "SELECT {0} FROM {1} ",
                ((pAttributes != null && pAttributes.Count > 0)? string.Join(",", pAttributes.ToArray()) : "*"),
                pDomainName);
            mSelectExpression.Append(this.CreateConditionsExpression(pConditions, pTableName));

            Debug.WriteLine(mSelectExpression.ToString());

            SelectRequest  mSelectRequest  = new SelectRequest().WithSelectExpression(mSelectExpression.ToString());
            SelectResponse mSelectResponse = this.aSimpleDBClient.Select(mSelectRequest);

            mSelectResponse = this.ProcessSimpleSelectRecursive(mSelectRequest, mSelectResponse);

            Debug.WriteLine(string.Format("ACCESS: {0}", DateTime.Now.Subtract(mStart).ToString()));

            return(mSelectResponse);
        }