问:
ASP.NET Webforms with async/await
My Webforms application which is based on .Net 4.6 has to use the async/await-functionality quite extensively. Because I'm quite new to this async/await topic I read quite a lot of best practices like this or this. But I still have some questions for which I haven't found any clear informations.

Regarding Page-Lifecycle-Events: I know that e.g. for the Page_Load-Event it's best practice to avoid async void-methods and register such methods like this:

```<code>protected void Page_Load(object sender, EventArgs e)
{
   PageAsyncTask pageAsyncTask = new PageAsyncTask(SomeAsyncMethod);
   Page.RegisterAsyncTask(pageAsyncTask);
   //Method to invoke the registered async-methods immedietly and not after the PreRender-Event
   Page.ExecuteRegisteredAsyncTasks();
 }
</code>```

My problem is that I want to call the async-method as soon as I registered it and not after the OnPreRender-event. This should be achieved by calling the ExecuteRegisteredAsyncTasks()-method. But in my case this has no effect and the async-method is still invoked after the PreRender-event. But why?

Regarding Control-Events: Is it better to register async-methods the same way I mentioned in the code-example above or can I use the async-void signature like:

```<code>protected async void OnClick(object sender, EventArgs e)
{
await SomeAsyncMethod();
}
</code>```

I found both examples but no clear informations which is the better solution and why.

Regarding Context and ConfigureAwait, it seems to be best practice to use await SomeAsyncMethod.ConfigureAwait(false) for a better performance and where the context is not important and not to use it where the context e.g. when manipulating GUI elements. But in my case it seems to make no difference if I call  await SomeAsyncMethod.ConfigureAwait(false) in my click-event. I can still manipulate my GUI-elements wihtout any problems. The example which I uses was this:

```<code>private async void button1_Click(object sender, EventArgs e)
{
  button1.Enabled = false;
  try
  {
    await SomeAsyncMethod().ConfigureAwait(false);
  }
  finally
  {
    //Manipulating still works even it's another context
    button1.Enabled = true;
  }
}
</code>```

So I wonder why the manipulating of the GUI-elements still work and if I really should use ConfigureAwait(false) on every async-method where the context is not important, which is quite tedious. I wonder if this has something to do with the usage of the Ajax-Functionality by Telerik which I use for my Webapplication. But this is just an assumption.

答:
ASP.NET WebForms has it's own asynchronous execution engine. Please refer to the documentation.

In any case, you typically want (or need) to get back to the current synchronization context on methods such as event handlers, so you shouldn't call ConfigureAwait(false) inside button1_Click, but you should call it inside SomeAsyncMethod.

Title: ASP.NET Webforms with async/await

Body:
My Webforms application which is based on .Net 4.6 has to use the async/await-functionality quite extensively. Because I'm quite new to this async/await topic I read quite a lot of best practices like this or this. But I still have some questions for which I haven't found any clear informations.

Regarding Page-Lifecycle-Events: I know that e.g. for the Page_Load-Event it's best practice to avoid async void-methods and register such methods like this:

protected void Page_Load(object sender, EventArgs e)
{
   PageAsyncTask pageAsyncTask = new PageAsyncTask(SomeAsyncMethod);
   Page.RegisterAsyncTask(pageAsyncTask);
   //Method to invoke the registered async-methods immedietly and not after the PreRender-Event
   Page.ExecuteRegisteredAsyncTasks();
 }

My problem is that I want to call the async-method as soon as I registered it and not after the OnPreRender-event. This should be achieved by calling the ExecuteRegisteredAsyncTasks()-method. But in my case this has no effect and the async-method is still invoked after the PreRender-event. But why?

Regarding Control-Events: Is it better to register async-methods the same way I mentioned in the code-example above or can I use the async-void signature like:

protected async void OnClick(object sender, EventArgs e)
{
await SomeAsyncMethod();
}

I found both examples but no clear informations which is the better solution and why.

Regarding Context and ConfigureAwait, it seems to be best practice to use await SomeAsyncMethod.ConfigureAwait(false) for a better performance and where the context is not important and not to use it where the context e.g. when manipulating GUI elements. But in my case it seems to make no difference if I call  await SomeAsyncMethod.ConfigureAwait(false) in my click-event. I can still manipulate my GUI-elements wihtout any problems. The example which I uses was this:

private async void button1_Click(object sender, EventArgs e)
{
  button1.Enabled = false;
  try
  {
    await SomeAsyncMethod().ConfigureAwait(false);
  }
  finally
  {
    //Manipulating still works even it's another context
    button1.Enabled = true;
  }
}

So I wonder why the manipulating of the GUI-elements still work and if I really should use ConfigureAwait(false) on every async-method where the context is not important, which is quite tedious. I wonder if this has something to do with the usage of the Ajax-Functionality by Telerik which I use for my Webapplication. But this is just an assumption.


来源: stackexchange

问:
UWP - Google Analytics - Set Custom dimensions
I use UWP.SDKforGoogleAnalytics.managed and i had wrote these rows

```<code>Dim _TrakerId As String = "UA-XXXX0-0"

Dim MyTraker As GoogleAnalytics.Tracker = GoogleAnalytics.AnalyticsManager.Current.CreateTracker(_TrakerId) MyTraker.ScreenName = "Images"

Dim Hit = GoogleAnalytics.HitBuilder.CreateScreenView.Build

MyTraker.Send(Hit)
</code>```

All work good... BUT... now i'd like to use Custom dimensions.
Can anyone help me ??
Where can i set the value ?
Thanks

答:
This is how you do it in C#

```<code>var myTracker = GoogleAnalytics.AnalyticsManager.Current.CreateTracker("XXXXX");
myTracker.ScreenName = "Images";
var hit = GoogleAnalytics.HitBuilder.CreateScreenView();
hit.SetCustomDimension(1, "Test");
myTracker.Send(hit.Build());
</code>```

VB

My vb is very rusty it might be something like this

