Beispiel #1
0
 public async Task <IHttpActionResult> PostCartAsync(Cart cart)
 {
     DataResource.Entry(cart.Customer).State = EntityState.Modified;
     foreach (var item in cart.Items)
     {
         DataResource.Entry(item.Product).State = EntityState.Modified;
     }
     DataResource.DbSetCarts.Add(cart);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
        public WhenGettingUserInfo()
        {
            this.userInfoResource = new UserInfoResource("A.N. Other", "/sub/myid");

            this.UserInfoResourceFactory.Create(this.AccessToken, Arg.Any <CancellationToken>()).Returns(this.userInfoResource);

            this.Client.SetAccessToken(this.AccessToken);

            this.response = this.Client.GetAsync("/ifttt/v1/user/info").Result;

            this.result = this.response.JsonBody <DataResource <UserInfoResource> >();
        }
Beispiel #3
0
        private async Task <DataResource> GetDataResourceAsync(DataQueryResource filterResource,
                                                               KeyParameterResource keyParameterResource)
        {
            var filter = mapper.Map <DataQueryResource, SubVariableDataQuery>(filterResource);

            filter.IsPaging            = false;
            filter.KeyParameterId      = keyParameterResource.Id;
            filter.KeyParameterLevelId = keyParameterResource.KeyParameterLevelId;
            filter.ParentRegionId      = CurrentUser.ParentRegionId;

            var queryResult = await _subVariablesData.GetSubVariableData(filter, true);

            var newDataResource = new DataResource
            {
                KeyParameterId      = keyParameterResource.Id,
                KeyParameterLevelId = keyParameterResource.KeyParameterLevelId
            };

            if (queryResult == null ||
                !queryResult.Items.Any())
            {
                return(newDataResource);
            }

            var years        = queryResult.Items.Select(i => i.Year).OrderBy(y => y).Distinct();
            var subVariables = queryResult.Items.Select(i => i.SubVariable.Name).Distinct().ToList();

            newDataResource.Years        = years;
            newDataResource.SubVariables = subVariables;
            newDataResource.Values       = new List <decimal[]>();

            for (var i = 0; i < subVariables.Count(); i++)
            {
                var items = queryResult.Items.Where(d => d.SubVariable.Name == subVariables[i])
                            .OrderBy(y => y.Year)
                            .Select(d => d.Value).ToArray();
                var itemsToAdd = new decimal[years.Count()];
                for (var j = 0; j < items.Length; j++)
                {
                    itemsToAdd[j] = items[j];
                }
                newDataResource.Values.Add(itemsToAdd);
            }

            return(newDataResource);
        }
Beispiel #4
0
        public WhenTurningOffAllDevices()
        {
            var request = new
            {
                actionFields = new { },
                ifttt_source = new { id = "2", url = "https://ifttt.com/myrecipes/personal/2" },
                user         = new { timezone = "Pacific Time (US & Canada)" }
            };

            var content = new StringContent(JsonConvert.SerializeObject(request));

            this.LinnApiActions.TurnOffAllDevices(this.AccessToken, Arg.Any <CancellationToken>()).Returns("id");

            this.Client.SetAccessToken(this.AccessToken);

            this.response = this.Client.PostAsync("/ifttt/v1/actions/turn_off_all_devices", content).Result;

            this.result = this.response.JsonBody <DataResource <ActionResponse[]> >();
        }
Beispiel #5
0
        public WhenConfiguringDeviceIdForTurningOffASpecificDevice()
        {
            var request = new { };

            var content = new StringContent(JsonConvert.SerializeObject(request));

            this.devices = new Dictionary <string, string>
            {
                [Guid.NewGuid().ToString()] = "Kitchen",
                [Guid.NewGuid().ToString()] = "Summer Room",
                [Guid.NewGuid().ToString()] = "Winter Room"
            };

            this.LinnApiActions.GetDeviceNames(this.AccessToken, Arg.Any <CancellationToken>()).Returns(this.devices);

            this.Client.SetAccessToken(this.AccessToken);

            this.response = this.Client.PostAsync("/ifttt/v1/actions/turn_off_device/fields/device_id/options", content).Result;

            this.result = this.response.JsonBody <DataResource <ActionFieldOption[]> >();
        }
Beispiel #6
0
        public WhenUnmutingASpecificDevice()
        {
            var deviceId = Guid.NewGuid().ToString();

            var request = new
            {
                actionFields = new { device_id = deviceId },
                ifttt_source = new { id = "2", url = "https://ifttt.com/myrecipes/personal/2" },
                user         = new { timezone = "Pacific Time (US & Canada)" }
            };

            var content = new StringContent(JsonConvert.SerializeObject(request));

            this.LinnApiActions.UnmuteDevice(this.AccessToken, deviceId, Arg.Any <CancellationToken>()).Returns("id");

            this.Client.SetAccessToken(this.AccessToken);

            this.response = this.Client.PostAsync("/ifttt/v1/actions/unmute_device", content).Result;

            this.result = this.response.JsonBody <DataResource <ActionResponse[]> >();
        }
Beispiel #7
0
        public static IFundCrawler CreateFundCrawler(DataResource resource)
        {
            IFundCrawler crawler = null;

            switch (resource)
            {
            case DataResource.BankOfTaiwan:
                crawler = new BankOfTaiwan();
                break;

            case DataResource.FundRich:
                crawler = new FundRich();
                break;

            case DataResource.FundYes:
                break;

            default:
                break;
            }
            return(crawler);
        }
        public WhenConfiguringPlaylistIdForPlayPlaylistOnASpecificDevice()
        {
            var request = new { };

            var content = new StringContent(JsonConvert.SerializeObject(request));

            this.playlists = new Dictionary <string, string>
            {
                [Guid.NewGuid().ToString()] = "Kids Bathtime",
                [Guid.NewGuid().ToString()] = "Holiday Drive",
                [Guid.NewGuid().ToString()] = "Poker Night",
                [Guid.NewGuid().ToString()] = "Morning After Blues"
            };

            this.LinnApiActions.GetPlaylistNames(this.AccessToken, Arg.Any <CancellationToken>()).Returns(this.playlists);

            this.Client.SetAccessToken(this.AccessToken);

            this.response = this.Client.PostAsync("/ifttt/v1/actions/play_playlist/fields/playlist_id/options", content).Result;

            this.result = this.response.JsonBody <DataResource <ActionFieldOption[]> >();
        }
Beispiel #9
0
        public WhenPlayMediaOnASpecificDeviceWithoutOptionalFields()
        {
            var deviceId = Guid.NewGuid().ToString();

            var mediaUrl = "https://localhost/" + Guid.NewGuid();

            var request = new
            {
                actionFields = new { device_id = deviceId, media_url = mediaUrl },
                ifttt_source = new { id = "2", url = "https://ifttt.com/myrecipes/personal/2" },
                user         = new { timezone = "Pacific Time (US & Canada)" }
            };

            var content = new StringContent(JsonConvert.SerializeObject(request));

            this.LinnApiActions.PlaySingleMedia(this.AccessToken, deviceId, mediaUrl, null, null, Arg.Any <CancellationToken>()).Returns("id");

            this.Client.SetAccessToken(this.AccessToken);

            this.response = this.Client.PostAsync("/ifttt/v1/actions/play_single_media", content).Result;

            this.result = this.response.JsonBody <DataResource <ActionResponse[]> >();
        }
Beispiel #10
0
 public ActionResult Post([FromBody] DataResource dataResource)
 {
     return(Ok(dataResource));
 }
Beispiel #11
0
 public async Task <IHttpActionResult> DeleteMemoryAsync(Memory memory)
 {
     DataResource.DbSetMemories.Attach(memory);
     DataResource.DbSetMemories.Remove(memory);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #12
0
 public async Task <IHttpActionResult> PutMemoryAsync(Memory memory)
 {
     DataResource.Entry(memory).State = EntityState.Modified;
     return(Ok(await DataResource.SaveChangesAsync()));
 }
 private void SetSort(DataResource.GaResource.GetRequest request)
 {
     String sort = "";
     // Enable sort according to time
     switch (Unit)
     {
         case TimeUnit.Day:
             sort += "ga:day,ga:month";
             break;
         case TimeUnit.Month:
             sort += "ga:month,ga:year";
             break;
         case TimeUnit.Week:
             sort += "ga:week,ga:year";
             break;
         case TimeUnit.Year:
             sort += "ga:year";
             break;
         case TimeUnit.None:
             if (sort != "")
                 sort = sort.Remove(sort.Length - 1);
             break;
     }
     request.Sort = sort;
 }
Beispiel #14
0
 public async Task <IHttpActionResult> DeletePSUAsync(PSU psu)
 {
     DataResource.DbSetPSUs.Attach(psu);
     DataResource.DbSetPSUs.Remove(psu);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #15
0
 public async Task <IHttpActionResult> DeleteMotherboardAsync(Motherboard motherboard)
 {
     DataResource.DbSetMotherboards.Attach(motherboard);
     DataResource.DbSetMotherboards.Remove(motherboard);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
 private void SetFilters(DataResource.GaResource.GetRequest request)
 {
     String filters = FiltersToString();
     if (filters != "")
         request.Filters = filters;
 }
 public async Task <IHttpActionResult> PostAsync(Customer customer)
 {
     DataResource.DbSetCustomers.Add(customer);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #18
0
 public async Task <IHttpActionResult> PutMotherboardAsync(Motherboard motherboard)
 {
     DataResource.Entry(motherboard).State = EntityState.Modified;
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #19
0
 public async Task <IHttpActionResult> PutCPUAsync(CPU cpu)
 {
     DataResource.Entry(cpu).State = EntityState.Modified;
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #20
0
 public async Task <IHttpActionResult> DeleteCPUAsync(CPU cpu)
 {
     DataResource.DbSetCPUs.Attach(cpu);
     DataResource.DbSetCPUs.Remove(cpu);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #21
0
 public async Task <IHttpActionResult> PostCPUAsync(CPU cpu)
 {
     DataResource.DbSetCPUs.Add(cpu);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #22
0
 public async Task <IHttpActionResult> DeleteCaseAsync(Case pcCase)
 {
     DataResource.DbSetCases.Attach(pcCase);
     DataResource.DbSetCases.Remove(pcCase);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #23
0
 public async Task <IHttpActionResult> PostCaseAsync(Case pcCase)
 {
     DataResource.DbSetCases.Add(pcCase);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #24
0
 public async Task <IHttpActionResult> PostMemoryAsync(Memory memory)
 {
     DataResource.DbSetMemories.Add(memory);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
 public async Task <IHttpActionResult> DeleteAsync(Customer customer)
 {
     DataResource.DbSetCustomers.Attach(customer);
     DataResource.DbSetCustomers.Remove(customer);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
        // Just loops though getting all the rows.  
        private static GaData ProcessResults(DataResource.GaResource.GetRequest request)
        {
            try
            {
                GaData result = request.Execute();
                List<IList<string>> allRows = new List<IList<string>>();

                //// Loop through until we arrive at an empty page
                while (result.Rows != null)
                {
                    //Add the rows to the final list
                    allRows.AddRange(result.Rows);

                    // We will know we are on the last page when the next page token is
                    // null.
                    // If this is the case, break.
                    if (result.NextLink == null)
                    {
                        break;
                    }

                    // Prepare the next page of results             
                    request.StartIndex = request.StartIndex + request.MaxResults;
                    // Execute and process the next page request
                    result = request.Execute();

                }
                GaData allData = result;
                allData.Rows = (List<IList<string>>)allRows;
                return allData;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }




        }
Beispiel #27
0
 public async Task <IHttpActionResult> PostStorageAsync(Storage storage)
 {
     DataResource.DbSetStorages.Add(storage);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
 private void SetDimensions(DataResource.GaResource.GetRequest request)
 {
     // Set the query dimensions
     // Considering the timeUnit choice
     String dimensions = DimensionsToString();
     String comma;
     if (dimensions == "")
         comma = "";
     else
         comma = ",";
     switch (Unit)
     {
         case TimeUnit.Day:
             dimensions = "ga:month,ga:day" + comma + dimensions;
             break;
         case TimeUnit.Month:
             dimensions = "ga:year,ga:month" + comma + dimensions;
             break;
         case TimeUnit.Week:
             dimensions = "ga:year,ga:week" + comma + dimensions;
             break;
         case TimeUnit.Year:
             dimensions = "ga:year" + comma + dimensions;
             break;
         case TimeUnit.None:
             break;
     }
     request.Dimensions = dimensions;
 }
Beispiel #29
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public AnalyticsService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     data       = new DataResource(this);
     management = new ManagementResource(this);
 }
 private void SetSegment(DataResource.GaResource.GetRequest request)
 {
     request.Segment = Segment.Id;
     if (request.Segment == "")
         request.Segment = null;
 }
Beispiel #31
0
 public async Task <IHttpActionResult> DeleteStorageAsync(Storage storage)
 {
     DataResource.DbSetStorages.Attach(storage);
     DataResource.DbSetStorages.Remove(storage);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #32
0
 private void loadDataResource()
 {
     this.data_resource = new DataResource();
 }
Beispiel #33
0
 public async Task <IHttpActionResult> PostPSUAsync(PSU psu)
 {
     DataResource.DbSetPSUs.Add(psu);
     return(Ok(await DataResource.SaveChangesAsync()));
 }
 public async Task <IHttpActionResult> PutAsync(Customer customer)
 {
     DataResource.Entry(customer).State         = EntityState.Modified;
     DataResource.Entry(customer.Address).State = EntityState.Modified;
     return(Ok(await DataResource.SaveChangesAsync()));
 }
Beispiel #35
0
 public async Task <IHttpActionResult> PutStorageAsync(Storage storage)
 {
     DataResource.Entry(storage).State = EntityState.Modified;
     return(Ok(await DataResource.SaveChangesAsync()));
 }