```<code>Dim _TrakerId As String = "UA-XXXX0-0"

Dim MyTraker As GoogleAnalytics.Tracker = GoogleAnalytics.AnalyticsManager.Current.CreateTracker(_TrakerId) MyTraker.ScreenName = "Images"

Dim Hit = GoogleAnalytics.HitBuilder.CreateScreenView
Hit.SetCustomDimension(1, "Test");
MyTraker.Send(Hit.Build)
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I use UWP.SDKforGoogleAnalytics.managed and i had wrote these rows

Dim _TrakerId As String = "UA-XXXX0-0"

Dim MyTraker As GoogleAnalytics.Tracker = GoogleAnalytics.AnalyticsManager.Current.CreateTracker(_TrakerId) MyTraker.ScreenName = "Images"

Dim Hit = GoogleAnalytics.HitBuilder.CreateScreenView.Build

MyTraker.Send(Hit)

All work good... BUT... now i'd like to use Custom dimensions.
Can anyone help me ??
Where can i set the value ?
Thanks

Body:
This is how you do it in C#

var myTracker = GoogleAnalytics.AnalyticsManager.Current.CreateTracker("XXXXX");
myTracker.ScreenName = "Images";
var hit = GoogleAnalytics.HitBuilder.CreateScreenView();
hit.SetCustomDimension(1, "Test");
myTracker.Send(hit.Build());

VB

My vb is very rusty it might be something like this

Dim _TrakerId As String = "UA-XXXX0-0"

Dim MyTraker As GoogleAnalytics.Tracker = GoogleAnalytics.AnalyticsManager.Current.CreateTracker(_TrakerId) MyTraker.ScreenName = "Images"

Dim Hit = GoogleAnalytics.HitBuilder.CreateScreenView
Hit.SetCustomDimension(1, "Test");
MyTraker.Send(Hit.Build)


问:
mysqlclient pip failure on Linux
I'm working on a Python3.4/Django project (on CentOS 6.8x64) and am trying to install the mysqlclient driver. Despite hours of googling I can't figure out how to sort out what looks like a compile error during install.

As far as I can tell I have all the necessary library packages installed but so far no luck. Here's the output (sorry for the verbosity):

```<code>$ sudo pip3 install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.3.10.tar.gz
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command /usr/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-qqqgbh_2/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-cwqrqsw1-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.4
    copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.4
    creating build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.4/MySQLdb
    creating build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.linux-x86_64-3.4
    gcc -pthread -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,3,10,'final',0) -D__version__=1.3.10 -I/usr/include/mysql -I/usr/include/python3.4m -c _mysql.c -o build/temp.linux-x86_64-3.4/_mysql.o
    _mysql.c: In function ‘_mysql_ConnectionObject_ping’:
    _mysql.c:1911: error: ‘MYSQL’ has no member named ‘reconnect’
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-qqqgbh_2/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-cwqrqsw1-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-qqqgbh_2/mysqlclient/
</code>```

答: Turns out it was a compatibility problem between mysqlclient and the latest version of MariaDB (10.2). I adjusted my package repo to point to older versions of MariaDB (10.0 or 10.1) and installed one of those then mysqlclient built and installed without issue.</p>

Title: mysqlclient pip failure on Linux

Body:
I'm working on a Python3.4/Django project (on CentOS 6.8x64) and am trying to install the mysqlclient driver. Despite hours of googling I can't figure out how to sort out what looks like a compile error during install.

As far as I can tell I have all the necessary library packages installed but so far no luck. Here's the output (sorry for the verbosity):

$ sudo pip3 install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.3.10.tar.gz
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command /usr/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-qqqgbh_2/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-cwqrqsw1-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.4
    copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.4
    creating build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.4/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.4/MySQLdb
    creating build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.4/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.linux-x86_64-3.4
    gcc -pthread -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,3,10,'final',0) -D__version__=1.3.10 -I/usr/include/mysql -I/usr/include/python3.4m -c _mysql.c -o build/temp.linux-x86_64-3.4/_mysql.o
    _mysql.c: In function ‘_mysql_ConnectionObject_ping’:
    _mysql.c:1911: error: ‘MYSQL’ has no member named ‘reconnect’
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-qqqgbh_2/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-cwqrqsw1-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-qqqgbh_2/mysqlclient/


问:
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 16 path $.locations[0]

code for response class

```<code>public class LocationHealth implements HealthStatusIdentifiable{

@SerializedName("health")
int health;
@SerializedName("location")
String location;
@SerializedName("company")
String company;
@SerializedName("pos")
CompanyPos companyPos;
@SerializedName("rosters")
RosterHealth rosterHelath;
@SerializedName("cafe_tabs")
CafeHealth cafeHealth;

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getCompany() {
    return company;
}

public void setCompany(String company) {
    this.company = company;
}

public CompanyPos getCompanyPos() {
    return companyPos;
}

public void setCompanyPos(CompanyPos companyPos) {
    this.companyPos = companyPos;
}

public RosterHealth getRosterHelath() {
    return rosterHelath;
}

public void setRosterHelath(RosterHealth rosterHelath) {
    this.rosterHelath = rosterHelath;
}

public CafeHealth getCafeHealth() {
    return cafeHealth;
}

public void setCafeHealth(CafeHealth cafeHealth) {
    this.cafeHealth = cafeHealth;
}

@Override
public String toString() {
    return location+" : "+company+" : "+health;
}

@Override
public int getHealthStatus() {
    if(health==100){
        return GOOD;
    }else if(health>50){
        return WARN;
    }else
        return ALERT;
}
</code>```

}

/CompanyPos.java/

```<code> public class CompanyPos implements HealthStatusIdentifiable{

@SerializedName("inactive")
int inactive;
@SerializedName("active")
int active;
@SerializedName("name")
String name;
@SerializedName("health")
int health;

public int getTotal(){
    return inactive+active;
}

public int getInactive() {
    return inactive;
}

public void setInactive(int inactive) {
    this.inactive = inactive;
}

public int getActive() {
    return active;
}

public void setActive(int active) {
    this.active = active;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

@Override
public int getHealthStatus() {
    if(inactive==0)
        return GOOD;
    if(inactive==1)
        return WARN;
    else
        return ALERT;
} }
</code>```

JSON FORMAT

{   "locations": [
      {
        "pos": {
          "inactive": 7,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "FS-Cafeteria-Bangalore",
        "company": "FirstSource",
        "location_id": 1,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Cafe-Hyderabad",
        "company": "General Electric",
        "location_id": 19,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Shankar Narayan Building",
        "company": "Infinera",
        "location_id": 84,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco Space",
        "company": "Northern Trust",
        "location_id": 82,
        "company_id": 70
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "SMS",
        "company": "Genpact",
        "location_id": 79,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Surya Tech Park",
        "company": "Genpact",
        "location_id": 78,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Pritech",
        "company": "Genpact",
        "location_id": 77,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.G-ETAMIN -CSR",
        "company": "Qualcomm",
        "location_id": 70,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Aneja Towers",
        "company": "FirstSource",
        "location_id": 69,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TECCI Park",
        "company": "FirstSource",
        "location_id": 68,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ETA PARK-Chennai",
        "company": "FirstSource",
        "location_id": 67,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Prestige Solitaire Building",
        "company": "Infinera",
        "location_id": 44,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco World",
        "company": "Epicor",
        "location_id": 2,
        "company_id": 3
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TVH Agnitio Park",
        "company": "Qualcomm",
        "location_id": 20,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-BTP",
        "company": "ABB",
        "location_id": 8,
        "company_id": 7
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "GE-Bengaluru",
        "company": "General Electric",
        "location_id": 5,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.E",
        "company": "Qualcomm",
        "location_id": 15,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.D",
        "company": "Qualcomm",
        "location_id": 14,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.C",
        "company": "Qualcomm",
        "location_id": 13,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "INDIA. N & T",
        "company": "Qualcomm",
        "location_id": 12,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.B",
        "company": "Qualcomm",
        "location_id": 11,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO. H- Vector",
        "company": "Qualcomm",
        "location_id": 10,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Britannia Cafe",
        "company": "Britannia",
        "location_id": 17,
        "company_id": 8
      },
      {
        "pos": {
          "inactive": 4,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Ecoworld",
        "company": "British Telecom",
        "location_id": 7,
        "company_id": 6
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Pritech",
        "company": "British Telecom",
        "location_id": 6,
        "company_id": 6
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-HEBBAL",
        "company": "ABB",
        "location_id": 85,
        "company_id": 7
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Corporate",
        "company": "Corporate",
        "location_id": 4,
        "company_id": 4
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Paladion Cafe",
        "company": "Paladion",
        "location_id": 18,
        "company_id": 9
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Mystifly",
        "company": "Mystifly",
        "location_id": 81,
        "company_id": 68
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Whitefield",
        "company": "Technicolor",
        "location_id": 80,
        "company_id": 69
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TEK MEDOWS-Chennai",
        "company": "FirstSource",
        "location_id": 66,
        "company_id": 1
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Bagmane Tech Park",
        "company": "Qualcomm",
        "location_id": 86,
        "company_id": 2
      }   ] }

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 16 path $.locations[0]

答:
Using the given JSON data, this is the proper structure of POJO Classes.

Don't forget to add package name in all classes.

```<code>import java.util.List;

public class Overall {

    private List<Location> locations = null;

    public List<Location> getLocations() {
        return locations;
    }

    public void setLocations(List<Location> locations) {
        this.locations = locations;
    }
}
</code>```

```<code>public class Location {

    private Pos pos;
    private Integer health;
    private Rosters rosters;
    private CafeTabs cafeTabs;
    private String location;
    private String company;
    private Integer locationId;
    private Integer companyId;

    public Pos getPos() {
        return pos;
    }

    public void setPos(Pos pos) {
        this.pos = pos;
    }

    public Integer getHealth() {
        return health;
    }

    public void setHealth(Integer health) {
        this.health = health;
    }

    public Rosters getRosters() {
        return rosters;
    }

    public void setRosters(Rosters rosters) {
        this.rosters = rosters;
    }

    public CafeTabs getCafeTabs() {
        return cafeTabs;
    }

    public void setCafeTabs(CafeTabs cafeTabs) {
        this.cafeTabs = cafeTabs;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public Integer getLocationId() {
        return locationId;
    }

    public void setLocationId(Integer locationId) {
        this.locationId = locationId;
    }

    public Integer getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }

}
</code>```

```<code>public class Pos {

    private Integer inactive;
    private Integer active;

    public Integer getInactive() {
        return inactive;
    }

    public void setInactive(Integer inactive) {
        this.inactive = inactive;
    }

    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }

}
</code>```

```<code>public class Rosters {

    private Integer attended;
    private Integer rosters;

    public Integer getAttended() {
        return attended;
    }

    public void setAttended(Integer attended) {
        this.attended = attended;
    }

    public Integer getRosters() {
        return rosters;
    }

    public void setRosters(Integer rosters) {
        this.rosters = rosters;
    }

}
</code>```

```<code>public class CafeTabs {

    private Integer liveTabs;
    private Integer totalCafeTabs;

    public Integer getLiveTabs() {
        return liveTabs;
    }

    public void setLiveTabs(Integer liveTabs) {
        this.liveTabs = liveTabs;
    }

    public Integer getTotalCafeTabs() {
        return totalCafeTabs;
    }

    public void setTotalCafeTabs(Integer totalCafeTabs) {
        this.totalCafeTabs = totalCafeTabs;
    }

}
</code>```

Body:
code for response class

public class LocationHealth implements HealthStatusIdentifiable{

@SerializedName("health")
int health;
@SerializedName("location")
String location;
@SerializedName("company")
String company;
@SerializedName("pos")
CompanyPos companyPos;
@SerializedName("rosters")
RosterHealth rosterHelath;
@SerializedName("cafe_tabs")
CafeHealth cafeHealth;

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getCompany() {
    return company;
}

public void setCompany(String company) {
    this.company = company;
}

public CompanyPos getCompanyPos() {
    return companyPos;
}

public void setCompanyPos(CompanyPos companyPos) {
    this.companyPos = companyPos;
}

public RosterHealth getRosterHelath() {
    return rosterHelath;
}

public void setRosterHelath(RosterHealth rosterHelath) {
    this.rosterHelath = rosterHelath;
}

public CafeHealth getCafeHealth() {
    return cafeHealth;
}

public void setCafeHealth(CafeHealth cafeHealth) {
    this.cafeHealth = cafeHealth;
}

@Override
public String toString() {
    return location+" : "+company+" : "+health;
}

@Override
public int getHealthStatus() {
    if(health==100){
        return GOOD;
    }else if(health>50){
        return WARN;
    }else
        return ALERT;
}

}

/CompanyPos.java/

 public class CompanyPos implements HealthStatusIdentifiable{

@SerializedName("inactive")
int inactive;
@SerializedName("active")
int active;
@SerializedName("name")
String name;
@SerializedName("health")
int health;

public int getTotal(){
    return inactive+active;
}

public int getInactive() {
    return inactive;
}

public void setInactive(int inactive) {
    this.inactive = inactive;
}

public int getActive() {
    return active;
}

public void setActive(int active) {
    this.active = active;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

@Override
public int getHealthStatus() {
    if(inactive==0)
        return GOOD;
    if(inactive==1)
        return WARN;
    else
        return ALERT;
} }

JSON FORMAT

{   "locations": [
      {
        "pos": {
          "inactive": 7,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "FS-Cafeteria-Bangalore",
        "company": "FirstSource",
        "location_id": 1,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Cafe-Hyderabad",
        "company": "General Electric",
        "location_id": 19,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Shankar Narayan Building",
        "company": "Infinera",
        "location_id": 84,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco Space",
        "company": "Northern Trust",
        "location_id": 82,
        "company_id": 70
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "SMS",
        "company": "Genpact",
        "location_id": 79,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Surya Tech Park",
        "company": "Genpact",
        "location_id": 78,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Pritech",
        "company": "Genpact",
        "location_id": 77,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.G-ETAMIN -CSR",
        "company": "Qualcomm",
        "location_id": 70,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Aneja Towers",
        "company": "FirstSource",
        "location_id": 69,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TECCI Park",
        "company": "FirstSource",
        "location_id": 68,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ETA PARK-Chennai",
        "company": "FirstSource",
        "location_id": 67,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Prestige Solitaire Building",
        "company": "Infinera",
        "location_id": 44,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco World",
        "company": "Epicor",
        "location_id": 2,
        "company_id": 3
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TVH Agnitio Park",
        "company": "Qualcomm",
        "location_id": 20,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-BTP",
        "company": "ABB",
        "location_id": 8,
        "company_id": 7
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "GE-Bengaluru",
        "company": "General Electric",
        "location_id": 5,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.E",
        "company": "Qualcomm",
        "location_id": 15,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.D",
        "company": "Qualcomm",
        "location_id": 14,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.C",
        "company": "Qualcomm",
        "location_id": 13,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "INDIA. N & T",
        "company": "Qualcomm",
        "location_id": 12,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.B",
        "company": "Qualcomm",
        "location_id": 11,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO. H- Vector",
        "company": "Qualcomm",
        "location_id": 10,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Britannia Cafe",
        "company": "Britannia",
        "location_id": 17,
        "company_id": 8
      },
      {
        "pos": {
          "inactive": 4,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Ecoworld",
        "company": "British Telecom",
        "location_id": 7,
        "company_id": 6
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Pritech",
        "company": "British Telecom",
        "location_id": 6,
        "company_id": 6
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-HEBBAL",
        "company": "ABB",
        "location_id": 85,
        "company_id": 7
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Corporate",
        "company": "Corporate",
        "location_id": 4,
        "company_id": 4
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Paladion Cafe",
        "company": "Paladion",
        "location_id": 18,
        "company_id": 9
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Mystifly",
        "company": "Mystifly",
        "location_id": 81,
        "company_id": 68
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Whitefield",
        "company": "Technicolor",
        "location_id": 80,
        "company_id": 69
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TEK MEDOWS-Chennai",
        "company": "FirstSource",
        "location_id": 66,
        "company_id": 1
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Bagmane Tech Park",
        "company": "Qualcomm",
        "location_id": 86,
        "company_id": 2
      }   ] }

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 16 path $.locations[0]

Body:
Using the given JSON data, this is the proper structure of POJO Classes.

Don't forget to add package name in all classes.

import java.util.List;

public class Overall {

    private List<Location> locations = null;

    public List<Location> getLocations() {
        return locations;
    }

    public void setLocations(List<Location> locations) {
        this.locations = locations;
    }
}

public class Location {

    private Pos pos;
    private Integer health;
    private Rosters rosters;
    private CafeTabs cafeTabs;
    private String location;
    private String company;
    private Integer locationId;
    private Integer companyId;

    public Pos getPos() {
        return pos;
    }

    public void setPos(Pos pos) {
        this.pos = pos;
    }

    public Integer getHealth() {
        return health;
    }

    public void setHealth(Integer health) {
        this.health = health;
    }

    public Rosters getRosters() {
        return rosters;
    }

    public void setRosters(Rosters rosters) {
        this.rosters = rosters;
    }

    public CafeTabs getCafeTabs() {
        return cafeTabs;
    }

    public void setCafeTabs(CafeTabs cafeTabs) {
        this.cafeTabs = cafeTabs;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public Integer getLocationId() {
        return locationId;
    }

    public void setLocationId(Integer locationId) {
        this.locationId = locationId;
    }

    public Integer getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }

}

public class Pos {

    private Integer inactive;
    private Integer active;

    public Integer getInactive() {
        return inactive;
    }

    public void setInactive(Integer inactive) {
        this.inactive = inactive;
    }

    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }

}

public class Rosters {

    private Integer attended;
    private Integer rosters;

    public Integer getAttended() {
        return attended;
    }

    public void setAttended(Integer attended) {
        this.attended = attended;
    }

    public Integer getRosters() {
        return rosters;
    }

    public void setRosters(Integer rosters) {
        this.rosters = rosters;
    }

}

public class CafeTabs {

    private Integer liveTabs;
    private Integer totalCafeTabs;

    public Integer getLiveTabs() {
        return liveTabs;
    }

    public void setLiveTabs(Integer liveTabs) {
        this.liveTabs = liveTabs;
    }

    public Integer getTotalCafeTabs() {
        return totalCafeTabs;
    }

    public void setTotalCafeTabs(Integer totalCafeTabs) {
        this.totalCafeTabs = totalCafeTabs;
    }

}


问:
translate typescript to javascript
I need this code is in Javascript

I am not specialized in language typescript.

this is code for play music and record audio in mobile with nativescript

do not think GitHub quickly give answer

in github issues

```<code>import { TNSPlayer } from 'nativescript-audio';

export class YourClass {
    private _player: TNSPlayer;

    constructor() {
        this._player = new TNSPlayer();
        this._player.initFromFile({
            audioFile: '~/audio/song.mp3', // ~ = app directory
            loop: false,
            completeCallback: this._trackComplete.bind(this),
            errorCallback: this._trackError.bind(this)
        }).then(() => {

            this._player.getAudioTrackDuration().then((duration) => {
                // iOS: duration is in seconds
                // Android: duration is in milliseconds
                console.log(`song duration:`, duration);
            });
        });
    }

    public togglePlay() {
        if (this._player.isAudioPlaying()) {
            this._player.pause();
        } else {
            this._player.play();
        }
    }

    private _trackComplete(args: any) {
        console.log('reference back to player:', args.player);

        // iOS only: flag indicating if completed succesfully
        console.log('whether song play completed successfully:', args.flag);
    }

    private _trackError(args: any) {
        console.log('reference back to player:', args.player);
        console.log('the error:', args.error);

        // Android only: extra detail on error
        console.log('extra info on the error:', args.extra);
    }
}
</code>```

答:
You can use typescript playground for instant conversion from typescript to javascript.
Here is the url http://www.typescriptlang.org/play

Or You can install typescript compiler in your machine and run tsc .

Title: translate typescript to javascript

Body:
I need this code is in Javascript

I am not specialized in language typescript.

this is code for play music and record audio in mobile with nativescript

do not think GitHub quickly give answer

in github issues

import { TNSPlayer } from 'nativescript-audio';

export class YourClass {
    private _player: TNSPlayer;

    constructor() {
        this._player = new TNSPlayer();
        this._player.initFromFile({
            audioFile: '~/audio/song.mp3', // ~ = app directory
            loop: false,
            completeCallback: this._trackComplete.bind(this),
            errorCallback: this._trackError.bind(this)
        }).then(() => {

            this._player.getAudioTrackDuration().then((duration) => {
                // iOS: duration is in seconds
                // Android: duration is in milliseconds
                console.log(`song duration:`, duration);
            });
        });
    }

    public togglePlay() {
        if (this._player.isAudioPlaying()) {
            this._player.pause();
        } else {
            this._player.play();
        }
    }

    private _trackComplete(args: any) {
        console.log('reference back to player:', args.player);

        // iOS only: flag indicating if completed succesfully
        console.log('whether song play completed successfully:', args.flag);
    }

    private _trackError(args: any) {
        console.log('reference back to player:', args.player);
        console.log('the error:', args.error);

        // Android only: extra detail on error
        console.log('extra info on the error:', args.extra);
    }
}


问:
Reuse already instanciated objects parsed by Gson
I am using the gson library to parse a json object that has the following structure:

```<code>{
    "data" : [
        {
            "id" : 1,
            "type" : "student",
            "name" : "Student 1",
            "subjects" : [
                {
                    "id": 1,
                    "type" : "subject"
                }
            ]
        },
        {
            "id" : 2,
            "type" : "student",
            "name" : "Student 2",
            "subjects" : [
                {
                    "id": 1,
                    "type" : "subject",
                    "name" : "Math"
                }
            ]
        },
        {
            "id" : 3,
            "type" : "office",
            "name" : "student 3",
            "subjects" : [
                {
                    "id": 1,
                    "type" : "subject",
                    "name" : "History"
                },
                {
                    "id": 2,
                    "type" : "subject",
                    "name" : "History"
                }
            ]
        }
    ]
}
</code>```

This is a very basic example, there are 3 students who assist to 0 or many classes. As you can see 2 or more students can have the same reference to a specific subject, but when I parse the object, Student 1 will have an object for subject 1, Student 2 will have a different object but with same information as the one for Student 1, so my question basically is, is there a way to reuse the already created objects? In this case is not a problem to have multiple references, but say you have a lot more objects, this will turn into a memory problem.

In theory what comes to mind is that before creating an object instance, there should be some kind of pool, so I look using the id and type, if I find the object I return it, otherwise I let the parser to create the instance for me. There is the JsonDeserializer interface, but there is a known problem for using the JSON deserialization context, also I cannot just do a new Gson() inside of it because my main Gson has some deserializers and strategies that I want to reuse. I could just recreate the gson but I don't think that's ideal, there should be a better way of doing it.

Also, I already have a TypeAdapter that initially preprocess the JSON that comes from the server, basically it removes some attributes and add some others resulting in the example, but I could not make it check for each individual object like the JsonDeserializer would do

I will appreciate any help or thoughts on this.

答:
One way you can do is by flattening the structure. i.e. you can skip sending entire subject objects in student object.

For example, a student object:

```<code>"student": [
    {
        id: "1234567890",
        name: "Bhalchandra Wadekar",
        subject: [
            "CS4040",
            "CS4010"
        ]
    }
]
</code>```

where, CS4040 and CS4010 are identifiers of individual subjects.

The subject objects:

```<code>"subject": [
    {
        id: "CS4040",
        name: "Mobile Design and Development"
    },
    {
        id: "CS4010",
        name: "Major Project"
    }
]
</code>```

The benefits of using this method are:

Reducing the amount of data you are receiving on individual request leading to faster response time.

A single object in memory for each subject. Therefore, you will be creating and using one object no matter how many students assist that subject.

Body:
I am using the gson library to parse a json object that has the following structure:

{
    "data" : [
        {
            "id" : 1,
            "type" : "student",
            "name" : "Student 1",
            "subjects" : [
                {
                    "id": 1,
                    "type" : "subject"
                }
            ]
        },
        {
            "id" : 2,
            "type" : "student",
            "name" : "Student 2",
            "subjects" : [
                {
                    "id": 1,
                    "type" : "subject",
                    "name" : "Math"
                }
            ]
        },
        {
            "id" : 3,
            "type" : "office",
            "name" : "student 3",
            "subjects" : [
                {
                    "id": 1,
                    "type" : "subject",
                    "name" : "History"
                },
                {
                    "id": 2,
                    "type" : "subject",
                    "name" : "History"
                }
            ]
        }
    ]
}

This is a very basic example, there are 3 students who assist to 0 or many classes. As you can see 2 or more students can have the same reference to a specific subject, but when I parse the object, Student 1 will have an object for subject 1, Student 2 will have a different object but with same information as the one for Student 1, so my question basically is, is there a way to reuse the already created objects? In this case is not a problem to have multiple references, but say you have a lot more objects, this will turn into a memory problem.

In theory what comes to mind is that before creating an object instance, there should be some kind of pool, so I look using the id and type, if I find the object I return it, otherwise I let the parser to create the instance for me. There is the JsonDeserializer interface, but there is a known problem for using the JSON deserialization context, also I cannot just do a new Gson() inside of it because my main Gson has some deserializers and strategies that I want to reuse. I could just recreate the gson but I don't think that's ideal, there should be a better way of doing it.

Also, I already have a TypeAdapter that initially preprocess the JSON that comes from the server, basically it removes some attributes and add some others resulting in the example, but I could not make it check for each individual object like the JsonDeserializer would do

I will appreciate any help or thoughts on this.

Body:
One way you can do is by flattening the structure. i.e. you can skip sending entire subject objects in student object.

For example, a student object:

"student": [
    {
        id: "1234567890",
        name: "Bhalchandra Wadekar",
        subject: [
            "CS4040",
            "CS4010"
        ]
    }
]

where, CS4040 and CS4010 are identifiers of individual subjects.

The subject objects:

"subject": [
    {
        id: "CS4040",
        name: "Mobile Design and Development"
    },
    {
        id: "CS4010",
        name: "Major Project"
    }
]

The benefits of using this method are:

Reducing the amount of data you are receiving on individual request leading to faster response time.

A single object in memory for each subject. Therefore, you will be creating and using one object no matter how many students assist that subject.


问:
Laravel: TokenMismatchException after uploading large video file
I already set the php.ini (nginx)

upload_max_size = 100MB

post_max_size = 200mb

I'm trying to upload a 15mb video to my program. At first i got this error.

TokenMismatchException in VerifyCsrfToken.php line 68:

So I added the '/lesson/store' in the exception from VerifyCSRFToken middleware.

Here's the shortcode highlighting the video input:

```<code><div class="form-group">
        <label class="control-label col-sm-2" for="video">Video:</label>
        <div class="col-sm-10">

            <input class="form-control" type="file" accept="video/*" name="video" id="video" required>

        </div>
     </div>
</code>```

And here's the whole form code:

```<code><form method="{{$method}}" action="{{url('')}}{{$action}}" class="form-horizontal"  runat="server"  enctype="multipart/form-data">

{{ csrf_field() }}

    <div class="form-group">
        <label class="control-label col-sm-2" for="title">Title:</label>
        <div class="col-sm-10">
          <input type="text" class="form-control" id="title" name="title"  placeholder="Enter title" required value="{{ $lesson->title or '' }}">
        </div>
     </div>
     <div class="form-group">
        <label class="control-label col-sm-2" for="description">Description:</label>
        <div class="col-sm-10">
            <textarea class="form-control" id="description" name="description">{{ $lesson->description or '' }}</textarea>
        </div>
     </div>
     <div class="form-group">
        <label class="control-label col-sm-2" for="episode">Episode:</label>
        <div class="col-sm-10">
          <input type="number" class="form-control" id="episode" name="episode"  placeholder="" required value="{{ $lesson->episode or '' }}">
        </div>
     </div>
     <div class="form-group">
        <label class="control-label col-sm-2" for="video">Video:</label>
        <div class="col-sm-10">

           @if( !empty( $lesson->video ) )
           <input class="form-control" type="file" accept="video/*" name="video" id="video">
           <div class="video">
            <video width="100%" style="height:200px" controls>
              <source src="{{url('uploads/courses/' . $lesson['course_id']. '/' . $lesson['video'])}}" type="video/mp4">
            Your browser does not support the video tag.
            </video>
           </div>
           @else
            <input class="form-control" type="file" accept="video/*" name="video" id="video" required>
           @endif
        </div>
     </div>

     <div class="form-group">
        <label class="col-sm-2"></label>
        <div class="col-sm-10">
            <input type="submit" value="{{$button}}" class="btn btn-success">
            <a href="{{ url()->previous() }}" class="btn btn-danger">Cancel</a>
        </div>
     </div>

</form>
</code>```

Then I tried to upload again and I received a validation errors says:

The video field is required

Because I have this in my code:

```<code> $this->validate($request, [
   'video' => 'required|mimetypes:video/avi,video/mpeg,video/quicktime,video/mp4|max:40000'
      ]);
</code>```

I really don't know how to fix this thing.

Update: I uploaded 5mb video and I got this validation error:

The video failed to upload.

答:
Add a hidden input field in your for verify csrf token as

```<code><input type="text" name="_token" hidden/>
</code>```

or

```<code>{{ csrf_field() }}
</code>```

Body:
I already set the php.ini (nginx)

upload_max_size = 100MB

post_max_size = 200mb

I'm trying to upload a 15mb video to my program. At first i got this error.

TokenMismatchException in VerifyCsrfToken.php line 68:

So I added the '/lesson/store' in the exception from VerifyCSRFToken middleware.

Here's the shortcode highlighting the video input:

        Video:

            <input class="form-control" type="file" accept="video/*" name="video" id="video" required>

And here's the whole form code:

<form method="{{$method}}" action="{{url('')}}{{$action}}" class="form-horizontal"  runat="server"  enctype="multipart/form-data">

{{ csrf_field() }}

        Title:

          <input type="text" class="form-control" id="title" name="title"  placeholder="Enter title" required value="{{ $lesson->title or '' }}">

        Description:

            <textarea class="form-control" id="description" name="description">{{ $lesson->description or '' }}</textarea>

        Episode:

          <input type="number" class="form-control" id="episode" name="episode"  placeholder="" required value="{{ $lesson->episode or '' }}">

        Video:

           @if( !empty( $lesson->video ) )
           <input class="form-control" type="file" accept="video/*" name="video" id="video">

            <video width="100%" style="height:200px" controls>
              <source src="{{url('uploads/courses/' . $lesson['course_id']. '/' . $lesson['video'])}}" type="video/mp4">
            Your browser does not support the video tag.
            </video>

           @else
            <input class="form-control" type="file" accept="video/*" name="video" id="video" required>
           @endif

            <input type="submit" value="{{$button}}" class="btn btn-success">
            previous() }}" class="btn btn-danger">Cancel

</form>

Then I tried to upload again and I received a validation errors says:

The video field is required

Because I have this in my code:

 $this->validate($request, [
   'video' => 'required|mimetypes:video/avi,video/mpeg,video/quicktime,video/mp4|max:40000'
      ]);

I really don't know how to fix this thing.

Update: I uploaded 5mb video and I got this validation error:

The video failed to upload.

Body:
Add a hidden input field in your for verify csrf token as

<input type="text" name="_token" hidden/>

or

{{ csrf_field() }}


问:
JavaScript: Selenium clicks login button before I input password occasionally
I want to log in twitter using selenium webdriver, this is my code:

```<code>var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder().
    forBrowser('chrome').
    build();

driver.get('https://twitter.com/login')
driver.findElement(By.className('js-username-field')).sendKeys('my email')
driver.findElement(By.className('js-password-field')).sendKeys('my pwd');
driver.findElement(By.css('button[type="submit"]')).click();
</code>```

When I test my code, occasionally something wrong happened:

Selenium input email;

Selenium click log in button;

After my code run complete, the password field remains empty. This lead to login failure.

答:
Try with adding a wait before the click method, as:

```<code>driver.wait(until.elementLocated(By.css("button[type='submit']")));
</code>```

This should solve it.

Body:
I want to log in twitter using selenium webdriver, this is my code:

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder().
    forBrowser('chrome').
    build();

driver.get('https://twitter.com/login')
driver.findElement(By.className('js-username-field')).sendKeys('my email')
driver.findElement(By.className('js-password-field')).sendKeys('my pwd');
driver.findElement(By.css('button[type="submit"]')).click();

When I test my code, occasionally something wrong happened:

Selenium input email;

Selenium click log in button;

After my code run complete, the password field remains empty. This lead to login failure.

Body:
Try with adding a wait before the click method, as:

driver.wait(until.elementLocated(By.css("button[type='submit']")));

This should solve it.


答:
Since you already have the files and can't change them, one way would be to use a utility that converts them to a format your Ruby understands, like JSON. If you have the JSON module in your Perl distribution (you probably have a system Perl), you also have the json_pp utility.

So you could shell out to that, and let it convert your Perl data structure (Data::Dumper is nothing else than that) to JSON:

$ cat data.pl | json_pp -f eval -t json > data.json
```

<p>and then use Ruby to convert that JSON to a Ruby data structure:</p>

```require 'json'
JSON.parse(File.read('data.json'))
#=> {
#     "localtime" => "Tue Jun  6 11:48:20 2017",
#     "ifHCOutOctets" => "74372744112",
#     "ifHCInOctets" => "13199010183",
#     # ...
#   }
```

Title: Parse Perl Data::Dumper output with ruby

Body:
I've a directory full of state files which were printed by Perl's Data::Dumper. The content looks like this:

$VAR1 = {
          'localtime' => 'Tue Jun  6 11:48:20 2017',
          'lookback_history' => {
                                  'ifHCOutOctets' => {
                                                       '1496742350.42394' => '74365529910',
                                                       '1496742455.72943' => '74366309899',
                                                       '1496742446.38562' => '74366309114',
                                                       '1496742500.42388' => '74372744112'
                                                     },
                                  'ifHCInOctets' => {
                                                      '1496742350.42394' => '13198364950',
                                                      '1496742455.72943' => '13198718163',
                                                      '1496742446.38562' => '13198705712',
                                                      '1496742500.42388' => '13199010183'
                                                    }
                                },
          'timestamp' => '1496742500.42388',
          'ifHCOutOctets' => '74372744112',
          'ifHCInOctets' => '13199010183'
        };

I've to analyze if the files contain unreproducible information.

Is there a way in ruby to parse those perl dumps?

Body:
Since you already have the files and can't change them, one way would be to use a utility that converts them to a format your Ruby understands, like JSON. If you have the JSON module in your Perl distribution (you probably have a system Perl), you also have the json_pp utility.

So you could shell out to that, and let it convert your Perl data structure (Data::Dumper is nothing else than that) to JSON:

$ cat data.pl | json_pp -f eval -t json > data.json

and then use Ruby to convert that JSON to a Ruby data structure:

require 'json'
JSON.parse(File.read('data.json'))
#=> {
#     "localtime" => "Tue Jun  6 11:48:20 2017",
#     "ifHCOutOctets" => "74372744112",
#     "ifHCInOctets" => "13199010183",
#     # ...
#   }


问:
How to show only date from DataGridView to label
I am working on C# and sql server. I saved date using DateTimePicker to sql. Now I am using DataGridView to show record then by selecting a row that data is shown on labels. Problem is I want to show only date but through the following method time is also coming along.

```<code> private void datagridpatient_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        lblgridpbirthday.Text = row.Cells["Birthday"].Value.ToString();
    }
</code>```

How to show only date?

答:
You have two choices:

```<code> blgridpbirthday.Text = Convert.ToDateTime(row.Cells["Birthday"].Value).ToShortDateString();
</code>```

or

```<code>lblgridpbirthday.Text = Convert.ToDateTime(row.Cells["Birthday"].Value).ToString("YourDateFormatHere");
</code>```

Body:
I am working on C# and sql server. I saved date using DateTimePicker to sql. Now I am using DataGridView to show record then by selecting a row that data is shown on labels. Problem is I want to show only date but through the following method time is also coming along.

 private void datagridpatient_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        lblgridpbirthday.Text = row.Cells["Birthday"].Value.ToString();
    }

How to show only date?

Body:
You have two choices:

 blgridpbirthday.Text = Convert.ToDateTime(row.Cells["Birthday"].Value).ToShortDateString();

or

lblgridpbirthday.Text = Convert.ToDateTime(row.Cells["Birthday"].Value).ToString("YourDateFormatHere");


问:
How to refresh a GridView?
I have a GridView which is pretty similar to the Google tutorial, except that I want to add the ImageViews on runtime (via a subactivity). The results are okay, but the layout of the View is messed up: The GridView doesn't fill the content of its parent, what do I have to do to design it properly?

Here the code of adding the children:

```<code>public void initializeWorkbench(GridView gv, Vector<String> items) {
        Prototype.workbench.setDimension(screenWidth, divider.height()+workbenchArea.height());
        Prototype.workbench.activateWorkbench();
        // this measures the workbench correctly
        Log.d(Prototype.TAG, "workbench width: "+Prototype.workbench.getMeasuredWidth());
        // 320
        Log.d(Prototype.TAG, "workbench height: "+Prototype.workbench.getMeasuredHeight());
        // 30
        ImageAdapter imgAdapter = new ImageAdapter(this.getContext(), items);
        gv.setAdapter(imgAdapter);
        gv.measure(screenWidth, screenHeight);
        gv.requestLayout();
        gv.forceLayout();
        Log.d(Prototype.TAG, "gv width: "+gv.getMeasuredWidth());
        // 22
        Log.d(Prototype.TAG, "gv height: "+gv.getMeasuredHeight());
        // 119
        Prototype.workbench.setDimension(screenWidth, divider.height()+workbenchArea.height());
    }
}
</code>```

activateWorkbench, setDimension and measure in the workbench (LinearLayout above the GridView):

```<code>public void activateWorkbench() {
    if(this.equals(Prototype.workbench)) {
        this.setOrientation(VERTICAL);
        show = true;
        measure();
    }
}

public void setDimension(int w, int h) {
    width = w;
    height = h;
    this.setLayoutParams(new LinearLayout.LayoutParams(width, height));
    this.invalidate();
}

private void measure() {
    if (this.getOrientation() == LinearLayout.VERTICAL) {
        int h = 0;
        int w = 0;
        this.measureChildren(0, 0);
        for (int i = 0; i < this.getChildCount(); i++) {
            View v = this.getChildAt(i);
            h += v.getMeasuredHeight();
            w = (w < v.getMeasuredWidth()) ? v.getMeasuredWidth() : w;
        }
        if (this.equals(Prototype.tagarea))
            height = (h < height) ? height : h;
        if (this.equals(Prototype.tagarea))
            width = (w < width) ? width : w;
    }
    this.setMeasuredDimension(width, height);
}
</code>```

The ImageAdapter constructor:

```<code>public ImageAdapter(Context c, Vector<String> items) {
    mContext = c;

    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // Something else is wrong. It may be one of many other states, but
        // all we need
        // to know is we can neither read nor write
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }

    if (mExternalStorageAvailable && mExternalStorageWriteable) {
        for (String item : items) {
            File f = new File(item);
            if (f.exists()) {
                try {
                    FileInputStream fis = new FileInputStream(f);
                    Bitmap b = BitmapFactory.decodeStream(fis);
                    bitmaps.add(b);
                    files.add(f);
                } catch (FileNotFoundException e) {
                    Log.e(Prototype.TAG, "", e);
                }
            }
        }
    }
}
</code>```

And the xml layout:

```<code><LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
                android:orientation="vertical"
                android:gravity="bottom"

                android:paddingLeft="0px"
                android:paddingTop="0px"
                android:paddingRight="0px">

    <com.unimelb.pt3.ui.TransparentPanel
            android:id="@+id/workbench"
            android:layout_width="fill_parent"
            android:layout_height="10px"
            android:paddingTop="0px"
            android:paddingLeft="0px"
            android:paddingBottom="0px"
            android:paddingRight="0px">

        <GridView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/gridview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:columnWidth="90dp"
            android:numColumns="auto_fit"
            android:verticalSpacing="10dp"
            android:horizontalSpacing="10dp"
            android:stretchMode="columnWidth"
            android:gravity="center" />

    </com.unimelb.pt3.ui.TransparentPanel>

</LinearLayout>
</code>```

答:
You are placing the GridView inside com.unimelb.pt3.ui.TransparentPanel which is 10px tall.

You shouldn't use px, you should use dp.

Change com.unimelb.pt3.ui.TransparentPanel's android:layout_height="10px" to android:layout_height="fill_parent"

ContentLicense: CC BY-SA 2.5

Title: How to refresh a GridView?

Body:
I have a GridView which is pretty similar to the Google tutorial, except that I want to add the ImageViews on runtime (via a subactivity). The results are okay, but the layout of the View is messed up: The GridView doesn't fill the content of its parent, what do I have to do to design it properly?

Here the code of adding the children:

public void initializeWorkbench(GridView gv, Vector<String> items) {
        Prototype.workbench.setDimension(screenWidth, divider.height()+workbenchArea.height());
        Prototype.workbench.activateWorkbench();
        // this measures the workbench correctly
        Log.d(Prototype.TAG, "workbench width: "+Prototype.workbench.getMeasuredWidth());
        // 320
        Log.d(Prototype.TAG, "workbench height: "+Prototype.workbench.getMeasuredHeight());
        // 30
        ImageAdapter imgAdapter = new ImageAdapter(this.getContext(), items);
        gv.setAdapter(imgAdapter);
        gv.measure(screenWidth, screenHeight);
        gv.requestLayout();
        gv.forceLayout();
        Log.d(Prototype.TAG, "gv width: "+gv.getMeasuredWidth());
        // 22
        Log.d(Prototype.TAG, "gv height: "+gv.getMeasuredHeight());
        // 119
        Prototype.workbench.setDimension(screenWidth, divider.height()+workbenchArea.height());
    }
}

activateWorkbench, setDimension and measure in the workbench (LinearLayout above the GridView):

public void activateWorkbench() {
    if(this.equals(Prototype.workbench)) {
        this.setOrientation(VERTICAL);
        show = true;
        measure();
    }
}

public void setDimension(int w, int h) {
    width = w;
    height = h;
    this.setLayoutParams(new LinearLayout.LayoutParams(width, height));
    this.invalidate();
}

private void measure() {
    if (this.getOrientation() == LinearLayout.VERTICAL) {
        int h = 0;
        int w = 0;
        this.measureChildren(0, 0);
        for (int i = 0; i < this.getChildCount(); i++) {
            View v = this.getChildAt(i);
            h += v.getMeasuredHeight();
            w = (w < v.getMeasuredWidth()) ? v.getMeasuredWidth() : w;
        }
        if (this.equals(Prototype.tagarea))
            height = (h < height) ? height : h;
        if (this.equals(Prototype.tagarea))
            width = (w < width) ? width : w;
    }
    this.setMeasuredDimension(width, height);
}

The ImageAdapter constructor:

public ImageAdapter(Context c, Vector<String> items) {
    mContext = c;

    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // Something else is wrong. It may be one of many other states, but
        // all we need
        // to know is we can neither read nor write
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }

    if (mExternalStorageAvailable && mExternalStorageWriteable) {
        for (String item : items) {
            File f = new File(item);
            if (f.exists()) {
                try {
                    FileInputStream fis = new FileInputStream(f);
                    Bitmap b = BitmapFactory.decodeStream(fis);
                    bitmaps.add(b);
                    files.add(f);
                } catch (FileNotFoundException e) {
                    Log.e(Prototype.TAG, "", e);
                }
            }
        }
    }
}

And the xml layout:

<LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
                android:orientation="vertical"
                android:gravity="bottom"

                android:paddingLeft="0px"
                android:paddingTop="0px"
                android:paddingRight="0px">

    <com.unimelb.pt3.ui.TransparentPanel
            android:id="@+id/workbench"
            android:layout_width="fill_parent"
            android:layout_height="10px"
            android:paddingTop="0px"
            android:paddingLeft="0px"
            android:paddingBottom="0px"
            android:paddingRight="0px">

        <GridView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/gridview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:columnWidth="90dp"
            android:numColumns="auto_fit"
            android:verticalSpacing="10dp"
            android:horizontalSpacing="10dp"
            android:stretchMode="columnWidth"
            android:gravity="center" />

    </com.unimelb.pt3.ui.TransparentPanel>

</LinearLayout>


问:
What is the purpose of the dollar sign in JavaScript?
The code in question is here:

```<code>var $item = $(this).parent().parent().find('input');
</code>```

What is the purpose of the dollar sign in the variable name, why not just exclude it?

答:
Dollar sign is used in ecmascript 2015-2016 as 'template literals'.
Example:

```<code>var a = 5;
var b = 10;
console.log(`Sum is equal: ${a + b}`); // 'Sum is equlat: 15'
</code>```

Here working example:
https://es6console.com/j3lg8xeo/
Notice this sign " ` ",its not normal quotes.

U can also meet $ while working with library jQuery.

$ sign in Regular Expressions means end of line.

ContentLicense: CC BY-SA 4.0

Body:
The code in question is here:

var $item = $(this).parent().parent().find('input');

What is the purpose of the dollar sign in the variable name, why not just exclude it?

Body:
Dollar sign is used in ecmascript 2015-2016 as 'template literals'.
Example:

var a = 5;
var b = 10;
console.log(`Sum is equal: ${a + b}`); // 'Sum is equlat: 15'

Here working example:
https://es6console.com/j3lg8xeo/
Notice this sign " ` ",its not normal quotes.

U can also meet $ while working with library jQuery.

$ sign in Regular Expressions means end of line.


问:
VBA Excel Change Content of another Cell based on content of one cell
Can you help me with this. The Excel looks something like this:

I hope to automate 2 tasks:

When cells in Column C contains word "processed" => clear content in corresponding cell in column A

When cells in Column C contains word "blue" => change corresponding cell in column B to 0

I have tried Offset, Looping and other various method but can't seem to get it right. Please help.

答: Use InStr-Function to check if it contains the substring. For Further Informations look here.


问:
Open e-mail application from ionic 2
I want to open the default e-mail client from an ionic 2 app.

I read that using the url scheme 'mailto:' should work. But for some reasons in my application it only works on android but not on iOS.

```<code>mailto(email) {
  this._platform.ready().then(() => {
      open('mailto:'+email, "_system");
  });
}
</code>```

No errors are raised when the function is called but nothing happens either, whereas if I use an http URL the default browser opens as expected on both platforms.

答:
```<code> let Link="mailto:someone@example.com?subject=Hello%20again";
    window.open(Link, "_system");
</code>```

Use this, you don't need a plugin for everything.

Title: Open e-mail application from ionic 2

Body:
I want to open the default e-mail client from an ionic 2 app.

I read that using the url scheme 'mailto:' should work. But for some reasons in my application it only works on android but not on iOS.

mailto(email) {
  this._platform.ready().then(() => {
      open('mailto:'+email, "_system");
  });
}

No errors are raised when the function is called but nothing happens either, whereas if I use an http URL the default browser opens as expected on both platforms.

Body:
 let Link="mailto:someone@example.com?subject=Hello%20again";
    window.open(Link, "_system");

Use this, you don't need a plugin for everything.


问:
Failure while exporting table from Oracle XE Database
We have XE running on a docker container. When trying to export a table I got the below error

```<code>expdp test/test@XE tables=UserProfile directory=/tmp dumpfile=profile.dmp logfile=logger

ORA-39006: internal error
ORA-39213: Metadata processing is not available
</code>```

I googled a bit and found that I need to execute the below command but that failed too

```<code>execute dbms_metadata_util.load_stylesheets
ERROR at line 1:
ORA-31609: error loading file "kucolumn.xsl" from file system directory
"/u01/app/oracle/product/11.2.0/xe/rdbms/xml/xsl"
ORA-06512: at "SYS.DBMS_METADATA_UTIL", line 2397
ORA-06512: at line 1
</code>```

I traversed to the directory and found that the "xsl" directory was missing, is this directory created by default with XE installation or we require a specific setting to get the "xsl" folder?

XE was installed using the rpm - oracle-xe-11.2.0-1.0.x86_64.rpm. Any idea what could be the issue?

答:
The value you specify as directory needs to be an Oracle database directory object, not the value of a directory on your file system.</p>

```<code>create directory export_directory as '/tmp';

expdp test/test@XE tables=UserProfile directory=export_directory dumpfile=profile.dmp logfile=logger
</code>```

Body:
We have XE running on a docker container. When trying to export a table I got the below error

expdp test/test@XE tables=UserProfile directory=/tmp dumpfile=profile.dmp logfile=logger

ORA-39006: internal error
ORA-39213: Metadata processing is not available

I googled a bit and found that I need to execute the below command but that failed too

execute dbms_metadata_util.load_stylesheets
ERROR at line 1:
ORA-31609: error loading file "kucolumn.xsl" from file system directory
"/u01/app/oracle/product/11.2.0/xe/rdbms/xml/xsl"
ORA-06512: at "SYS.DBMS_METADATA_UTIL", line 2397
ORA-06512: at line 1

I traversed to the directory and found that the "xsl" directory was missing, is this directory created by default with XE installation or we require a specific setting to get the "xsl" folder?

XE was installed using the rpm - oracle-xe-11.2.0-1.0.x86_64.rpm. Any idea what could be the issue?

Body:
The value you specify as directory needs to be an Oracle database directory object, not the value of a directory on your file system.

create directory export_directory as '/tmp';

expdp test/test@XE tables=UserProfile directory=export_directory dumpfile=profile.dmp logfile=logger


问:
Symfony3.3: autowire a controller with scalar argument
The my controller contains an action with an scalar dependency $bugReportRecipient.

```<code>class DefaultController
{
    public function bugReportAction(SwiftTwigMailer $swiftTwigMailer, string $bugReportRecipient, Request $request)
    {
        // more code
    }
}
</code>```

My service definition looks like this:

```<code>AppBundle\Controller\DefaultController:
    autowire: true
    tags: ['controller.service_arguments']
</code>```

If I run the action this error is shown:

Controller "AppBundle\Controller\DefaultController::bugReportAction()" requires that you provide a value for the "$bugReportRecipient" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

How can I inject this argument? I haven't found any helpful in the symfony documentation so far.

[EDIT]:

The argument $bugReportRecipient is parameter which is defined in my parameters.yml.

答:
The value for the action comes from the same place as before - you either set a default value in the function definition, or at least have a value given by the route, which might be set like such:

```<code>* @Route("/bug-report/{bugReportRecipient}", name="bugreport",
*        defaults={"bugReportRecipient" = "username"})
</code>```

The SwiftTwigMailer is injected because of the controller.service_arguments tag in the same way as Request has been before.

Note - you can still set a variable's default value in the @Route for a variable that does not appear in the {URL} part - but it has to be set somewhere.

I've used this technique for setting different values for a variable based on the specific route that is being used.

```<code> * @Route("/",         name="homepage_menus",
 *        defaults={"hasMenus"=true, "partnerLinks"=false})
 * @Route("/partners", name="homepage_partner_footer",
 *        defaults={"hasMenus"=false,"partnerLinks"=true})
</code>```

Neither of these variables (they also have defaults already set in the function definition) can appear in the URL, but are set based on the route that is used.

If the $bugReportRecipient is a parameter, it can be set in the service definition like such:

```<code>arguments:
    $bugReportRecipient: "%kernel.environment%" # or whatever
</code>```

There does not appear to be a way to set it on the action level, and so you will have to make the controller a more formal service, and set at least this parameter on the class-level.

You may also be able to use the Expression language to do this.

```<code>services:
    AppBundle\Mailer:
        arguments: ["@=container.hasParameter('some_param') ? parameter('some_param') : 'default_value'"]
</code>```

Body:
The my controller contains an action with an scalar dependency $bugReportRecipient.

class DefaultController
{
    public function bugReportAction(SwiftTwigMailer $swiftTwigMailer, string $bugReportRecipient, Request $request)
    {
        // more code
    }
}

My service definition looks like this:

AppBundle\Controller\DefaultController:
    autowire: true
    tags: ['controller.service_arguments']

If I run the action this error is shown:

Controller "AppBundle\Controller\DefaultController::bugReportAction()" requires that you provide a value for the "$bugReportRecipient" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

How can I inject this argument? I haven't found any helpful in the symfony documentation so far.

[EDIT]:

The argument $bugReportRecipient is parameter which is defined in my parameters.yml.

Body:
The value for the action comes from the same place as before - you either set a default value in the function definition, or at least have a value given by the route, which might be set like such:

* @Route("/bug-report/{bugReportRecipient}", name="bugreport",
*        defaults={"bugReportRecipient" = "username"})

The SwiftTwigMailer is injected because of the controller.service_arguments tag in the same way as Request has been before.

Note - you can still set a variable's default value in the @Route for a variable that does not appear in the {URL} part - but it has to be set somewhere.

I've used this technique for setting different values for a variable based on the specific route that is being used.

 * @Route("/",         name="homepage_menus",
 *        defaults={"hasMenus"=true, "partnerLinks"=false})
 * @Route("/partners", name="homepage_partner_footer",
 *        defaults={"hasMenus"=false,"partnerLinks"=true})

Neither of these variables (they also have defaults already set in the function definition) can appear in the URL, but are set based on the route that is used.

If the $bugReportRecipient is a parameter, it can be set in the service definition like such:

arguments:
    $bugReportRecipient: "%kernel.environment%" # or whatever

There does not appear to be a way to set it on the action level, and so you will have to make the controller a more formal service, and set at least this parameter on the class-level.

You may also be able to use the Expression language to do this.

services:
    AppBundle\Mailer:
        arguments: ["@=container.hasParameter('some_param') ? parameter('some_param') : 'default_value'"]


问:
SQL Query (Simple)
I would like to know how could a return the number of songs registred each year based on this table:

```<code>Musics={MusicID, SingerID, Recorder, YearOfRecord}
MusicID as PK
</code>```

Thanks for the attention

答:
```<code>Select YearOfRecord, COUNT(MusicID) AS NumberOFSongs
   FROM Musics GROUP BY YearOfRecord
</code>```

Title: SQL Query (Simple)

Body:
I would like to know how could a return the number of songs registred each year based on this table:

Musics={MusicID, SingerID, Recorder, YearOfRecord}
MusicID as PK

Thanks for the attention